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