diff --git a/src/widgets/styles/qstylefactory.cpp b/src/widgets/styles/qstylefactory.cpp index 38765e64b6..a9db52327d 100644 --- a/src/widgets/styles/qstylefactory.cpp +++ b/src/widgets/styles/qstylefactory.cpp @@ -53,7 +53,7 @@ #include "qgtkstyle_p.h" #endif #ifndef QT_NO_STYLE_WINDOWSXP -#include "qwindowsxpstyle.h" +#include "qwindowsxpstyle_p.h" #endif #ifndef QT_NO_STYLE_WINDOWSVISTA #include "qwindowsvistastyle_p.h" diff --git a/src/widgets/styles/qwindowsvistastyle_p.h b/src/widgets/styles/qwindowsvistastyle_p.h index 7d90bcf049..7ca4c8dbe5 100644 --- a/src/widgets/styles/qwindowsvistastyle_p.h +++ b/src/widgets/styles/qwindowsvistastyle_p.h @@ -42,7 +42,7 @@ #ifndef QWINDOWSVISTASTYLE_P_H #define QWINDOWSVISTASTYLE_P_H -#include +#include QT_BEGIN_HEADER diff --git a/src/widgets/styles/qwindowsvistastyle_p_p.h b/src/widgets/styles/qwindowsvistastyle_p_p.h index 7c3ea4ff7f..fad1626d56 100644 --- a/src/widgets/styles/qwindowsvistastyle_p_p.h +++ b/src/widgets/styles/qwindowsvistastyle_p_p.h @@ -56,7 +56,7 @@ #include "qwindowsvistastyle_p.h" #if !defined(QT_NO_STYLE_WINDOWSVISTA) -#include +#include #include #include #include diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 67e5118558..4aa2ef37ce 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -38,8 +38,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "qwindowsxpstyle.h" #include "qwindowsxpstyle_p.h" +#include "qwindowsxpstyle_p_p.h" #if !defined(QT_NO_STYLE_WINDOWSXP) || defined(QT_PLUGIN) @@ -1159,6 +1159,7 @@ void QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa \ingroup appearance \inmodule QtWidgets + \internal \warning This style is only available on the Windows XP platform because it makes use of Windows XP's style engine. diff --git a/src/widgets/styles/qwindowsxpstyle.h b/src/widgets/styles/qwindowsxpstyle.h deleted file mode 100644 index f930121c07..0000000000 --- a/src/widgets/styles/qwindowsxpstyle.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSXPSTYLE_H -#define QWINDOWSXPSTYLE_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - - -#if !defined(QT_NO_STYLE_WINDOWSXP) - -class QWindowsXPStylePrivate; -class Q_WIDGETS_EXPORT QWindowsXPStyle : public QWindowsStyle -{ - Q_OBJECT -public: - QWindowsXPStyle(); - QWindowsXPStyle(QWindowsXPStylePrivate &dd); - ~QWindowsXPStyle(); - - void unpolish(QApplication*); - void polish(QApplication*); - void polish(QWidget*); - void polish(QPalette&); - void unpolish(QWidget*); - - void drawPrimitive(PrimitiveElement pe, const QStyleOption *option, QPainter *p, - const QWidget *widget = 0) const; - void drawControl(ControlElement element, const QStyleOption *option, QPainter *p, - const QWidget *wwidget = 0) const; - QRect subElementRect(SubElement r, const QStyleOption *option, const QWidget *widget = 0) const; - QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *option, SubControl sc, - const QWidget *widget = 0) const; - void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *option, QPainter *p, - const QWidget *widget = 0) const; - QSize sizeFromContents(ContentsType ct, const QStyleOption *option, const QSize &contentsSize, - const QWidget *widget = 0) const; - int pixelMetric(PixelMetric pm, const QStyleOption *option = 0, - const QWidget *widget = 0) const; - int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, - QStyleHintReturn *returnData = 0) const; - - QPalette standardPalette() const; - QPixmap standardPixmap(StandardPixmap standardIcon, const QStyleOption *option, - const QWidget *widget = 0) const; - QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option = 0, - const QWidget *widget = 0) const; - -private: - Q_DISABLE_COPY(QWindowsXPStyle) - Q_DECLARE_PRIVATE(QWindowsXPStyle) - friend class QStyleFactory; - void *reserved; -}; - -#endif // QT_NO_STYLE_WINDOWSXP - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QWINDOWSXPSTYLE_H diff --git a/src/widgets/styles/qwindowsxpstyle_p.h b/src/widgets/styles/qwindowsxpstyle_p.h index fa3f23bf84..646c3932c9 100644 --- a/src/widgets/styles/qwindowsxpstyle_p.h +++ b/src/widgets/styles/qwindowsxpstyle_p.h @@ -42,341 +42,63 @@ #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 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 -#include "qwindowsxpstyle.h" -#include "qwindowsstyle_p.h" -#include -#include - -// Note, these tests are duplicated in qwizard_win.cpp. -#ifdef Q_CC_GNU -# include -# if (__W32API_MAJOR_VERSION >= 3 || (__W32API_MAJOR_VERSION == 2 && __W32API_MINOR_VERSION >= 5)) -# ifdef _WIN32_WINNT -# undef _WIN32_WINNT -# endif -# define _WIN32_WINNT 0x0501 -# include -# endif -#endif - -#include - -#if WINVER >= 0x0600 -#include -#else -#include -#endif - -#include +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -// Older Platform SDKs do not have the extended DrawThemeBackgroundEx -// function. We add the needed parts here, and use the extended -// function dynamically, if available in uxtheme.dll. Else, we revert -// back to using the DrawThemeBackground function. -#ifndef DTBG_OMITBORDER -# ifndef DTBG_CLIPRECT -# define DTBG_CLIPRECT 0x00000001 -# endif -# ifndef DTBG_DRAWSOLID -# define DTBG_DRAWSOLID 0x00000002 -# endif -# ifndef DTBG_OMITBORDER -# define DTBG_OMITBORDER 0x00000004 -# endif -# ifndef DTBG_OMITCONTENT -# define DTBG_OMITCONTENT 0x00000008 -# endif -# ifndef DTBG_COMPUTINGREGION -# define DTBG_COMPUTINGREGION 0x00000010 -# endif -# ifndef DTBG_MIRRORDC -# define DTBG_MIRRORDC 0x00000020 -# endif - typedef struct _DTBGOPTS - { - DWORD dwSize; - DWORD dwFlags; - RECT rcClip; - } DTBGOPTS, *PDTBGOPTS; -#endif // _DTBGOPTS - -// Undefined for some compile environments -#ifndef TMT_TEXTCOLOR -# define TMT_TEXTCOLOR 3803 -#endif -#ifndef TMT_BORDERCOLORHINT -# define TMT_BORDERCOLORHINT 3822 -#endif -#ifndef TMT_BORDERSIZE -# define TMT_BORDERSIZE 2403 -#endif -#ifndef TMT_BORDERONLY -# define TMT_BORDERONLY 2203 -#endif -#ifndef TMT_TRANSPARENTCOLOR -# define TMT_TRANSPARENTCOLOR 3809 -#endif -#ifndef TMT_CAPTIONMARGINS -# define TMT_CAPTIONMARGINS 3603 -#endif -#ifndef TMT_CONTENTMARGINS -# define TMT_CONTENTMARGINS 3602 -#endif -#ifndef TMT_SIZINGMARGINS -# define TMT_SIZINGMARGINS 3601 -#endif -#ifndef TMT_GLYPHTYPE -# define TMT_GLYPHTYPE 4012 -#endif -#ifndef TMT_BGTYPE -# define TMT_BGTYPE 4001 -#endif -#ifndef TMT_TEXTSHADOWTYPE -# define TMT_TEXTSHADOWTYPE 4010 -#endif -#ifndef TMT_BORDERCOLOR -# define TMT_BORDERCOLOR 3801 -#endif -#ifndef BT_IMAGEFILE -# define BT_IMAGEFILE 0 -#endif -#ifndef BT_BORDERFILL -# define BT_BORDERFILL 1 -#endif -#ifndef BT_NONE -# define BT_NONE 2 -#endif -#ifndef TMT_FILLCOLOR -# define TMT_FILLCOLOR 3802 -#endif -#ifndef TMT_PROGRESSCHUNKSIZE -# define TMT_PROGRESSCHUNKSIZE 2411 -#endif - -// 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 - -#ifndef GT_NONE -# define GT_NONE 0 -#endif -#ifndef GT_IMAGEGLYPH -# define GT_IMAGEGLYPH 1 -#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 #if !defined(QT_NO_STYLE_WINDOWSXP) -// Declarations ----------------------------------------------------------------------------------- -class XPThemeData +class QWindowsXPStylePrivate; +class QWindowsXPStyle : public QWindowsStyle { + Q_OBJECT public: - explicit XPThemeData(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, - int part = 0, int state = 0, const QRect &r = QRect()) - : widget(w), painter(p), theme(themeIn), htheme(0), partId(part), stateId(state), - mirrorHorizontally(false), mirrorVertically(false), noBorder(false), - noContent(false), rotate(0), rect(r) - {} + QWindowsXPStyle(); + QWindowsXPStyle(QWindowsXPStylePrivate &dd); + ~QWindowsXPStyle(); - HRGN mask(QWidget *widget); - HTHEME handle(); + void unpolish(QApplication*); + void polish(QApplication*); + void polish(QWidget*); + void polish(QPalette&); + void unpolish(QWidget*); - RECT toRECT(const QRect &qr); - bool isValid(); + void drawPrimitive(PrimitiveElement pe, const QStyleOption *option, QPainter *p, + const QWidget *widget = 0) const; + void drawControl(ControlElement element, const QStyleOption *option, QPainter *p, + const QWidget *wwidget = 0) const; + QRect subElementRect(SubElement r, const QStyleOption *option, const QWidget *widget = 0) const; + QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *option, SubControl sc, + const QWidget *widget = 0) const; + void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *option, QPainter *p, + const QWidget *widget = 0) const; + QSize sizeFromContents(ContentsType ct, const QStyleOption *option, const QSize &contentsSize, + const QWidget *widget = 0) const; + int pixelMetric(PixelMetric pm, const QStyleOption *option = 0, + const QWidget *widget = 0) const; + int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, + QStyleHintReturn *returnData = 0) const; - const QWidget *widget; - QPainter *painter; - - int theme; - HTHEME htheme; - int partId; - int stateId; - - uint mirrorHorizontally : 1; - uint mirrorVertically : 1; - uint noBorder : 1; - uint noContent : 1; - uint rotate; - QRect rect; -}; - -struct ThemeMapKey { - int theme; - int partId; - int stateId; - bool noBorder; - bool noContent; - - ThemeMapKey() : partId(-1), stateId(-1) {} - ThemeMapKey(const XPThemeData &data) - : theme(data.theme), partId(data.partId), stateId(data.stateId), - noBorder(data.noBorder), noContent(data.noContent) {} - -}; - -inline uint 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; // Which type of alpha on part & state - - bool dataValid : 1; // Only used to detect if hash value is ok - bool partIsTransparent : 1; - bool hasAnyData : 1; // False = part & state has not data, NOP - 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), hasAnyData(false), - hasAlphaChannel(false), wasAlphaSwapped(false), hadInvalidAlpha(false) {} -}; - -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, - TreeViewTheme, - WindowTheme, - StatusTheme, - NThemes - }; - - QWindowsXPStylePrivate() - : QWindowsStylePrivate(), hasInitColors(false), bufferDC(0), bufferBitmap(0), nullBitmap(0), - bufferPixels(0), bufferW(0), bufferH(0) - { init(); } - - ~QWindowsXPStylePrivate() - { cleanup(); } - - static HWND winId(const QWidget *widget); - - void init(bool force = false); - void cleanup(bool force = false); - void cleanupHandleMap(); - const QPixmap *tabBody(QWidget *widget); - - HBITMAP buffer(int w = 0, int h = 0); - HDC bufferHDC() - { return bufferDC;} - - static bool resolveSymbols(); - static bool useXP(bool update = false); - - bool isTransparent(XPThemeData &themeData); - QRegion region(XPThemeData &themeData); - - void setTransparency(QWidget *widget, XPThemeData &themeData); - void drawBackground(XPThemeData &themeData); - void drawBackgroundThruNativeBuffer(XPThemeData &themeData); - void drawBackgroundDirectly(XPThemeData &themeData); - - bool hasAnyData(const QRect &rect); - bool hasAlphaChannel(const QRect &rect); - bool fixAlphaChannel(const QRect &rect); - bool swapAlphaChannel(const QRect &rect, bool allPixels = false); - - QRgb groupBoxTextColor; - QRgb groupBoxTextColorDisabled; - QRgb sliderTickColor; - bool hasInitColors; - - 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]; } - - QIcon dockFloat, dockClose; + QPalette standardPalette() const; + QPixmap standardPixmap(StandardPixmap standardIcon, const QStyleOption *option, + const QWidget *widget = 0) const; + QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option = 0, + const QWidget *widget = 0) const; private: -#ifdef DEBUG_XP_STYLE - void dumpNativeDIB(int w, int h); - void showProperties(XPThemeData &themeData); -#endif - - static QBasicAtomicInt ref; - static bool use_xp; - static QPixmap *tabbody; - - QHash alphaCache; - HDC bufferDC; - HBITMAP bufferBitmap; - HBITMAP nullBitmap; - uchar *bufferPixels; - int bufferW, bufferH; - - static HTHEME m_themes[NThemes]; + Q_DISABLE_COPY(QWindowsXPStyle) + Q_DECLARE_PRIVATE(QWindowsXPStyle) + friend class QStyleFactory; + void *reserved; }; -#endif // QT_NO_STYLE_WINDOWS +#endif // QT_NO_STYLE_WINDOWSXP QT_END_NAMESPACE -#endif //QWINDOWSXPSTYLE_P_H +QT_END_HEADER + +#endif // QWINDOWSXPSTYLE_P_H diff --git a/src/widgets/styles/qwindowsxpstyle_p_p.h b/src/widgets/styles/qwindowsxpstyle_p_p.h new file mode 100644 index 0000000000..6bd5e58aec --- /dev/null +++ b/src/widgets/styles/qwindowsxpstyle_p_p.h @@ -0,0 +1,382 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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 "qwindowsxpstyle_p.h" +#include "qwindowsstyle_p.h" +#include +#include + +// Note, these tests are duplicated in qwizard_win.cpp. +#ifdef Q_CC_GNU +# include +# if (__W32API_MAJOR_VERSION >= 3 || (__W32API_MAJOR_VERSION == 2 && __W32API_MINOR_VERSION >= 5)) +# ifdef _WIN32_WINNT +# undef _WIN32_WINNT +# endif +# define _WIN32_WINNT 0x0501 +# include +# endif +#endif + +#include + +#if WINVER >= 0x0600 +#include +#else +#include +#endif + +#include + +QT_BEGIN_NAMESPACE + +// Older Platform SDKs do not have the extended DrawThemeBackgroundEx +// function. We add the needed parts here, and use the extended +// function dynamically, if available in uxtheme.dll. Else, we revert +// back to using the DrawThemeBackground function. +#ifndef DTBG_OMITBORDER +# ifndef DTBG_CLIPRECT +# define DTBG_CLIPRECT 0x00000001 +# endif +# ifndef DTBG_DRAWSOLID +# define DTBG_DRAWSOLID 0x00000002 +# endif +# ifndef DTBG_OMITBORDER +# define DTBG_OMITBORDER 0x00000004 +# endif +# ifndef DTBG_OMITCONTENT +# define DTBG_OMITCONTENT 0x00000008 +# endif +# ifndef DTBG_COMPUTINGREGION +# define DTBG_COMPUTINGREGION 0x00000010 +# endif +# ifndef DTBG_MIRRORDC +# define DTBG_MIRRORDC 0x00000020 +# endif + typedef struct _DTBGOPTS + { + DWORD dwSize; + DWORD dwFlags; + RECT rcClip; + } DTBGOPTS, *PDTBGOPTS; +#endif // _DTBGOPTS + +// Undefined for some compile environments +#ifndef TMT_TEXTCOLOR +# define TMT_TEXTCOLOR 3803 +#endif +#ifndef TMT_BORDERCOLORHINT +# define TMT_BORDERCOLORHINT 3822 +#endif +#ifndef TMT_BORDERSIZE +# define TMT_BORDERSIZE 2403 +#endif +#ifndef TMT_BORDERONLY +# define TMT_BORDERONLY 2203 +#endif +#ifndef TMT_TRANSPARENTCOLOR +# define TMT_TRANSPARENTCOLOR 3809 +#endif +#ifndef TMT_CAPTIONMARGINS +# define TMT_CAPTIONMARGINS 3603 +#endif +#ifndef TMT_CONTENTMARGINS +# define TMT_CONTENTMARGINS 3602 +#endif +#ifndef TMT_SIZINGMARGINS +# define TMT_SIZINGMARGINS 3601 +#endif +#ifndef TMT_GLYPHTYPE +# define TMT_GLYPHTYPE 4012 +#endif +#ifndef TMT_BGTYPE +# define TMT_BGTYPE 4001 +#endif +#ifndef TMT_TEXTSHADOWTYPE +# define TMT_TEXTSHADOWTYPE 4010 +#endif +#ifndef TMT_BORDERCOLOR +# define TMT_BORDERCOLOR 3801 +#endif +#ifndef BT_IMAGEFILE +# define BT_IMAGEFILE 0 +#endif +#ifndef BT_BORDERFILL +# define BT_BORDERFILL 1 +#endif +#ifndef BT_NONE +# define BT_NONE 2 +#endif +#ifndef TMT_FILLCOLOR +# define TMT_FILLCOLOR 3802 +#endif +#ifndef TMT_PROGRESSCHUNKSIZE +# define TMT_PROGRESSCHUNKSIZE 2411 +#endif + +// 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 + +#ifndef GT_NONE +# define GT_NONE 0 +#endif +#ifndef GT_IMAGEGLYPH +# define GT_IMAGEGLYPH 1 +#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 + +#if !defined(QT_NO_STYLE_WINDOWSXP) + +// Declarations ----------------------------------------------------------------------------------- +class XPThemeData +{ +public: + explicit XPThemeData(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + int part = 0, int state = 0, const QRect &r = QRect()) + : widget(w), painter(p), theme(themeIn), htheme(0), partId(part), stateId(state), + mirrorHorizontally(false), mirrorVertically(false), noBorder(false), + noContent(false), rotate(0), rect(r) + {} + + HRGN mask(QWidget *widget); + HTHEME handle(); + + RECT toRECT(const QRect &qr); + bool isValid(); + + const QWidget *widget; + QPainter *painter; + + int theme; + HTHEME htheme; + int partId; + int stateId; + + uint mirrorHorizontally : 1; + uint mirrorVertically : 1; + uint noBorder : 1; + uint noContent : 1; + uint rotate; + QRect rect; +}; + +struct ThemeMapKey { + int theme; + int partId; + int stateId; + bool noBorder; + bool noContent; + + ThemeMapKey() : partId(-1), stateId(-1) {} + ThemeMapKey(const XPThemeData &data) + : theme(data.theme), partId(data.partId), stateId(data.stateId), + noBorder(data.noBorder), noContent(data.noContent) {} + +}; + +inline uint 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; // Which type of alpha on part & state + + bool dataValid : 1; // Only used to detect if hash value is ok + bool partIsTransparent : 1; + bool hasAnyData : 1; // False = part & state has not data, NOP + 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), hasAnyData(false), + hasAlphaChannel(false), wasAlphaSwapped(false), hadInvalidAlpha(false) {} +}; + +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, + TreeViewTheme, + WindowTheme, + StatusTheme, + NThemes + }; + + QWindowsXPStylePrivate() + : QWindowsStylePrivate(), hasInitColors(false), bufferDC(0), bufferBitmap(0), nullBitmap(0), + bufferPixels(0), bufferW(0), bufferH(0) + { init(); } + + ~QWindowsXPStylePrivate() + { cleanup(); } + + static HWND winId(const QWidget *widget); + + void init(bool force = false); + void cleanup(bool force = false); + void cleanupHandleMap(); + const QPixmap *tabBody(QWidget *widget); + + HBITMAP buffer(int w = 0, int h = 0); + HDC bufferHDC() + { return bufferDC;} + + static bool resolveSymbols(); + static bool useXP(bool update = false); + + bool isTransparent(XPThemeData &themeData); + QRegion region(XPThemeData &themeData); + + void setTransparency(QWidget *widget, XPThemeData &themeData); + void drawBackground(XPThemeData &themeData); + void drawBackgroundThruNativeBuffer(XPThemeData &themeData); + void drawBackgroundDirectly(XPThemeData &themeData); + + bool hasAnyData(const QRect &rect); + bool hasAlphaChannel(const QRect &rect); + bool fixAlphaChannel(const QRect &rect); + bool swapAlphaChannel(const QRect &rect, bool allPixels = false); + + QRgb groupBoxTextColor; + QRgb groupBoxTextColorDisabled; + QRgb sliderTickColor; + bool hasInitColors; + + 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]; } + + QIcon dockFloat, dockClose; + +private: +#ifdef DEBUG_XP_STYLE + void dumpNativeDIB(int w, int h); + void showProperties(XPThemeData &themeData); +#endif + + static QBasicAtomicInt ref; + static bool use_xp; + static QPixmap *tabbody; + + QHash alphaCache; + HDC bufferDC; + HBITMAP bufferBitmap; + HBITMAP nullBitmap; + uchar *bufferPixels; + int bufferW, bufferH; + + static HTHEME m_themes[NThemes]; +}; + +#endif // QT_NO_STYLE_WINDOWS + +QT_END_NAMESPACE + +#endif //QWINDOWSXPSTYLE_P_P_H diff --git a/src/widgets/styles/styles.pri b/src/widgets/styles/styles.pri index 82ee5e06a7..c68018f2a2 100644 --- a/src/widgets/styles/styles.pri +++ b/src/widgets/styles/styles.pri @@ -87,7 +87,8 @@ contains( styles, windowsvista ) { } contains( styles, windowsxp ) { - HEADERS += styles/qwindowsxpstyle.h + HEADERS += styles/qwindowsxpstyle_p.h + HEADERS += styles/qwindowsxpstyle_p_p.h SOURCES += styles/qwindowsxpstyle.cpp !contains( styles, windows ) { message( windowsxp requires windows ) diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp index 73dec7d566..d4d26cc9cf 100644 --- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp +++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp @@ -75,10 +75,6 @@ #include #endif -#ifdef Q_OS_WIN -#include -#endif - #ifdef Q_OS_WINCE #include #endif @@ -392,9 +388,10 @@ void tst_QStyle::testWindowsStyle() // WindowsXP style void tst_QStyle::testWindowsXPStyle() { - QWindowsXPStyle xpstyle; - QVERIFY(testAllFunctions(&xpstyle)); - lineUpLayoutTest(&xpstyle); + QStyle *xpstyle = QStyleFactory::create("WindowsXP"); + QVERIFY(testAllFunctions(xpstyle)); + lineUpLayoutTest(xpstyle); + delete xpstyle; } #endif