diff options
author | Dmitriy Shilin <dshil@fastmail.com> | 2019-01-08 04:06:08 -0800 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-01-13 16:41:23 +0100 |
commit | 889b57e48d94d11cd76578f421ef27534300a894 (patch) | |
tree | 372bd1feb952aef402c4249cd4f8c676b1588d61 /vcl | |
parent | 087962e390719b6027b4c2cf795c49a2b92624d7 (diff) |
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@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/win/scoped_gdi.hxx | 25 | ||||
-rw-r--r-- | vcl/win/gdi/salnativewidgets-luna.cxx | 19 |
2 files changed, 31 insertions, 13 deletions
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); } } } |