X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/097aeb99031e36e4306926d652e4bcccda8b71cb..5d483828d77426eed11fa19c3f2f318383a118dc:/src/msw/bitmap.cpp diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 00dfae1667..79b21b8e87 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,23 @@ 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); + + if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); + + return TRUE; +#else + return FALSE; +#endif } wxBitmap::wxBitmap(int w, int h, int d) @@ -302,7 +317,7 @@ wxBitmap::wxBitmap(void *data, long type, int width, int height, int depth) (void)Create(data, type, width, height, depth); } -wxBitmap::wxBitmap(const wxString& filename, long type) +wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type) { Init(); @@ -350,6 +365,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") ) @@ -391,7 +412,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) } // set bitmap parameters - wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") ); + wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") ); SetWidth( width ); SetHeight( bmpHeight ); if (depth == -1) depth = wxDisplayDepth(); @@ -570,7 +591,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 +600,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 +725,8 @@ wxImage wxBitmap::ConvertToImage() const return image; } +#endif // wxUSE_IMAGE + bool wxBitmap::LoadFile(const wxString& filename, long type) { UnRef(); @@ -716,16 +739,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 +781,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; } // ----------------------------------------------------------------------------