⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwindowsxpstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 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://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** 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 "qwindowsxpstyle_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 <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 <qlabel.h>#include <qvarlengtharray.h>#include <qdebug.h>// 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();// Theme data helper ------------------------------------------------------------------------------/* \internal    Returns true if the themedata is valid for use.*/bool XPThemeData::isValid(){    return QWindowsXPStylePrivate::useXP() && name.size() && 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 XPThemeData::handle(){    if (!QWindowsXPStylePrivate::useXP())        return 0;    if (!htheme && QWindowsXPStylePrivate::handleMap)        htheme = QWindowsXPStylePrivate::handleMap->operator[](name);    if (!htheme) {        htheme = pOpenThemeData(QWindowsXPStylePrivate::winId(widget),                                (TCHAR*)name.utf16());        if (htheme) {            if (!QWindowsXPStylePrivate::handleMap)                QWindowsXPStylePrivate::handleMap = new QMap<QString, HTHEME>;            QWindowsXPStylePrivate::handleMap->operator[](name) = htheme;        }    }    return htheme;}/* \internal    Converts a QRect to the native RECT structure.*/RECT XPThemeData::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 XPThemeData::mask(){    if (!pIsThemeBackgroundPartiallyTransparent(handle(), partId, stateId))        return 0;    HRGN hrgn;    HDC dc = painter == 0 ? 0 : painter->paintEngine()->getDC();    RECT nativeRect = toRECT(rect);    pGetThemeBackgroundRegion(handle(), dc, partId, stateId, &nativeRect, &hrgn);    if (dc)        painter->paintEngine()->releaseDC(dc);    return hrgn;}// QWindowsXPStylePrivate -------------------------------------------------------------------------// Static initializationsQWidget *QWindowsXPStylePrivate::limboWidget = 0;QPixmap *QWindowsXPStylePrivate::tabbody = 0;QMap<QString,HTHEME> *QWindowsXPStylePrivate::handleMap = 0;bool QWindowsXPStylePrivate::use_xp = false;QAtomic QWindowsXPStylePrivate::ref = QAtomic(-1); // -1 based refcounting/* \internal    Checks if the theme engine can/should be used, or if we should    fall back to Windows style.*/bool QWindowsXPStylePrivate::useXP(bool update){    if (!update)        return use_xp;    return (use_xp = resolveSymbols() && pIsThemeActive()            && (pIsAppThemed() || !QApplication::instance()));}/* \internal    Handles refcounting, and queries the theme engine for usage.*/void QWindowsXPStylePrivate::init(bool force){    if (ref.ref() && !force)        return;    if (!force) // -1 based atomic refcounting        ref.ref();    useXP(true);}/* \internal    Cleans up all static data.*/void QWindowsXPStylePrivate::cleanup(bool force){    if(bufferBitmap) {        if (bufferDC && nullBitmap)            SelectObject(bufferDC, nullBitmap);        DeleteObject(bufferBitmap);        bufferBitmap = 0;    }    if(bufferDC)        DeleteDC(bufferDC);    bufferDC = 0;    if (ref.deref() && !force)        return;    if (!force)  // -1 based atomic refcounting        ref.deref();    use_xp = false;    cleanupHandleMap();    if (limboWidget)        limboWidget->deleteLater();    delete tabbody;    limboWidget = 0;    tabbody = 0;}/* \internal    Closes all open theme data handles to ensure that we don't leak    resources, and that we don't refere to old handles when for    example the user changes the theme style.*/void QWindowsXPStylePrivate::cleanupHandleMap(){    if (!handleMap)        return;    QMap<QString, HTHEME>::Iterator it;    for (it = handleMap->begin(); it != handleMap->end(); ++it)        pCloseThemeData(it.value());    delete handleMap;    handleMap = 0;}/*! \internal    This function will always return a valid window handle, and might    create a limbo widget to do so.    We often need a window handle to for example open theme data, so    this function ensures that we get one.*/HWND QWindowsXPStylePrivate::winId(const QWidget *widget){    if (widget && widget->testAttribute(Qt::WA_WState_Created)) {        return widget->winId();    }    if (!limboWidget) {        limboWidget = new QWidget(0);        limboWidget->setObjectName(QLatin1String("xp_limbo_widget"));    }    return limboWidget->winId();}/*! \internal    Returns the pointer to a tab widgets body pixmap, scaled to the    height of the screen. This way the theme engine doesn't need to    scale the body for every time we ask for it. (Speed optimization)*/const QPixmap *QWindowsXPStylePrivate::tabBody(QWidget *){    if (!tabbody) {        SIZE sz;        XPThemeData theme(0, 0, QLatin1String("TAB"), TABP_BODY);        pGetThemePartSize(theme.handle(), qt_win_display_dc(), TABP_BODY, 0, 0, TS_TRUE, &sz);        tabbody = new QPixmap(sz.cx, QApplication::desktop()->screenGeometry().height());        QPainter painter(tabbody);        theme.rect = QRect(0, 0, sz.cx, sz.cy);        drawBackground(theme);        // We fill with the last line of the themedata, that        // way we don't get a tiled pixmap inside big tabs        QPixmap temp(sz.cx, 1);        painter.drawPixmap(0, 0, temp, 0, sz.cy-1, -1, -1);        painter.drawTiledPixmap(0, sz.cy, sz.cx, tabbody->height()-sz.cy, temp);    }    return tabbody;}/*! \internal    Returns true if all the necessary theme engine symbols were    resolved.*/bool QWindowsXPStylePrivate::resolveSymbols(){    static bool tried = false;    if (!tried) {        tried = true;        QLibrary themeLib(QLatin1String("uxtheme"));        pIsAppThemed = (PtrIsAppThemed)themeLib.resolve("IsAppThemed");        if (pIsAppThemed) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -