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
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKWINDOWSXPSTYLE_P_P_H
6#define QQUICKWINDOWSXPSTYLE_P_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
20
21#include <private/qquickwindowsstyle_p_p.h>
22
23#include <QtCore/qmap.h>
24#include <QtCore/qt_windows.h>
25
26#include <uxtheme.h>
27#include <vssym32.h>
28
29#include <limits.h>
30
31QT_BEGIN_NAMESPACE
32
33class QDebug;
34
35namespace QQC2 {
36
37// TMT_TEXTSHADOWCOLOR is wrongly defined in mingw
38#if TMT_TEXTSHADOWCOLOR != 3818
39#undef TMT_TEXTSHADOWCOLOR
40#define TMT_TEXTSHADOWCOLOR 3818
41#endif
42#ifndef TST_NONE
43# define TST_NONE 0
44#endif
45
46// These defines are missing from the tmschema, but still exist as
47// states for their parts
48#ifndef MINBS_INACTIVE
49#define MINBS_INACTIVE 5
50#endif
51#ifndef MAXBS_INACTIVE
52#define MAXBS_INACTIVE 5
53#endif
54#ifndef RBS_INACTIVE
55#define RBS_INACTIVE 5
56#endif
57#ifndef HBS_INACTIVE
58#define HBS_INACTIVE 5
59#endif
60#ifndef CBS_INACTIVE
61#define CBS_INACTIVE 5
62#endif
63
64// Uncomment define below to build debug assisting code, and output
65// #define DEBUG_XP_STYLE
66
67// Declarations -----------------------------------------------------------------------------------
69{
70public:
71 explicit XPThemeData(const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
72 int part = 0, int state = 0, const QRect &r = QRect())
73 : window(w), painter(p), theme(themeIn), partId(part), stateId(state),
74 mirrorHorizontally(false), mirrorVertically(false), noBorder(false),
75 noContent(false), rect(r)
76 {}
77
78 HTHEME handle();
79
80 static RECT toRECT(const QRect &qr);
81 bool isValid();
82
83 QSizeF size();
84 QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS);
86
87 static QSizeF themeSize(const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0);
88 static QMarginsF themeMargins(const QRect &rect, const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
89 int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
90 static QMarginsF themeMargins(const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
91 int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
92
95
96 int theme;
97 HTHEME htheme = nullptr;
98 int partId;
100
107};
108
110 int theme = 0;
111 int partId = -1;
112 int stateId = -1;
113 bool noBorder = false;
114 bool noContent = false;
115
116 ThemeMapKey() = default;
118 : theme(data.theme), partId(data.partId), stateId(data.stateId),
119 noBorder(data.noBorder), noContent(data.noContent) {}
120
121};
122
123inline size_t qHash(const ThemeMapKey &key)
124{ return key.theme ^ key.partId ^ key.stateId; }
125
126inline bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
127{
128 return k1.theme == k2.theme
129 && k1.partId == k2.partId
130 && k1.stateId == k2.stateId;
131}
132
134 UnknownAlpha = -1, // Alpha of part & state not yet known
135 NoAlpha, // Totally opaque, no need to touch alpha (RGB)
136 MaskAlpha, // Alpha channel must be fixed (ARGB)
137 RealAlpha // Proper alpha values from Windows (ARGB_Premultiplied)
138};
139
141 AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state
142
143 bool dataValid : 1; // Only used to detect if hash value is ok
145 bool hasAlphaChannel : 1; // True = part & state has real Alpha
146 bool wasAlphaSwapped : 1; // True = alpha channel needs to be swapped
147 bool hadInvalidAlpha : 1; // True = alpha channel contained invalid alpha values
148
151};
152
153#ifndef QT_NO_DEBUG_STREAM
154QDebug operator<<(QDebug d, const XPThemeData &t);
155QDebug operator<<(QDebug d, const ThemeMapKey &k);
156QDebug operator<<(QDebug d, const ThemeMapData &td);
157#endif
158
160{
161 Q_DECLARE_PUBLIC(QWindowsXPStyle)
162public:
185
188
191
192 static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr);
193 static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr);
194
195 static HWND winId(const QWindow *window);
196
197 void init(bool force = false);
198 void cleanup(bool force = false);
199 void cleanupHandleMap();
200
201 HBITMAP buffer(int w = 0, int h = 0);
203 { return bufferDC;}
204
205 static bool useXP(bool update = false);
206 static QRect scrollBarGripperBounds(QStyle::State flags, XPThemeData *theme);
207
208 bool isTransparent(XPThemeData &themeData);
209 QRegion region(XPThemeData &themeData);
210
211 bool drawBackground(XPThemeData &themeData, qreal correctionFactor = 1);
212 bool drawBackgroundThruNativeBuffer(XPThemeData &themeData, qreal aditionalDevicePixelRatio, qreal correctionFactor);
213 bool drawBackgroundDirectly(HDC dc, XPThemeData &themeData, qreal aditionalDevicePixelRatio);
214
215 bool hasAlphaChannel(const QRect &rect);
216 bool fixAlphaChannel(const QRect &rect);
217 bool swapAlphaChannel(const QRect &rect, bool allPixels = false);
218
222 bool hasInitColors = false;
223
224 static HTHEME createTheme(int theme, HWND hwnd);
225 static QString themeName(int theme);
226 static inline bool hasTheme(int theme) { return theme >= 0 && theme < NThemes && m_themes[theme]; }
227 static bool isItemViewDelegateLineEdit(const QWidget *widget);
228 static bool isLineEditBaseColorSet(const QStyleOption *option, const QWidget *widget);
229
231
232private:
233#ifdef DEBUG_XP_STYLE
234 void dumpNativeDIB(int w, int h);
236#endif
237
238 static bool initVistaTreeViewTheming();
239 static void cleanupVistaTreeViewTheming();
240
241 static QBasicAtomicInt ref;
242 static bool use_xp;
243
244 QHash<ThemeMapKey, ThemeMapData> alphaCache;
245 HDC bufferDC = nullptr;
246 HBITMAP bufferBitmap = nullptr;
247 HBITMAP nullBitmap = nullptr;
248 uchar *bufferPixels = nullptr;
249 int bufferW = 0;
250 int bufferH = 0;
251
252 static HWND m_vistaTreeViewHelper;
253 static HTHEME m_themes[NThemes];
254};
255
257{
258 QSizeF result(0, 0);
259 if (isValid()) {
260 SIZE size;
261 if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size)))
262 result = QSize(size.cx, size.cy);
263 }
264 return result;
265}
266
267inline QMarginsF XPThemeData::margins(const QRect &qRect, int propId)
268{
269 QMarginsF result(0, 0, 0 ,0);
270 if (isValid()) {
271 MARGINS margins;
272 RECT rect = XPThemeData::toRECT(qRect);
273 if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins)))
274 result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
275 }
276 return result;
277}
278
279inline QMarginsF XPThemeData::margins(int propId)
280{
281 QMarginsF result(0, 0, 0 ,0);
282 if (isValid()) {
283 MARGINS margins;
284 if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins)))
285 result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
286 }
287 return result;
288}
289
290inline QSizeF XPThemeData::themeSize(const QWindow *w, QPainter *p, int themeIn, int part, int state)
291{
292 XPThemeData theme(w, p, themeIn, part, state);
293 return theme.size();
294}
295
296inline QMarginsF XPThemeData::themeMargins(const QRect &rect, const QWindow *w, QPainter *p, int themeIn,
297 int part, int state, int propId)
298{
299 XPThemeData theme(w, p, themeIn, part, state);
300 return theme.margins(rect, propId);
301}
302
303inline QMarginsF XPThemeData::themeMargins(const QWindow *w, QPainter *p, int themeIn,
304 int part, int state, int propId)
305{
306 XPThemeData theme(w, p, themeIn, part, state);
307 return theme.margins(propId);
308}
309
310} //namespace QQC2
311
312QT_END_NAMESPACE
313
314#endif //QQUICKWINDOWSXPSTYLE_P_P_H
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)
HBITMAP buffer(int w=0, int h=0)
static QString themeName(int 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.
QPixmap standardPixmap(StandardPixmap standardIcon, const QStyleOption *option) const override
void drawPrimitive(PrimitiveElement pe, const QStyleOption *option, QPainter *p) const override
QRect subElementRect(SubElement r, const QStyleOption *option) const override
QMargins ninePatchMargins(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, const QSize &imageSize) const override
QWindowsXPStyle(QWindowsXPStylePrivate &dd)
int styleHint(StyleHint hint, const QStyleOption *option=nullptr, QStyleHintReturn *returnData=nullptr) const override
~QWindowsXPStyle() override
QSize sizeFromContents(ContentsType ct, const QStyleOption *option, const QSize &contentsSize) const override
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr) const override
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *option, QPainter *p) const override
void drawControl(ControlElement element, const QStyleOption *option, QPainter *p) const override
int pixelMetric(PixelMetric pm, const QStyleOption *option=nullptr) const override
QPalette standardPalette() const override
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *option, SubControl sc) const override
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)
QMarginsF margins(int propId=TMT_CONTENTMARGINS)
static QMarginsF themeMargins(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())
static const int windowsItemHMargin
static void populateTitleBarButtonTheme(const QStyle *proxy, const QStyleOptionComplex *option, QStyle::SubControl subControl, bool isTitleBarActive, int part, XPThemeData *theme)
static HRGN qt_hrgn_from_qregion(const QRegion &region)
static const int windowsArrowHMargin
static HWND createTreeViewHelperWindow()
static QRegion scaleRegion(const QRegion &region, qreal factor)
static const int windowsRightBorder
static void qt_add_rect(HRGN &winRegion, QRect r)
static Qt::Orientation progressBarOrientation(const QStyleOption *option=nullptr)
static const int windowsItemFrame
static const int windowsItemVMargin
static const wchar_t * themeNames[QWindowsXPStylePrivate::NThemes]
static bool buttonVisible(const QStyle::SubControl sc, const QStyleOptionTitleBar *tb)
size_t qHash(const ThemeMapKey &key)
static QRectF scaleRect(const QRectF &r, qreal factor)
bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
#define RBS_INACTIVE
#define TMT_TEXTSHADOWCOLOR
#define TST_NONE
ThemeMapKey(const XPThemeData &data)
ThemeMapKey()=default