]>
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.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 class wxBitmapRefData
: public wxObjectRefData
67 wxBitmapRefData(void);
68 ~wxBitmapRefData(void);
78 wxBitmapRefData::wxBitmapRefData(void)
88 wxBitmapRefData::~wxBitmapRefData(void)
91 if (m_pixmap
) gdk_imlib_free_pixmap( m_pixmap
);
93 if (m_pixmap
) gdk_pixmap_unref( m_pixmap
);
95 if (m_mask
) delete m_mask
;
96 if (m_palette
) delete m_palette
;
99 //-----------------------------------------------------------------------------
101 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
103 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxGDIObject
)
105 wxBitmap::wxBitmap(void)
107 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
110 wxBitmap::wxBitmap( const int width
, const int height
, const int depth
)
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
;
119 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
122 wxBitmap::wxBitmap( char **bits
)
124 m_refData
= new wxBitmapRefData();
126 GdkBitmap
*mask
= NULL
;
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
);
132 M_BMPDATA
->m_pixmap
= NULL
;
133 int res
= gdk_imlib_data_to_pixmap( bits
, &M_BMPDATA
->m_pixmap
, &mask
);
138 M_BMPDATA
->m_mask
= new wxMask();
139 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
142 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
143 M_BMPDATA
->m_bpp
= 24; // ?
145 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
148 wxBitmap::wxBitmap( const wxBitmap
& bmp
)
152 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
155 wxBitmap::wxBitmap( const wxBitmap
* bmp
)
157 if (bmp
) Ref( *bmp
);
159 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
162 wxBitmap::wxBitmap( const wxString
&filename
, const int type
)
164 LoadFile( filename
, type
);
167 wxBitmap::~wxBitmap(void)
169 if (wxTheBitmapList
) wxTheBitmapList
->DeleteObject(this);
172 wxBitmap
& wxBitmap::operator = ( const wxBitmap
& bmp
)
174 if (*this == bmp
) return (*this);
179 bool wxBitmap::operator == ( const wxBitmap
& bmp
)
181 return m_refData
== bmp
.m_refData
;
184 bool wxBitmap::operator != ( const wxBitmap
& bmp
)
186 return m_refData
!= bmp
.m_refData
;
189 bool wxBitmap::Ok(void) const
191 return m_refData
!= NULL
;
194 int wxBitmap::GetHeight(void) const
197 return M_BMPDATA
->m_height
;
200 int wxBitmap::GetWidth(void) const
203 return M_BMPDATA
->m_width
;
206 int wxBitmap::GetDepth(void) const
209 return M_BMPDATA
->m_bpp
;
212 void wxBitmap::SetHeight( const int height
)
215 M_BMPDATA
->m_height
= height
;
218 void wxBitmap::SetWidth( const int width
)
221 M_BMPDATA
->m_width
= width
;
224 void wxBitmap::SetDepth( const int depth
)
227 M_BMPDATA
->m_bpp
= depth
;
230 wxMask
*wxBitmap::GetMask(void) const
232 if (!Ok()) return NULL
;
233 return M_BMPDATA
->m_mask
;
236 void wxBitmap::SetMask( wxMask
*mask
)
239 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
240 M_BMPDATA
->m_mask
= mask
;
243 bool wxBitmap::SaveFile( const wxString
&WXUNUSED(name
), const int WXUNUSED(type
),
244 wxPalette
*WXUNUSED(palette
) )
249 bool wxBitmap::LoadFile( const wxString
&name
, const int WXUNUSED(type
) )
254 m_refData
= new wxBitmapRefData();
255 M_BMPDATA
->m_mask
= NULL
;
257 GdkBitmap
*mask
= NULL
;
259 int res
= gdk_imlib_load_file_to_pixmap( WXSTRINGCAST name
, &M_BMPDATA
->m_pixmap
, &mask
);
269 M_BMPDATA
->m_mask
= new wxMask();
270 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
273 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
274 M_BMPDATA
->m_bpp
= 24; // ?
282 wxPalette
*wxBitmap::GetPalette(void) const
284 if (!Ok()) return NULL
;
285 return M_BMPDATA
->m_palette
;
288 GdkPixmap
*wxBitmap::GetPixmap(void) const
290 if (!Ok()) return NULL
;
291 return M_BMPDATA
->m_pixmap
;