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
19template <typename H, auto DeleterFunc> struct GDIDeleter
20{
21 using pointer = H;
22 void operator()(H h) { DeleterFunc(h); }
23};
24
25template <typename H, auto DeleterFunc>
26using ScopedGDI = std::unique_ptr<H, GDIDeleter<H, DeleterFunc>>;
27
34
35template <typename ScopedH, auto SelectorFunc> class ScopedSelectedGDI
36{
37public:
38 ScopedSelectedGDI(HDC hDC, typename ScopedH::pointer h)
39 : m_hDC(hDC)
41 , m_hOrigH(SelectorFunc(hDC, h))
42 {
43 }
44
45 ~ScopedSelectedGDI() { SelectorFunc(m_hDC, m_hOrigH); }
46
47private:
48 HDC m_hDC;
49 ScopedH m_hSelectedH;
50 typename ScopedH::pointer m_hOrigH;
51};
52
56
57template <sal_uLong ID> class ScopedCachedHDC
58{
59public:
60 explicit ScopedCachedHDC(HBITMAP hBitmap)
61 : m_hDC(ImplGetCachedDC(ID, hBitmap))
62 {
63 }
64
66
67 HDC get() const { return m_hDC; }
68
69private:
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: */
ScopedCachedHDC(HBITMAP hBitmap)
Definition: scoped_gdi.hxx:60
HDC get() const
Definition: scoped_gdi.hxx:67
ScopedSelectedGDI(HDC hDC, typename ScopedH::pointer h)
Definition: scoped_gdi.hxx:38
ScopedH::pointer m_hOrigH
Definition: scoped_gdi.hxx:50
ScopedH m_hSelectedH
Definition: scoped_gdi.hxx:49
sal_Int32 h
ScopedGDI< HRGN, DeleteRegion > ScopedHRGN
Definition: scoped_gdi.hxx:29
std::unique_ptr< H, GDIDeleter< H, DeleterFunc > > ScopedGDI
Definition: scoped_gdi.hxx:26
ScopedGDI< HPEN, DeletePen > ScopedHPEN
Definition: scoped_gdi.hxx:31
ScopedGDI< HBITMAP, DeleteBitmap > ScopedHBITMAP
Definition: scoped_gdi.hxx:33
ScopedGDI< HFONT, DeleteFont > ScopedHFONT
Definition: scoped_gdi.hxx:32
ScopedGDI< HDC, DeleteDC > ScopedHDC
Definition: scoped_gdi.hxx:30
ScopedGDI< HBRUSH, DeleteBrush > ScopedHBRUSH
Definition: scoped_gdi.hxx:28
void operator()(H h)
Definition: scoped_gdi.hxx:22
HDC ImplGetCachedDC(sal_uLong nID, HBITMAP hBmp=nullptr)
void ImplReleaseCachedDC(sal_uLong nID)