X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2aeec9ecccdb1b051848768f45a4ac1859ded5f3..803c55373484d1e2bfed85b46cbbfff8bfad1276:/src/msw/bitmap.cpp diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 0fe0be85c7..4c21494fcb 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -45,6 +45,7 @@ #include "wx/msw/dib.h" #include "wx/image.h" +#include "wx/xpmdecod.h" // missing from mingw32 header #ifndef CLR_INVALID @@ -283,9 +284,20 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) // Create from XPM data bool wxBitmap::CreateFromXpm(const char **data) { +#if wxUSE_IMAGE && wxUSE_XPM Init(); - return Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0); + wxCHECK_MSG( data != NULL, FALSE, wxT("invalid bitmap data") ) + + wxXPMDecoder decoder; + wxImage img = decoder.ReadData(data); + wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") ) + + *this = wxBitmap(img); + return TRUE; +#else + return FALSE; +#endif } wxBitmap::wxBitmap(int w, int h, int d) @@ -350,6 +362,12 @@ bool wxBitmap::Create(int w, int h, int d) return Ok(); } +// ---------------------------------------------------------------------------- +// wxImage to/from conversions +// ---------------------------------------------------------------------------- + +#if wxUSE_IMAGE + bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) { wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") ) @@ -570,7 +588,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) // check the wxBitmap object GetBitmapData()->SetOk(); #endif // WXWIN_COMPATIBILITY_2 - + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); return TRUE; @@ -579,7 +597,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) wxImage wxBitmap::ConvertToImage() const { wxImage image; - + wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") ); // create an wxImage object @@ -704,6 +722,8 @@ wxImage wxBitmap::ConvertToImage() const return image; } +#endif // wxUSE_IMAGE + bool wxBitmap::LoadFile(const wxString& filename, long type) { UnRef(); @@ -716,16 +736,20 @@ bool wxBitmap::LoadFile(const wxString& filename, long type) return handler->LoadFile(this, filename, type, -1, -1); } +#if wxUSE_IMAGE else { wxImage image; - if ( !image.LoadFile( filename, type ) || !image.Ok() ) - return FALSE; - - *this = image.ConvertToBitmap(); + if ( image.LoadFile( filename, type ) && image.Ok() ) + { + *this = image.ConvertToBitmap(); - return TRUE; + return TRUE; + } } +#endif // wxUSE_IMAGE + + return FALSE; } bool wxBitmap::Create(void *data, long type, int width, int height, int depth) @@ -754,15 +778,19 @@ bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *pal { return handler->SaveFile(this, filename, type, palette); } +#if wxUSE_IMAGE else { // FIXME what about palette? shouldn't we use it? wxImage image( *this ); - if (!image.Ok()) - return FALSE; - - return image.SaveFile( filename, type ); + if ( image.Ok() ) + { + return image.SaveFile(filename, type); + } } +#endif // wxUSE_IMAGE + + return FALSE; } // ----------------------------------------------------------------------------