X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/340196c001690cd784e7e3f2fc54cd449324f914..342751763793b5cdad252d731aac0618d0674e5b:/src/msw/bitmap.cpp diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 3dddc4177e..e74cf073a4 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -50,12 +50,10 @@ // macros // ---------------------------------------------------------------------------- -#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) -#endif // ============================================================================ // implementation @@ -122,12 +120,37 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon) wxBitmapRefData *refData = new wxBitmapRefData; m_refData = refData; - refData->m_width = icon.GetWidth(); - refData->m_height = icon.GetHeight(); + int w = icon.GetWidth(), + h = icon.GetHeight(); + + refData->m_width = w; + refData->m_height = h; refData->m_depth = wxDisplayDepth(); refData->m_hBitmap = (WXHBITMAP)iconInfo.hbmColor; - refData->m_bitmapMask = new wxMask((WXHBITMAP)iconInfo.hbmMask); + + // the mask returned by GetIconInfo() is inversed compared to the usual + // wxWin convention + HBITMAP hbmpMask = ::CreateBitmap(w, h, 1, 1, 0); + + // the icons mask is opposite to the usual wxWin convention + HDC dcSrc = ::CreateCompatibleDC(NULL); + HDC dcDst = ::CreateCompatibleDC(NULL); + (void)SelectObject(dcSrc, iconInfo.hbmMask); + (void)SelectObject(dcDst, hbmpMask); + + HBRUSH brush = ::CreateSolidBrush(RGB(255, 255, 255)); + RECT rect = { 0, 0, w, h }; + FillRect(dcDst, &rect, brush); + + BitBlt(dcDst, 0, 0, w, h, dcSrc, 0, 0, SRCINVERT); + + SelectObject(dcDst, NULL); + SelectObject(dcSrc, NULL); + DeleteDC(dcDst); + DeleteDC(dcSrc); + + refData->m_bitmapMask = new wxMask((WXHBITMAP)hbmpMask); #if WXWIN_COMPATIBILITY_2 refData->m_ok = TRUE; @@ -149,9 +172,9 @@ bool wxBitmap::CopyFromCursor(const wxCursor& cursor) wxFAIL_MSG( _T("don't know how to convert cursor to bitmap") ); return FALSE; -#endif // Win16 - +#else return CopyFromIconOrCursor(cursor); +#endif // Win16 } bool wxBitmap::CopyFromIcon(const wxIcon& icon) @@ -226,6 +249,46 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits SetHBITMAP((WXHBITMAP)hbmp); } +// GRG, Dic/99 +wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const +{ + wxCHECK_MSG( Ok() && + (rect.x >= 0) && (rect.y >= 0) && + (rect.x+rect.width <= GetWidth()) && + (rect.y+rect.height <= GetHeight()), + wxNullBitmap, wxT("Invalid bitmap or bitmap region") ); + + wxBitmap ret( rect.width, rect.height, GetDepth() ); + wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") ); + + // copy bitmap data + HDC dcSrc = ::CreateCompatibleDC(NULL); + HDC dcDst = ::CreateCompatibleDC(NULL); + SelectObject(dcSrc, (HBITMAP) GetHBITMAP()); + SelectObject(dcDst, (HBITMAP) ret.GetHBITMAP()); + BitBlt(dcDst, 0, 0, rect.width, rect.height, dcSrc, rect.x, rect.y, SRCCOPY); + + // copy mask if there is one + if (GetMask()) + { + HBITMAP hbmpMask = ::CreateBitmap(rect.width, rect.height, 1, 1, 0); + + SelectObject(dcSrc, (HBITMAP) GetMask()->GetMaskBitmap()); + SelectObject(dcDst, (HBITMAP) hbmpMask); + BitBlt(dcDst, 0, 0, rect.width, rect.height, dcSrc, rect.x, rect.y, SRCCOPY); + + wxMask *mask = new wxMask((WXHBITMAP) hbmpMask); + ret.SetMask(mask); + } + + SelectObject(dcDst, NULL); + SelectObject(dcSrc, NULL); + DeleteDC(dcDst); + DeleteDC(dcSrc); + + return ret; +} + // Create from XPM data wxBitmap::wxBitmap(char **data, wxControl *WXUNUSED(anItem)) {