+ M_BMPDATA->m_mask = (wxMask *) 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()
+{
+}
+
+bool wxBitmap::operator == ( const wxBitmap& bmp ) const
+{
+ return m_refData == bmp.m_refData;
+}
+
+bool wxBitmap::operator != ( const wxBitmap& bmp ) const
+{
+ return m_refData != bmp.m_refData;
+}
+
+bool wxBitmap::Ok() const
+{
+ return (m_refData != NULL) &&
+ (M_BMPDATA->m_bitmap || M_BMPDATA->m_pixmap);
+}
+
+int wxBitmap::GetHeight() const
+{
+ wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_height;
+}
+
+int wxBitmap::GetWidth() const
+{
+ wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_width;
+}
+
+int wxBitmap::GetDepth() const
+{
+ wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_bpp;
+}
+
+wxMask *wxBitmap::GetMask() const
+{
+ wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_mask;
+}
+
+void wxBitmap::SetMask( wxMask *mask )
+{
+ wxCHECK_RET( Ok(), wxT("invalid bitmap") );
+
+ 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( Ok() &&
+ (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.Ok(), 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( Ok(), false, wxT("invalid bitmap") );
+
+ // Try to save the bitmap via wxImage handlers:
+ {
+ wxImage image = ConvertToImage();
+ if (image.Ok()) 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 = (GdkBitmap*) 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.Ok() )
+ return false;
+
+ *this = wxBitmap(image);
+ }
+
+ return true;
+}
+
+#if wxUSE_PALETTE
+wxPalette *wxBitmap::GetPalette() const
+{
+ if (!Ok())
+ return (wxPalette *) NULL;
+
+ return M_BMPDATA->m_palette;
+}
+
+void wxBitmap::SetPalette(const wxPalette& WXUNUSED(palette))
+{
+ // TODO
+}
+#endif // wxUSE_PALETTE
+
+void wxBitmap::SetHeight( int height )
+{
+ if (!m_refData)
+ m_refData = new wxBitmapRefData();
+
+ M_BMPDATA->m_height = height;
+}
+
+void wxBitmap::SetWidth( int width )
+{
+ if (!m_refData)
+ m_refData = new wxBitmapRefData();
+
+ M_BMPDATA->m_width = width;
+}
+
+void wxBitmap::SetDepth( int depth )
+{
+ if (!m_refData)
+ m_refData = new wxBitmapRefData();
+
+ 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( Ok(), (GdkPixmap *) NULL, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_pixmap;
+}
+
+bool wxBitmap::HasPixmap() const
+{
+ wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_pixmap != NULL;
+}
+
+GdkBitmap *wxBitmap::GetBitmap() const
+{
+ wxCHECK_MSG( Ok(), (GdkBitmap *) NULL, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_bitmap;
+}
+
+void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp)
+{
+ return NULL;
+}
+
+void wxBitmap::UngetRawData(wxPixelDataBase& WXUNUSED(data))
+{
+}
+
+
+bool wxBitmap::HasAlpha() const
+{
+ return false;
+}
+
+void wxBitmap::UseAlpha()
+{
+}
+
+//-----------------------------------------------------------------------------
+// wxBitmapHandler
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler,wxBitmapHandlerBase)
+
+wxBitmapHandler::~wxBitmapHandler()
+{
+}
+
+bool wxBitmapHandler::Create(wxBitmap * WXUNUSED(bitmap),
+ void * WXUNUSED(data),
+ long WXUNUSED(type),
+ int WXUNUSED(width),
+ int WXUNUSED(height),
+ int WXUNUSED(depth))
+{
+ wxFAIL_MSG( _T("not implemented") );
+
+ return false;
+}
+
+bool wxBitmapHandler::LoadFile(wxBitmap * WXUNUSED(bitmap),
+ const wxString& WXUNUSED(name),
+ long WXUNUSED(flags),
+ int WXUNUSED(desiredWidth),
+ int WXUNUSED(desiredHeight))
+{
+ wxFAIL_MSG( _T("not implemented") );
+
+ return false;
+}
+
+bool wxBitmapHandler::SaveFile(const wxBitmap * WXUNUSED(bitmap),
+ const wxString& WXUNUSED(name),
+ int WXUNUSED(type),
+ const wxPalette * WXUNUSED(palette))
+{
+ wxFAIL_MSG( _T("not implemented") );
+
+ return false;
+}
+
+/* static */ void wxBitmap::InitStandardHandlers()
+{
+ // TODO: Insert handler based on GdkPixbufs handler later
+}