X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d9c8e68e58c5d6b0debc5df02b8fa6dba719e12e..37b8e6798782278fdfe4f3c1291aaff55cdbb8c9:/src/msw/bitmap.cpp diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 7f7aa14f75..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 @@ -174,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) @@ -251,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)) {