Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowswindowclassdescription.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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
6
7#include <QtGui/qwindow.h>
8#include <QtCore/qvariant.h>
9
11
13
14using namespace Qt::StringLiterals;
15
16QString QWindowsWindowClassDescription::classNameSuffix(Qt::WindowFlags type, unsigned int style, bool hasIcon)
17{
18 QString suffix;
19
20 switch (type) {
21 case Qt::Popup:
22 suffix += "Popup"_L1;
23 break;
24 case Qt::Tool:
25 suffix += "Tool"_L1;
26 break;
27 case Qt::ToolTip:
28 suffix += "ToolTip"_L1;
29 break;
30 default:
31 break;
32 }
33
34 if (style & CS_DROPSHADOW)
35 suffix += "DropShadow"_L1;
36 if (style & CS_SAVEBITS)
37 suffix += "SaveBits"_L1;
38 if (style & CS_OWNDC)
39 suffix += "OwnDC"_L1;
40 if (hasIcon)
41 suffix += "Icon"_L1;
42
43 return suffix;
44}
45
46bool QWindowsWindowClassDescription::computeHasIcon(Qt::WindowFlags flags, Qt::WindowFlags type)
47{
48 bool hasIcon = true;
49
50 switch (type) {
51 case Qt::Tool:
52 case Qt::ToolTip:
53 case Qt::Popup:
54 hasIcon = false;
55 break;
56 case Qt::Dialog:
57 if (!(flags & Qt::WindowSystemMenuHint))
58 hasIcon = false; // QTBUG-2027, dialogs without system menu.
59 break;
60 }
61
62 return hasIcon;
63}
64
65unsigned int QWindowsWindowClassDescription::computeWindowStyles(Qt::WindowFlags flags, Qt::WindowFlags type, WindowStyleOptions options)
66{
67 unsigned int style = CS_DBLCLKS;
68
69 // The following will not set CS_OWNDC for any widget window, even if it contains a
70 // QOpenGLWidget or QQuickWidget later on. That cannot be detected at this stage.
71 if (options.testFlag(WindowStyleOption::GLSurface) || (flags & Qt::MSWindowsOwnDC))
72 style |= CS_OWNDC;
73 if (!(flags & Qt::NoDropShadowWindowHint) && (type == Qt::Popup || options.testFlag(WindowStyleOption::DropShadow)))
74 style |= CS_DROPSHADOW;
75
76 switch (type) {
77 case Qt::Tool:
78 case Qt::ToolTip:
79 case Qt::Popup:
80 style |= CS_SAVEBITS; // Save/restore background
81 break;
82 }
83
84 return style;
85}
86
87QWindowsWindowClassDescription QWindowsWindowClassDescription::fromName(QString name, WNDPROC procedure)
88{
89 return { std::move(name), procedure };
90}
91
92QWindowsWindowClassDescription QWindowsWindowClassDescription::fromWindow(const QWindow *window, WNDPROC procedure)
93{
94 Q_ASSERT(window);
95
96 const Qt::WindowFlags flags = window->flags();
97 const Qt::WindowFlags type = flags & Qt::WindowType_Mask;
98
99 WindowStyleOptions options = WindowStyleOption::None;
100 if (window->surfaceType() == QSurface::OpenGLSurface)
101 options |= WindowStyleOption::GLSurface;
102 if (window->property("_q_windowsDropShadow").toBool())
103 options |= WindowStyleOption::DropShadow;
104
106 description.procedure = procedure;
107 description.style = computeWindowStyles(flags, type, options);
108 description.hasIcon = computeHasIcon(flags, type);
109 description.name = "QWindow"_L1 + classNameSuffix(type, description.style, description.hasIcon);
110
111 return description;
112}
113
114QDebug operator<<(QDebug dbg, const QWindowsWindowClassDescription &description)
115{
116 dbg << description.name
117 << " style=0x" << Qt::hex << description.style << Qt::dec
118 << " brush=" << description.brush
119 << " hasIcon=" << description.hasIcon;
120
121 return dbg;
122}
123
124QT_END_NAMESPACE
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const QWindowsWindowClassDescription &description)