]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/bitmap.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "bitmap.h"
15 #include "wx/bitmap.h"
16 #include "gdk/gdkprivate.h"
19 #include "../gdk_imlib/gdk_imlib.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 IMPLEMENT_DYNAMIC_CLASS(wxMask
,wxObject
)
33 wxMask::wxMask( const wxBitmap
& WXUNUSED(bitmap
), const wxColour
& WXUNUSED(colour
) )
37 wxMask::wxMask( const wxBitmap
& WXUNUSED(bitmap
), int WXUNUSED(paletteIndex
) )
41 wxMask::wxMask( const wxBitmap
& WXUNUSED(bitmap
) )
48 // do not delete the mask, gdk_imlib does it for you
50 if (m_bitmap
) gdk_bitmap_unref( m_bitmap
);
54 GdkBitmap
*wxMask::GetBitmap(void) const
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 // CMB 20/5/98: added m_bitmap for GdkBitmaps
64 class wxBitmapRefData
: public wxObjectRefData
68 wxBitmapRefData(void);
69 ~wxBitmapRefData(void);
78 GdkImlibImage
*m_image
;
83 wxBitmapRefData::wxBitmapRefData(void)
97 wxBitmapRefData::~wxBitmapRefData(void)
100 if (m_pixmap
) gdk_imlib_free_pixmap( m_pixmap
);
101 if (m_image
) gdk_imlib_destroy_image( m_image
);
103 if (m_pixmap
) gdk_pixmap_unref( m_pixmap
);
105 if (m_bitmap
) gdk_bitmap_unref( m_bitmap
);
106 if (m_mask
) delete m_mask
;
107 if (m_palette
) delete m_palette
;
110 //-----------------------------------------------------------------------------
112 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
114 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxGDIObject
)
116 wxBitmap::wxBitmap(void)
118 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
121 wxBitmap::wxBitmap( int width
, int height
, int depth
)
123 m_refData
= new wxBitmapRefData();
124 M_BMPDATA
->m_mask
= NULL
;
125 M_BMPDATA
->m_pixmap
=
126 gdk_pixmap_new( (GdkWindow
*) &gdk_root_parent
, width
, height
, depth
);
127 M_BMPDATA
->m_width
= width
;
128 M_BMPDATA
->m_height
= height
;
129 M_BMPDATA
->m_bpp
= depth
;
131 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
134 wxBitmap::wxBitmap( char **bits
)
136 m_refData
= new wxBitmapRefData();
138 #ifndef USE_GDK_IMLIB
140 GdkBitmap
*mask
= NULL
;
142 M_BMPDATA
->m_pixmap
=
143 gdk_pixmap_create_from_xpm_d( (GdkWindow
*) &gdk_root_parent
, &mask
, NULL
, (gchar
**) bits
);
147 M_BMPDATA
->m_mask
= new wxMask();
148 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
151 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
155 M_BMPDATA
->m_image
= gdk_imlib_create_image_from_xpm_data( bits
);
160 M_BMPDATA
->m_bpp
= 24; // ?
162 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
165 wxBitmap::wxBitmap( const wxBitmap
& bmp
)
169 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
172 wxBitmap::wxBitmap( const wxBitmap
* bmp
)
174 if (bmp
) Ref( *bmp
);
176 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
179 wxBitmap::wxBitmap( const wxString
&filename
, int type
)
181 LoadFile( filename
, type
);
183 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
186 // CMB 15/5/98: add constructor for xbm bitmaps
187 wxBitmap::wxBitmap( const char bits
[], int width
, int height
, int WXUNUSED(depth
))
189 m_refData
= new wxBitmapRefData();
191 M_BMPDATA
->m_mask
= NULL
;
192 M_BMPDATA
->m_bitmap
=
193 gdk_bitmap_create_from_data( (GdkWindow
*) &gdk_root_parent
, (gchar
*) bits
, width
, height
);
194 M_BMPDATA
->m_width
= width
;
195 M_BMPDATA
->m_height
= height
;
196 M_BMPDATA
->m_bpp
= 1;
198 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
201 wxBitmap::~wxBitmap(void)
203 if (wxTheBitmapList
) wxTheBitmapList
->DeleteObject(this);
206 wxBitmap
& wxBitmap::operator = ( const wxBitmap
& bmp
)
208 if (*this == bmp
) return (*this);
213 bool wxBitmap::operator == ( const wxBitmap
& bmp
)
215 return m_refData
== bmp
.m_refData
;
218 bool wxBitmap::operator != ( const wxBitmap
& bmp
)
220 return m_refData
!= bmp
.m_refData
;
223 bool wxBitmap::Ok(void) const
225 return m_refData
!= NULL
;
228 int wxBitmap::GetHeight(void) const
231 return M_BMPDATA
->m_height
;
234 int wxBitmap::GetWidth(void) const
237 return M_BMPDATA
->m_width
;
240 int wxBitmap::GetDepth(void) const
243 return M_BMPDATA
->m_bpp
;
246 void wxBitmap::SetHeight( int height
)
249 M_BMPDATA
->m_height
= height
;
252 void wxBitmap::SetWidth( int width
)
255 M_BMPDATA
->m_width
= width
;
258 void wxBitmap::SetDepth( int depth
)
261 M_BMPDATA
->m_bpp
= depth
;
264 wxMask
*wxBitmap::GetMask(void) const
266 if (!Ok()) return NULL
;
268 return M_BMPDATA
->m_mask
;
271 void wxBitmap::SetMask( wxMask
*mask
)
275 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
276 M_BMPDATA
->m_mask
= mask
;
279 void wxBitmap::Resize( int height
, int width
)
285 if (M_BMPDATA
->m_bitmap
) return; // not supported for bitmaps
287 if (!M_BMPDATA
->m_image
) RecreateImage();
289 if (M_BMPDATA
->m_pixmap
) gdk_imlib_free_pixmap( M_BMPDATA
->m_pixmap
);
290 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
292 GdkImlibImage
* image
= gdk_imlib_clone_scaled_image( M_BMPDATA
->m_image
, height
, width
);
293 gdk_imlib_destroy_image( M_BMPDATA
->m_image
);
294 M_BMPDATA
->m_image
= image
;
295 M_BMPDATA
->m_height
= height
;
296 M_BMPDATA
->m_width
= width
;
303 bool wxBitmap::SaveFile( const wxString
&name
, int WXUNUSED(type
),
304 wxPalette
*WXUNUSED(palette
) )
308 if (!Ok()) return FALSE
;
310 if (!M_BMPDATA
->m_image
) RecreateImage();
312 return gdk_imlib_save_image( M_BMPDATA
->m_image
, WXSTRINGCAST name
, NULL
);
319 bool wxBitmap::LoadFile( const wxString
&name
, int WXUNUSED(type
) )
324 m_refData
= new wxBitmapRefData();
326 M_BMPDATA
->m_image
= gdk_imlib_load_image( WXSTRINGCAST name
);
328 if (!M_BMPDATA
->m_image
)
336 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
337 M_BMPDATA
->m_bpp
= 24; // ?
345 wxPalette
*wxBitmap::GetPalette(void) const
347 if (!Ok()) return NULL
;
348 return M_BMPDATA
->m_palette
;
351 GdkPixmap
*wxBitmap::GetPixmap(void) const
353 if (!Ok()) return NULL
;
354 return M_BMPDATA
->m_pixmap
;
357 GdkBitmap
*wxBitmap::GetBitmap(void) const
359 if (!Ok()) return NULL
;
361 return M_BMPDATA
->m_bitmap
;
364 void wxBitmap::DestroyImage(void)
368 if (M_BMPDATA
->m_image
)
370 gdk_imlib_destroy_image( M_BMPDATA
->m_image
);
371 M_BMPDATA
->m_image
= NULL
;
375 void wxBitmap::RecreateImage(void)
379 void wxBitmap::Render(void)
385 gdk_imlib_render( M_BMPDATA
->m_image
, M_BMPDATA
->m_image
->rgb_width
, M_BMPDATA
->m_image
->rgb_height
);
386 M_BMPDATA
->m_width
= M_BMPDATA
->m_image
->rgb_width
;
387 M_BMPDATA
->m_height
= M_BMPDATA
->m_image
->rgb_height
;
388 M_BMPDATA
->m_pixmap
= gdk_imlib_move_image( M_BMPDATA
->m_image
);
389 GdkBitmap
*mask
= gdk_imlib_move_mask( M_BMPDATA
->m_image
);
392 M_BMPDATA
->m_mask
= new wxMask();
393 M_BMPDATA
->m_mask
->m_bitmap
= mask
;