[Libreoffice-commits] core.git: vcl/inc vcl/win

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sun Jan 13 15:41:48 UTC 2019


 vcl/inc/win/scoped_gdi.hxx            |   25 +++++++++++++++++++++++++
 vcl/win/gdi/salnativewidgets-luna.cxx |   19 ++++++-------------
 2 files changed, 31 insertions(+), 13 deletions(-)

New commits:
commit 889b57e48d94d11cd76578f421ef27534300a894
Author:     Dmitriy Shilin <dshil at fastmail.com>
AuthorDate: Tue Jan 8 04:06:08 2019 -0800
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Jan 13 16:41:23 2019 +0100

    tdf#107792 vcl/win: introduce ScopedSelectedHPEN
    
    Change-Id: Ifbf42e083388c1e678615489ffba1245e2b49665
    Reviewed-on: https://gerrit.libreoffice.org/65963
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/vcl/inc/win/scoped_gdi.hxx b/vcl/inc/win/scoped_gdi.hxx
index 80fbea8b4463..ce6eadc8d0af 100644
--- a/vcl/inc/win/scoped_gdi.hxx
+++ b/vcl/inc/win/scoped_gdi.hxx
@@ -33,9 +33,34 @@ struct HDCDeleter
     void operator()(HDC hDC) { DeleteDC(hDC); }
 };
 
+struct HPENDeleter
+{
+    using pointer = HPEN;
+    void operator()(HPEN hPen) { DeletePen(hPen); }
+};
+
 using ScopedHBRUSH = std::unique_ptr<HBRUSH, HBRUSHDeleter>;
 using ScopedHRGN = std::unique_ptr<HRGN, HRGNDeleter>;
 using ScopedHDC = std::unique_ptr<HDC, HDCDeleter>;
+using ScopedHPEN = std::unique_ptr<HPEN, HPENDeleter>;
+
+class ScopedSelectedHPEN
+{
+public:
+    ScopedSelectedHPEN(HDC hDC, HPEN hPen)
+        : m_hDC(hDC)
+        , m_hOrigPen(SelectPen(hDC, hPen))
+        , m_hSelectedPen(hPen)
+    {
+    }
+
+    ~ScopedSelectedHPEN() { SelectPen(m_hDC, m_hOrigPen); }
+
+private:
+    HDC m_hDC;
+    HPEN m_hOrigPen;
+    ScopedHPEN m_hSelectedPen;
+};
 
 #endif // INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX
 
diff --git a/vcl/win/gdi/salnativewidgets-luna.cxx b/vcl/win/gdi/salnativewidgets-luna.cxx
index bda55c40fabf..7f5a33737d15 100644
--- a/vcl/win/gdi/salnativewidgets-luna.cxx
+++ b/vcl/win/gdi/salnativewidgets-luna.cxx
@@ -44,6 +44,7 @@
 #include <win/svsys.h>
 #include <win/salgdi.h>
 #include <win/saldata.hxx>
+#include <win/scoped_gdi.hxx>
 
 #include <uxtheme.h>
 #include <vssym32.h>
@@ -52,6 +53,7 @@
 #include <string>
 #include <boost/optional.hpp>
 #include <ControlCacheKey.hxx>
+
 using namespace std;
 
 typedef map< wstring, HTHEME > ThemeMap;
@@ -457,20 +459,15 @@ static void impl_drawAeroToolbar( HDC hDC, RECT rc, bool bHorizontal )
         GdiGradientFill( hDC, vert, 2, g_rect, 1, GRADIENT_FILL_RECT_V );
 
         // and a darker horizontal line under that
-        HPEN hpen = CreatePen( PS_SOLID, 1, RGB( 0xb0, 0xb0, 0xb0 ) );
-        HPEN hOrigPen = static_cast<HPEN>(SelectObject(hDC, hpen));
+        ScopedSelectedHPEN(hDC, CreatePen(PS_SOLID, 1, RGB( 0xb0, 0xb0, 0xb0)));
 
         MoveToEx( hDC, rc.left, gradient_bottom, nullptr );
         LineTo( hDC, rc.right, gradient_bottom );
-
-        SelectObject(hDC, hOrigPen);
-        DeleteObject(hpen);
     }
     else
     {
-        HBRUSH hbrush = CreateSolidBrush( RGB( 0xf0, 0xf0, 0xf0 ) );
-        FillRect( hDC, &rc, hbrush );
-        DeleteObject( hbrush );
+        ScopedHBRUSH hbrush(CreateSolidBrush(RGB(0xf0, 0xf0, 0xf0)));
+        FillRect(hDC, &rc, hbrush.get());
 
         // darker line to distinguish the toolbar and viewshell
         // it is drawn only for the horizontal toolbars; it did not look well
@@ -483,14 +480,10 @@ static void impl_drawAeroToolbar( HDC hDC, RECT rc, bool bHorizontal )
             to_x = rc.right;
             from_y = to_y = rc.top;
 
-            HPEN hpen = CreatePen( PS_SOLID, 1, RGB( 0xb0, 0xb0, 0xb0 ) );
-            HPEN hOrigPen = static_cast<HPEN>(SelectObject(hDC, hpen));
+            ScopedSelectedHPEN(hDC, CreatePen(PS_SOLID, 1, RGB( 0xb0, 0xb0, 0xb0)));
 
             MoveToEx( hDC, from_x, from_y, nullptr );
             LineTo( hDC, to_x, to_y );
-
-            SelectObject(hDC, hOrigPen);
-            DeleteObject(hpen);
         }
     }
 }


More information about the Libreoffice-commits mailing list