X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/097aeb99031e36e4306926d652e4bcccda8b71cb..491b5be8305968871bc289453ed088a70c3de044:/src/msw/bitmap.cpp diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 00dfae1667..8e8b4e0832 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -43,8 +43,12 @@ #include "wx/msw/private.h" #include "wx/log.h" +#if !defined(__WXMICROWIN__) #include "wx/msw/dib.h" +#endif + #include "wx/image.h" +#include "wx/xpmdecod.h" // missing from mingw32 header #ifndef CLR_INVALID @@ -111,6 +115,7 @@ void wxBitmap::Init() bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon) { +#ifndef __WXMICROWIN__ // it may be either HICON or HCURSOR HICON hicon = (HICON)icon.GetHandle(); @@ -144,6 +149,9 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon) #endif // WXWIN_COMPATIBILITY_2 return TRUE; +#else + return FALSE; +#endif } #endif // Win32 @@ -218,6 +226,7 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) { Init(); +#ifndef __WXMICROWIN__ wxBitmapRefData *refData = new wxBitmapRefData; m_refData = refData; @@ -233,9 +242,9 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) // we assume that it is in XBM format which is not quite the same as // the format CreateBitmap() wants because the order of bytes in the // line is inversed! - static const size_t bytesPerLine = (width + 7) / 8; - static const size_t padding = bytesPerLine % 2; - static const size_t len = height * ( padding + bytesPerLine ); + const size_t bytesPerLine = (width + 7) / 8; + const size_t padding = bytesPerLine % 2; + const size_t len = height * ( padding + bytesPerLine ); data = (char *)malloc(len); const char *src = bits; char *dst = data; @@ -278,14 +287,26 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) } SetHBITMAP((WXHBITMAP)hbmp); +#endif } // 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) @@ -302,7 +323,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(); @@ -311,6 +332,7 @@ wxBitmap::wxBitmap(const wxString& filename, long type) bool wxBitmap::Create(int w, int h, int d) { +#ifndef __WXMICROWIN__ UnRef(); m_refData = new wxBitmapRefData; @@ -346,12 +368,24 @@ bool wxBitmap::Create(int w, int h, int d) #if WXWIN_COMPATIBILITY_2 GetBitmapData()->m_ok = hbmp != 0; #endif // WXWIN_COMPATIBILITY_2 - return Ok(); +#else + return FALSE; +#endif } +// ---------------------------------------------------------------------------- +// wxImage to/from conversions +// ---------------------------------------------------------------------------- + +#if wxUSE_IMAGE + bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) { +#ifdef __WXMICROWIN__ + // TODO + return FALSE; +#else wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") ) m_refData = new wxBitmapRefData(); @@ -391,7 +425,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,16 +604,21 @@ 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; +#endif } wxImage wxBitmap::ConvertToImage() const { +#ifdef __WXMICROWIN__ + // TODO + return wxImage(); +#else wxImage image; - + wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") ); // create an wxImage object @@ -702,8 +741,11 @@ wxImage wxBitmap::ConvertToImage() const free(lpBits); return image; +#endif } +#endif // wxUSE_IMAGE + bool wxBitmap::LoadFile(const wxString& filename, long type) { UnRef(); @@ -716,16 +758,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 +800,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; } // ---------------------------------------------------------------------------- @@ -771,6 +821,7 @@ bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *pal wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const { +#ifndef __WXMICROWIN__ wxCHECK_MSG( Ok() && (rect.x >= 0) && (rect.y >= 0) && (rect.x+rect.width <= GetWidth()) && @@ -806,6 +857,9 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const DeleteDC(dcSrc); return ret; +#else + return wxBitmap(); +#endif } // ---------------------------------------------------------------------------- @@ -848,6 +902,9 @@ void wxBitmap::SetMask(wxMask *mask) // Contributed by Frederic Villeneuve wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const { +#ifdef __WXMICROWIN__ + return wxBitmap(); +#else wxMemoryDC memDC; wxBitmap tmpBitmap(GetWidth(), GetHeight(), dc.GetDepth()); HPALETTE hPal = (HPALETTE) NULL; @@ -892,6 +949,7 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const wxFreeDIB(lpDib); return tmpBitmap; +#endif } // ---------------------------------------------------------------------------- @@ -935,6 +993,7 @@ wxMask::~wxMask() // Create a mask from a mono bitmap (copies the bitmap). bool wxMask::Create(const wxBitmap& bitmap) { +#ifndef __WXMICROWIN__ wxCHECK_MSG( bitmap.Ok() && bitmap.GetDepth() == 1, FALSE, _T("can't create mask from invalid or not monochrome bitmap") ); @@ -959,6 +1018,9 @@ bool wxMask::Create(const wxBitmap& bitmap) SelectObject(destDC, 0); DeleteDC(destDC); return TRUE; +#else + return FALSE; +#endif } // Create a mask from a bitmap and a palette index indicating @@ -986,6 +1048,7 @@ bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) // the transparent area bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) { +#ifndef __WXMICROWIN__ wxCHECK_MSG( bitmap.Ok(), FALSE, _T("invalid bitmap in wxMask::Create") ); if ( m_maskBitmap ) @@ -1011,6 +1074,10 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) bool ok = TRUE; + // SelectObject() will fail + wxASSERT_MSG( !bitmap.GetSelectedInto(), + _T("bitmap can't be selected in another DC") ); + HGDIOBJ hbmpSrcOld = ::SelectObject(srcDC, GetHbitmapOf(bitmap)); if ( !hbmpSrcOld ) { @@ -1061,6 +1128,9 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) ::DeleteDC(destDC); return ok; +#else + return FALSE; +#endif } // ---------------------------------------------------------------------------- @@ -1127,6 +1197,7 @@ bool wxBitmapHandler::SaveFile(wxBitmap *WXUNUSED(bitmap), // DIB functions // ---------------------------------------------------------------------------- +#ifndef __WXMICROWIN__ bool wxCreateDIB(long xSize, long ySize, long bitsPerPixel, HPALETTE hPal, LPBITMAPINFO* lpDIBHeader) { @@ -1174,6 +1245,7 @@ void wxFreeDIB(LPBITMAPINFO lpDIBHeader) { free(lpDIBHeader); } +#endif // ---------------------------------------------------------------------------- // other helper functions @@ -1181,6 +1253,7 @@ void wxFreeDIB(LPBITMAPINFO lpDIBHeader) extern HBITMAP wxInvertMask(HBITMAP hbmpMask, int w, int h) { +#ifndef __WXMICROWIN__ wxCHECK_MSG( hbmpMask, 0, _T("invalid bitmap in wxInvertMask") ); // get width/height from the bitmap if not given @@ -1218,4 +1291,7 @@ extern HBITMAP wxInvertMask(HBITMAP hbmpMask, int w, int h) ::DeleteDC(hdcDst); return hbmpInvMask; +#else + return 0; +#endif }