Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickwindowsxpstyle_p_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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
4#ifndef QQUICKWINDOWSXPSTYLE_P_P_H
5#define QQUICKWINDOWSXPSTYLE_P_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18//#include <QtWidgets/private/qtwidgetsglobal_p.h>
21#include <QtCore/qmap.h>
22#include <qt_windows.h>
23
24#include <uxtheme.h>
25#include <vssym32.h>
26
27#include <limits.h>
28
30
31class QDebug;
32
33namespace QQC2 {
34
35// TMT_TEXTSHADOWCOLOR is wrongly defined in mingw
36#if TMT_TEXTSHADOWCOLOR != 3818
37#undef TMT_TEXTSHADOWCOLOR
38#define TMT_TEXTSHADOWCOLOR 3818
39#endif
40#ifndef TST_NONE
41# define TST_NONE 0
42#endif
43
44// These defines are missing from the tmschema, but still exist as
45// states for their parts
46#ifndef MINBS_INACTIVE
47#define MINBS_INACTIVE 5
48#endif
49#ifndef MAXBS_INACTIVE
50#define MAXBS_INACTIVE 5
51#endif
52#ifndef RBS_INACTIVE
53#define RBS_INACTIVE 5
54#endif
55#ifndef HBS_INACTIVE
56#define HBS_INACTIVE 5
57#endif
58#ifndef CBS_INACTIVE
59#define CBS_INACTIVE 5
60#endif
61
62// Uncomment define below to build debug assisting code, and output
63// #define DEBUG_XP_STYLE
64
65// Declarations -----------------------------------------------------------------------------------
67{
68public:
69 explicit XPThemeData(const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
70 int part = 0, int state = 0, const QRect &r = QRect())
71 : window(w), painter(p), theme(themeIn), partId(part), stateId(state),
74 {}
75
76 HTHEME handle();
77
78 static RECT toRECT(const QRect &qr);
79 bool isValid();
80
81 QSizeF size();
82 QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS);
84
85 static QSizeF themeSize(const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0);
86 static QMarginsF themeMargins(const QRect &rect, const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
87 int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
88 static QMarginsF themeMargins(const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
89 int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
90
93
94 int theme;
95 HTHEME htheme = nullptr;
96 int partId;
98
105};
106
108 int theme = 0;
109 int partId = -1;
110 int stateId = -1;
111 bool noBorder = false;
112 bool noContent = false;
113
114 ThemeMapKey() = default;
118
119};
120
121inline size_t qHash(const ThemeMapKey &key)
122{ return key.theme ^ key.partId ^ key.stateId; }
123
124inline bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
125{
126 return k1.theme == k2.theme
127 && k1.partId == k2.partId
128 && k1.stateId == k2.stateId;
129}
130
132 UnknownAlpha = -1, // Alpha of part & state not yet known
133 NoAlpha, // Totally opaque, no need to touch alpha (RGB)
134 MaskAlpha, // Alpha channel must be fixed (ARGB)
135 RealAlpha // Proper alpha values from Windows (ARGB_Premultiplied)
137
139 AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state
140
141 bool dataValid : 1; // Only used to detect if hash value is ok
143 bool hasAlphaChannel : 1; // True = part & state has real Alpha
144 bool wasAlphaSwapped : 1; // True = alpha channel needs to be swapped
145 bool hadInvalidAlpha : 1; // True = alpha channel contained invalid alpha values
146
149};
150
151#ifndef QT_NO_DEBUG_STREAM
152QDebug operator<<(QDebug d, const XPThemeData &t);
155#endif
156
158{
159 Q_DECLARE_PUBLIC(QWindowsXPStyle)
160public:
183
186
189
190 static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr);
191 static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr);
192
193 static HWND winId(const QWindow *window);
194
195 void init(bool force = false);
196 void cleanup(bool force = false);
197 void cleanupHandleMap();
198
199 HBITMAP buffer(int w = 0, int h = 0);
201 { return bufferDC;}
202
203 static bool useXP(bool update = false);
204 static QRect scrollBarGripperBounds(QStyle::State flags, XPThemeData *theme);
205
206 bool isTransparent(XPThemeData &themeData);
207 QRegion region(XPThemeData &themeData);
208
209 bool drawBackground(XPThemeData &themeData, qreal correctionFactor = 1);
210 bool drawBackgroundThruNativeBuffer(XPThemeData &themeData, qreal aditionalDevicePixelRatio, qreal correctionFactor);
211 bool drawBackgroundDirectly(HDC dc, XPThemeData &themeData, qreal aditionalDevicePixelRatio);
212
213 bool hasAlphaChannel(const QRect &rect);
214 bool fixAlphaChannel(const QRect &rect);
215 bool swapAlphaChannel(const QRect &rect, bool allPixels = false);
216
220 bool hasInitColors = false;
221
222 static HTHEME createTheme(int theme, HWND hwnd);
223 static QString themeName(int theme);
224 static inline bool hasTheme(int theme) { return theme >= 0 && theme < NThemes && m_themes[theme]; }
227
229
230private:
231#ifdef DEBUG_XP_STYLE
232 void dumpNativeDIB(int w, int h);
233 void showProperties(XPThemeData &themeData);
234#endif
235
236 static bool initVistaTreeViewTheming();
237 static void cleanupVistaTreeViewTheming();
238
239 static QBasicAtomicInt ref;
240 static bool use_xp;
241
242 QHash<ThemeMapKey, ThemeMapData> alphaCache;
243 HDC bufferDC = nullptr;
244 HBITMAP bufferBitmap = nullptr;
245 HBITMAP nullBitmap = nullptr;
246 uchar *bufferPixels = nullptr;
247 int bufferW = 0;
248 int bufferH = 0;
249
250 static HWND m_vistaTreeViewHelper;
251 static HTHEME m_themes[NThemes];
252};
253
255{
256 QSizeF result(0, 0);
257 if (isValid()) {
258 SIZE size;
259 if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size)))
260 result = QSize(size.cx, size.cy);
261 }
262 return result;
263}
264
265inline QMarginsF XPThemeData::margins(const QRect &qRect, int propId)
266{
267 QMarginsF result(0, 0, 0 ,0);
268 if (isValid()) {
269 MARGINS margins;
270 RECT rect = XPThemeData::toRECT(qRect);
271 if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins)))
272 result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
273 }
274 return result;
275}
276
278{
279 QMarginsF result(0, 0, 0 ,0);
280 if (isValid()) {
281 MARGINS margins;
282 if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins)))
283 result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
284 }
285 return result;
286}
287
288inline QSizeF XPThemeData::themeSize(const QWindow *w, QPainter *p, int themeIn, int part, int state)
289{
290 XPThemeData theme(w, p, themeIn, part, state);
291 return theme.size();
292}
293
294inline QMarginsF XPThemeData::themeMargins(const QRect &rect, const QWindow *w, QPainter *p, int themeIn,
295 int part, int state, int propId)
296{
297 XPThemeData theme(w, p, themeIn, part, state);
298 return theme.margins(rect, propId);
299}
300
302 int part, int state, int propId)
303{
304 XPThemeData theme(w, p, themeIn, part, state);
305 return theme.margins(propId);
306}
307
308} //namespace QQC2
309
311
312#endif //QQUICKWINDOWSXPSTYLE_P_P_H
\inmodule QtCore
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
\inmodule QtCore
Definition qmargins.h:270
\inmodule QtCore
Definition qmargins.h:24
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
bool fixAlphaChannel(const QRect &rect)
bool drawBackground(XPThemeData &themeData, qreal correctionFactor=1)
bool drawBackgroundDirectly(HDC dc, XPThemeData &themeData, qreal aditionalDevicePixelRatio)
bool hasAlphaChannel(const QRect &rect)
static HWND winId(const QWindow *window)
QRegion region(XPThemeData &themeData)
static QRect scrollBarGripperBounds(QStyle::State flags, XPThemeData *theme)
static bool isItemViewDelegateLineEdit(const QWidget *widget)
bool drawBackgroundThruNativeBuffer(XPThemeData &themeData, qreal aditionalDevicePixelRatio, qreal correctionFactor)
static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option=nullptr, const QWidget *widget=nullptr)
bool isTransparent(XPThemeData &themeData)
static bool useXP(bool update=false)
bool swapAlphaChannel(const QRect &rect, bool allPixels=false)
static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option=nullptr)
static bool isLineEditBaseColorSet(const QStyleOption *option, const QWidget *widget)
static HTHEME createTheme(int theme, HWND hwnd)
The QWindowsXPStyle class provides a Microsoft Windows XP-like look and feel.
QMarginsF margins(const QRect &rect, int propId=TMT_CONTENTMARGINS)
static RECT toRECT(const QRect &qr)
static QSizeF themeSize(const QWindow *w=nullptr, QPainter *p=nullptr, int themeIn=-1, int part=0, int state=0)
static QMarginsF themeMargins(const QRect &rect, const QWindow *w=nullptr, QPainter *p=nullptr, int themeIn=-1, int part=0, int state=0, int propId=TMT_CONTENTMARGINS)
XPThemeData(const QWindow *w=nullptr, QPainter *p=nullptr, int themeIn=-1, int part=0, int state=0, const QRect &r=QRect())
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
\inmodule QtGui
Definition qwindow.h:63
QOpenGLWidget * widget
[1]
rect
[4]
else opt state
[0]
QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType)
size_t qHash(const ThemeMapKey &key)
bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
Combined button and popup list for selecting options.
#define SIZE(large, small, mini)
static QString themeName()
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint buffer
GLbitfield flags
GLint ref
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLuint GLenum option
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:13
#define k1
unsigned char uchar
Definition qtypes.h:32
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
#define TMT_CONTENTMARGINS
aWidget window() -> setWindowTitle("New Window Title")
[2]
ThemeMapKey(const XPThemeData &data)
ThemeMapKey()=default