diff options
author | Dmitriy Shilin <dshil@fastmail.com> | 2019-01-08 04:20:29 -0800 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-01-18 15:20:43 +0100 |
commit | f00fc7ee17153ff70fa4fb2052a5b555af0c054c (patch) | |
tree | a49f2b853a072303b43b04b49b9e93f75224003d /vcl/inc/win/scoped_gdi.hxx | |
parent | 8e50e218d26dfab1038570476e11d616f91d3768 (diff) |
tdf#107792 vcl/win: introduce ScopedSelectedHFONT
Change-Id: If06ef869fc68976ee3ac6e671edd1bb4f992e716
Reviewed-on: https://gerrit.libreoffice.org/65964
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'vcl/inc/win/scoped_gdi.hxx')
-rw-r--r-- | vcl/inc/win/scoped_gdi.hxx | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/vcl/inc/win/scoped_gdi.hxx b/vcl/inc/win/scoped_gdi.hxx index ce6eadc8d0af..edbc086ada9c 100644 --- a/vcl/inc/win/scoped_gdi.hxx +++ b/vcl/inc/win/scoped_gdi.hxx @@ -15,53 +15,42 @@ #include <memory> -struct HBRUSHDeleter +template <typename H, auto DeleterFunc> struct GDIDeleter { - using pointer = HBRUSH; - void operator()(HBRUSH hBrush) { DeleteBrush(hBrush); } + using pointer = H; + void operator()(H h) { DeleterFunc(h); } }; -struct HRGNDeleter -{ - using pointer = HRGN; - void operator()(HRGN hRgn) { DeleteRegion(hRgn); } -}; +template <typename H, auto DeleterFunc> +using ScopedGDI = std::unique_ptr<H, GDIDeleter<H, DeleterFunc>>; -struct HDCDeleter -{ - using pointer = HDC; - void operator()(HDC hDC) { DeleteDC(hDC); } -}; +using ScopedHBRUSH = ScopedGDI<HBRUSH, DeleteBrush>; +using ScopedHRGN = ScopedGDI<HRGN, DeleteRegion>; +using ScopedHDC = ScopedGDI<HDC, DeleteDC>; +using ScopedHPEN = ScopedGDI<HPEN, DeletePen>; +using ScopedHFONT = ScopedGDI<HFONT, DeleteFont>; -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 +template <typename ScopedH, auto SelectorFunc> class ScopedSelectedGDI { public: - ScopedSelectedHPEN(HDC hDC, HPEN hPen) + ScopedSelectedGDI(HDC hDC, typename ScopedH::pointer h) : m_hDC(hDC) - , m_hOrigPen(SelectPen(hDC, hPen)) - , m_hSelectedPen(hPen) + , m_hSelectedH(h) + , m_hOrigH(SelectorFunc(hDC, h)) { } - ~ScopedSelectedHPEN() { SelectPen(m_hDC, m_hOrigPen); } + ~ScopedSelectedGDI() { SelectorFunc(m_hDC, m_hOrigH); } private: HDC m_hDC; - HPEN m_hOrigPen; - ScopedHPEN m_hSelectedPen; + ScopedH m_hSelectedH; + typename ScopedH::pointer m_hOrigH; }; +using ScopedSelectedHPEN = ScopedSelectedGDI<ScopedHPEN, SelectPen>; +using ScopedSelectedHFONT = ScopedSelectedGDI<ScopedHFONT, SelectFont>; + #endif // INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |