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