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/qhash.h>
24#include <QtCore/qmap.h>
25#include <QtCore/qt_windows.h>
26
27#include <uxtheme.h>
28#include <vssym32.h>
29
30#include <limits.h>
31
32QT_BEGIN_NAMESPACE
33
34class QDebug;
35
36namespace QQC2 {
37
38// TMT_TEXTSHADOWCOLOR is wrongly defined in mingw
39#if TMT_TEXTSHADOWCOLOR != 3818
40#undef TMT_TEXTSHADOWCOLOR
41#define TMT_TEXTSHADOWCOLOR 3818
42#endif
43#ifndef TST_NONE
44# define TST_NONE 0
45#endif
46
47// These defines are missing from the tmschema, but still exist as
48// states for their parts
49#ifndef MINBS_INACTIVE
50#define MINBS_INACTIVE 5
51#endif
52#ifndef MAXBS_INACTIVE
53#define MAXBS_INACTIVE 5
54#endif
55#ifndef RBS_INACTIVE
56#define RBS_INACTIVE 5
57#endif
58#ifndef HBS_INACTIVE
59#define HBS_INACTIVE 5
60#endif
61#ifndef CBS_INACTIVE
62#define CBS_INACTIVE 5
63#endif
64
65// Uncomment define below to build debug assisting code, and output
66// #define DEBUG_XP_STYLE
67
68// Declarations -----------------------------------------------------------------------------------
70{
71public:
72 explicit XPThemeData(const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
73 int part = 0, int state = 0, const QRect &r = QRect())
74 : window(w), painter(p), theme(themeIn), partId(part), stateId(state),
75 mirrorHorizontally(false), mirrorVertically(false), noBorder(false),
76 noContent(false), rect(r)
77 {}
78
79 HTHEME handle();
80
81 static RECT toRECT(const QRect &qr);
82 bool isValid();
83
84 QSizeF size();
85 QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS);
87
88 static QSizeF themeSize(const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0);
89 static QMarginsF themeMargins(const QRect &rect, const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
90 int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
91 static QMarginsF themeMargins(const QWindow *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
92 int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
93
96
97 int theme;
98 HTHEME htheme = nullptr;
99 int partId;
101
108};
109
111 int theme = 0;
112 int partId = -1;
113 int stateId = -1;
114 bool noBorder = false;
115 bool noContent = false;
116
117 ThemeMapKey() = default;
119 : theme(data.theme), partId(data.partId), stateId(data.stateId),
120 noBorder(data.noBorder), noContent(data.noContent) {}
121
122private:
123 friend size_t qHash(const ThemeMapKey &key, size_t seed = 0) noexcept
124 { return qHashMulti(seed, key.theme, key.partId, key.stateId); }
125
126};
127
128inline bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
129{
130 return k1.theme == k2.theme
131 && k1.partId == k2.partId
132 && k1.stateId == k2.stateId;
133}
134
136 UnknownAlpha = -1, // Alpha of part & state not yet known
137 NoAlpha, // Totally opaque, no need to touch alpha (RGB)
138 MaskAlpha, // Alpha channel must be fixed (ARGB)
139 RealAlpha // Proper alpha values from Windows (ARGB_Premultiplied)
140};
141
143 AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state
144
145 bool dataValid : 1; // Only used to detect if hash value is ok
147 bool hasAlphaChannel : 1; // True = part & state has real Alpha
148 bool wasAlphaSwapped : 1; // True = alpha channel needs to be swapped
149 bool hadInvalidAlpha : 1; // True = alpha channel contained invalid alpha values
150
153};
154
155#ifndef QT_NO_DEBUG_STREAM
156QDebug operator<<(QDebug d, const XPThemeData &t);
157QDebug operator<<(QDebug d, const ThemeMapKey &k);
158QDebug operator<<(QDebug d, const ThemeMapData &td);
159#endif
160
162{
163 Q_DECLARE_PUBLIC(QWindowsXPStyle)
164public:
187
190
193
194 static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr);
195 static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr);
196
197 static HWND winId(const QWindow *window);
198
199 void init(bool force = false);
200 void cleanup(bool force = false);
201 void cleanupHandleMap();
202
203 HBITMAP buffer(int w = 0, int h = 0);
205 { return bufferDC;}
206
207 static bool useXP(bool update = false);
208 static QRect scrollBarGripperBounds(QStyle::State flags, XPThemeData *theme);
209
210 bool isTransparent(XPThemeData &themeData);
211 QRegion region(XPThemeData &themeData);
212
213 bool drawBackground(XPThemeData &themeData, qreal correctionFactor = 1);
214 bool drawBackgroundThruNativeBuffer(XPThemeData &themeData, qreal aditionalDevicePixelRatio, qreal correctionFactor);
215 bool drawBackgroundDirectly(HDC dc, XPThemeData &themeData, qreal aditionalDevicePixelRatio);
216
217 bool hasAlphaChannel(const QRect &rect);
218 bool fixAlphaChannel(const QRect &rect);
219 bool swapAlphaChannel(const QRect &rect, bool allPixels = false);
220
224 bool hasInitColors = false;
225
226 static HTHEME createTheme(int theme, HWND hwnd);
227 static QString themeName(int theme);
228 static inline bool hasTheme(int theme) { return theme >= 0 && theme < NThemes && m_themes[theme]; }
229 static bool isItemViewDelegateLineEdit(const QWidget *widget);
230 static bool isLineEditBaseColorSet(const QStyleOption *option, const QWidget *widget);
231
233
234private:
235#ifdef DEBUG_XP_STYLE
236 void dumpNativeDIB(int w, int h);
238#endif
239
240 static bool initVistaTreeViewTheming();
241 static void cleanupVistaTreeViewTheming();
242
243 static QBasicAtomicInt ref;
244 static bool use_xp;
245
246 QHash<ThemeMapKey, ThemeMapData> alphaCache;
247 HDC bufferDC = nullptr;
248 HBITMAP bufferBitmap = nullptr;
249 HBITMAP nullBitmap = nullptr;
250 uchar *bufferPixels = nullptr;
251 int bufferW = 0;
252 int bufferH = 0;
253
254 static HWND m_vistaTreeViewHelper;
255 static HTHEME m_themes[NThemes];
256};
257
259{
260 QSizeF result(0, 0);
261 if (isValid()) {
262 SIZE size;
263 if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size)))
264 result = QSize(size.cx, size.cy);
265 }
266 return result;
267}
268
269inline QMarginsF XPThemeData::margins(const QRect &qRect, int propId)
270{
271 QMarginsF result(0, 0, 0 ,0);
272 if (isValid()) {
273 MARGINS margins;
274 RECT rect = XPThemeData::toRECT(qRect);
275 if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins)))
276 result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
277 }
278 return result;
279}
280
281inline QMarginsF XPThemeData::margins(int propId)
282{
283 QMarginsF result(0, 0, 0 ,0);
284 if (isValid()) {
285 MARGINS margins;
286 if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins)))
287 result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
288 }
289 return result;
290}
291
292inline QSizeF XPThemeData::themeSize(const QWindow *w, QPainter *p, int themeIn, int part, int state)
293{
294 XPThemeData theme(w, p, themeIn, part, state);
295 return theme.size();
296}
297
298inline QMarginsF XPThemeData::themeMargins(const QRect &rect, const QWindow *w, QPainter *p, int themeIn,
299 int part, int state, int propId)
300{
301 XPThemeData theme(w, p, themeIn, part, state);
302 return theme.margins(rect, propId);
303}
304
305inline QMarginsF XPThemeData::themeMargins(const QWindow *w, QPainter *p, int themeIn,
306 int part, int state, int propId)
307{
308 XPThemeData theme(w, p, themeIn, part, state);
309 return theme.margins(propId);
310}
311
312} //namespace QQC2
313
314QT_END_NAMESPACE
315
316#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)
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
friend size_t qHash(const ThemeMapKey &key, size_t seed=0) noexcept
ThemeMapKey(const XPThemeData &data)
ThemeMapKey()=default