LibreOffice Module vcl (master)  1
scoped_gdi.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX
11 #define INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX
12 
13 #include <win/svsys.h>
14 #include <win/wincomp.hxx>
15 #include <win/saldata.hxx>
16 
17 #include <memory>
18 
19 template <typename H, auto DeleterFunc> struct GDIDeleter
20 {
21  using pointer = H;
22  void operator()(H h) { DeleterFunc(h); }
23 };
24 
25 template <typename H, auto DeleterFunc>
26 using ScopedGDI = std::unique_ptr<H, GDIDeleter<H, DeleterFunc>>;
27 
34 
35 template <typename ScopedH, auto SelectorFunc> class ScopedSelectedGDI
36 {
37 public:
38  ScopedSelectedGDI(HDC hDC, typename ScopedH::pointer h)
39  : m_hDC(hDC)
40  , m_hSelectedH(h)
41  , m_hOrigH(SelectorFunc(hDC, h))
42  {
43  }
44 
45  ~ScopedSelectedGDI() { SelectorFunc(m_hDC, m_hOrigH); }
46 
47 private:
48  HDC m_hDC;
49  ScopedH m_hSelectedH;
50  typename ScopedH::pointer m_hOrigH;
51 };
52 
56 
57 template <sal_uLong ID> class ScopedCachedHDC
58 {
59 public:
60  explicit ScopedCachedHDC(HBITMAP hBitmap)
61  : m_hDC(ImplGetCachedDC(ID, hBitmap))
62  {
63  }
64 
66 
67  HDC get() const { return m_hDC; }
68 
69 private:
70  HDC m_hDC;
71 };
72 
73 #endif // INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX
74 
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
ScopedGDI< HBITMAP, DeleteBitmap > ScopedHBITMAP
Definition: scoped_gdi.hxx:33
std::unique_ptr< H, GDIDeleter< H, DeleterFunc >> ScopedGDI
Definition: scoped_gdi.hxx:26
#define ID
ScopedH m_hSelectedH
Definition: scoped_gdi.hxx:49
ScopedGDI< HPEN, DeletePen > ScopedHPEN
Definition: scoped_gdi.hxx:31
ScopedGDI< HRGN, DeleteRegion > ScopedHRGN
Definition: scoped_gdi.hxx:29
ScopedH::pointer m_hOrigH
Definition: scoped_gdi.hxx:50
ScopedSelectedGDI(HDC hDC, typename ScopedH::pointer h)
Definition: scoped_gdi.hxx:38
ScopedGDI< HBRUSH, DeleteBrush > ScopedHBRUSH
Definition: scoped_gdi.hxx:28
void ImplReleaseCachedDC(sal_uLong nID)
ScopedGDI< HFONT, DeleteFont > ScopedHFONT
Definition: scoped_gdi.hxx:32
void operator()(H h)
Definition: scoped_gdi.hxx:22
ScopedCachedHDC(HBITMAP hBitmap)
Definition: scoped_gdi.hxx:60
HDC ImplGetCachedDC(sal_uLong nID, HBITMAP hBmp=nullptr)
ScopedGDI< HDC, DeleteDC > ScopedHDC
Definition: scoped_gdi.hxx:30