summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowswindowclassdescription.cpp
blob: 55e36b4587a6f3773dd560e980add7b087f8fdbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qwindowswindowclassdescription.h"

#include <QtGui/qwindow.h>

#include "qwindowswindowclassregistry.h"

QT_BEGIN_NAMESPACE

using namespace Qt::StringLiterals;

QString QWindowsWindowClassDescription::classNameSuffix(Qt::WindowFlags type, unsigned int style, bool hasIcon)
{
    QString suffix;

    switch (type) {
        case Qt::Popup:
            suffix += "Popup"_L1;
            break;
        case Qt::Tool:
            suffix += "Tool"_L1;
            break;
        case Qt::ToolTip:
            suffix += "ToolTip"_L1;
            break;
        default:
            break;
    }

    if (style & CS_DROPSHADOW)
        suffix += "DropShadow"_L1;
    if (style & CS_SAVEBITS)
        suffix += "SaveBits"_L1;
    if (style & CS_OWNDC)
        suffix += "OwnDC"_L1;
    if (hasIcon)
        suffix += "Icon"_L1;

    return suffix;
}

bool QWindowsWindowClassDescription::computeHasIcon(Qt::WindowFlags flags, Qt::WindowFlags type)
{
    bool hasIcon = true;

    switch (type) {
        case Qt::Tool:
        case Qt::ToolTip:
        case Qt::Popup:
            hasIcon = false;
            break;
        case Qt::Dialog:
            if (!(flags & Qt::WindowSystemMenuHint))
                hasIcon = false; // QTBUG-2027, dialogs without system menu.
            break;
    }

    return hasIcon;
}

QWindowsWindowClassDescription QWindowsWindowClassDescription::fromName(QString name, WNDPROC procedure)
{
    return { std::move(name), procedure };
}

QWindowsWindowClassDescription QWindowsWindowClassDescription::fromWindow(const QWindow *window, WNDPROC procedure)
{
    Q_ASSERT(window);

    QWindowsWindowClassDescription description;
    description.procedure = procedure;

    const Qt::WindowFlags flags = window->flags();
    const Qt::WindowFlags type = flags & Qt::WindowType_Mask;
    // Determine style and icon.
    description.style = CS_DBLCLKS;
    description.hasIcon = computeHasIcon(flags, type);
    // The following will not set CS_OWNDC for any widget window, even if it contains a
    // QOpenGLWidget or QQuickWidget later on. That cannot be detected at this stage.
    if (window->surfaceType() == QSurface::OpenGLSurface || (flags & Qt::MSWindowsOwnDC))
        description.style |= CS_OWNDC;
    if (!(flags & Qt::NoDropShadowWindowHint)
        && (type == Qt::Popup || window->property("_q_windowsDropShadow").toBool())) {
        description.style |= CS_DROPSHADOW;
    }
    switch (type) {
        case Qt::Tool:
        case Qt::ToolTip:
        case Qt::Popup:
            description.style |= CS_SAVEBITS; // Save/restore background
            break;
    }
    description.name = "QWindow"_L1 + classNameSuffix(type, description.style, description.hasIcon);

    return description;
}

QDebug operator<<(QDebug dbg, const QWindowsWindowClassDescription &description)
{
    dbg << description.name
        << " style=0x" << Qt::hex << description.style << Qt::dec
        << " brush=" << description.brush
        << " hasIcon=" << description.hasIcon;

    return dbg;
}

QT_END_NAMESPACE