~onli/simdock/master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 *   Copyright 2007 Simone Della Longa <simonedll@yahoo.it>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#include "background.h"

using namespace std;

//get the currently used background 
wxBitmap* getRootWallpaper()
{
    wxBitmap* backImage = new wxBitmap();
    WnckScreen *screen = wnck_screen_get_default ();

    Pixmap pm = wnck_screen_get_background_pixmap(screen);
    int i = 0;
    while(i < 5)
    {
        if (pm != None) {
            break;
        }
        wxMilliSleep(1000);
        pm  = wnck_screen_get_background_pixmap(screen);
        i++;
    }
    
    if (pm != None) {
        backImage->SetPixmap(
                            gdk_pixmap_foreign_new(
                                pm
                                )
                            );
    } else {
        wxSize sz = wxGetDisplaySize();
        backImage = new wxBitmap (sz.GetWidth(), sz.GetHeight());
        wxMemoryDC dc;
        dc.SelectObject(*backImage);
        dc.SetBackground(*wxTRANSPARENT_BRUSH);
        dc.Clear();
        dc.SelectObject(*backImage);
    }
    return backImage;
}

wxBitmap *fixImage (wxString url, int type, wxColour c)
{
  if (url.IsEmpty ())
    return NULL;

  wxImage img = wxImage (url); 
  wxSize sz = wxGetDisplaySize();
  int w = sz.GetWidth();
  int h = sz.GetHeight();
  printf ("Image size:%d,%d Screen size:%d,%d\n", img.GetWidth (),
	  img.GetHeight (), w, h);
  // cout << wx2std(c.GetAsString(wxC2S_HTML_SYNTAX)) <<endl;
  switch (type)
    {
    case STRETCHED:
      return new wxBitmap (img.Scale (w, h, wxIMAGE_QUALITY_HIGH));
      break;
    case CENTERED:
      int x, y;
      if (img.GetWidth () > w)
	x = 0;
      else
	x = (w - img.GetWidth ()) / 2;
      if (img.GetHeight () > h)
	y = 0;
      else
	y = (h - img.GetHeight ()) / 2;


      img.Resize (wxSize (w, h), wxPoint (x, y), c.Red (), c.Green (),
		  c.Blue ());
      return new wxBitmap (img);
      break;
    default:
      return new wxBitmap (img);
      break;

    }

  return NULL;
}