]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/bitmap.cpp
b06f111e55edc921f33db0902a253c02aab38b6b
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"
17 #include "gdk/gdkprivate.h"
20 #include "../gdk_imlib/gdk_imlib.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 IMPLEMENT_DYNAMIC_CLASS(wxMask
,wxObject
)
31 m_bitmap
= (GdkBitmap
*) NULL
;
34 wxMask::wxMask( const wxBitmap
& WXUNUSED(bitmap
), const wxColour
& WXUNUSED(colour
) )
38 wxMask::wxMask( const wxBitmap
& WXUNUSED(bitmap
), int WXUNUSED(paletteIndex
) )
42 wxMask::wxMask( const wxBitmap
& WXUNUSED(bitmap
) )
49 // do not delete the mask, gdk_imlib does it for you
51 if (m_bitmap
) gdk_bitmap_unref( m_bitmap
);
55 GdkBitmap
*wxMask::GetBitmap(void) const
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 // CMB 20/5/98: added m_bitmap for GdkBitmaps
65 class wxBitmapRefData
: public wxObjectRefData
69 wxBitmapRefData(void);
70 ~wxBitmapRefData(void);
79 GdkImlibImage
*m_image
;
84 wxBitmapRefData::wxBitmapRefData(void)
86 m_pixmap
= (GdkPixmap
*) NULL
;
87 m_bitmap
= (GdkBitmap
*) NULL
;
88 m_mask
= (wxMask
*) NULL
;
92 m_palette
= (wxPalette
*) NULL
;
94 m_image
= (GdkImlibImage
*) NULL
;
98 wxBitmapRefData::~wxBitmapRefData(void)
101 if (m_pixmap
) gdk_imlib_free_pixmap( m_pixmap
);
102 if (m_image
) gdk_imlib_kill_image( m_image
);
104 if (m_pixmap
) gdk_pixmap_unref( m_pixmap
);
106 if (m_bitmap
) gdk_bitmap_unref( m_bitmap
);
107 if (m_mask
) delete m_mask
;
108 if (m_palette
) delete m_palette
;
111 //-----------------------------------------------------------------------------
113 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
115 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxGDIObject
)
117 wxBitmap::wxBitmap(void)
119 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
122 wxBitmap::wxBitmap( int width
, int height
, int depth
)
124 m_refData
= new wxBitmapRefData();
125 M_BMPDATA
->m_mask
= (wxMask
*) NULL
;
126 M_BMPDATA
->m_pixmap
=
127 gdk_pixmap_new( (GdkWindow
*) &gdk_root_parent
, width
, height
, depth
);
128 M_BMPDATA
->m_width
= width
;
129 M_BMPDATA
->m_height
= height
;
130 M_BMPDATA
->m_bpp
= depth
;
132 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
135 wxBitmap::wxBitmap( char **bits
)
137 m_refData
= new wxBitmapRefData();
139 #ifndef USE_GDK_IMLIB
141 GdkBitmap
*mask
= NULL
;
143 M_BMPDATA
->m_pixmap
=
144 gdk_pixmap_create_from_xpm_d( (GdkWindow
*) &gdk_root_parent
, &mask
, NULL
, (gchar
**) bits
);
148 M_BMPDATA
->m_mask
= new wxMask();
149 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
152 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
156 M_BMPDATA
->m_image
= gdk_imlib_create_image_from_xpm_data( bits
);
161 M_BMPDATA
->m_bpp
= 24; // ?
163 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
166 wxBitmap::wxBitmap( const wxBitmap
& bmp
)
170 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
173 wxBitmap::wxBitmap( const wxBitmap
* bmp
)
175 if (bmp
) Ref( *bmp
);
177 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
180 wxBitmap::wxBitmap( const wxString
&filename
, int type
)
182 LoadFile( filename
, type
);
184 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
187 // CMB 15/5/98: add constructor for xbm bitmaps
188 wxBitmap::wxBitmap( const char bits
[], int width
, int height
, int WXUNUSED(depth
))
190 m_refData
= new wxBitmapRefData();
192 M_BMPDATA
->m_mask
= (wxMask
*) NULL
;
193 M_BMPDATA
->m_bitmap
=
194 gdk_bitmap_create_from_data( (GdkWindow
*) &gdk_root_parent
, (gchar
*) bits
, width
, height
);
195 M_BMPDATA
->m_width
= width
;
196 M_BMPDATA
->m_height
= height
;
197 M_BMPDATA
->m_bpp
= 1;
199 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
202 wxBitmap::~wxBitmap(void)
204 if (wxTheBitmapList
) wxTheBitmapList
->DeleteObject(this);
207 wxBitmap
& wxBitmap::operator = ( const wxBitmap
& bmp
)
209 if (*this == bmp
) return (*this);
214 bool wxBitmap::operator == ( const wxBitmap
& bmp
)
216 return m_refData
== bmp
.m_refData
;
219 bool wxBitmap::operator != ( const wxBitmap
& bmp
)
221 return m_refData
!= bmp
.m_refData
;
224 bool wxBitmap::Ok(void) const
226 return m_refData
!= NULL
;
229 int wxBitmap::GetHeight(void) const
232 return M_BMPDATA
->m_height
;
235 int wxBitmap::GetWidth(void) const
238 return M_BMPDATA
->m_width
;
241 int wxBitmap::GetDepth(void) const
244 return M_BMPDATA
->m_bpp
;
247 void wxBitmap::SetHeight( int height
)
250 M_BMPDATA
->m_height
= height
;
253 void wxBitmap::SetWidth( int width
)
256 M_BMPDATA
->m_width
= width
;
259 void wxBitmap::SetDepth( int depth
)
262 M_BMPDATA
->m_bpp
= depth
;
265 wxMask
*wxBitmap::GetMask(void) const
267 if (!Ok()) return (wxMask
*) NULL
;
269 return M_BMPDATA
->m_mask
;
272 void wxBitmap::SetMask( wxMask
*mask
)
276 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
277 M_BMPDATA
->m_mask
= mask
;
280 void wxBitmap::Resize( int height
, int width
)
286 if (M_BMPDATA
->m_bitmap
) return; // not supported for bitmaps
288 if (!M_BMPDATA
->m_image
) RecreateImage();
290 if (M_BMPDATA
->m_pixmap
) gdk_imlib_free_pixmap( M_BMPDATA
->m_pixmap
);
291 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
293 GdkImlibImage
* image
= gdk_imlib_clone_scaled_image( M_BMPDATA
->m_image
, height
, width
);
294 gdk_imlib_destroy_image( M_BMPDATA
->m_image
);
295 M_BMPDATA
->m_image
= image
;
296 M_BMPDATA
->m_height
= height
;
297 M_BMPDATA
->m_width
= width
;
304 bool wxBitmap::SaveFile( const wxString
&name
, int WXUNUSED(type
),
305 wxPalette
*WXUNUSED(palette
) )
309 if (!Ok()) return FALSE
;
311 if (!M_BMPDATA
->m_image
) RecreateImage();
313 return gdk_imlib_save_image( M_BMPDATA
->m_image
, WXSTRINGCAST name
, (GdkImlibSaveInfo
*) NULL
);
320 bool wxBitmap::LoadFile( const wxString
&name
, int WXUNUSED(type
) )
325 m_refData
= new wxBitmapRefData();
327 M_BMPDATA
->m_image
= gdk_imlib_load_image( WXSTRINGCAST name
);
329 if (!M_BMPDATA
->m_image
)
337 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
338 M_BMPDATA
->m_bpp
= 24; // ?
346 wxPalette
*wxBitmap::GetPalette(void) const
348 if (!Ok()) return (wxPalette
*) NULL
;
349 return M_BMPDATA
->m_palette
;
352 GdkPixmap
*wxBitmap::GetPixmap(void) const
354 if (!Ok()) return (GdkPixmap
*) NULL
;
355 return M_BMPDATA
->m_pixmap
;
358 GdkBitmap
*wxBitmap::GetBitmap(void) const
360 if (!Ok()) return (GdkBitmap
*) NULL
;
362 return M_BMPDATA
->m_bitmap
;
365 void wxBitmap::DestroyImage(void)
369 if (M_BMPDATA
->m_image
)
371 gdk_imlib_destroy_image( M_BMPDATA
->m_image
);
372 M_BMPDATA
->m_image
= (GdkImlibImage
*) NULL
;
376 void wxBitmap::RecreateImage(void)
380 void wxBitmap::Render(void)
386 gdk_imlib_render( M_BMPDATA
->m_image
, M_BMPDATA
->m_image
->rgb_width
, M_BMPDATA
->m_image
->rgb_height
);
387 M_BMPDATA
->m_width
= M_BMPDATA
->m_image
->rgb_width
;
388 M_BMPDATA
->m_height
= M_BMPDATA
->m_image
->rgb_height
;
389 M_BMPDATA
->m_pixmap
= gdk_imlib_move_image( M_BMPDATA
->m_image
);
390 GdkBitmap
*mask
= gdk_imlib_move_mask( M_BMPDATA
->m_image
);
393 M_BMPDATA
->m_mask
= new wxMask();
394 M_BMPDATA
->m_mask
->m_bitmap
= mask
;