+ M_BMPDATA->m_mask = NULL;
+ M_BMPDATA->m_bitmap = gdk_bitmap_create_from_data
+ (
+ wxGetRootWindow()->window,
+ (gchar *) bits,
+ width,
+ height
+ );
+ M_BMPDATA->m_width = width;
+ M_BMPDATA->m_height = height;
+ M_BMPDATA->m_bpp = 1;
+
+ wxASSERT_MSG( M_BMPDATA->m_bitmap, wxT("couldn't create bitmap") );
+ }
+}
+
+wxBitmap::~wxBitmap()
+{
+}
+
+int wxBitmap::GetHeight() const
+{
+ wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_height;
+}
+
+int wxBitmap::GetWidth() const
+{
+ wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_width;
+}
+
+int wxBitmap::GetDepth() const
+{
+ wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_bpp;
+}
+
+wxMask *wxBitmap::GetMask() const
+{
+ wxCHECK_MSG( IsOk(), NULL, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_mask;
+}
+
+void wxBitmap::SetMask( wxMask *mask )
+{
+ wxCHECK_RET( IsOk(), wxT("invalid bitmap") );
+
+ AllocExclusive();
+ if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask;
+
+ M_BMPDATA->m_mask = mask;
+}
+
+bool wxBitmap::CopyFromIcon(const wxIcon& icon)
+{
+ *this = icon;
+ return true;
+}
+
+wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
+{
+ wxCHECK_MSG( IsOk() &&
+ (rect.x >= 0) && (rect.y >= 0) &&
+ (rect.x+rect.width <= M_BMPDATA->m_width) && (rect.y+rect.height <= M_BMPDATA->m_height),
+ wxNullBitmap, wxT("invalid bitmap or bitmap region") );
+
+ wxBitmap ret( rect.width, rect.height, M_BMPDATA->m_bpp );
+ wxASSERT_MSG( ret.IsOk(), wxT("GetSubBitmap error") );
+
+ if (ret.GetPixmap())
+ {
+ GdkGC *gc = gdk_gc_new( ret.GetPixmap() );
+ gdk_draw_pixmap( ret.GetPixmap(), gc, GetPixmap(), rect.x, rect.y, 0, 0, rect.width, rect.height );
+ gdk_gc_destroy( gc );
+ }
+ else
+ {
+ GdkGC *gc = gdk_gc_new( ret.GetBitmap() );
+ GdkColor col;
+ col.pixel = 0xFFFFFF;
+ gdk_gc_set_foreground( gc, &col );
+ col.pixel = 0;
+ gdk_gc_set_background( gc, &col );
+ gdk_wx_draw_bitmap( ret.GetBitmap(), gc, GetBitmap(), rect.x, rect.y, 0, 0, rect.width, rect.height );
+ gdk_gc_destroy( gc );
+ }
+
+ if (GetMask())
+ {
+ wxMask *mask = new wxMask;
+ mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, rect.width, rect.height, 1 );
+
+ GdkGC *gc = gdk_gc_new( mask->m_bitmap );
+ GdkColor col;
+ col.pixel = 0xFFFFFF;
+ gdk_gc_set_foreground( gc, &col );
+ col.pixel = 0;
+ gdk_gc_set_background( gc, &col );
+ gdk_wx_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, rect.x, rect.y, 0, 0, rect.width, rect.height );
+ gdk_gc_destroy( gc );
+
+ ret.SetMask( mask );
+ }
+
+ return ret;
+}
+
+bool wxBitmap::SaveFile( const wxString &name, wxBitmapType type, const wxPalette *WXUNUSED(palette) ) const
+{
+ wxCHECK_MSG( IsOk(), false, wxT("invalid bitmap") );
+
+ // Try to save the bitmap via wxImage handlers:
+ {
+ wxImage image = ConvertToImage();
+ if (image.IsOk()) return image.SaveFile( name, type );
+ }
+
+ return false;
+}
+
+bool wxBitmap::LoadFile( const wxString &name, wxBitmapType type )
+{
+ UnRef();
+
+ if (!wxFileExists(name))
+ return false;
+
+ GdkVisual *visual = wxTheApp->GetGdkVisual();
+
+ if (type == wxBITMAP_TYPE_XPM)
+ {
+ m_refData = new wxBitmapRefData();
+
+ GdkBitmap *mask = NULL;
+
+ M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm
+ (
+ wxGetRootWindow()->window,
+ &mask,
+ NULL,
+ name.fn_str()
+ );
+
+ if (mask)
+ {
+ M_BMPDATA->m_mask = new wxMask();
+ M_BMPDATA->m_mask->m_bitmap = mask;
+ }
+
+ gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
+
+ M_BMPDATA->m_bpp = visual->depth;
+ }
+ else // try if wxImage can load it
+ {
+ wxImage image;
+ if ( !image.LoadFile( name, type ) || !image.IsOk() )
+ return false;
+
+ *this = wxBitmap(image);
+ }
+
+ return true;
+}
+
+#if wxUSE_PALETTE
+wxPalette *wxBitmap::GetPalette() const
+{
+ if (!IsOk())
+ return NULL;
+
+ return M_BMPDATA->m_palette;
+}
+
+void wxBitmap::SetPalette(const wxPalette& WXUNUSED(palette))
+{
+ // TODO
+}
+#endif // wxUSE_PALETTE
+
+void wxBitmap::SetHeight( int height )
+{
+ AllocExclusive();
+ M_BMPDATA->m_height = height;
+}
+
+void wxBitmap::SetWidth( int width )
+{
+ AllocExclusive();
+ M_BMPDATA->m_width = width;
+}
+
+void wxBitmap::SetDepth( int depth )
+{
+ AllocExclusive();
+ M_BMPDATA->m_bpp = depth;
+}
+
+void wxBitmap::SetPixmap( GdkPixmap *pixmap )
+{
+ if (!m_refData)
+ m_refData = new wxBitmapRefData();
+
+ M_BMPDATA->m_pixmap = pixmap;
+}
+
+void wxBitmap::SetBitmap( GdkPixmap *bitmap )
+{
+ if (!m_refData)
+ m_refData = new wxBitmapRefData();
+
+ M_BMPDATA->m_bitmap = bitmap;
+}
+
+GdkPixmap *wxBitmap::GetPixmap() const
+{
+ wxCHECK_MSG( IsOk(), NULL, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_pixmap;
+}
+
+bool wxBitmap::HasPixmap() const
+{
+ wxCHECK_MSG( IsOk(), false, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_pixmap != NULL;
+}
+
+GdkBitmap *wxBitmap::GetBitmap() const
+{
+ wxCHECK_MSG( IsOk(), NULL, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_bitmap;
+}
+
+void *wxBitmap::GetRawData(wxPixelDataBase& WXUNUSED(data), int WXUNUSED(bpp))
+{
+ return NULL;
+}
+
+void wxBitmap::UngetRawData(wxPixelDataBase& WXUNUSED(data))
+{
+}
+
+bool wxBitmap::HasAlpha() const
+{
+ return false;
+}
+
+/* static */ void wxBitmap::InitStandardHandlers()
+{
+ // TODO: Insert handler based on GdkPixbufs handler later
+}