]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/bitmap.cpp
added some wxMSW stuff
[wxWidgets.git] / src / gtk1 / bitmap.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "bitmap.h"
13 #endif
14
15 #include "wx/bitmap.h"
16 #include "gdk/gdkprivate.h"
17
18 #ifdef USE_GDK_IMLIB
19 #include "gdk_imlib.h"
20 #endif
21
22 //-----------------------------------------------------------------------------
23 // wxMask
24 //-----------------------------------------------------------------------------
25
26 IMPLEMENT_DYNAMIC_CLASS(wxMask,wxObject)
27
28 wxMask::wxMask(void)
29 {
30 m_bitmap = NULL;
31 };
32
33 wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), const wxColour& WXUNUSED(colour) )
34 {
35 };
36
37 wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), const int WXUNUSED(paletteIndex) )
38 {
39 };
40
41 wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap) )
42 {
43 };
44
45 wxMask::~wxMask(void)
46 {
47 #ifdef USE_GDK_IMLIB
48 // do not delete the mask, gdk_imlib does it for you
49 #else
50 if (m_bitmap) gdk_bitmap_unref( m_bitmap );
51 #endif
52 };
53
54 GdkBitmap *wxMask::GetBitmap(void) const
55 {
56 return m_bitmap;
57 };
58
59 //-----------------------------------------------------------------------------
60 // wxBitmap
61 //-----------------------------------------------------------------------------
62
63 class wxBitmapRefData: public wxObjectRefData
64 {
65 public:
66
67 wxBitmapRefData(void);
68 ~wxBitmapRefData(void);
69
70 GdkPixmap *m_pixmap;
71 wxMask *m_mask;
72 int m_width;
73 int m_height;
74 int m_bpp;
75 wxPalette *m_palette;
76 };
77
78 wxBitmapRefData::wxBitmapRefData(void)
79 {
80 m_pixmap = NULL;
81 m_mask = NULL;
82 m_width = 0;
83 m_height = 0;
84 m_bpp = 0;
85 m_palette = NULL;
86 };
87
88 wxBitmapRefData::~wxBitmapRefData(void)
89 {
90 #ifdef USE_GDK_IMLIB
91 if (m_pixmap) gdk_imlib_free_pixmap( m_pixmap );
92 #else
93 if (m_pixmap) gdk_pixmap_unref( m_pixmap );
94 #endif
95 if (m_mask) delete m_mask;
96 if (m_palette) delete m_palette;
97 };
98
99 //-----------------------------------------------------------------------------
100
101 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
102
103 IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxGDIObject)
104
105 wxBitmap::wxBitmap(void)
106 {
107 if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
108 };
109
110 wxBitmap::wxBitmap( const int width, const int height, const int depth )
111 {
112 m_refData = new wxBitmapRefData();
113 M_BMPDATA->m_mask = NULL;
114 M_BMPDATA->m_pixmap =
115 gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, width, height, depth );
116 gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
117 M_BMPDATA->m_bpp = depth;
118
119 if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
120 };
121
122 wxBitmap::wxBitmap( char **bits )
123 {
124 m_refData = new wxBitmapRefData();
125
126 GdkBitmap *mask = NULL;
127
128 #ifndef USE_GDK_IMLIB
129 M_BMPDATA->m_pixmap =
130 gdk_pixmap_create_from_xpm_d( (GdkWindow*) &gdk_root_parent, &mask, NULL, (gchar **) bits );
131 #else
132 M_BMPDATA->m_pixmap = NULL;
133 int res = gdk_imlib_data_to_pixmap( bits, &M_BMPDATA->m_pixmap, &mask );
134 #endif
135
136 if (mask)
137 {
138 M_BMPDATA->m_mask = new wxMask();
139 M_BMPDATA->m_mask->m_bitmap = mask;
140 };
141
142 gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
143 M_BMPDATA->m_bpp = 24; // ?
144
145 if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
146 };
147
148 wxBitmap::wxBitmap( const wxBitmap& bmp )
149 {
150 Ref( bmp );
151
152 if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
153 };
154
155 wxBitmap::wxBitmap( const wxBitmap* bmp )
156 {
157 if (bmp) Ref( *bmp );
158
159 if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
160 };
161
162 wxBitmap::wxBitmap( const wxString &filename, const int type )
163 {
164 LoadFile( filename, type );
165 };
166
167 wxBitmap::~wxBitmap(void)
168 {
169 if (wxTheBitmapList) wxTheBitmapList->DeleteObject(this);
170 };
171
172 wxBitmap& wxBitmap::operator = ( const wxBitmap& bmp )
173 {
174 if (*this == bmp) return (*this);
175 Ref( bmp );
176 return *this;
177 };
178
179 bool wxBitmap::operator == ( const wxBitmap& bmp )
180 {
181 return m_refData == bmp.m_refData;
182 };
183
184 bool wxBitmap::operator != ( const wxBitmap& bmp )
185 {
186 return m_refData != bmp.m_refData;
187 };
188
189 bool wxBitmap::Ok(void) const
190 {
191 return m_refData != NULL;
192 };
193
194 int wxBitmap::GetHeight(void) const
195 {
196 if (!Ok()) return 0;
197 return M_BMPDATA->m_height;
198 };
199
200 int wxBitmap::GetWidth(void) const
201 {
202 if (!Ok()) return 0;
203 return M_BMPDATA->m_width;
204 };
205
206 int wxBitmap::GetDepth(void) const
207 {
208 if (!Ok()) return 0;
209 return M_BMPDATA->m_bpp;
210 };
211
212 void wxBitmap::SetHeight( const int height )
213 {
214 if (!Ok()) return;
215 M_BMPDATA->m_height = height;
216 };
217
218 void wxBitmap::SetWidth( const int width )
219 {
220 if (!Ok()) return;
221 M_BMPDATA->m_width = width;
222 };
223
224 void wxBitmap::SetDepth( const int depth )
225 {
226 if (!Ok()) return;
227 M_BMPDATA->m_bpp = depth;
228 };
229
230 wxMask *wxBitmap::GetMask(void) const
231 {
232 if (!Ok()) return NULL;
233 return M_BMPDATA->m_mask;
234 };
235
236 void wxBitmap::SetMask( wxMask *mask )
237 {
238 if (!Ok()) return;
239 if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask;
240 M_BMPDATA->m_mask = mask;
241 };
242
243 bool wxBitmap::SaveFile( const wxString &WXUNUSED(name), const int WXUNUSED(type),
244 wxPalette *WXUNUSED(palette) )
245 {
246 return FALSE;
247 };
248
249 bool wxBitmap::LoadFile( const wxString &name, const int WXUNUSED(type) )
250 {
251 #ifdef USE_GDK_IMLIB
252
253 UnRef();
254 m_refData = new wxBitmapRefData();
255 M_BMPDATA->m_mask = NULL;
256
257 GdkBitmap *mask = NULL;
258
259 int res = gdk_imlib_load_file_to_pixmap( WXSTRINGCAST name, &M_BMPDATA->m_pixmap, &mask );
260
261 if (res != 1)
262 {
263 UnRef();
264 return FALSE;
265 };
266
267 if (mask)
268 {
269 M_BMPDATA->m_mask = new wxMask();
270 M_BMPDATA->m_mask->m_bitmap = mask;
271 }
272
273 gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
274 M_BMPDATA->m_bpp = 24; // ?
275
276 return TRUE;
277 #endif
278
279 return FALSE;
280 };
281
282 wxPalette *wxBitmap::GetPalette(void) const
283 {
284 if (!Ok()) return NULL;
285 return M_BMPDATA->m_palette;
286 };
287
288 GdkPixmap *wxBitmap::GetPixmap(void) const
289 {
290 if (!Ok()) return NULL;
291 return M_BMPDATA->m_pixmap;
292 };
293