X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6840be66eb772c08f0cbb43de677509d5d132bb..f23b6f74bbf43799594924e94382b13587b4a57e:/include/wx/msw/private.h diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index 0b87d49b20..a2a08d8316 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -244,15 +244,26 @@ struct WXDLLEXPORT wxCOLORMAP extern wxCOLORMAP *wxGetStdColourMap(); // create a wxRect from Windows RECT -inline wxRect wxRectFromRECT(const RECT& r) +inline wxRect wxRectFromRECT(const RECT& rc) { - return wxRect(r.left, r.top, r.right - r.left, r.bottom - r.top); + return wxRect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); } // copy Windows RECT to our wxRect -inline void wxCopyRECTToRect(const RECT& r, wxRect& rect) +inline void wxCopyRECTToRect(const RECT& rc, wxRect& rect) { - rect = wxRectFromRECT(r); + rect = wxRectFromRECT(rc); +} + +// and vice versa +inline void wxCopyRectToRECT(const wxRect& rect, RECT& rc) +{ + // note that we don't use wxRect::GetRight() as it is one of compared to + // wxRectFromRECT() above + rc.top = rect.y; + rc.left = rect.x; + rc.right = rect.x + rect.width; + rc.bottom = rect.y + rect.height; } // translations between HIMETRIC units (which OLE likes) and pixels (which are @@ -415,25 +426,60 @@ private: DECLARE_NO_COPY_CLASS(SelectInHDC) }; +// a class which cleans up any GDI object +class AutoGDIObject +{ +protected: + AutoGDIObject(HGDIOBJ gdiobj) : m_gdiobj(gdiobj) { } + ~AutoGDIObject() { if ( m_gdiobj ) ::DeleteObject(m_gdiobj); } + + HGDIOBJ GetObject() const { return m_gdiobj; } + +private: + HGDIOBJ m_gdiobj; +}; + // a class for temporary bitmaps -class CompatibleBitmap +class CompatibleBitmap : private AutoGDIObject { public: CompatibleBitmap(HDC hdc, int w, int h) + : AutoGDIObject(::CreateCompatibleBitmap(hdc, w, h)) { - m_hbmp = ::CreateCompatibleBitmap(hdc, w, h); } - ~CompatibleBitmap() + operator HBITMAP() const { return (HBITMAP)GetObject(); } +}; + +// class automatically destroys the region object +class AutoHRGN : private AutoGDIObject +{ +public: + AutoHRGN(HRGN hrgn) : AutoGDIObject(hrgn) { } + + operator HRGN() const { return (HRGN)GetObject(); } +}; + +// class sets the specified clipping region during its life time +class HDCClipper +{ +public: + HDCClipper(HDC hdc, HRGN hrgn) + : m_hdc(hdc) { - if ( m_hbmp ) - ::DeleteObject(m_hbmp); + if ( !::SelectClipRgn(hdc, hrgn) ) + wxLogLastError(_T("SelectClipRgn")); } - operator HBITMAP() const { return m_hbmp; } + ~HDCClipper() + { + ::SelectClipRgn(m_hdc, NULL); + } private: - HBITMAP m_hbmp; + HDC m_hdc; + + DECLARE_NO_COPY_CLASS(HDCClipper) }; // when working with global pointers (which is unfortunately still necessary @@ -557,8 +603,8 @@ private: #define GetHaccel() ((HACCEL)GetHACCEL()) #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL())) -#define GetHbrush() ((HPEN)GetResourceHandle()) -#define GetHbrushOf(brush) ((HPEN)(brush).GetResourceHandle()) +#define GetHbrush() ((HBRUSH)GetResourceHandle()) +#define GetHbrushOf(brush) ((HBRUSH)(brush).GetResourceHandle()) #define GetHmenu() ((HMENU)GetHMenu()) #define GetHmenuOf(menu) ((HMENU)menu->GetHMenu()) @@ -676,6 +722,14 @@ extern WXDLLEXPORT wxSize wxGetHiconSize(HICON hicon); // Lines are drawn differently for WinCE and regular WIN32 WXDLLEXPORT void wxDrawLine(HDC hdc, int x1, int y1, int x2, int y2); +// fill the client rect of the given window on the provided dc using this brush +inline void wxFillRect(HWND hwnd, HDC hdc, HBRUSH hbr) +{ + RECT rc; + ::GetClientRect(hwnd, &rc); + ::FillRect(hdc, &rc, hbr); +} + // ---------------------------------------------------------------------------- // 32/64 bit helpers // ---------------------------------------------------------------------------- @@ -740,5 +794,4 @@ inline void *wxSetWindowUserData(HWND hwnd, void *data) #endif // wxUSE_GUI -#endif - // _WX_PRIVATE_H_ +#endif // _WX_PRIVATE_H_