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
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
#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())
// 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
// ----------------------------------------------------------------------------
#endif // wxUSE_GUI
-#endif
- // _WX_PRIVATE_H_
+#endif // _WX_PRIVATE_H_