From: Vadim Zeitlin Date: Thu, 7 Jul 2011 13:05:22 +0000 (+0000) Subject: Add wxDCImpl::MSWApplyGDIPlusTransform() to formalize wxRendererMSW hack. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/53d4bdbc15e1ea445f993bde69eea277ea572016 Add wxDCImpl::MSWApplyGDIPlusTransform() to formalize wxRendererMSW hack. Replace the dynamic_cast<> used in wxMSW wxRenderer implementation code with a virtual function call. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68180 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dc.h b/include/wx/dc.h index 1f1731d4a6..f6346888ac 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -512,6 +512,19 @@ public: // this needs to overidden if the axis is inverted virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); +#ifdef __WXMSW__ + // Native Windows functions using the underlying HDC don't honour GDI+ + // transformations which may be applied to it. Using this function we can + // transform the coordinates manually before passing them to such functions + // (as in e.g. wxRendererMSW code). It doesn't do anything if this is not a + // wxGCDC. + virtual wxRect MSWApplyGDIPlusTransform(const wxRect& r) const + { + return r; + } +#endif // __WXMSW__ + + // --------------------------------------------------------- // the actual drawing API diff --git a/include/wx/dcgraph.h b/include/wx/dcgraph.h index b002a0408a..15369a32fe 100644 --- a/include/wx/dcgraph.h +++ b/include/wx/dcgraph.h @@ -193,6 +193,10 @@ public: virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; +#ifdef __WXMSW__ + virtual wxRect MSWApplyGDIPlusTransform(const wxRect& r) const; +#endif // __WXMSW__ + protected: // scaling variables bool m_logicalFunctionSupported; diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index ab615e482f..0582a2e025 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -1156,4 +1156,21 @@ void wxGCDCImpl::DoDrawCheckMark(wxCoord x, wxCoord y, wxDCImpl::DoDrawCheckMark(x,y,width,height); } +#ifdef __WXMSW__ +wxRect wxGCDCImpl::MSWApplyGDIPlusTransform(const wxRect& r) const +{ + wxGraphicsContext* const gc = GetGraphicsContext(); + wxCHECK_MSG( gc, r, wxT("Invalid wxGCDC") ); + + double x = 0, + y = 0; + gc->GetTransform().TransformPoint(&x, &y); + + wxRect rect(r); + rect.Offset(x, y); + + return rect; +} +#endif // __WXMSW__ + #endif // wxUSE_GRAPHICS_CONTEXT diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index 380ad2e383..d1b57d14fe 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -114,28 +114,6 @@ #define DFCS_HOT 0x1000 #endif -// When we're using GDI+, the DC might have transforms applied to it, -// but the renderer APIs don't respect them. So we need to apply -// the transforms to the rect ourselves. -inline -wxRect applyGDIPlusTransformsToRect(wxDC& dc, const wxRect& r) -{ - wxRect rect = r; -#if wxUSE_GRAPHICS_CONTEXT - wxGCDC* gcdc = dynamic_cast(&dc); - if (gcdc) - { - double xtrans = 0; - double ytrans = 0; - wxGraphicsContext* gc = gcdc->GetGraphicsContext(); - gc->GetTransform().TransformPoint(&xtrans, &ytrans); - rect.x = rect.x + (int)xtrans; - rect.y = rect.y + (int)ytrans; - } -#endif - return rect; -} - // ---------------------------------------------------------------------------- // methods common to wxRendererMSW and wxRendererXP // ---------------------------------------------------------------------------- @@ -417,7 +395,9 @@ wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win), const wxRect& rect, int flags) { - wxRect adjustedRect = applyGDIPlusTransformsToRect(dc, rect); + wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); + + wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); RECT r; wxCopyRectToRECT(adjustedRect, r); @@ -439,7 +419,9 @@ wxRendererMSW::DoDrawFrameControl(UINT type, const wxRect& rect, int flags) { - wxRect adjustedRect = applyGDIPlusTransformsToRect(dc, rect); + wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); + + wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); RECT r; wxCopyRectToRECT(adjustedRect, r); @@ -642,7 +624,9 @@ wxRendererXP::DrawComboBoxDropButton(wxWindow * win, return; } - wxRect adjustedRect = applyGDIPlusTransformsToRect(dc, rect); + wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); + + wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); RECT r; wxCopyRectToRECT(adjustedRect, r); @@ -683,7 +667,9 @@ wxRendererXP::DrawHeaderButton(wxWindow *win, return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); } - wxRect adjustedRect = applyGDIPlusTransformsToRect(dc, rect); + wxCHECK_MSG( dc.GetImpl(), -1, wxT("Invalid wxDC") ); + + wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); RECT r; wxCopyRectToRECT(adjustedRect, r); @@ -727,7 +713,9 @@ wxRendererXP::DrawTreeItemButton(wxWindow *win, return; } - wxRect adjustedRect = applyGDIPlusTransformsToRect(dc, rect); + wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); + + wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); RECT r; wxCopyRectToRECT(adjustedRect, r); @@ -767,7 +755,9 @@ wxRendererXP::DoDrawButtonLike(HTHEME htheme, const wxRect& rect, int flags) { - wxRect adjustedRect = applyGDIPlusTransformsToRect(dc, rect); + wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); + + wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); RECT r; wxCopyRectToRECT(adjustedRect, r);