From 5bfe0fdcc48718a4b16d20f6faf5c1ee5e6cb792 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 1 Feb 2018 17:35:02 +0100 Subject: [PATCH 1/2] Add helper wxRendererMSWBase::ConvertToRECT() Combine MSWApplyGDIPlusTransform() and wxCopyRectToRECT() into a single helper function to simplify the code and, importantly, to make it more difficult to forget call the former function. No real changes, this is a pure refactoring. --- src/msw/renderer.cpp | 45 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index fff5432e6d..e08ceb2a09 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -99,6 +99,16 @@ public: wxDC& dc, const wxRect& rect, int flags = 0) wxOVERRIDE = 0; + +protected: + // Helper function returning the MSW RECT corresponding to the wxRect + // adjusted for the given wxDC. + static RECT ConvertToRECT(wxDC& dc, const wxRect& rect) + { + RECT rc; + wxCopyRectToRECT(dc.GetImpl()->MSWApplyGDIPlusTransform(rect), rc); + return rc; + } }; // ---------------------------------------------------------------------------- @@ -411,10 +421,7 @@ wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win), { wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); - wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); - - RECT r; - wxCopyRectToRECT(adjustedRect, r); + RECT r = ConvertToRECT(dc, rect); int style = DFCS_SCROLLCOMBOBOX; if ( flags & wxCONTROL_DISABLED ) @@ -435,10 +442,7 @@ wxRendererMSW::DoDrawFrameControl(UINT type, { wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); - wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); - - RECT r; - wxCopyRectToRECT(adjustedRect, r); + RECT r = ConvertToRECT(dc, rect); int style = kind; if ( flags & wxCONTROL_CHECKED ) @@ -613,10 +617,7 @@ wxRendererXP::DrawComboBoxDropButton(wxWindow * win, wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); - wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); - - RECT r; - wxCopyRectToRECT(adjustedRect, r); + RECT r = ConvertToRECT(dc, rect); int state; if ( flags & wxCONTROL_PRESSED ) @@ -656,10 +657,7 @@ wxRendererXP::DrawHeaderButton(wxWindow *win, wxCHECK_MSG( dc.GetImpl(), -1, wxT("Invalid wxDC") ); - wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); - - RECT r; - wxCopyRectToRECT(adjustedRect, r); + RECT r = ConvertToRECT(dc, rect); int state; if ( flags & wxCONTROL_PRESSED ) @@ -702,10 +700,7 @@ wxRendererXP::DrawTreeItemButton(wxWindow *win, wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); - wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); - - RECT r; - wxCopyRectToRECT(adjustedRect, r); + RECT r = ConvertToRECT(dc, rect); int state = flags & wxCONTROL_EXPANDED ? GLPS_OPENED : GLPS_CLOSED; ::DrawThemeBackground @@ -744,10 +739,7 @@ wxRendererXP::DoDrawButtonLike(HTHEME htheme, { wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); - wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); - - RECT r; - wxCopyRectToRECT(adjustedRect, r); + RECT r = ConvertToRECT(dc, rect); // the base state is always 1, whether it is PBS_NORMAL, // {CBS,RBS}_UNCHECKEDNORMAL or CBS_NORMAL @@ -876,10 +868,7 @@ wxRendererXP::DrawCollapseButton(wxWindow *win, if (flags & wxCONTROL_EXPANDED) flags |= wxCONTROL_CHECKED; - wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); - - RECT r; - wxCopyRectToRECT(adjustedRect, r); + RECT r = ConvertToRECT(dc, rect); ::DrawThemeBackground ( From 92891cee476b2bd1a7d8848227bdb42cd37f2488 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 1 Feb 2018 17:38:23 +0100 Subject: [PATCH 2/2] Add missing GDI+ adjustments to wxRendererXP A few methods, notably including DrawFocusRect() and DrawItemText(), were missing MSWApplyGDIPlusTransform() calls that need to be done before drawing on an HDC corresponding to a wxGCDC object. Add them by replacing calls to wxCopyRectToRECT() with the just added ConvertToRECT() function, which adjusts the coordinates and copies wxRect to RECT at once. --- src/msw/renderer.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index e08ceb2a09..1886d68516 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -322,8 +322,7 @@ void wxRendererMSWBase::DrawFocusRect(wxWindow * WXUNUSED(win), const wxRect& rect, int WXUNUSED(flags)) { - RECT rc; - wxCopyRectToRECT(rect, rc); + RECT rc = ConvertToRECT(dc, rect); ::DrawFocusRect(GetHdcOf(dc.GetTempHDC()), &rc); } @@ -919,8 +918,8 @@ wxRendererXP::DrawItemSelectionRect(wxWindow *win, if ( ::IsThemePartDefined(hTheme, LVP_LISTITEM, 0) ) { - RECT rc; - wxCopyRectToRECT(rect, rc); + RECT rc = ConvertToRECT(dc, rect); + if ( ::IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTITEM, itemState) ) ::DrawThemeParentBackground(GetHwndOf(win), GetHdcOf(dc.GetTempHDC()), &rc); @@ -956,8 +955,7 @@ void wxRendererXP::DrawItemText(wxWindow* win, if ( s_DrawThemeTextEx && // Might be not available if we're under XP ::IsThemePartDefined(hTheme, LVP_LISTITEM, 0) ) { - RECT rc; - wxCopyRectToRECT(rect, rc); + RECT rc = ConvertToRECT(dc, rect); WXDTTOPTS textOpts; textOpts.dwSize = sizeof(textOpts); @@ -1081,8 +1079,7 @@ void wxRendererXP::DrawGauge(wxWindow* win, return; } - RECT r; - wxCopyRectToRECT(rect, r); + RECT r = ConvertToRECT(dc, rect); ::DrawThemeBackground( hTheme,