X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/13111b2ac81e694d6b69822dff61838ae66052b2..54ca0d120a10e57b7f2c75269a136e4a68508447:/src/gtk/bitmap.cpp?ds=inline diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 88a1477166..ed3595f860 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -18,15 +18,23 @@ #include "wx/dcmemory.h" #include -#include +#include + +extern void gdk_wx_draw_bitmap (GdkDrawable *drawable, + GdkGC *gc, + GdkDrawable *src, + gint xsrc, + gint ysrc, + gint xdest, + gint ydest, + gint width, + gint height); -// in GTK+ 1.3 gdk_root_parent was renamed into gdk_parent_root -#ifdef __WXGTK13__ - #define gdk_root_parent gdk_parent_root -#else // GTK+ <= 1.2 - // need to get the declaration of gdk_root_parent from private header - #include -#endif // GTK+ 1.3/1.2 +//----------------------------------------------------------------------------- +// data +//----------------------------------------------------------------------------- + +extern GtkWidget *wxRootWindow; //----------------------------------------------------------------------------- // wxMask @@ -75,8 +83,7 @@ bool wxMask::Create( const wxBitmap& bitmap, wxImage image( bitmap ); if (!image.Ok()) return FALSE; - GdkWindow *parent = (GdkWindow*) &gdk_root_parent; - m_bitmap = gdk_pixmap_new( parent, image.GetWidth(), image.GetHeight(), 1 ); + m_bitmap = gdk_pixmap_new( wxRootWindow->window, image.GetWidth(), image.GetHeight(), 1 ); GdkGC *gc = gdk_gc_new( m_bitmap ); GdkColor color; @@ -95,20 +102,22 @@ bool wxMask::Create( const wxBitmap& bitmap, unsigned char green = colour.Green(); unsigned char blue = colour.Blue(); - GdkVisual *visual = gdk_visual_get_system(); + GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + wxASSERT( visual ); + int bpp = visual->depth; if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15; if (bpp == 15) { red = red & 0xf8; - blue = blue & 0xf8; green = green & 0xf8; + blue = blue & 0xf8; } if (bpp == 16) { red = red & 0xf8; - blue = blue & 0xfc; - green = green & 0xf8; + green = green & 0xfc; + blue = blue & 0xf8; } color.red = 0; @@ -175,13 +184,13 @@ bool wxMask::Create( const wxBitmap& bitmap ) wxCHECK_MSG( bitmap.GetBitmap(), FALSE, wxT("Cannot create mask from colour bitmap") ); - m_bitmap = gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, bitmap.GetWidth(), bitmap.GetHeight(), 1 ); + m_bitmap = gdk_pixmap_new( wxRootWindow->window, bitmap.GetWidth(), bitmap.GetHeight(), 1 ); if (!m_bitmap) return FALSE; GdkGC *gc = gdk_gc_new( m_bitmap ); - gdk_draw_bitmap( m_bitmap, gc, bitmap.GetBitmap(), 0, 0, 0, 0, bitmap.GetWidth(), bitmap.GetHeight() ); + gdk_wx_draw_bitmap( m_bitmap, gc, bitmap.GetBitmap(), 0, 0, 0, 0, bitmap.GetWidth(), bitmap.GetHeight() ); gdk_gc_unref( gc ); @@ -244,13 +253,24 @@ wxBitmap::wxBitmap() wxBitmap::wxBitmap( int width, int height, int depth ) { - wxCHECK_RET( (width > 0) && (height > 0), wxT("invalid bitmap size") ) + Create( width, height, depth ); + + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); +} + +bool wxBitmap::Create( int width, int height, int depth ) +{ + UnRef(); + + wxCHECK_MSG( (width > 0) && (height > 0), FALSE, wxT("invalid bitmap size") ) - GdkWindow *parent = (GdkWindow*) &gdk_root_parent; - if (depth == -1) depth = gdk_window_get_visual( parent )->depth; + GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + wxASSERT( visual ); - wxCHECK_RET( (depth == gdk_window_get_visual( parent )->depth) || - (depth == 1), wxT("invalid bitmap depth") ) + if (depth == -1) depth = visual->depth; + + wxCHECK_MSG( (depth == visual->depth) || + (depth == 1), FALSE, wxT("invalid bitmap depth") ) m_refData = new wxBitmapRefData(); M_BMPDATA->m_mask = (wxMask *) NULL; @@ -258,28 +278,29 @@ wxBitmap::wxBitmap( int width, int height, int depth ) M_BMPDATA->m_height = height; if (depth == 1) { - M_BMPDATA->m_bitmap = gdk_pixmap_new( parent, width, height, 1 ); + M_BMPDATA->m_bitmap = gdk_pixmap_new( wxRootWindow->window, width, height, 1 ); M_BMPDATA->m_bpp = 1; } else { - M_BMPDATA->m_pixmap = gdk_pixmap_new( parent, width, height, depth ); - M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; + M_BMPDATA->m_pixmap = gdk_pixmap_new( wxRootWindow->window, width, height, depth ); + M_BMPDATA->m_bpp = visual->depth; } - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); + return Ok(); } - bool wxBitmap::CreateFromXpm( const char **bits ) { wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") ) + GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + wxASSERT( visual ); + m_refData = new wxBitmapRefData(); GdkBitmap *mask = (GdkBitmap*) NULL; - GdkWindow *parent = (GdkWindow*) &gdk_root_parent; - M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( parent, &mask, NULL, (gchar **) bits ); + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( wxRootWindow->window, &mask, NULL, (gchar **) bits ); wxCHECK_MSG( M_BMPDATA->m_pixmap, FALSE, wxT("couldn't create pixmap") ); @@ -291,7 +312,8 @@ bool wxBitmap::CreateFromXpm( const char **bits ) gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; // ? + M_BMPDATA->m_bpp = visual->depth; // ? + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); return TRUE; @@ -317,7 +339,7 @@ wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth M_BMPDATA->m_mask = (wxMask *) NULL; M_BMPDATA->m_bitmap = - gdk_bitmap_create_from_data( (GdkWindow*) &gdk_root_parent, (gchar *) bits, width, height ); + gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) bits, width, height ); M_BMPDATA->m_width = width; M_BMPDATA->m_height = height; M_BMPDATA->m_bpp = 1; @@ -339,12 +361,12 @@ wxBitmap& wxBitmap::operator = ( const wxBitmap& bmp ) return *this; } -bool wxBitmap::operator == ( const wxBitmap& bmp ) +bool wxBitmap::operator == ( const wxBitmap& bmp ) const { return m_refData == bmp.m_refData; } -bool wxBitmap::operator != ( const wxBitmap& bmp ) +bool wxBitmap::operator != ( const wxBitmap& bmp ) const { return m_refData != bmp.m_refData; } @@ -410,18 +432,17 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const else { GdkGC *gc = gdk_gc_new( ret.GetBitmap() ); - gdk_draw_bitmap( ret.GetBitmap(), gc, GetBitmap(), rect.x, rect.y, 0, 0, rect.width, rect.height ); + 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; - GdkWindow *parent = (GdkWindow*) &gdk_root_parent; - mask->m_bitmap = gdk_pixmap_new( parent, rect.width, rect.height, 1 ); + mask->m_bitmap = gdk_pixmap_new( wxRootWindow->window, rect.width, rect.height, 1 ); GdkGC *gc = gdk_gc_new( mask->m_bitmap ); - gdk_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, 0, 0, rect.x, rect.y, rect.width, rect.height ); + gdk_wx_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, 0, 0, rect.x, rect.y, rect.width, rect.height ); gdk_gc_destroy( gc ); ret.SetMask( mask ); @@ -449,14 +470,16 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) if (!wxFileExists(name)) return FALSE; + GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + wxASSERT( visual ); + if (type == wxBITMAP_TYPE_XPM) { m_refData = new wxBitmapRefData(); GdkBitmap *mask = (GdkBitmap*) NULL; - GdkWindow *parent = (GdkWindow*) &gdk_root_parent; - M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm( parent, &mask, NULL, name.fn_str() ); + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm( wxRootWindow->window, &mask, NULL, name.fn_str() ); if (mask) { @@ -465,7 +488,8 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) } gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; + + M_BMPDATA->m_bpp = visual->depth; } else // try if wxImage can load it { @@ -513,6 +537,13 @@ void wxBitmap::SetPixmap( GdkPixmap *pixmap ) 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") );