X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e4db172a3b318df9aff178eb6c5da149d56e0859..666e33ab46ed911cd94513c43fcc2bb191704000:/src/msw/bitmap.cpp diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 789fc53acf..8ef2b8b3f3 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -24,6 +24,8 @@ #pragma hdrstop #endif +#include "wx/bitmap.h" + #ifndef WX_PRECOMP #include @@ -32,22 +34,19 @@ #include "wx/app.h" #include "wx/palette.h" #include "wx/dcmemory.h" - #include "wx/bitmap.h" #include "wx/icon.h" #include "wx/log.h" + #include "wx/image.h" #endif #include "wx/msw/private.h" #if wxUSE_WXDIB -#include "wx/msw/dib.h" + #include "wx/msw/dib.h" #endif -#include "wx/image.h" -#include "wx/xpmdecod.h" - #ifdef wxHAVE_RAW_BITMAP -#include "wx/rawbmp.h" + #include "wx/rawbmp.h" #endif // missing from mingw32 header @@ -206,8 +205,13 @@ wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data) m_selectedInto = NULL; #endif - // can't copy the mask as the other bitmap destroys it + // (deep) copy the mask if present m_bitmapMask = NULL; + if (data.m_bitmapMask) + m_bitmapMask = new wxMask(*data.m_bitmapMask); + + // FIXME: we don't copy m_hBitmap currently but we should, see wxBitmap:: + // CloneRefData() wxASSERT_MSG( !data.m_isDIB, _T("can't copy bitmap locked for raw access!") ); @@ -253,6 +257,10 @@ wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *dataOrig) const if ( !data ) return NULL; + // FIXME: this method is backwards, it should just create a new + // wxBitmapRefData using its copy ctor but instead it modifies this + // bitmap itself and then returns its m_refData -- which works, of + // course (except in !wxUSE_WXDIB), but is completely illogical wxBitmap *self = wx_const_cast(wxBitmap *, this); #if wxUSE_WXDIB @@ -265,10 +273,19 @@ wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *dataOrig) const else #endif // wxUSE_WXDIB { - // don't copy the bitmap data, but do copy the size, depth, ... + // copy the bitmap data self->m_refData = new wxBitmapRefData(*data); } + // copy also the mask + wxMask * const maskSrc = data->GetMask(); + if ( maskSrc ) + { + wxBitmapRefData *selfdata = wx_static_cast(wxBitmapRefData *, m_refData); + + selfdata->SetMask(new wxMask(*maskSrc)); + } + return m_refData; } @@ -444,7 +461,7 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) reversed |= (unsigned char)(val & 0x01); val >>= 1; } - *dst++ = reversed; + *dst++ = ~reversed; } if ( padding ) @@ -472,24 +489,6 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) #endif } -// Create from XPM data -bool wxBitmap::CreateFromXpm(const char **data) -{ -#if wxUSE_IMAGE && wxUSE_XPM && wxUSE_WXDIB - 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 - wxUnusedVar(data); - return false; -#endif -} - wxBitmap::wxBitmap(int w, int h, int d) { (void)Create(w, h, d); @@ -500,7 +499,7 @@ wxBitmap::wxBitmap(int w, int h, const wxDC& dc) (void)Create(w, h, dc); } -wxBitmap::wxBitmap(void *data, long type, int width, int height, int depth) +wxBitmap::wxBitmap(const void* data, long type, int width, int height, int depth) { (void)Create(data, type, width, height, depth); } @@ -1025,7 +1024,7 @@ bool wxBitmap::LoadFile(const wxString& filename, long type) return false; } -bool wxBitmap::Create(void *data, long type, int width, int height, int depth) +bool wxBitmap::Create(const void* data, long type, int width, int height, int depth) { UnRef(); @@ -1165,15 +1164,6 @@ wxDC *wxBitmap::GetSelectedInto() const #endif -#if WXWIN_COMPATIBILITY_2_4 - -int wxBitmap::GetQuality() const -{ - return 0; -} - -#endif // WXWIN_COMPATIBILITY_2_4 - void wxBitmap::UseAlpha() { if ( GetBitmapData() ) @@ -1217,14 +1207,6 @@ void wxBitmap::SetMask(wxMask *mask) GetBitmapData()->SetMask(mask); } -#if WXWIN_COMPATIBILITY_2_4 - -void wxBitmap::SetQuality(int WXUNUSED(quality)) -{ -} - -#endif // WXWIN_COMPATIBILITY_2_4 - // ---------------------------------------------------------------------------- // raw bitmap access support // ---------------------------------------------------------------------------- @@ -1346,6 +1328,39 @@ wxMask::wxMask() m_maskBitmap = 0; } +// Copy constructor +wxMask::wxMask(const wxMask &mask) + : wxObject() +{ + BITMAP bmp; + + HDC srcDC = CreateCompatibleDC(0); + HDC destDC = CreateCompatibleDC(0); + + // GetBitmapDimensionEx won't work if SetBitmapDimensionEx wasn't used + // so we'll use GetObject() API here: + if (::GetObject((HGDIOBJ)mask.m_maskBitmap, sizeof(bmp), &bmp) == 0) + { + wxFAIL_MSG(wxT("Cannot retrieve the dimensions of the wxMask to copy")); + return; + } + + // create our HBITMAP + int w = bmp.bmWidth, h = bmp.bmHeight; + m_maskBitmap = (WXHBITMAP)CreateCompatibleBitmap(srcDC, w, h); + + // copy the mask's HBITMAP into our HBITMAP + SelectObject(srcDC, (HBITMAP) mask.m_maskBitmap); + SelectObject(destDC, (HBITMAP) m_maskBitmap); + + BitBlt(destDC, 0, 0, w, h, srcDC, 0, 0, SRCCOPY); + + SelectObject(srcDC, 0); + DeleteDC(srcDC); + SelectObject(destDC, 0); + DeleteDC(destDC); +} + // Construct a mask from a bitmap and a colour indicating // the transparent area wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour) @@ -1511,13 +1526,13 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) // ---------------------------------------------------------------------------- bool wxBitmapHandler::Create(wxGDIImage *image, - void *data, + const void* data, long flags, int width, int height, int depth) { wxBitmap *bitmap = wxDynamicCast(image, wxBitmap); - return bitmap ? Create(bitmap, data, flags, width, height, depth) : false; + return bitmap && Create(bitmap, data, flags, width, height, depth); } bool wxBitmapHandler::Load(wxGDIImage *image, @@ -1527,7 +1542,7 @@ bool wxBitmapHandler::Load(wxGDIImage *image, { wxBitmap *bitmap = wxDynamicCast(image, wxBitmap); - return bitmap ? LoadFile(bitmap, name, flags, width, height) : false; + return bitmap && LoadFile(bitmap, name, flags, width, height); } bool wxBitmapHandler::Save(wxGDIImage *image, @@ -1536,11 +1551,11 @@ bool wxBitmapHandler::Save(wxGDIImage *image, { wxBitmap *bitmap = wxDynamicCast(image, wxBitmap); - return bitmap ? SaveFile(bitmap, name, type) : false; + return bitmap && SaveFile(bitmap, name, type); } bool wxBitmapHandler::Create(wxBitmap *WXUNUSED(bitmap), - void *WXUNUSED(data), + const void* WXUNUSED(data), long WXUNUSED(type), int WXUNUSED(width), int WXUNUSED(height),