Refactor windows vista style for Qt widgets

Removed windows xp style and Cleanup windows vista style for Qt
widgets.

Change-Id: Ia05e8bca9bad477cec535d2288d9773546e0e116
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Santhosh Kumar 2022-10-06 15:57:53 +02:00
parent ef3813fc1e
commit 46f98147f4
11 changed files with 3910 additions and 5093 deletions

View File

@ -14,8 +14,9 @@ qt_internal_add_plugin(QWindowsVistaStylePlugin
main.cpp
qwindowsvistastyle.cpp qwindowsvistastyle_p.h
qwindowsvistastyle_p_p.h
qwindowsxpstyle.cpp qwindowsxpstyle_p.h
qwindowsxpstyle_p_p.h
qwindowsvistaanimation.cpp qwindowsvistaanimation_p.h
qwindowsthemedata.cpp qwindowsthemedata_p.h
LIBRARIES
gdi32
user32

View File

@ -0,0 +1,59 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwindowsthemedata_p.h"
#include "qwindowsvistastyle_p_p.h"
/* \internal
Returns \c true if the QWindowsThemeData is valid for use.
*/
bool QWindowsThemeData::isValid()
{
return QWindowsVistaStylePrivate::useVista() && theme >= 0 && handle();
}
/* \internal
Returns the theme engine handle to the specific class.
If the handle hasn't been opened before, it opens the data, and
adds it to a static map, for caching.
*/
HTHEME QWindowsThemeData::handle()
{
if (!QWindowsVistaStylePrivate::useVista())
return nullptr;
if (!htheme)
htheme = QWindowsVistaStylePrivate::createTheme(theme, QWindowsVistaStylePrivate::winId(widget));
return htheme;
}
/* \internal
Converts a QRect to the native RECT structure.
*/
RECT QWindowsThemeData::toRECT(const QRect &qr)
{
RECT r;
r.left = qr.x();
r.right = qr.x() + qr.width();
r.top = qr.y();
r.bottom = qr.y() + qr.height();
return r;
}
/* \internal
Returns the native region of a part, if the part is considered
transparent. The region is scaled to the parts size (rect).
*/
HRGN QWindowsThemeData::mask(QWidget *widget)
{
if (!IsThemeBackgroundPartiallyTransparent(handle(), partId, stateId))
return nullptr;
HRGN hrgn;
HDC dc = nullptr;
if (widget)
dc = QWindowsVistaStylePrivate::hdcForWidgetBackingStore(widget);
RECT nativeRect = toRECT(rect);
GetThemeBackgroundRegion(handle(), dc, partId, stateId, &nativeRect, &hrgn);
return hrgn;
}

View File

@ -0,0 +1,183 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOWSTHEMEDATA_P_H
#define QWINDOWSTHEMEDATA_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <qwidget.h>
#include <qt_windows.h>
#include <uxtheme.h>
#include <vssym32.h>
#include <limits.h>
// TMT_TEXTSHADOWCOLOR is wrongly defined in mingw
#if TMT_TEXTSHADOWCOLOR != 3818
#undef TMT_TEXTSHADOWCOLOR
#define TMT_TEXTSHADOWCOLOR 3818
#endif
#ifndef TST_NONE
# define TST_NONE 0
#endif
// These defines are missing from the tmschema, but still exist as
// states for their parts
#ifndef MINBS_INACTIVE
#define MINBS_INACTIVE 5
#endif
#ifndef MAXBS_INACTIVE
#define MAXBS_INACTIVE 5
#endif
#ifndef RBS_INACTIVE
#define RBS_INACTIVE 5
#endif
#ifndef HBS_INACTIVE
#define HBS_INACTIVE 5
#endif
#ifndef CBS_INACTIVE
#define CBS_INACTIVE 5
#endif
// Declarations -----------------------------------------------------------------------------------
class QWindowsThemeData
{
public:
explicit QWindowsThemeData(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
int part = 0, int state = 0, const QRect &r = QRect())
: widget(w), painter(p), theme(themeIn), partId(part), stateId(state),
mirrorHorizontally(false), mirrorVertically(false), noBorder(false),
noContent(false), invertPixels(false), rect(r)
{}
HRGN mask(QWidget *widget);
HTHEME handle();
bool isValid();
QSizeF size();
static QSizeF themeSize(const QWidget *w = nullptr, QPainter *p = nullptr,
int themeIn = -1, int part = 0, int state = 0);
static RECT toRECT(const QRect &qr);
QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS);
QMarginsF margins(int propId = TMT_CONTENTMARGINS);
const QWidget *widget;
QPainter *painter;
int theme;
HTHEME htheme = nullptr;
int partId;
int stateId;
uint mirrorHorizontally : 1;
uint mirrorVertically : 1;
uint noBorder : 1;
uint noContent : 1;
uint invertPixels : 1;
uint rotate = 0;
QRect rect;
};
struct ThemeMapKey {
int theme = 0;
int partId = -1;
int stateId = -1;
bool noBorder = false;
bool noContent = false;
ThemeMapKey() = default;
ThemeMapKey(const QWindowsThemeData &data)
: theme(data.theme), partId(data.partId), stateId(data.stateId),
noBorder(data.noBorder), noContent(data.noContent) {}
};
inline size_t qHash(const ThemeMapKey &key)
{ return key.theme ^ key.partId ^ key.stateId; }
inline bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
{
return k1.theme == k2.theme
&& k1.partId == k2.partId
&& k1.stateId == k2.stateId;
}
enum AlphaChannelType {
UnknownAlpha = -1, // Alpha of part & state not yet known
NoAlpha, // Totally opaque, no need to touch alpha (RGB)
MaskAlpha, // Alpha channel must be fixed (ARGB)
RealAlpha // Proper alpha values from Windows (ARGB_Premultiplied)
};
struct ThemeMapData {
AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state
bool dataValid : 1; // Only used to detect if hash value is ok
bool partIsTransparent : 1;
bool hasAlphaChannel : 1; // True = part & state has real Alpha
bool wasAlphaSwapped : 1; // True = alpha channel needs to be swapped
bool hadInvalidAlpha : 1; // True = alpha channel contained invalid alpha values
ThemeMapData() : dataValid(false), partIsTransparent(false),
hasAlphaChannel(false), wasAlphaSwapped(false), hadInvalidAlpha(false) {}
};
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const QWindowsThemeData &t);
QDebug operator<<(QDebug d, const ThemeMapKey &k);
QDebug operator<<(QDebug d, const ThemeMapData &td);
#endif
inline QSizeF QWindowsThemeData::size()
{
QSizeF result(0, 0);
if (isValid()) {
SIZE size;
if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size)))
result = QSize(size.cx, size.cy);
}
return result;
}
inline QSizeF QWindowsThemeData::themeSize(const QWidget *w, QPainter *p, int themeIn, int part, int state)
{
QWindowsThemeData theme(w, p, themeIn, part, state);
return theme.size();
}
inline QMarginsF QWindowsThemeData::margins(const QRect &qRect, int propId)
{
QMarginsF result(0, 0, 0 ,0);
if (isValid()) {
MARGINS margins;
RECT rect = QWindowsThemeData::toRECT(qRect);
if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins)))
result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
}
return result;
}
inline QMarginsF QWindowsThemeData::margins(int propId)
{
QMarginsF result(0, 0, 0 ,0);
if (isValid()) {
MARGINS margins;
if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins)))
result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
}
return result;
}
#endif // QWINDOWSTHEMEDATA_P_H

View File

@ -0,0 +1,15 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwindowsvistaanimation_p.h"
#include "qwindowsvistastyle_p_p.h"
bool QWindowsVistaAnimation::isUpdateNeeded() const
{
return QWindowsVistaStylePrivate::useVista();
}
void QWindowsVistaAnimation::paint(QPainter *painter, const QStyleOption *option)
{
painter->drawImage(option->rect, currentImage());
}

View File

@ -0,0 +1,49 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOWSVISTAANIMATION_P_H
#define QWINDOWSVISTAANIMATION_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <private/qstyleanimation_p.h>
#include <QtWidgets/private/qwindowsstyle_p.h>
class QWindowsVistaAnimation : public QBlendStyleAnimation
{
Q_OBJECT
public:
QWindowsVistaAnimation(Type type, QObject *target) : QBlendStyleAnimation(type, target) { }
bool isUpdateNeeded() const override;
void paint(QPainter *painter, const QStyleOption *option);
};
// Handles state transition animations
class QWindowsVistaTransition : public QWindowsVistaAnimation
{
Q_OBJECT
public:
QWindowsVistaTransition(QObject *target) : QWindowsVistaAnimation(Transition, target) {}
};
// Handles pulse animations (default buttons)
class QWindowsVistaPulse: public QWindowsVistaAnimation
{
Q_OBJECT
public:
QWindowsVistaPulse(QObject *target) : QWindowsVistaAnimation(Pulse, target) {}
};
#endif // QWINDOWSVISTAANIMATION_P_H

File diff suppressed because it is too large Load Diff

View File

@ -16,12 +16,12 @@
//
#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include "qwindowsxpstyle_p.h"
#include <QtWidgets/private/qwindowsstyle_p.h>
QT_BEGIN_NAMESPACE
class QWindowsVistaStylePrivate;
class QWindowsVistaStyle : public QWindowsXPStyle
class QWindowsVistaStyle : public QWindowsStyle
{
Q_OBJECT
public:

View File

@ -17,14 +17,16 @@
#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include "qwindowsvistastyle_p.h"
#include "qwindowsxpstyle_p_p.h"
#include <private/qstyleanimation_p.h>
#include "qwindowsthemedata_p.h"
#include <private/qpaintengine_raster_p.h>
#include <qpaintengine.h>
#include <qwidget.h>
#include <qapplication.h>
#include <qpixmapcache.h>
#include <qstyleoption.h>
#include <QtWidgets/private/qwindowsstyle_p_p.h>
#include <qmap.h>
#if QT_CONFIG(pushbutton)
#include <qpushbutton.h>
#endif
@ -73,93 +75,102 @@
#if QT_CONFIG(commandlinkbutton)
#include <qcommandlinkbutton.h>
#endif
#include <qlabel.h>
#include <qheaderview.h>
QT_BEGIN_NAMESPACE
#if !defined(SCHEMA_VERIFY_VSSYM32)
#define TMT_ANIMATIONDURATION 5006
#define TMT_TRANSITIONDURATIONS 6000
#define EP_EDITBORDER_NOSCROLL 6
#define EP_EDITBORDER_HVSCROLL 9
#define EP_BACKGROUND 3
#define EBS_NORMAL 1
#define EBS_HOT 2
#define EBS_DISABLED 3
#define EBS_READONLY 5
#define PBS_DEFAULTED_ANIMATING 6
#define MBI_NORMAL 1
#define MBI_HOT 2
#define MBI_PUSHED 3
#define MBI_DISABLED 4
#define MB_ACTIVE 1
#define MB_INACTIVE 2
#define PP_FILL 5
#define PP_FILLVERT 6
#define PP_MOVEOVERLAY 8
#define PP_MOVEOVERLAYVERT 10
#define MENU_BARBACKGROUND 7
#define MENU_BARITEM 8
#define MENU_POPUPCHECK 11
#define MENU_POPUPCHECKBACKGROUND 12
#define MENU_POPUPGUTTER 13
#define MENU_POPUPITEM 14
#define MENU_POPUPBORDERS 10
#define MENU_POPUPSEPARATOR 15
#define MC_CHECKMARKNORMAL 1
#define MC_CHECKMARKDISABLED 2
#define MC_BULLETNORMAL 3
#define MC_BULLETDISABLED 4
#define ABS_UPHOVER 17
#define ABS_DOWNHOVER 18
#define ABS_LEFTHOVER 19
#define ABS_RIGHTHOVER 20
#define CP_DROPDOWNBUTTONRIGHT 6
#define CP_DROPDOWNBUTTONLEFT 7
#define SCRBS_HOVER 5
#define TVP_HOTGLYPH 4
#define SPI_GETCLIENTAREAANIMATION 0x1042
#define TDLG_PRIMARYPANEL 1
#define TDLG_SECONDARYPANEL 8
#endif
class QWindowsVistaAnimation : public QBlendStyleAnimation
{
Q_OBJECT
public:
QWindowsVistaAnimation(Type type, QObject *target) : QBlendStyleAnimation(type, target) { }
bool isUpdateNeeded() const override;
void paint(QPainter *painter, const QStyleOption *option);
};
// Handles state transition animations
class QWindowsVistaTransition : public QWindowsVistaAnimation
{
Q_OBJECT
public:
QWindowsVistaTransition(QObject *target) : QWindowsVistaAnimation(Transition, target) {}
};
// Handles pulse animations (default buttons)
class QWindowsVistaPulse: public QWindowsVistaAnimation
{
Q_OBJECT
public:
QWindowsVistaPulse(QObject *target) : QWindowsVistaAnimation(Pulse, target) {}
};
class QWindowsVistaStylePrivate : public QWindowsXPStylePrivate
class QWindowsVistaStylePrivate : public QWindowsStylePrivate
{
Q_DECLARE_PUBLIC(QWindowsVistaStyle)
public:
enum Theme {
ButtonTheme,
ComboboxTheme,
EditTheme,
HeaderTheme,
ListViewTheme,
MenuTheme,
ProgressTheme,
RebarTheme,
ScrollBarTheme,
SpinTheme,
TabTheme,
TaskDialogTheme,
ToolBarTheme,
ToolTipTheme,
TrackBarTheme,
WindowTheme,
StatusTheme,
VistaTreeViewTheme, // arrow shape treeview indicators (Vista) obtained from "explorer" theme.
NThemes
};
QWindowsVistaStylePrivate()
{ init(); }
~QWindowsVistaStylePrivate()
{ cleanup(); }
static HTHEME createTheme(int theme, HWND hwnd);
static QString themeName(int theme);
static inline bool hasTheme(int theme) { return theme >= 0 && theme < NThemes && m_themes[theme]; }
static bool isItemViewDelegateLineEdit(const QWidget *widget);
static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr);
static int fixedPixelMetric(QStyle::PixelMetric pm);
static inline bool useVista();
static bool isLineEditBaseColorSet(const QStyleOption *option, const QWidget *widget);
static QRect scrollBarGripperBounds(QStyle::State flags, const QWidget *widget, QWindowsThemeData *theme);
static HWND winId(const QWidget *widget);
static bool useVista(bool update = false);
static QBackingStore *backingStoreForWidget(const QWidget *widget);
static HDC hdcForWidgetBackingStore(const QWidget *widget);
void init(bool force = false);
void cleanup(bool force = false);
void cleanupHandleMap();
HBITMAP buffer(int w = 0, int h = 0);
HDC bufferHDC()
{ return bufferDC; }
bool isTransparent(QWindowsThemeData &QWindowsThemeData);
QRegion region(QWindowsThemeData &QWindowsThemeData);
bool drawBackground(QWindowsThemeData &QWindowsThemeData, qreal correctionFactor = 1);
bool drawBackgroundThruNativeBuffer(QWindowsThemeData &QWindowsThemeData, qreal aditionalDevicePixelRatio, qreal correctionFactor);
bool drawBackgroundDirectly(HDC dc, QWindowsThemeData &QWindowsThemeData, qreal aditionalDevicePixelRatio);
bool hasAlphaChannel(const QRect &rect);
bool fixAlphaChannel(const QRect &rect);
bool swapAlphaChannel(const QRect &rect, bool allPixels = false);
QRgb groupBoxTextColor = 0;
QRgb groupBoxTextColorDisabled = 0;
QRgb sliderTickColor = 0;
bool hasInitColors = false;
QIcon dockFloat, dockClose;
QTime animationTime() const;
bool transitionsEnabled() const;
private:
static bool initVistaTreeViewTheming();
static void cleanupVistaTreeViewTheming();
static QBasicAtomicInt ref;
static bool useVistaTheme;
QHash<ThemeMapKey, ThemeMapData> alphaCache;
HDC bufferDC = nullptr;
HBITMAP bufferBitmap = nullptr;
HBITMAP nullBitmap = nullptr;
uchar *bufferPixels = nullptr;
int bufferW = 0;
int bufferH = 0;
static HWND m_vistaTreeViewHelper;
static HTHEME m_themes[NThemes];
};
QT_END_NAMESPACE

File diff suppressed because it is too large Load Diff

View File

@ -1,69 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOWSXPSTYLE_P_H
#define QWINDOWSXPSTYLE_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include <QtWidgets/private/qwindowsstyle_p.h>
QT_BEGIN_NAMESPACE
class QWindowsXPStylePrivate;
class QWindowsXPStyle : public QWindowsStyle
{
Q_OBJECT
public:
~QWindowsXPStyle() override;
void polish(QWidget*) override;
void polish(QPalette&) override;
void unpolish(QWidget*) override;
void drawPrimitive(PrimitiveElement pe, const QStyleOption *option, QPainter *p,
const QWidget *widget = nullptr) const override;
void drawControl(ControlElement element, const QStyleOption *option, QPainter *p,
const QWidget *wwidget = nullptr) const override;
QRect subElementRect(SubElement r, const QStyleOption *option,
const QWidget *widget = nullptr) const override;
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *option, SubControl sc,
const QWidget *widget = nullptr) const override;
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *option, QPainter *p,
const QWidget *widget = nullptr) const override;
QSize sizeFromContents(ContentsType ct, const QStyleOption *option, const QSize &contentsSize,
const QWidget *widget = nullptr) const override;
int pixelMetric(PixelMetric pm, const QStyleOption *option = nullptr,
const QWidget *widget = nullptr) const override;
int styleHint(StyleHint hint, const QStyleOption *option = nullptr,
const QWidget *widget = nullptr,
QStyleHintReturn *returnData = nullptr) const override;
QPalette standardPalette() const override;
QPixmap standardPixmap(StandardPixmap standardIcon, const QStyleOption *option,
const QWidget *widget = nullptr) const override;
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option = nullptr,
const QWidget *widget = nullptr) const override;
protected:
QWindowsXPStyle(QWindowsXPStylePrivate &dd);
private:
Q_DISABLE_COPY_MOVE(QWindowsXPStyle)
Q_DECLARE_PRIVATE(QWindowsXPStyle)
friend class QStyleFactory;
};
QT_END_NAMESPACE
#endif // QWINDOWSXPSTYLE_P_H

View File

@ -1,309 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOWSXPSTYLE_P_P_H
#define QWINDOWSXPSTYLE_P_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
// file may change from version to version without notice, or even be removed.
//
// We mean it.
//
#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include "qwindowsxpstyle_p.h"
#include <QtWidgets/private/qwindowsstyle_p_p.h>
#include <qmap.h>
#include <qt_windows.h>
#include <uxtheme.h>
#include <vssym32.h>
#include <limits.h>
QT_BEGIN_NAMESPACE
class QDebug;
// TMT_TEXTSHADOWCOLOR is wrongly defined in mingw
#if TMT_TEXTSHADOWCOLOR != 3818
#undef TMT_TEXTSHADOWCOLOR
#define TMT_TEXTSHADOWCOLOR 3818
#endif
#ifndef TST_NONE
# define TST_NONE 0
#endif
// These defines are missing from the tmschema, but still exist as
// states for their parts
#ifndef MINBS_INACTIVE
#define MINBS_INACTIVE 5
#endif
#ifndef MAXBS_INACTIVE
#define MAXBS_INACTIVE 5
#endif
#ifndef RBS_INACTIVE
#define RBS_INACTIVE 5
#endif
#ifndef HBS_INACTIVE
#define HBS_INACTIVE 5
#endif
#ifndef CBS_INACTIVE
#define CBS_INACTIVE 5
#endif
// Uncomment define below to build debug assisting code, and output
// #define DEBUG_XP_STYLE
// Declarations -----------------------------------------------------------------------------------
class XPThemeData
{
public:
explicit XPThemeData(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
int part = 0, int state = 0, const QRect &r = QRect())
: widget(w), painter(p), theme(themeIn), partId(part), stateId(state),
mirrorHorizontally(false), mirrorVertically(false), noBorder(false),
noContent(false), rect(r)
{}
HRGN mask(QWidget *widget);
HTHEME handle();
static RECT toRECT(const QRect &qr);
bool isValid();
QSizeF size();
QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS);
QMarginsF margins(int propId = TMT_CONTENTMARGINS);
static QSizeF themeSize(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0);
static QMarginsF themeMargins(const QRect &rect, const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
static QMarginsF themeMargins(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
const QWidget *widget;
QPainter *painter;
int theme;
HTHEME htheme = nullptr;
int partId;
int stateId;
uint mirrorHorizontally : 1;
uint mirrorVertically : 1;
uint noBorder : 1;
uint noContent : 1;
uint rotate = 0;
QRect rect;
};
struct ThemeMapKey {
int theme = 0;
int partId = -1;
int stateId = -1;
bool noBorder = false;
bool noContent = false;
ThemeMapKey() = default;
ThemeMapKey(const XPThemeData &data)
: theme(data.theme), partId(data.partId), stateId(data.stateId),
noBorder(data.noBorder), noContent(data.noContent) {}
};
inline size_t qHash(const ThemeMapKey &key)
{ return key.theme ^ key.partId ^ key.stateId; }
inline bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
{
return k1.theme == k2.theme
&& k1.partId == k2.partId
&& k1.stateId == k2.stateId;
}
enum AlphaChannelType {
UnknownAlpha = -1, // Alpha of part & state not yet known
NoAlpha, // Totally opaque, no need to touch alpha (RGB)
MaskAlpha, // Alpha channel must be fixed (ARGB)
RealAlpha // Proper alpha values from Windows (ARGB_Premultiplied)
};
struct ThemeMapData {
AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state
bool dataValid : 1; // Only used to detect if hash value is ok
bool partIsTransparent : 1;
bool hasAlphaChannel : 1; // True = part & state has real Alpha
bool wasAlphaSwapped : 1; // True = alpha channel needs to be swapped
bool hadInvalidAlpha : 1; // True = alpha channel contained invalid alpha values
ThemeMapData() : dataValid(false), partIsTransparent(false),
hasAlphaChannel(false), wasAlphaSwapped(false), hadInvalidAlpha(false) {}
};
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const XPThemeData &t);
QDebug operator<<(QDebug d, const ThemeMapKey &k);
QDebug operator<<(QDebug d, const ThemeMapData &td);
#endif
class QWindowsXPStylePrivate : public QWindowsStylePrivate
{
Q_DECLARE_PUBLIC(QWindowsXPStyle)
public:
enum Theme {
ButtonTheme,
ComboboxTheme,
EditTheme,
HeaderTheme,
ListViewTheme,
MenuTheme,
ProgressTheme,
RebarTheme,
ScrollBarTheme,
SpinTheme,
TabTheme,
TaskDialogTheme,
ToolBarTheme,
ToolTipTheme,
TrackBarTheme,
XpTreeViewTheme, // '+'/'-' shape treeview indicators (XP)
WindowTheme,
StatusTheme,
VistaTreeViewTheme, // arrow shape treeview indicators (Vista) obtained from "explorer" theme.
NThemes
};
QWindowsXPStylePrivate()
{ init(); }
~QWindowsXPStylePrivate()
{ cleanup(); }
static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr);
static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr);
static HWND winId(const QWidget *widget);
void init(bool force = false);
void cleanup(bool force = false);
void cleanupHandleMap();
HBITMAP buffer(int w = 0, int h = 0);
HDC bufferHDC()
{ return bufferDC;}
static bool useXP(bool update = false);
static QRect scrollBarGripperBounds(QStyle::State flags, const QWidget *widget, XPThemeData *theme);
bool isTransparent(XPThemeData &themeData);
QRegion region(XPThemeData &themeData);
bool drawBackground(XPThemeData &themeData, qreal correctionFactor = 1);
bool drawBackgroundThruNativeBuffer(XPThemeData &themeData, qreal aditionalDevicePixelRatio, qreal correctionFactor);
bool drawBackgroundDirectly(HDC dc, XPThemeData &themeData, qreal aditionalDevicePixelRatio);
bool hasAlphaChannel(const QRect &rect);
bool fixAlphaChannel(const QRect &rect);
bool swapAlphaChannel(const QRect &rect, bool allPixels = false);
QRgb groupBoxTextColor = 0;
QRgb groupBoxTextColorDisabled = 0;
QRgb sliderTickColor = 0;
bool hasInitColors = false;
static HTHEME createTheme(int theme, HWND hwnd);
static QString themeName(int theme);
static inline bool hasTheme(int theme) { return theme >= 0 && theme < NThemes && m_themes[theme]; }
static bool isItemViewDelegateLineEdit(const QWidget *widget);
static bool isLineEditBaseColorSet(const QStyleOption *option, const QWidget *widget);
QIcon dockFloat, dockClose;
private:
#ifdef DEBUG_XP_STYLE
void dumpNativeDIB(int w, int h);
void showProperties(XPThemeData &themeData);
#endif
static bool initVistaTreeViewTheming();
static void cleanupVistaTreeViewTheming();
static QBasicAtomicInt ref;
static bool use_xp;
QHash<ThemeMapKey, ThemeMapData> alphaCache;
HDC bufferDC = nullptr;
HBITMAP bufferBitmap = nullptr;
HBITMAP nullBitmap = nullptr;
uchar *bufferPixels = nullptr;
int bufferW = 0;
int bufferH = 0;
static HWND m_vistaTreeViewHelper;
static HTHEME m_themes[NThemes];
};
inline QSizeF XPThemeData::size()
{
QSizeF result(0, 0);
if (isValid()) {
SIZE size;
if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size)))
result = QSize(size.cx, size.cy);
}
return result;
}
inline QMarginsF XPThemeData::margins(const QRect &qRect, int propId)
{
QMarginsF result(0, 0, 0 ,0);
if (isValid()) {
MARGINS margins;
RECT rect = XPThemeData::toRECT(qRect);
if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins)))
result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
}
return result;
}
inline QMarginsF XPThemeData::margins(int propId)
{
QMarginsF result(0, 0, 0 ,0);
if (isValid()) {
MARGINS margins;
if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins)))
result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
}
return result;
}
inline QSizeF XPThemeData::themeSize(const QWidget *w, QPainter *p, int themeIn, int part, int state)
{
XPThemeData theme(w, p, themeIn, part, state);
return theme.size();
}
inline QMarginsF XPThemeData::themeMargins(const QRect &rect, const QWidget *w, QPainter *p, int themeIn,
int part, int state, int propId)
{
XPThemeData theme(w, p, themeIn, part, state);
return theme.margins(rect, propId);
}
inline QMarginsF XPThemeData::themeMargins(const QWidget *w, QPainter *p, int themeIn,
int part, int state, int propId)
{
XPThemeData theme(w, p, themeIn, part, state);
return theme.margins(propId);
}
QT_END_NAMESPACE
#endif //QWINDOWSXPSTYLE_P_P_H