1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_gfx_AutoHelpersWin_h
8 #define mozilla_gfx_AutoHelpersWin_h
15 // Get the global device context, and auto-release it on destruction.
18 AutoDC() { mDC
= ::GetDC(nullptr); }
20 ~AutoDC() { ::ReleaseDC(nullptr, mDC
); }
22 HDC
GetDC() { return mDC
; }
28 // Select a font into the given DC, and auto-restore.
29 class AutoSelectFont
{
31 AutoSelectFont(HDC aDC
, LOGFONTW
* aLogFont
) : mOwnsFont(false) {
32 mFont
= ::CreateFontIndirectW(aLogFont
);
36 mOldFont
= (HFONT
)::SelectObject(aDC
, mFont
);
42 AutoSelectFont(HDC aDC
, HFONT aFont
) : mOwnsFont(false) {
45 mOldFont
= (HFONT
)::SelectObject(aDC
, aFont
);
50 ::SelectObject(mDC
, mOldFont
);
52 ::DeleteObject(mFont
);
57 bool IsValid() const { return mFont
!= nullptr; }
59 HFONT
GetFont() const { return mFont
; }
69 } // namespace mozilla
71 #endif // mozilla_gfx_AutoHelpersWin_h