1 /* vim: se cin sw=2 ts=2 et : */
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "mozilla/ArrayUtils.h"
9 #include "mozilla/WindowsVersion.h"
11 #include "nsUXThemeData.h"
13 #include "nsToolkit.h"
14 #include "nsUXThemeConstants.h"
15 #include "gfxWindowsPlatform.h"
17 using namespace mozilla
;
18 using namespace mozilla::widget
;
20 MOZ_RUNINIT
nsUXThemeData::ThemeHandle
nsUXThemeData::sThemes
[eUXNumClasses
];
22 nsUXThemeData::ThemeHandle::~ThemeHandle() { Close(); }
24 void nsUXThemeData::ThemeHandle::OpenOnce(HWND aWindow
, LPCWSTR aClassList
) {
25 if (mHandle
.isSome()) {
29 mHandle
= Some(OpenThemeData(aWindow
, aClassList
));
32 void nsUXThemeData::ThemeHandle::Close() {
33 if (mHandle
.isNothing()) {
37 if (HANDLE rawHandle
= mHandle
.extract()) {
38 CloseThemeData(rawHandle
);
42 nsUXThemeData::ThemeHandle::operator HANDLE() {
43 return mHandle
.valueOr(nullptr);
46 void nsUXThemeData::Invalidate() {
47 for (auto& theme
: sThemes
) {
53 nsUXThemeData::GetTheme(nsUXThemeClass cls
) {
54 NS_ASSERTION(cls
< eUXNumClasses
, "Invalid theme class!");
55 sThemes
[cls
].OpenOnce(nullptr, GetClassName(cls
));
59 const wchar_t* nsUXThemeData::GetClassName(nsUXThemeClass cls
) {
80 MOZ_ASSERT_UNREACHABLE("unknown uxtheme class");
85 bool nsUXThemeData::sIsHighContrastOn
= false;
88 void nsUXThemeData::UpdateNativeThemeInfo() {
89 HIGHCONTRAST highContrastInfo
;
90 highContrastInfo
.cbSize
= sizeof(HIGHCONTRAST
);
92 SystemParametersInfo(SPI_GETHIGHCONTRAST
, 0, &highContrastInfo
, 0) &&
93 highContrastInfo
.dwFlags
& HCF_HIGHCONTRASTON
;