📄 qwindowsxpstyle.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.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 GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qwindowsxpstyle.h"#include "qwindowsstyle_p.h"#if !defined(QT_NO_STYLE_WINDOWSXP) || defined(QT_PLUGIN)#include <private/qobject_p.h>#include <private/qpaintengine_raster_p.h>#include <qlibrary.h>#include <qmap.h>#include <qpainter.h>#include <qpaintengine.h>#include <qwidget.h>#include <qapplication.h>#include <qpixmapcache.h>#include <qdesktopwidget.h>#include <qtoolbutton.h>#include <qtabbar.h>#include <qcombobox.h>#include <qscrollbar.h>#include <qheaderview.h>#include <qspinbox.h>#include <qstackedwidget.h>#include <qpushbutton.h>#include <qtoolbar.h>#include <qdockwidget.h>#include <qlabel.h>#include <qt_windows.h>// Uncomment define below to build debug assisting code, and output//#define DEBUG_XP_STYLE#include <qdebug.h>#ifdef Q_CC_GNU# include <w32api.h># 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 <commctrl.h># endif#endif#include <uxtheme.h>#include <tmschema.h>#include <limits.h>// 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 BT_IMAGEFILE# define BT_IMAGEFILE 0#endif#ifndef TMT_FILLCOLOR# define TMT_FILLCOLOR 3802#endif#ifndef TMT_TEXTSHADOWCOLOR# define TMT_TEXTSHADOWCOLOR 3818#endif#ifndef GT_NONE# define GT_NONE 0#endif#ifndef GT_IMAGEGLYPH# define GT_IMAGEGLYPH 1#endif// 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// 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// Runtime resolved theme engine function callstypedef bool (WINAPI *PtrIsAppThemed)();typedef bool (WINAPI *PtrIsThemeActive)();typedef HRESULT (WINAPI *PtrGetThemePartSize)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, OPTIONAL RECT *prc, enum THEMESIZE eSize, OUT SIZE *psz);typedef HTHEME (WINAPI *PtrOpenThemeData)(HWND hwnd, LPCWSTR pszClassList);typedef HRESULT (WINAPI *PtrCloseThemeData)(HTHEME hTheme);typedef HRESULT (WINAPI *PtrDrawThemeBackground)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect);typedef HRESULT (WINAPI *PtrDrawThemeBackgroundEx)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const DTBGOPTS *pOptions);typedef HRESULT (WINAPI *PtrGetCurrentThemeName)(OUT LPWSTR pszThemeFileName, int cchMaxNameChars, OUT OPTIONAL LPWSTR pszColorBuff, int cchMaxColorChars, OUT OPTIONAL LPWSTR pszSizeBuff, int cchMaxSizeChars);typedef HRESULT (WINAPI *PtrGetThemeDocumentationProperty)(LPCWSTR pszThemeName, LPCWSTR pszPropertyName, OUT LPWSTR pszValueBuff, int cchMaxValChars);typedef HRESULT (WINAPI *PtrGetThemeBool)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT BOOL *pfVal);typedef HRESULT (WINAPI *PtrGetThemeColor)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT COLORREF *pColor);typedef HRESULT (WINAPI *PtrGetThemeEnumValue)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT int *piVal);typedef HRESULT (WINAPI *PtrGetThemeFilename)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT LPWSTR pszThemeFileName, int cchMaxBuffChars);typedef HRESULT (WINAPI *PtrGetThemeFont)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, OUT LOGFONT *pFont);typedef HRESULT (WINAPI *PtrGetThemeInt)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT int *piVal);typedef HRESULT (WINAPI *PtrGetThemeIntList)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT INTLIST *pIntList);typedef HRESULT (WINAPI *PtrGetThemeMargins)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, OPTIONAL RECT *prc, OUT MARGINS *pMargins);typedef HRESULT (WINAPI *PtrGetThemeMetric)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, OUT int *piVal);typedef HRESULT (WINAPI *PtrGetThemePartSize)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, OPTIONAL RECT *prc, enum THEMESIZE eSize, OUT SIZE *psz);typedef HRESULT (WINAPI *PtrGetThemePosition)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT POINT *pPoint);typedef HRESULT (WINAPI *PtrGetThemePropertyOrigin)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT enum PROPERTYORIGIN *pOrigin);typedef HRESULT (WINAPI *PtrGetThemeRect)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT RECT *pRect);typedef HRESULT (WINAPI *PtrGetThemeString)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT LPWSTR pszBuff, int cchMaxBuffChars);typedef HRESULT (WINAPI *PtrGetThemeBackgroundRegion)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, const RECT *pRect, OUT HRGN *pRegion);typedef BOOL (WINAPI *PtrIsThemeBackgroundPartiallyTransparent)(HTHEME hTheme, int iPartId, int iStateId);static PtrIsAppThemed pIsAppThemed = 0;static PtrIsThemeActive pIsThemeActive = 0;static PtrOpenThemeData pOpenThemeData = 0;static PtrCloseThemeData pCloseThemeData = 0;static PtrDrawThemeBackground pDrawThemeBackground = 0;static PtrDrawThemeBackgroundEx pDrawThemeBackgroundEx = 0;static PtrGetCurrentThemeName pGetCurrentThemeName = 0;static PtrGetThemeBool pGetThemeBool = 0;static PtrGetThemeColor pGetThemeColor = 0;static PtrGetThemeEnumValue pGetThemeEnumValue = 0;static PtrGetThemeFilename pGetThemeFilename = 0;static PtrGetThemeFont pGetThemeFont = 0;static PtrGetThemeInt pGetThemeInt = 0;static PtrGetThemeIntList pGetThemeIntList = 0;static PtrGetThemeMargins pGetThemeMargins = 0;static PtrGetThemeMetric pGetThemeMetric = 0;static PtrGetThemePartSize pGetThemePartSize = 0;static PtrGetThemePosition pGetThemePosition = 0;static PtrGetThemePropertyOrigin pGetThemePropertyOrigin = 0;static PtrGetThemeRect pGetThemeRect = 0;static PtrGetThemeString pGetThemeString = 0;static PtrGetThemeBackgroundRegion pGetThemeBackgroundRegion = 0;static PtrGetThemeDocumentationProperty pGetThemeDocumentationProperty = 0;static PtrIsThemeBackgroundPartiallyTransparent pIsThemeBackgroundPartiallyTransparent = 0;// General const valuesstatic const int windowsItemFrame = 2; // menu item frame widthstatic const int windowsSepHeight = 9; // separator item heightstatic const int windowsItemHMargin = 3; // menu item hor text marginstatic const int windowsItemVMargin = 0; // menu item ver text marginstatic const int windowsArrowHMargin = 6; // arrow horizontal marginstatic const int windowsCheckMarkHMargin = 0; // horiz. margins of check markstatic const int windowsRightBorder = 12; // right border on windows// External function callsextern Q_GUI_EXPORT HDC qt_win_display_dc();// Declarations -----------------------------------------------------------------------------------class XPThemeData{public: XPThemeData(const QWidget *w = 0, QPainter *p = 0, const QString &theme = QString(), int part = 0, int state = 0, const QRect &r = QRect()) : widget(w), painter(p), name(theme), htheme(0), partId(part), stateId(state), mirrorHorizontally(false), mirrorVertically(false), noBorder(false), noContent(false), rotate(0), rect(r) {} HRGN mask(); HTHEME handle(); RECT toRECT(const QRect &qr); bool isValid(); const QWidget *widget; QPainter *painter; QString name; HTHEME htheme; int partId; int stateId; uint mirrorHorizontally : 1; uint mirrorVertically : 1; uint noBorder : 1; uint noContent : 1; uint rotate; QRect rect;};struct ThemeMapKey { QString name; int partId; int stateId; bool noBorder; bool noContent; ThemeMapKey() : partId(-1), stateId(-1) {} ThemeMapKey(const XPThemeData &data) : name(data.name), partId(data.partId), stateId(data.stateId), noBorder(data.noBorder), noContent(data.noContent) {}};inline uint qHash(const ThemeMapKey &key){ return qHash(key.name) ^ key.partId ^ key.stateId; }inline bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2){ return k1.name == k2.name && 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: 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 inline 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); QRgb groupBoxTextColor; QRgb groupBoxTextColorDisabled; QRgb sliderTickColor; bool hasInitColors; static QMap<QString,HTHEME> *handleMap; QIcon dockFloat, dockClose;private:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -