1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QWIZARD_WIN_P_H
41 #define QWIZARD_WIN_P_H
42 
43 //
44 //  W A R N I N G
45 //  -------------
46 //
47 // This file is not part of the Qt API.  It exists purely as an
48 // implementation detail.  This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtWidgets/private/qtwidgetsglobal_p.h>
55 
56 #if QT_CONFIG(style_windowsvista)
57 
58 #include <qobject.h>
59 #include <qwidget.h>
60 #include <qabstractbutton.h>
61 #include <QtWidgets/private/qwidget_p.h>
62 #include <QtWidgets/private/qstylehelper_p.h>
63 #include <qt_windows.h>
64 
65 QT_REQUIRE_CONFIG(wizard);
66 
67 QT_BEGIN_NAMESPACE
68 
69 class QVistaBackButton : public QAbstractButton
70 {
71 public:
72     QVistaBackButton(QWidget *widget);
73 
74     QSize sizeHint() const override;
minimumSizeHint()75     inline QSize minimumSizeHint() const override
76     { return sizeHint(); }
77 
78     void enterEvent(QEvent *event) override;
79     void leaveEvent(QEvent *event) override;
80     void paintEvent(QPaintEvent *event) override;
81 };
82 
83 class QWizard;
84 
85 class QVistaHelper : public QObject
86 {
87     Q_DISABLE_COPY_MOVE(QVistaHelper)
88 public:
89     QVistaHelper(QWizard *wizard);
90     ~QVistaHelper() override;
91     enum TitleBarChangeType { NormalTitleBar, ExtendedTitleBar };
92     void updateCustomMargins(bool vistaMargins);
93     bool setDWMTitleBar(TitleBarChangeType type);
94     void setTitleBarIconAndCaptionVisible(bool visible);
95     void mouseEvent(QEvent *event);
96 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
97     bool handleWinEvent(MSG *message, qintptr *result);
98 #else
99     bool handleWinEvent(MSG *message, long *result);
100 #endif
101     void resizeEvent(QResizeEvent *event);
102     void paintEvent(QPaintEvent *event);
backButton()103     QVistaBackButton *backButton() const { return backButton_; }
104     void disconnectBackButton();
hideBackButton()105     void hideBackButton() { if (backButton_) backButton_->hide(); }
106     QColor basicWindowFrameColor();
107     enum VistaState { VistaAero, VistaBasic, Classic, Dirty };
108     static VistaState vistaState();
titleBarSize()109     static int titleBarSize() { return QVistaHelper::titleBarSizeDp() / QVistaHelper::m_devicePixelRatio; }
titleBarSizeDp()110     static int titleBarSizeDp() { return QVistaHelper::frameSizeDp() + QVistaHelper::captionSizeDp(); }
topPadding(const QPaintDevice * device)111     static int topPadding(const QPaintDevice *device) { // padding under text
112         return int(QStyleHelper::dpiScaled(4, device));
113     }
114     static int topOffset(const QPaintDevice *device);
115 
116     static HDC backingStoreDC(const QWidget *wizard, QPoint *offset);
117 
118 private:
119     HWND wizardHWND() const;
120     bool drawTitleText(QPainter *painter, const QString &text, const QRect &rect, HDC hdc);
121     static bool drawBlackRect(const QRect &rect, HDC hdc);
122 
frameSize()123     static int frameSize() { return QVistaHelper::frameSizeDp() / QVistaHelper::m_devicePixelRatio; }
124     static int frameSizeDp();
captionSize()125     static int captionSize() { return QVistaHelper::captionSizeDp() / QVistaHelper::m_devicePixelRatio; }
126     static int captionSizeDp();
127 
backButtonSize(const QPaintDevice * device)128     static int backButtonSize(const QPaintDevice *device)
129         { return int(QStyleHelper::dpiScaled(30, device)); }
130     static int iconSize(const QPaintDevice *device);
131     static int glowSize(const QPaintDevice *device);
leftMargin(const QPaintDevice * device)132     int leftMargin(const QPaintDevice *device)
133         { return backButton_->isVisible() ? backButtonSize(device) + iconSpacing : 0; }
134 
135     int titleOffset();
136     void drawTitleBar(QPainter *painter);
137     void setMouseCursor(QPoint pos);
138     void collapseTopFrameStrut();
139 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
140     bool winEvent(MSG *message, qintptr *result);
141 #else
142     bool winEvent(MSG *message, long *result);
143 #endif
144     void mouseMoveEvent(QMouseEvent *event);
145     void mousePressEvent(QMouseEvent *event);
146     void mouseReleaseEvent(QMouseEvent *event);
147     bool eventFilter(QObject *obj, QEvent *event) override;
148 
149     static int instanceCount;
150     static VistaState cachedVistaState;
151     static bool isCompositionEnabled();
152     static bool isThemeActive();
153     enum Changes { resizeTop, movePosition, noChange } change;
154     QPoint pressedPos;
155     bool pressed;
156     QRect rtTop;
157     QRect rtTitle;
158     QWizard *wizard;
159     QVistaBackButton *backButton_;
160 
161     int titleBarOffset;  // Extra spacing above the text
162     int iconSpacing;    // Space between button and icon
163     static int m_devicePixelRatio;
164 };
165 
166 
167 QT_END_NAMESPACE
168 
169 #endif // style_windowsvista
170 #endif // QWIZARD_WIN_P_H
171