X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1e6feb95a79834836e88143b15d9f424ebe79621..abfcca57dd0d805ceec9e19c4be207614d79252a:/src/msw/bitmap.cpp?ds=sidebyside diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 437a6c4452..c4b2b8bed5 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -43,7 +43,10 @@ #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" @@ -112,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(); @@ -140,11 +144,18 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon) refData->m_bitmapMask = new wxMask((WXHBITMAP) wxInvertMask(iconInfo.hbmMask, w, h)); + + // delete the old one now as we don't need it any more + ::DeleteObject(iconInfo.hbmMask); + #if WXWIN_COMPATIBILITY_2 refData->m_ok = TRUE; #endif // WXWIN_COMPATIBILITY_2 return TRUE; +#else + return FALSE; +#endif } #endif // Win32 @@ -219,6 +230,7 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) { Init(); +#ifndef __WXMICROWIN__ wxBitmapRefData *refData = new wxBitmapRefData; m_refData = refData; @@ -234,9 +246,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; @@ -279,6 +291,7 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) } SetHBITMAP((WXHBITMAP)hbmp); +#endif } // Create from XPM data @@ -288,15 +301,15 @@ bool wxBitmap::CreateFromXpm(const char **data) Init(); 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; + return FALSE; #endif } @@ -323,6 +336,7 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type) bool wxBitmap::Create(int w, int h, int d) { +#ifndef __WXMICROWIN__ UnRef(); m_refData = new wxBitmapRefData; @@ -358,8 +372,10 @@ 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 } // ---------------------------------------------------------------------------- @@ -370,6 +386,10 @@ bool wxBitmap::Create(int w, int h, int d) 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(); @@ -415,6 +435,9 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) if (depth == -1) depth = wxDisplayDepth(); SetDepth( depth ); + // Copy the palette from the source image + SetPalette(image.GetPalette()); + // create a DIB header int headersize = sizeof(BITMAPINFOHEADER); BITMAPINFO *lpDIBh = (BITMAPINFO *) malloc( headersize ); @@ -451,12 +474,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(); @@ -507,8 +532,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() ) @@ -592,10 +619,15 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) 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") ); @@ -720,6 +752,7 @@ wxImage wxBitmap::ConvertToImage() const free(lpBits); return image; +#endif } #endif // wxUSE_IMAGE @@ -770,7 +803,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); @@ -799,6 +834,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()) && @@ -834,6 +870,9 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const DeleteDC(dcSrc); return ret; +#else + return wxBitmap(); +#endif } // ---------------------------------------------------------------------------- @@ -856,6 +895,8 @@ void wxBitmap::SetOk(bool isOk) } #endif // WXWIN_COMPATIBILITY_2 +#if wxUSE_PALETTE + void wxBitmap::SetPalette(const wxPalette& palette) { EnsureHasData(); @@ -863,6 +904,8 @@ void wxBitmap::SetPalette(const wxPalette& palette) GetBitmapData()->m_bitmapPalette = palette; } +#endif // wxUSE_PALETTE + void wxBitmap::SetMask(wxMask *mask) { EnsureHasData(); @@ -876,12 +919,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()); @@ -898,6 +945,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 @@ -920,6 +970,7 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const wxFreeDIB(lpDib); return tmpBitmap; +#endif } // ---------------------------------------------------------------------------- @@ -963,6 +1014,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") ); @@ -987,6 +1039,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 @@ -998,6 +1053,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; @@ -1007,6 +1064,8 @@ bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) return Create(bitmap, transparentColour); } } +#endif // wxUSE_PALETTE + return FALSE; } @@ -1014,6 +1073,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 ) @@ -1027,7 +1087,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) // scan the bitmap for the transparent colour and set the corresponding // pixels in the mask to BLACK and the rest to WHITE - COLORREF maskColour = wxColourToRGB(colour); + COLORREF maskColour = RGB(colour.Red(), colour.Green(), colour.Blue()); m_maskBitmap = (WXHBITMAP)::CreateBitmap(width, height, 1, 1, 0); HDC srcDC = ::CreateCompatibleDC(NULL); @@ -1093,6 +1153,9 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) ::DeleteDC(destDC); return ok; +#else + return FALSE; +#endif } // ---------------------------------------------------------------------------- @@ -1159,6 +1222,7 @@ bool wxBitmapHandler::SaveFile(wxBitmap *WXUNUSED(bitmap), // DIB functions // ---------------------------------------------------------------------------- +#ifndef __WXMICROWIN__ bool wxCreateDIB(long xSize, long ySize, long bitsPerPixel, HPALETTE hPal, LPBITMAPINFO* lpDIBHeader) { @@ -1206,6 +1270,7 @@ void wxFreeDIB(LPBITMAPINFO lpDIBHeader) { free(lpDIBHeader); } +#endif // ---------------------------------------------------------------------------- // other helper functions @@ -1213,6 +1278,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 @@ -1250,4 +1316,7 @@ extern HBITMAP wxInvertMask(HBITMAP hbmpMask, int w, int h) ::DeleteDC(hdcDst); return hbmpInvMask; +#else + return 0; +#endif }