calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / inc / win / scoped_gdi.hxx
blobd02ad9545749deca192d3170a2dc43df4e31b455
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.
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 */
10 #ifndef INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX
11 #define INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX
13 #include <win/svsys.h>
14 #include <win/wincomp.hxx>
15 #include <win/saldata.hxx>
17 #include <memory>
19 template <typename H, auto DeleterFunc> struct GDIDeleter
21 using pointer = H;
22 void operator()(H h) { DeleterFunc(h); }
25 template <typename H, auto DeleterFunc>
26 using ScopedGDI = std::unique_ptr<H, GDIDeleter<H, DeleterFunc>>;
28 using ScopedHBRUSH = ScopedGDI<HBRUSH, DeleteBrush>;
29 using ScopedHRGN = ScopedGDI<HRGN, DeleteRegion>;
30 using ScopedHDC = ScopedGDI<HDC, DeleteDC>;
31 using ScopedHPEN = ScopedGDI<HPEN, DeletePen>;
32 using ScopedHFONT = ScopedGDI<HFONT, DeleteFont>;
33 using ScopedHBITMAP = ScopedGDI<HBITMAP, DeleteBitmap>;
35 template <typename ScopedH, auto SelectorFunc> class ScopedSelectedGDI
37 public:
38 ScopedSelectedGDI(HDC hDC, typename ScopedH::pointer h)
39 : m_hDC(hDC)
40 , m_hSelectedH(h)
41 , m_hOrigH(SelectorFunc(hDC, h))
45 ~ScopedSelectedGDI() { SelectorFunc(m_hDC, m_hOrigH); }
47 private:
48 HDC m_hDC;
49 ScopedH m_hSelectedH;
50 typename ScopedH::pointer m_hOrigH;
53 using ScopedSelectedHPEN = ScopedSelectedGDI<ScopedHPEN, SelectPen>;
54 using ScopedSelectedHFONT = ScopedSelectedGDI<ScopedHFONT, SelectFont>;
55 using ScopedSelectedHBRUSH = ScopedSelectedGDI<ScopedHBRUSH, SelectBrush>;
57 template <sal_uLong ID> class ScopedCachedHDC
59 public:
60 explicit ScopedCachedHDC(HBITMAP hBitmap)
61 : m_hDC(ImplGetCachedDC(ID, hBitmap))
65 ~ScopedCachedHDC() { ImplReleaseCachedDC(ID); }
67 HDC get() const { return m_hDC; }
69 private:
70 HDC m_hDC;
73 #endif // INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */