1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
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>
19 template <typename H
, auto DeleterFunc
> struct GDIDeleter
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
38 ScopedSelectedGDI(HDC hDC
, typename
ScopedH::pointer h
)
41 , m_hOrigH(SelectorFunc(hDC
, h
))
45 ~ScopedSelectedGDI() { SelectorFunc(m_hDC
, m_hOrigH
); }
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
60 explicit ScopedCachedHDC(HBITMAP hBitmap
)
61 : m_hDC(ImplGetCachedDC(ID
, hBitmap
))
65 ~ScopedCachedHDC() { ImplReleaseCachedDC(ID
); }
67 HDC
get() const { return 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: */