X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e8fdc26406cd8bd822955c9d1f12be86781ad379..3bef6c4cf30e426d9aeb11535d39bbb562b2b730:/src/gtk/bitmap.cpp diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 9d7cbed51a..476a09919f 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -117,6 +117,29 @@ wxBitmap::wxBitmap( int width, int height, int depth ) if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); } +wxBitmap::wxBitmap( const char **bits ) +{ + wxCHECK_RET( bits != NULL, "invalid bitmap data" ) + + 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 ); + + 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 = gdk_window_get_visual( parent )->depth; // ? + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); +} + wxBitmap::wxBitmap( char **bits ) { wxCHECK_RET( bits != NULL, "invalid bitmap data" ) @@ -204,33 +227,21 @@ bool wxBitmap::Ok(void) const int wxBitmap::GetHeight(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return -1; - } + wxCHECK_MSG( Ok(), -1, "invalid bitmap" ); return M_BMPDATA->m_height; } int wxBitmap::GetWidth(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return -1; - } + wxCHECK_MSG( Ok(), -1, "invalid bitmap" ); return M_BMPDATA->m_width; } int wxBitmap::GetDepth(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return -1; - } + wxCHECK_MSG( Ok(), -1, "invalid bitmap" ); return M_BMPDATA->m_bpp; } @@ -264,22 +275,14 @@ void wxBitmap::SetDepth( int depth ) wxMask *wxBitmap::GetMask(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return (wxMask *) NULL; - } + wxCHECK_MSG( Ok(), (wxMask *) NULL, "invalid bitmap" ); return M_BMPDATA->m_mask; } void wxBitmap::SetMask( wxMask *mask ) { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return; - } + wxCHECK_RET( Ok(), "invalid bitmap" ); if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; @@ -288,11 +291,7 @@ void wxBitmap::SetMask( wxMask *mask ) bool wxBitmap::SaveFile( const wxString &name, int type, wxPalette *WXUNUSED(palette) ) { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return FALSE; - } + wxCHECK_MSG( Ok(), FALSE, "invalid bitmap" ); if (type == wxBITMAP_TYPE_PNG) { @@ -348,27 +347,20 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) wxPalette *wxBitmap::GetPalette(void) const { if (!Ok()) return (wxPalette *) NULL; + return M_BMPDATA->m_palette; } GdkPixmap *wxBitmap::GetPixmap(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return (GdkPixmap *) NULL; - } + wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, "invalid bitmap" ); return M_BMPDATA->m_pixmap; } GdkBitmap *wxBitmap::GetBitmap(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return (GdkBitmap *) NULL; - } + wxCHECK_MSG( Ok(), (GdkBitmap *) NULL, "invalid bitmap" ); return M_BMPDATA->m_bitmap; } @@ -413,7 +405,7 @@ wxBitmap::wxBitmap( const wxImage &image ) GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap ); if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent ); int bpp = visual->depth; - if ((bpp == 16) && (visual->red_mask == 0xfc00)) bpp = 15; + if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15; if (bpp < 8) bpp = 8; // Render @@ -538,11 +530,7 @@ wxImage wxBitmap::ConvertToImage() const { wxImage image; - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return image; - } + wxCHECK_MSG( Ok(), image, "invalid bitmap" ); GdkImage *gdk_image = gdk_image_get( M_BMPDATA->m_pixmap, 0, 0, M_BMPDATA->m_width, M_BMPDATA->m_height ); @@ -554,7 +542,7 @@ wxImage wxBitmap::ConvertToImage() const GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap ); if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent ); int bpp = visual->depth; - if ((bpp == 16) && (visual->red_mask == 0xfc00)) bpp = 15; + if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15; GdkColormap *cmap = gtk_widget_get_default_colormap();