]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/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.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
), const 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);
80 wxBitmapRefData::wxBitmapRefData(void)
91 wxBitmapRefData::~wxBitmapRefData(void)
94 if (m_pixmap
) gdk_imlib_free_pixmap( m_pixmap
);
96 if (m_pixmap
) gdk_pixmap_unref( m_pixmap
);
97 if (m_bitmap
) gdk_bitmap_unref( m_bitmap
);
99 if (m_mask
) delete m_mask
;
100 if (m_palette
) delete m_palette
;
103 //-----------------------------------------------------------------------------
105 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
107 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxGDIObject
)
109 wxBitmap::wxBitmap(void)
111 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
114 wxBitmap::wxBitmap( const int width
, const int height
, const int depth
)
116 m_refData
= new wxBitmapRefData();
117 M_BMPDATA
->m_mask
= NULL
;
118 M_BMPDATA
->m_pixmap
=
119 gdk_pixmap_new( (GdkWindow
*) &gdk_root_parent
, width
, height
, depth
);
120 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
121 M_BMPDATA
->m_bpp
= depth
;
123 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
126 wxBitmap::wxBitmap( char **bits
)
128 m_refData
= new wxBitmapRefData();
130 GdkBitmap
*mask
= NULL
;
132 #ifndef USE_GDK_IMLIB
133 M_BMPDATA
->m_pixmap
=
134 gdk_pixmap_create_from_xpm_d( (GdkWindow
*) &gdk_root_parent
, &mask
, NULL
, (gchar
**) bits
);
136 M_BMPDATA
->m_pixmap
= NULL
;
137 int res
= gdk_imlib_data_to_pixmap( bits
, &M_BMPDATA
->m_pixmap
, &mask
);
142 M_BMPDATA
->m_mask
= new wxMask();
143 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
146 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
147 M_BMPDATA
->m_bpp
= 24; // ?
149 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
152 wxBitmap::wxBitmap( const wxBitmap
& bmp
)
156 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
159 wxBitmap::wxBitmap( const wxBitmap
* bmp
)
161 if (bmp
) Ref( *bmp
);
163 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
166 wxBitmap::wxBitmap( const wxString
&filename
, const int type
)
168 LoadFile( filename
, type
);
171 // CMB 15/5/98: add constructor for xbm bitmaps
172 wxBitmap::wxBitmap( const char bits
[], const int width
, const int height
, const int WXUNUSED(depth
))
174 m_refData
= new wxBitmapRefData();
176 M_BMPDATA
->m_mask
= NULL
;
177 M_BMPDATA
->m_bitmap
=
178 gdk_bitmap_create_from_data( (GdkWindow
*) &gdk_root_parent
, (gchar
*) bits
, width
, height
);
179 gdk_window_get_size( M_BMPDATA
->m_bitmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
180 M_BMPDATA
->m_bpp
= 1;
182 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
185 wxBitmap::~wxBitmap(void)
187 if (wxTheBitmapList
) wxTheBitmapList
->DeleteObject(this);
190 wxBitmap
& wxBitmap::operator = ( const wxBitmap
& bmp
)
192 if (*this == bmp
) return (*this);
197 bool wxBitmap::operator == ( const wxBitmap
& bmp
)
199 return m_refData
== bmp
.m_refData
;
202 bool wxBitmap::operator != ( const wxBitmap
& bmp
)
204 return m_refData
!= bmp
.m_refData
;
207 bool wxBitmap::Ok(void) const
209 return m_refData
!= NULL
;
212 int wxBitmap::GetHeight(void) const
215 return M_BMPDATA
->m_height
;
218 int wxBitmap::GetWidth(void) const
221 return M_BMPDATA
->m_width
;
224 int wxBitmap::GetDepth(void) const
227 return M_BMPDATA
->m_bpp
;
230 void wxBitmap::SetHeight( const int height
)
233 M_BMPDATA
->m_height
= height
;
236 void wxBitmap::SetWidth( const int width
)
239 M_BMPDATA
->m_width
= width
;
242 void wxBitmap::SetDepth( const int depth
)
245 M_BMPDATA
->m_bpp
= depth
;
248 wxMask
*wxBitmap::GetMask(void) const
250 if (!Ok()) return NULL
;
251 return M_BMPDATA
->m_mask
;
254 void wxBitmap::SetMask( wxMask
*mask
)
257 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
258 M_BMPDATA
->m_mask
= mask
;
261 bool wxBitmap::SaveFile( const wxString
&WXUNUSED(name
), const int WXUNUSED(type
),
262 wxPalette
*WXUNUSED(palette
) )
267 bool wxBitmap::LoadFile( const wxString
&name
, const int WXUNUSED(type
) )
272 m_refData
= new wxBitmapRefData();
273 M_BMPDATA
->m_mask
= NULL
;
275 GdkBitmap
*mask
= NULL
;
277 int res
= gdk_imlib_load_file_to_pixmap( WXSTRINGCAST name
, &M_BMPDATA
->m_pixmap
, &mask
);
287 M_BMPDATA
->m_mask
= new wxMask();
288 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
291 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
292 M_BMPDATA
->m_bpp
= 24; // ?
300 wxPalette
*wxBitmap::GetPalette(void) const
302 if (!Ok()) return NULL
;
303 return M_BMPDATA
->m_palette
;
306 GdkPixmap
*wxBitmap::GetPixmap(void) const
308 if (!Ok()) return NULL
;
309 return M_BMPDATA
->m_pixmap
;
312 GdkBitmap
*wxBitmap::GetBitmap(void) const
314 if (!Ok()) return NULL
;
315 return M_BMPDATA
->m_bitmap
;