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
qwindowsthemedata_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 QWINDOWSTHEMEDATA_P_H
6#define QWINDOWSTHEMEDATA_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 <qwidget.h>
20
21#include <QtCore/qhashfunctions.h>
22#include <qt_windows.h>
23
24#include <uxtheme.h>
25#include <vssym32.h>
26
27#include <limits.h>
28
29
30// TMT_TEXTSHADOWCOLOR is wrongly defined in mingw
31#if TMT_TEXTSHADOWCOLOR != 3818
32#undef TMT_TEXTSHADOWCOLOR
33#define TMT_TEXTSHADOWCOLOR 3818
34#endif
35#ifndef TST_NONE
36# define TST_NONE 0
37#endif
38
39// These defines are missing from the tmschema, but still exist as
40// states for their parts
41#ifndef MINBS_INACTIVE
42#define MINBS_INACTIVE 5
43#endif
44#ifndef MAXBS_INACTIVE
45#define MAXBS_INACTIVE 5
46#endif
47#ifndef RBS_INACTIVE
48#define RBS_INACTIVE 5
49#endif
50#ifndef HBS_INACTIVE
51#define HBS_INACTIVE 5
52#endif
53#ifndef CBS_INACTIVE
54#define CBS_INACTIVE 5
55#endif
56
57QT_BEGIN_NAMESPACE
58
59// Declarations -----------------------------------------------------------------------------------
60class QWindowsThemeData
61{
62public:
63 explicit QWindowsThemeData(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
64 int part = 0, int state = 0, const QRect &r = QRect())
65 : widget(w), painter(p), theme(themeIn), partId(part), stateId(state),
66 mirrorHorizontally(false), mirrorVertically(false), noBorder(false),
67 noContent(false), invertPixels(false), rect(r)
68 {}
69
70 HRGN mask(QWidget *widget);
71 HTHEME handle();
72 bool isValid();
73 QSizeF size();
74
75 static QSizeF themeSize(const QWidget *w = nullptr, QPainter *p = nullptr,
76 int themeIn = -1, int part = 0, int state = 0);
77 static RECT toRECT(const QRect &qr);
78
79 QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS);
80 QMarginsF margins(int propId = TMT_CONTENTMARGINS);
81
82 const QWidget *widget;
83 QPainter *painter;
84
85 int theme;
86 HTHEME htheme = nullptr;
87 int partId;
88 int stateId;
89
90 uint mirrorHorizontally : 1;
91 uint mirrorVertically : 1;
92 uint noBorder : 1;
93 uint noContent : 1;
94 uint invertPixels : 1;
95 uint rotate = 0;
96 QRect rect;
97};
98
100 int theme = 0;
101 int partId = -1;
102 int stateId = -1;
103 bool noBorder = false;
104 bool noContent = false;
105
106 ThemeMapKey() = default;
107 ThemeMapKey(const QWindowsThemeData &data)
108 : theme(data.theme), partId(data.partId), stateId(data.stateId),
109 noBorder(data.noBorder), noContent(data.noContent) {}
110
111 friend size_t qHash(const ThemeMapKey &key, size_t seed = 0) noexcept
112 { return qHashMulti(seed, key.theme, key.partId, key.stateId); }
113};
114
115inline bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
116{
117 return k1.theme == k2.theme
118 && k1.partId == k2.partId
119 && k1.stateId == k2.stateId;
120}
121
123 UnknownAlpha = -1, // Alpha of part & state not yet known
124 NoAlpha, // Totally opaque, no need to touch alpha (RGB)
125 MaskAlpha, // Alpha channel must be fixed (ARGB)
126 RealAlpha // Proper alpha values from Windows (ARGB_Premultiplied)
127};
128
130 AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state
131
132 bool dataValid : 1; // Only used to detect if hash value is ok
134 bool hasAlphaChannel : 1; // True = part & state has real Alpha
135 bool wasAlphaSwapped : 1; // True = alpha channel needs to be swapped
136 bool hadInvalidAlpha : 1; // True = alpha channel contained invalid alpha values
137
140};
141
142
143#ifndef QT_NO_DEBUG_STREAM
144QDebug operator<<(QDebug d, const QWindowsThemeData &t);
145QDebug operator<<(QDebug d, const ThemeMapKey &k);
146QDebug operator<<(QDebug d, const ThemeMapData &td);
147#endif
148
149inline QSizeF QWindowsThemeData::size()
150{
151 QSizeF result(0, 0);
152 if (isValid()) {
153 SIZE size;
154 if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size)))
155 result = QSize(size.cx, size.cy);
156 }
157 return result;
158}
159
160inline QSizeF QWindowsThemeData::themeSize(const QWidget *w, QPainter *p, int themeIn, int part, int state)
161{
162 QWindowsThemeData theme(w, p, themeIn, part, state);
163 return theme.size();
164}
165
166inline QMarginsF QWindowsThemeData::margins(const QRect &qRect, int propId)
167{
168 QMarginsF result(0, 0, 0 ,0);
169 if (isValid()) {
170 MARGINS margins;
171 RECT rect = QWindowsThemeData::toRECT(qRect);
172 if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins)))
173 result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
174 }
175 return result;
176}
177
178inline QMarginsF QWindowsThemeData::margins(int propId)
179{
180 QMarginsF result(0, 0, 0 ,0);
181 if (isValid()) {
182 MARGINS margins;
183 if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins)))
184 result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
185 }
186 return result;
187}
188
189QT_END_NAMESPACE
190
191#endif // QWINDOWSTHEMEDATA_P_H
friend class QPainter
friend class QWidget
Definition qpainter.h:432
QVarLengthFlatMap< QWindows11Style::Icon, QIcon, 16 > m_standardIcons
The QWindows11Style class provides a look and feel suitable for applications on Microsoft Windows 11.
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override
QWindows11Style()
Constructs a QWindows11Style object.
bool eventFilter(QObject *obj, QEvent *event) override
void unpolish(QWidget *widget) override
void polish(QWidget *widget) override
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const override
QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const override
void unpolish(QApplication *app) override
QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget) const override
QWindows11Style(QWindows11StylePrivate &dd)
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
void polish(QPalette &pal) override
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const override
int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
int styleHint(StyleHint hint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const override
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override
QRect subElementRect(QStyle::SubElement element, const QStyleOption *option, const QWidget *widget=nullptr) const override
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
void polish(QApplication *app) override
~QWindows11Style() override
Destructor.
HBITMAP buffer(int w=0, int h=0)
static int fixedPixelMetric(QStyle::PixelMetric pm)
static HDC hdcForWidgetBackingStore(const QWidget *widget)
static QBackingStore * backingStoreForWidget(const QWidget *widget)
bool swapAlphaChannel(const QRect &rect, bool allPixels=false)
bool drawBackgroundThruNativeBuffer(QWindowsThemeData &QWindowsThemeData, qreal aditionalDevicePixelRatio, qreal correctionFactor)
static HWND winId(const QWidget *widget)
void init(bool force=false)
static bool isLineEditBaseColorSet(const QStyleOption *option, const QWidget *widget)
bool drawBackgroundDirectly(HDC dc, QWindowsThemeData &QWindowsThemeData, qreal aditionalDevicePixelRatio)
static bool isItemViewDelegateLineEdit(const QWidget *widget)
static bool useVista(bool update=false)
bool fixAlphaChannel(const QRect &rect)
void cleanup(bool force=false)
bool isTransparent(QWindowsThemeData &QWindowsThemeData)
bool hasAlphaChannel(const QRect &rect)
QRegion region(QWindowsThemeData &QWindowsThemeData)
bool drawBackground(QWindowsThemeData &QWindowsThemeData, qreal correctionFactor=1)
static HTHEME createTheme(int theme, const QWidget *widget)
static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option=nullptr, const QWidget *widget=nullptr)
static QString themeName(int theme)
The QWindowsVistaStyle class provides a look and feel suitable for applications on Microsoft Windows ...
QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const override
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const override
int styleHint(StyleHint hint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const override
SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget=nullptr) const override
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override
void polish(QWidget *widget) override
int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=nullptr) const override
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
\reimp
~QWindowsVistaStyle() override
Destructor.
void polish(QPalette &pal) override
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=nullptr) const override
QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const override
QWindowsVistaStyle(QWindowsVistaStylePrivate &dd)
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const override
void unpolish(QWidget *widget) override
WinFontIconEngine(const QString &glyph, const QFont &font)
QString string() const override
void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override
Uses the given painter to paint the icon with the required mode and state into the rectangle rect.
QString key() const override
\variable QIconEngine::ScaledPixmapArgument::size
QIconEngine * clone() const override
Reimplement this method to return a clone of this icon engine.
void setScale(double scale)
Combined button and popup list for selecting options.
WINUI3Color
@ dividerStrokeDefault
@ fillControlAltSecondary
@ fillControlTertiary
@ frameColorStrongDisabled
@ textOnAccentPrimary
@ fillControlDefault
@ controlStrokeSecondary
@ frameColorStrong
@ surfaceStroke
@ fillControlDisabled
@ fillMicaAltSecondary
@ subtleHighlightColor
@ textPrimary
@ controlFillSolid
@ fillAccentSecondary
@ frameColorLight
@ subtlePressedColor
@ fillMicaAltDefault
@ textDisabled
@ fillControlSecondary
@ textSecondary
@ controlStrokeOnAccentSecondary
@ fillAccentDefault
@ textOnAccentSecondary
@ focusFrameOuterStroke
@ textOnAccentDisabled
@ fillControlAltQuarternary
@ fillControlInputActive
@ menuPanelFill
@ controlStrongFill
@ fillMicaAltTransparent
@ controlStrokePrimary
@ fillAccentDisabled
@ fillControlAltTertiary
@ fillControlAltDisabled
@ focusFrameInnerStroke
@ fillAccentTertiary
bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
@ UnknownAlpha
AlphaChannelType alphaType
friend size_t qHash(const ThemeMapKey &key, size_t seed=0) noexcept
ThemeMapKey(const QWindowsThemeData &data)
ThemeMapKey()=default