]>
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)
94 wxBitmapRefData::~wxBitmapRefData(void)
97 if (m_pixmap
) gdk_imlib_free_pixmap( m_pixmap
);
98 if (m_image
) gdk_imlib_destroy_image( m_image
);
100 if (m_pixmap
) gdk_pixmap_unref( m_pixmap
);
102 if (m_bitmap
) gdk_bitmap_unref( m_bitmap
);
103 if (m_mask
) delete m_mask
;
104 if (m_palette
) delete m_palette
;
107 //-----------------------------------------------------------------------------
109 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
111 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxGDIObject
)
113 wxBitmap::wxBitmap(void)
115 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
118 wxBitmap::wxBitmap( int width
, int height
, int depth
)
120 m_refData
= new wxBitmapRefData();
121 M_BMPDATA
->m_mask
= NULL
;
122 M_BMPDATA
->m_pixmap
=
123 gdk_pixmap_new( (GdkWindow
*) &gdk_root_parent
, width
, height
, depth
);
124 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
125 M_BMPDATA
->m_bpp
= depth
;
127 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
130 wxBitmap::wxBitmap( char **bits
)
132 m_refData
= new wxBitmapRefData();
134 #ifndef USE_GDK_IMLIB
136 GdkBitmap
*mask
= NULL
;
138 M_BMPDATA
->m_pixmap
=
139 gdk_pixmap_create_from_xpm_d( (GdkWindow
*) &gdk_root_parent
, &mask
, NULL
, (gchar
**) bits
);
143 M_BMPDATA
->m_mask
= new wxMask();
144 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
149 M_BMPDATA
->m_image
= gdk_imlib_create_image_from_xpm_data( bits
);
154 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
155 M_BMPDATA
->m_bpp
= 24; // ?
157 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
160 wxBitmap::wxBitmap( const wxBitmap
& bmp
)
164 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
167 wxBitmap::wxBitmap( const wxBitmap
* bmp
)
169 if (bmp
) Ref( *bmp
);
171 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
174 wxBitmap::wxBitmap( const wxString
&filename
, int type
)
176 LoadFile( filename
, type
);
179 // CMB 15/5/98: add constructor for xbm bitmaps
180 wxBitmap::wxBitmap( const char bits
[], int width
, int height
, int WXUNUSED(depth
))
182 m_refData
= new wxBitmapRefData();
184 M_BMPDATA
->m_mask
= NULL
;
185 M_BMPDATA
->m_bitmap
=
186 gdk_bitmap_create_from_data( (GdkWindow
*) &gdk_root_parent
, (gchar
*) bits
, width
, height
);
187 gdk_window_get_size( M_BMPDATA
->m_bitmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
188 M_BMPDATA
->m_bpp
= 1;
190 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
193 wxBitmap::~wxBitmap(void)
195 if (wxTheBitmapList
) wxTheBitmapList
->DeleteObject(this);
198 wxBitmap
& wxBitmap::operator = ( const wxBitmap
& bmp
)
200 if (*this == bmp
) return (*this);
205 bool wxBitmap::operator == ( const wxBitmap
& bmp
)
207 return m_refData
== bmp
.m_refData
;
210 bool wxBitmap::operator != ( const wxBitmap
& bmp
)
212 return m_refData
!= bmp
.m_refData
;
215 bool wxBitmap::Ok(void) const
217 return m_refData
!= NULL
;
220 int wxBitmap::GetHeight(void) const
223 return M_BMPDATA
->m_height
;
226 int wxBitmap::GetWidth(void) const
229 return M_BMPDATA
->m_width
;
232 int wxBitmap::GetDepth(void) const
235 return M_BMPDATA
->m_bpp
;
238 void wxBitmap::SetHeight( int height
)
241 M_BMPDATA
->m_height
= height
;
244 void wxBitmap::SetWidth( int width
)
247 M_BMPDATA
->m_width
= width
;
250 void wxBitmap::SetDepth( int depth
)
253 M_BMPDATA
->m_bpp
= depth
;
256 wxMask
*wxBitmap::GetMask(void) const
258 if (!Ok()) return NULL
;
260 return M_BMPDATA
->m_mask
;
263 void wxBitmap::SetMask( wxMask
*mask
)
267 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
268 M_BMPDATA
->m_mask
= mask
;
271 void wxBitmap::Resize( int height
, int width
)
279 if (M_BMPDATA
->m_bitmap
) return; // not supported for bitmaps
281 if (!M_BMPDATA
->m_image
) RecreateImage();
283 if (M_BMPDATA
->m_pixmap
) gdk_imlib_free_pixmap( M_BMPDATA
->m_pixmap
);
284 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
286 GdkImlibImage
* image
= gdk_imlib_clone_scaled_image( M_BMPDATA
->m_image
, height
, width
);
287 gdk_imlib_destroy_image( M_BMPDATA
->m_image
);
288 M_BMPDATA
->m_image
= image
;
289 M_BMPDATA
->m_height
= height
;
290 M_BMPDATA
->m_width
= width
;
297 bool wxBitmap::SaveFile( const wxString
&name
, int WXUNUSED(type
),
298 wxPalette
*WXUNUSED(palette
) )
302 if (!Ok()) return FALSE
;
304 if (!M_BMPDATA
->m_image
) RecreateImage();
306 return gdk_imlib_save_image( M_BMPDATA
->m_image
, WXSTRINGCAST name
, NULL
);
313 bool wxBitmap::LoadFile( const wxString
&name
, int WXUNUSED(type
) )
318 m_refData
= new wxBitmapRefData();
320 M_BMPDATA
->m_image
= gdk_imlib_load_image( WXSTRINGCAST name
);
322 if (!M_BMPDATA
->m_image
)
330 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
331 M_BMPDATA
->m_bpp
= 24; // ?
339 wxPalette
*wxBitmap::GetPalette(void) const
341 if (!Ok()) return NULL
;
342 return M_BMPDATA
->m_palette
;
345 GdkPixmap
*wxBitmap::GetPixmap(void) const
347 if (!Ok()) return NULL
;
348 return M_BMPDATA
->m_pixmap
;
351 GdkBitmap
*wxBitmap::GetBitmap(void) const
353 if (!Ok()) return NULL
;
355 return M_BMPDATA
->m_bitmap
;
358 void wxBitmap::DestroyImage(void)
362 if (M_BMPDATA
->m_image
)
364 gdk_imlib_destroy_image( M_BMPDATA
->m_image
);
365 M_BMPDATA
->m_image
= NULL
;
369 void wxBitmap::RecreateImage(void)
373 void wxBitmap::Render(void)
379 gdk_imlib_render( M_BMPDATA
->m_image
, M_BMPDATA
->m_image
->rgb_width
, M_BMPDATA
->m_image
->rgb_height
);
381 M_BMPDATA
->m_pixmap
= gdk_imlib_move_image( M_BMPDATA
->m_image
);
382 GdkBitmap
*mask
= gdk_imlib_move_mask( M_BMPDATA
->m_image
);
385 M_BMPDATA
->m_mask
= new wxMask();
386 M_BMPDATA
->m_mask
->m_bitmap
= mask
;