Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwindowsthemecache.cpp
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qwindowsthemecache_p.h"
6
#
include
<
QtCore
/
qdebug
.
h
>
7
#
include
<
QtCore
/
qhash
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
// Theme names matching the QWindowsVistaStylePrivate::Theme enumeration.
12
constexpr
const
wchar_t
*
themeNames
[] = {
13
L"BUTTON", L"COMBOBOX", L"EDIT", L"HEADER", L"LISTVIEW",
14
L"MENU", L"PROGRESS", L"REBAR", L"SCROLLBAR", L"SPIN",
15
L"TAB", L"TASKDIALOG", L"TOOLBAR", L"TOOLTIP", L"TRACKBAR",
16
L"WINDOW", L"STATUS", L"TREEVIEW"
17
};
18
19
typedef
std
::
array
<
HTHEME
,
std
::
size
(
themeNames
)>
ThemeArray
;
20
typedef
QHash
<
HWND
,
ThemeArray
>
ThemesCache
;
21
Q_GLOBAL_STATIC
(
ThemesCache
,
themesCache
);
22
23
QString
QWindowsThemeCache
::themeName(
int
theme)
24
{
25
return
theme >= 0 && theme <
int
(std::size(themeNames))
26
? QString::fromWCharArray(themeNames[theme]) : QString();
27
}
28
29
HTHEME
QWindowsThemeCache
::createTheme(
int
theme, HWND hwnd)
30
{
31
if
(Q_UNLIKELY(theme < 0 || theme >=
int
(std::size(themeNames)) || !hwnd)) {
32
qWarning(
"Invalid parameters #%d, %p"
, theme, hwnd);
33
return
nullptr
;
34
}
35
36
// Get or create themes array for this window.
37
ThemesCache
*cache = themesCache();
38
auto
it = cache->find(hwnd);
39
if
(it == cache->end())
40
it = cache->insert(hwnd,
ThemeArray
{});
41
42
// Get or create theme data
43
ThemeArray
&themes = *it;
44
if
(!themes[theme]) {
45
const
wchar_t
*name =
themeNames
[theme];
46
themes[theme] = OpenThemeData(hwnd, name);
47
if
(Q_UNLIKELY(!themes[theme]))
48
qErrnoWarning(
"OpenThemeData() failed for theme %d (%s)."
,
49
theme, qPrintable(themeName(theme)));
50
}
51
return
themes[theme];
52
}
53
54
static
void
clearThemes
(
ThemeArray
&themes)
55
{
56
for
(
auto
&theme : themes) {
57
if
(theme) {
58
CloseThemeData(theme);
59
theme =
nullptr
;
60
}
61
}
62
}
63
64
void
QWindowsThemeCache
::
clearThemeCache
(HWND hwnd)
65
{
66
ThemesCache
*cache = themesCache();
67
auto
it = cache->find(hwnd);
68
if
(it == cache->end())
69
return
;
70
clearThemes(*it);
71
}
72
73
void
QWindowsThemeCache
::
clearAllThemeCaches
()
74
{
75
ThemesCache
*cache = themesCache();
76
for
(
auto
&themeArray : *cache)
77
clearThemes(themeArray);
78
}
79
80
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QWindowsThemeCache
Definition
qwindowsthemecache_p.h:27
QWindowsThemeCache::clearAllThemeCaches
Q_GUI_EXPORT void clearAllThemeCaches()
Definition
qwindowsthemecache.cpp:73
QWindowsThemeCache::clearThemeCache
Q_GUI_EXPORT void clearThemeCache(HWND hwnd)
Definition
qwindowsthemecache.cpp:64
Q_GLOBAL_STATIC
Q_GLOBAL_STATIC(QReadWriteLock, g_updateMutex)
ThemeArray
std::array< HTHEME, std::size(themeNames)> ThemeArray
Definition
qwindowsthemecache.cpp:19
clearThemes
static void clearThemes(ThemeArray &themes)
Definition
qwindowsthemecache.cpp:54
ThemesCache
QHash< HWND, ThemeArray > ThemesCache
Definition
qwindowsthemecache.cpp:20
themeNames
QT_BEGIN_NAMESPACE constexpr const wchar_t * themeNames[]
Definition
qwindowsthemecache.cpp:12
qtbase
src
gui
platform
windows
qwindowsthemecache.cpp
Generated on
for Qt by
1.18.0