X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fec19ea9ff590f401ad17b1e2109b1e95d2f5e91..a111f2b216a90bacb254644d3cae526eddc9f9f1:/src/msw/bitmap.cpp diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 18958ff192..a68e54fa7d 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(), *this, wxT("invalid image") ); + wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") ); SetWidth( width ); SetHeight( bmpHeight ); if (depth == -1) depth = wxDisplayDepth(); @@ -400,7 +434,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) // create a DIB header int headersize = sizeof(BITMAPINFOHEADER); BITMAPINFO *lpDIBh = (BITMAPINFO *) malloc( headersize ); - wxCHECK_MSG( lpDIBh, bitmap, wxT("could not allocate memory for DIB header") ); + wxCHECK_MSG( lpDIBh, FALSE, wxT("could not allocate memory for DIB header") ); // Fill in the DIB header lpDIBh->bmiHeader.biSize = headersize; lpDIBh->bmiHeader.biWidth = (DWORD)width; @@ -433,12 +467,14 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) hbitmap = ::CreateCompatibleBitmap( hdc, width, bmpHeight ); ::SelectObject( memdc, hbitmap); +#if wxUSE_PALETTE HPALETTE hOldPalette = 0; if (image.GetPalette().Ok()) { hOldPalette = ::SelectPalette(memdc, (HPALETTE) image.GetPalette().GetHPALETTE(), FALSE); ::RealizePalette(memdc); } +#endif // wxUSE_PALETTE // copy image data into DIB data and then into DDB (in a loop) unsigned char *data = image.GetData(); @@ -489,8 +525,10 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) } SetHBITMAP( (WXHBITMAP) hbitmap ); +#if wxUSE_PALETTE if (hOldPalette) SelectPalette(memdc, hOldPalette, FALSE); +#endif // wxUSE_PALETTE // similarly, created an mono-bitmap for the possible mask if( image.HasMask() ) @@ -570,16 +608,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 +745,11 @@ wxImage wxBitmap::ConvertToImage() const free(lpBits); return image; +#endif } +#endif // wxUSE_IMAGE + bool wxBitmap::LoadFile(const wxString& filename, long type) { UnRef(); @@ -716,16 +762,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) @@ -746,7 +796,9 @@ bool wxBitmap::Create(void *data, long type, int width, int height, int depth) return handler->Create(this, data, type, width, height, depth); } -bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *palette) +bool wxBitmap::SaveFile(const wxString& filename, + int type, + const wxPalette *palette) { wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler); @@ -754,15 +806,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 +827,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 +863,9 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const DeleteDC(dcSrc); return ret; +#else + return wxBitmap(); +#endif } // ---------------------------------------------------------------------------- @@ -828,6 +888,8 @@ void wxBitmap::SetOk(bool isOk) } #endif // WXWIN_COMPATIBILITY_2 +#if wxUSE_PALETTE + void wxBitmap::SetPalette(const wxPalette& palette) { EnsureHasData(); @@ -835,6 +897,8 @@ void wxBitmap::SetPalette(const wxPalette& palette) GetBitmapData()->m_bitmapPalette = palette; } +#endif // wxUSE_PALETTE + void wxBitmap::SetMask(wxMask *mask) { EnsureHasData(); @@ -848,12 +912,16 @@ 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; LPBITMAPINFO lpDib; void *lpBits = (void*) NULL; +#if wxUSE_PALETTE if( GetPalette() && GetPalette()->Ok() ) { tmpBitmap.SetPalette(*GetPalette()); @@ -870,6 +938,9 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const memDC.SelectObject(tmpBitmap); memDC.SetPalette( palette ); } +#else // !wxUSE_PALETTE + hPal = (HPALETTE) ::GetStockObject(DEFAULT_PALETTE); +#endif // wxUSE_PALETTE/!wxUSE_PALETTE // set the height negative because in a DIB the order of the lines is // reversed @@ -892,6 +963,7 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const wxFreeDIB(lpDib); return tmpBitmap; +#endif } // ---------------------------------------------------------------------------- @@ -935,6 +1007,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 +1032,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 @@ -970,6 +1046,8 @@ bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) ::DeleteObject((HBITMAP) m_maskBitmap); m_maskBitmap = 0; } + +#if wxUSE_PALETTE if (bitmap.Ok() && bitmap.GetPalette()->Ok()) { unsigned char red, green, blue; @@ -979,6 +1057,8 @@ bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) return Create(bitmap, transparentColour); } } +#endif // wxUSE_PALETTE + return FALSE; } @@ -986,6 +1066,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 +1092,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 +1146,9 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) ::DeleteDC(destDC); return ok; +#else + return FALSE; +#endif } // ---------------------------------------------------------------------------- @@ -1127,6 +1215,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 +1263,7 @@ void wxFreeDIB(LPBITMAPINFO lpDIBHeader) { free(lpDIBHeader); } +#endif // ---------------------------------------------------------------------------- // other helper functions @@ -1181,6 +1271,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 +1309,7 @@ extern HBITMAP wxInvertMask(HBITMAP hbmpMask, int w, int h) ::DeleteDC(hdcDst); return hbmpInvMask; +#else + return 0; +#endif }