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#pragma once
11
12#include <win/svsys.h>
13#include <win/wincomp.hxx>
14#include <win/saldata.hxx>
15
16#include <memory>
17
18template <typename H, auto DeleterFunc> struct GDIDeleter
19{
20 using pointer = H;
21 void operator()(H h) { DeleterFunc(h); }
22};
23
24template <typename H, auto DeleterFunc>
25using ScopedGDI = std::unique_ptr<H, GDIDeleter<H, DeleterFunc>>;
26
33
34template <typename ScopedH, auto SelectorFunc> class ScopedSelectedGDI
35{
36public:
37 ScopedSelectedGDI(HDC hDC, typename ScopedH::pointer h)
38 : m_hDC(hDC)
40 , m_hOrigH(SelectorFunc(hDC, h))
41 {
42 }
43
44 ~ScopedSelectedGDI() { SelectorFunc(m_hDC, m_hOrigH); }
45
46private:
47 HDC m_hDC;
48 ScopedH m_hSelectedH;
49 typename ScopedH::pointer m_hOrigH;
50};
51
55
56template <sal_uLong ID> class ScopedCachedHDC
57{
58public:
59 explicit ScopedCachedHDC(HBITMAP hBitmap)
60 : m_hDC(ImplGetCachedDC(ID, hBitmap))
61 {
62 }
63
65
66 HDC get() const { return m_hDC; }
67
68private:
69 HDC m_hDC;
70};
71
72/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
ScopedCachedHDC(HBITMAP hBitmap)
Definition: scoped_gdi.hxx:59
HDC get() const
Definition: scoped_gdi.hxx:66
ScopedSelectedGDI(HDC hDC, typename ScopedH::pointer h)
Definition: scoped_gdi.hxx:37
ScopedH::pointer m_hOrigH
Definition: scoped_gdi.hxx:49
ScopedH m_hSelectedH
Definition: scoped_gdi.hxx:48
sal_Int32 h
ScopedGDI< HRGN, DeleteRegion > ScopedHRGN
Definition: scoped_gdi.hxx:28
std::unique_ptr< H, GDIDeleter< H, DeleterFunc > > ScopedGDI
Definition: scoped_gdi.hxx:25
ScopedGDI< HPEN, DeletePen > ScopedHPEN
Definition: scoped_gdi.hxx:30
ScopedGDI< HBITMAP, DeleteBitmap > ScopedHBITMAP
Definition: scoped_gdi.hxx:32
ScopedGDI< HFONT, DeleteFont > ScopedHFONT
Definition: scoped_gdi.hxx:31
ScopedGDI< HDC, DeleteDC > ScopedHDC
Definition: scoped_gdi.hxx:29
ScopedGDI< HBRUSH, DeleteBrush > ScopedHBRUSH
Definition: scoped_gdi.hxx:27
void operator()(H h)
Definition: scoped_gdi.hxx:21
HDC ImplGetCachedDC(sal_uLong nID, HBITMAP hBmp=nullptr)
void ImplReleaseCachedDC(sal_uLong nID)