From: Friedemann Kleint Date: Mon, 28 Nov 2011 13:33:54 +0000 (+0100) Subject: QtGui: Bring back HBITMAP/HICON conversion functions. X-Git-Tag: qt-v5.0.0-alpha1~2512 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b8d330904b279de57d70caef70ab2d2a6770f0cc;p=profile%2Fivi%2Fqtbase.git QtGui: Bring back HBITMAP/HICON conversion functions. - Move the conversion functions from the Lighthouse plugin to QtGui as qt_pixmap/From/To/HBITMAP/HICON(). - Re-enable them in Widgets (QFileIconProvider, QWindowsStyle). - Use them in QtPrintSupport. Change-Id: I1436bc604160d94c78ef270ad2b31bf3b20b5c90 Reviewed-by: Samuel Rødal --- diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri index ba200bf..b8eb546 100644 --- a/src/gui/image/image.pri +++ b/src/gui/image/image.pri @@ -46,6 +46,7 @@ SOURCES += \ image/qvolatileimage.cpp SOURCES += image/qpixmap_qpa.cpp +win32: SOURCES += image/qpixmap_win.cpp !symbian|contains(S60_VERSION, 3.1)|contains(S60_VERSION, 3.2) { SOURCES += image/qvolatileimagedata.cpp diff --git a/src/plugins/platforms/windows/pixmaputils.cpp b/src/gui/image/qpixmap_win.cpp similarity index 88% rename from src/plugins/platforms/windows/pixmaputils.cpp rename to src/gui/image/qpixmap_win.cpp index 539b3b3..6b6dea7 100644 --- a/src/plugins/platforms/windows/pixmaputils.cpp +++ b/src/gui/image/qpixmap_win.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the QtGui module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** GNU Lesser General Public License Usage @@ -39,21 +39,24 @@ ** ****************************************************************************/ -#include "pixmaputils.h" +#include "qpixmap.h" +#include "qplatformpixmap_qpa.h" +#include "qpixmap_raster_p.h" -#include -#include -#include -#include - -#include -#include - -#include +#include +#include +#include QT_BEGIN_NAMESPACE -HBITMAP createIconMask(const QBitmap &bitmap) +enum HBitmapFormat +{ + HBitmapNoAlpha, + HBitmapPremultipliedAlpha, + HBitmapAlpha +}; + +Q_GUI_EXPORT HBITMAP qt_createIconMask(const QBitmap &bitmap) { QImage bm = bitmap.toImage().convertToFormat(QImage::Format_Mono); const int w = bm.width(); @@ -67,7 +70,7 @@ HBITMAP createIconMask(const QBitmap &bitmap) return hbm; } -HBITMAP qPixmapToWinHBITMAP(const QPixmap &p, HBitmapFormat format) +Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0) { if (p.isNull()) return 0; @@ -77,7 +80,7 @@ HBITMAP qPixmapToWinHBITMAP(const QPixmap &p, HBitmapFormat format) QRasterPlatformPixmap *data = new QRasterPlatformPixmap(p.depth() == 1 ? QRasterPlatformPixmap::BitmapType : QRasterPlatformPixmap::PixmapType); data->fromImage(p.toImage(), Qt::AutoColor); - return qPixmapToWinHBITMAP(QPixmap(data), format); + return qt_pixmapToWinHBITMAP(QPixmap(data), hbitmapFormat); } QRasterPlatformPixmap *d = static_cast(p.handle()); @@ -113,9 +116,9 @@ HBITMAP qPixmapToWinHBITMAP(const QPixmap &p, HBitmapFormat format) // Copy over the data QImage::Format imageFormat = QImage::Format_ARGB32; - if (format == HBitmapAlpha) + if (hbitmapFormat == HBitmapAlpha) imageFormat = QImage::Format_RGB32; - else if (format == HBitmapPremultipliedAlpha) + else if (hbitmapFormat == HBitmapPremultipliedAlpha) imageFormat = QImage::Format_ARGB32_Premultiplied; const QImage image = rasterImage->convertToFormat(imageFormat); const int bytes_per_line = w * 4; @@ -125,7 +128,7 @@ HBITMAP qPixmapToWinHBITMAP(const QPixmap &p, HBitmapFormat format) return bitmap; } -QPixmap qPixmapFromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format) +Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat = 0) { // Verify size BITMAP bitmap_info; @@ -160,7 +163,7 @@ QPixmap qPixmapFromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format) QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied; uint mask = 0; - if (format == HBitmapNoAlpha) { + if (hbitmapFormat == HBitmapNoAlpha) { imageFormat = QImage::Format_RGB32; mask = 0xff000000; } @@ -188,7 +191,7 @@ QPixmap qPixmapFromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format) return QPixmap::fromImage(image); } -HICON qPixmapToWinHICON(const QPixmap &p) +Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &p) { QBitmap maskBitmap = p.mask(); if (maskBitmap.isNull()) { @@ -198,8 +201,8 @@ HICON qPixmapToWinHICON(const QPixmap &p) ICONINFO ii; ii.fIcon = true; - ii.hbmMask = createIconMask(maskBitmap); - ii.hbmColor = qPixmapToWinHBITMAP(p, HBitmapAlpha); + ii.hbmMask = qt_createIconMask(maskBitmap); + ii.hbmColor = qt_pixmapToWinHBITMAP(p, HBitmapAlpha); ii.xHotspot = 0; ii.yHotspot = 0; @@ -211,7 +214,7 @@ HICON qPixmapToWinHICON(const QPixmap &p) return hIcon; } -static QImage qImageFromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h) +Q_GUI_EXPORT QImage qt_imageFromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h) { BITMAPINFO bmi; memset(&bmi, 0, sizeof(bmi)); @@ -228,7 +231,7 @@ static QImage qImageFromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h) return image; // Get bitmap bits - QScopedPointer data(new uchar [bmi.bmiHeader.biSizeImage]); + QScopedArrayPointer data(new uchar [bmi.bmiHeader.biSizeImage]); if (!GetDIBits(hdc, bitmap, 0, h, data.data(), &bmi, DIB_RGB_COLORS)) { qErrnoWarning("%s: failed to get bitmap bits", __FUNCTION__); return QImage(); @@ -242,7 +245,7 @@ static QImage qImageFromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h) return image; } -QPixmap qPixmapFromWinHICON(HICON icon) +Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon) { bool foundAlpha = false; HDC screenDevice = GetDC(0); @@ -276,7 +279,7 @@ QPixmap qPixmapFromWinHICON(HICON icon) HBITMAP winBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bitmapInfo, DIB_RGB_COLORS, (VOID**)&bits, NULL, 0); HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap); DrawIconEx( hdc, 0, 0, icon, iconinfo.xHotspot * 2, iconinfo.yHotspot * 2, 0, 0, DI_NORMAL); - QImage image = qImageFromWinHBITMAP(hdc, winBitmap, w, h); + QImage image = qt_imageFromWinHBITMAP(hdc, winBitmap, w, h); for (int y = 0 ; y < h && !foundAlpha ; y++) { const QRgb *scanLine= reinterpret_cast(image.scanLine(y)); @@ -290,7 +293,7 @@ QPixmap qPixmapFromWinHICON(HICON icon) if (!foundAlpha) { //If no alpha was found, we use the mask to set alpha values DrawIconEx( hdc, 0, 0, icon, w, h, 0, 0, DI_MASK); - const QImage mask = qImageFromWinHBITMAP(hdc, winBitmap, w, h); + const QImage mask = qt_imageFromWinHBITMAP(hdc, winBitmap, w, h); for (int y = 0 ; y < h ; y++){ QRgb *scanlineImage = reinterpret_cast(image.scanLine(y)); diff --git a/src/plugins/platforms/windows/pixmaputils.h b/src/plugins/platforms/windows/pixmaputils.h deleted file mode 100644 index 0708cdf..0000000 --- a/src/plugins/platforms/windows/pixmaputils.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PIXMAPUTILS_H -#define PIXMAPUTILS_H - -#include "qtwindows_additional.h" - -#include - -QT_BEGIN_NAMESPACE - -class QBitmap; -class QPixmap; - -enum HBitmapFormat -{ - HBitmapNoAlpha, - HBitmapPremultipliedAlpha, - HBitmapAlpha -}; - -HBITMAP createIconMask(const QBitmap &bitmap); - -HBITMAP qPixmapToWinHBITMAP(const QPixmap &p, HBitmapFormat format); -HICON qPixmapToWinHICON(const QPixmap &p); - -QPixmap qPixmapFromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format); -QPixmap qPixmapFromWinHICON(HICON icon); - -QT_END_NAMESPACE - -#endif // PIXMAPUTILS_H diff --git a/src/plugins/platforms/windows/qwindowscursor.cpp b/src/plugins/platforms/windows/qwindowscursor.cpp index 509a940..a3edd78 100644 --- a/src/plugins/platforms/windows/qwindowscursor.cpp +++ b/src/plugins/platforms/windows/qwindowscursor.cpp @@ -43,7 +43,6 @@ #include "qwindowscontext.h" #include "qwindowswindow.h" #include "qwindowsscreen.h" -#include "pixmaputils.h" #include #include @@ -57,6 +56,9 @@ QT_BEGIN_NAMESPACE +Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0); +Q_GUI_EXPORT HBITMAP qt_createIconMask(const QBitmap &bitmap); + /*! \class QWindowsCursor \brief Platform cursor implementation @@ -84,8 +86,8 @@ HCURSOR QWindowsCursor::createPixmapCursor(const QPixmap &pixmap, int hotX, int mask.fill(Qt::color1); } - HBITMAP ic = qPixmapToWinHBITMAP(pixmap, HBitmapAlpha); - const HBITMAP im = createIconMask(mask); + HBITMAP ic = qt_pixmapToWinHBITMAP(pixmap, /* HBitmapAlpha */ 2); + const HBITMAP im = qt_createIconMask(mask); ICONINFO ii; ii.fIcon = 0; diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 96f3917..08696a6 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -42,7 +42,6 @@ #include "qwindowsscreen.h" #include "qwindowscontext.h" #include "qwindowswindow.h" -#include "pixmaputils.h" #include "qwindowscursor.h" #include "qtwindows_additional.h" @@ -150,6 +149,8 @@ QList QWindowsScreen::screens() QPixmap QWindowsScreen::grabWindow(WId window, int x, int y, int width, int height) const { + Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat = 0); + if (QWindowsContext::verboseIntegration) qDebug() << __FUNCTION__ << window << x << y << width << height; RECT r; @@ -174,7 +175,7 @@ QPixmap QWindowsScreen::grabWindow(WId window, int x, int y, int width, int heig SelectObject(bitmap_dc, null_bitmap); DeleteDC(bitmap_dc); - const QPixmap pixmap = qPixmapFromWinHBITMAP(bitmap, HBitmapNoAlpha); + const QPixmap pixmap = qt_pixmapFromWinHBITMAP(bitmap); DeleteObject(bitmap); ReleaseDC(0, display_dc); diff --git a/src/plugins/platforms/windows/windows.pro b/src/plugins/platforms/windows/windows.pro index 33ca07d..4b72025 100644 --- a/src/plugins/platforms/windows/windows.pro +++ b/src/plugins/platforms/windows/windows.pro @@ -43,7 +43,6 @@ SOURCES += \ qwindowsmime.cpp \ qwindowsdrag.cpp \ qwindowscursor.cpp \ - pixmaputils.cpp \ qwindowsinputcontext.cpp \ qwindowsaccessibility.cpp \ qwindowstheme.cpp \ @@ -70,7 +69,6 @@ HEADERS += \ qwindowsdrag.h \ qwindowsinternalmimedata.h \ qwindowscursor.h \ - pixmaputils.h \ array.h \ qwindowsinputcontext.h \ qwindowsaccessibility.h \ diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 603ac6a..52fd765 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE +Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0); extern QPainterPath qt_regionToPath(const QRegion ®ion); // #define QT_DEBUG_DRAW @@ -626,64 +627,6 @@ enum HBitmapFormat HBitmapAlpha }; -HBITMAP qPixmapToWinHBITMAP(const QPixmap &p, HBitmapFormat format) -{ - if (p.isNull()) - return 0; - - HBITMAP bitmap = 0; - if (p.handle()->classId() != QPlatformPixmap::RasterClass) { - QRasterPlatformPixmap *data = new QRasterPlatformPixmap(p.depth() == 1 ? - QRasterPlatformPixmap::BitmapType : QRasterPlatformPixmap::PixmapType); - data->fromImage(p.toImage(), Qt::AutoColor); - return qPixmapToWinHBITMAP(QPixmap(data), format); - } - - QRasterPlatformPixmap *d = static_cast(p.handle()); - const QImage *rasterImage = d->buffer(); - const int w = rasterImage->width(); - const int h = rasterImage->height(); - - HDC display_dc = GetDC(0); - - // Define the header - BITMAPINFO bmi; - memset(&bmi, 0, sizeof(bmi)); - bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi.bmiHeader.biWidth = w; - bmi.bmiHeader.biHeight = -h; - bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biBitCount = 32; - bmi.bmiHeader.biCompression = BI_RGB; - bmi.bmiHeader.biSizeImage = w * h * 4; - - // Create the pixmap - uchar *pixels = 0; - bitmap = CreateDIBSection(display_dc, &bmi, DIB_RGB_COLORS, (void **) &pixels, 0, 0); - ReleaseDC(0, display_dc); - if (!bitmap) { - qErrnoWarning("%s, failed to create dibsection", __FUNCTION__); - return 0; - } - if (!pixels) { - qErrnoWarning("%s, did not allocate pixel data", __FUNCTION__); - return 0; - } - - // Copy over the data - QImage::Format imageFormat = QImage::Format_ARGB32; - if (format == HBitmapAlpha) - imageFormat = QImage::Format_RGB32; - else if (format == HBitmapPremultipliedAlpha) - imageFormat = QImage::Format_ARGB32_Premultiplied; - const QImage image = rasterImage->convertToFormat(imageFormat); - const int bytes_per_line = w * 4; - for (int y=0; y < h; ++y) - memcpy(pixels + y * bytes_per_line, image.scanLine(y), bytes_per_line); - - return bitmap; -} - void QWin32PrintEngine::drawPixmap(const QRectF &targetRect, const QPixmap &originalPixmap, const QRectF &sourceRect) @@ -760,7 +703,7 @@ void QWin32PrintEngine::drawPixmap(const QRectF &targetRect, } QPixmap p = pixmap.copy(tileSize * x, tileSize * y, imgw, imgh); - HBITMAP hbitmap = qPixmapToWinHBITMAP(p, HBitmapNoAlpha); + HBITMAP hbitmap = qt_pixmapToWinHBITMAP(p, HBitmapNoAlpha); HDC display_dc = GetDC(0); HDC hbitmap_hdc = CreateCompatibleDC(display_dc); HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap); @@ -795,7 +738,7 @@ void QWin32PrintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pm, cons int dc_state = SaveDC(d->hdc); HDC display_dc = GetDC(0); - HBITMAP hbitmap = qPixmapToWinHBITMAP(pm, HBitmapNoAlpha); + HBITMAP hbitmap = qt_pixmapToWinHBITMAP(pm, HBitmapNoAlpha); HDC hbitmap_hdc = CreateCompatibleDC(display_dc); HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap); diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index 6177700..075c8b8 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -320,6 +320,8 @@ bool QVistaHelper::setDWMTitleBar(TitleBarChangeType type) void QVistaHelper::drawTitleBar(QPainter *painter) { + Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &); + Q_ASSERT(backButton_); QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); QBackingStore *backingStore = backButton_->backingStore(); @@ -351,9 +353,10 @@ void QVistaHelper::drawTitleBar(QPainter *painter) QRect(titleOffset() - glowOffset, verticalCenter - textHeight / 2, textWidth, textHeight), hdc); - if (!wizard->windowIcon().isNull()) { + const QIcon windowIcon = wizard->windowIcon(); + if (!windowIcon.isNull()) { QRect rect(leftMargin(), verticalCenter - iconSize() / 2, iconSize(), iconSize()); - HICON hIcon = 0; //###FIXME wizard->windowIcon().pixmap(iconSize()).toWinHICON(); + const HICON hIcon = qt_pixmapToWinHICON(windowIcon.pixmap(iconSize())); DrawIconEx(hdc, rect.left(), rect.top(), hIcon, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT); DestroyIcon(hIcon); } diff --git a/src/widgets/itemviews/qfileiconprovider.cpp b/src/widgets/itemviews/qfileiconprovider.cpp index d4dd9e8..1821171 100644 --- a/src/widgets/itemviews/qfileiconprovider.cpp +++ b/src/widgets/itemviews/qfileiconprovider.cpp @@ -46,11 +46,14 @@ #include #include #include -#if defined(Q_WS_WIN) +#if defined(Q_OS_WIN) # define _WIN32_IE 0x0500 # include # include # include + +Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon); + #elif defined(Q_WS_MAC) # include #endif @@ -96,7 +99,7 @@ class QFileIconProviderPrivate public: QFileIconProviderPrivate(); QIcon getIcon(QStyle::StandardPixmap name) const; -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN QIcon getWinIcon(const QFileInfo &fi) const; #elif defined(Q_WS_MAC) QIcon getMacIcon(const QFileInfo &fi) const; @@ -229,7 +232,7 @@ QIcon QFileIconProvider::icon(IconType type) const return QIcon(); } -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const { QIcon retIcon; @@ -284,7 +287,7 @@ QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const } if (pixmap.isNull()) { #ifndef Q_OS_WINCE - pixmap = QPixmap::fromWinHICON(info.hIcon); + pixmap = qt_pixmapFromWinHICON(info.hIcon); #else pixmap = QPixmap::fromWinHICON(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL)); #endif @@ -314,7 +317,7 @@ QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const key = QString::fromLatin1("qt_dir_%1").arg(info.iIcon); } #ifndef Q_OS_WINCE - pixmap = QPixmap::fromWinHICON(info.hIcon); + pixmap = qt_pixmapFromWinHICON(info.hIcon); #else pixmap = QPixmap::fromWinHICON(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL)); #endif @@ -418,13 +421,13 @@ QIcon QFileIconProvider::icon(const QFileInfo &info) const QIcon retIcon = d->getMacIcon(info); if (!retIcon.isNull()) return retIcon; -#elif defined Q_WS_WIN +#elif defined Q_OS_WIN QIcon icon = d->getWinIcon(info); if (!icon.isNull()) return icon; #endif if (info.isRoot()) -#if defined (Q_WS_WIN) && !defined(Q_WS_WINCE) +#if defined (Q_OS_WIN) && !defined(Q_WS_WINCE) { UINT type = GetDriveType((wchar_t *)info.absoluteFilePath().utf16()); @@ -482,7 +485,7 @@ QString QFileIconProvider::type(const QFileInfo &info) const } if (info.isDir()) -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN return QApplication::translate("QFileDialog", "File Folder", "Match Windows Explorer"); #else return QApplication::translate("QFileDialog", "Folder", "All other platforms"); diff --git a/src/widgets/kernel/win.pri b/src/widgets/kernel/win.pri index 5ecf4dd..4288e09 100644 --- a/src/widgets/kernel/win.pri +++ b/src/widgets/kernel/win.pri @@ -1,4 +1,5 @@ # Qt/Windows only configuration file # -------------------------------------------------------------------- - INCLUDEPATH += ../3rdparty/wintab +INCLUDEPATH += ../3rdparty/wintab +LIBS *= -lshell32 diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 6e84597..f883ace 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -79,7 +79,7 @@ QT_BEGIN_NAMESPACE -#if defined(Q_WS_WIN) +#if defined(Q_OS_WIN) QT_BEGIN_INCLUDE_NAMESPACE #include "qt_windows.h" @@ -109,7 +109,9 @@ typedef struct typedef HRESULT (WINAPI *PtrSHGetStockIconInfo)(int siid, int uFlags, QSHSTOCKICONINFO *psii); static PtrSHGetStockIconInfo pSHGetStockIconInfo = 0; -#endif //Q_WS_WIN +Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &); +Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon); +#endif //Q_OS_WIN QT_BEGIN_INCLUDE_NAMESPACE #include @@ -123,7 +125,7 @@ enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight }; QWindowsStylePrivate::QWindowsStylePrivate() : alt_down(false), menuBarTimer(0), animationFps(10), animateTimer(0), animateStep(0) { -#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) if ((QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) { QSystemLibrary shellLib(QLatin1String("shell32")); @@ -290,7 +292,7 @@ QWindowsStyle::~QWindowsStyle() { } -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN static inline QRgb colorref2qrgb(COLORREF col) { return qRgb(GetRValue(col), GetGValue(col), GetBValue(col)); @@ -312,7 +314,7 @@ void QWindowsStyle::polish(QApplication *app) d->inactiveGradientCaptionColor = app->palette().dark().color(); d->inactiveCaptionText = app->palette().background().color(); -#if defined(Q_WS_WIN) //fetch native title bar colors +#if defined(Q_OS_WIN) //fetch native title bar colors if(app->desktopSettingsAware()){ DWORD activeCaption = GetSysColor(COLOR_ACTIVECAPTION); DWORD gradientActiveCaption = GetSysColor(COLOR_GRADIENTACTIVECAPTION); @@ -390,7 +392,7 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW break; #endif case PM_MaximumDragDistance: -#if defined(Q_WS_WIN) +#if defined(Q_OS_WIN) { HDC hdcScreen = GetDC(0); int dpi = GetDeviceCaps(hdcScreen, LOGPIXELSX); @@ -487,7 +489,7 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW #endif // QT_NO_MENU -#if defined(Q_WS_WIN) +#if defined(Q_OS_WIN) case PM_TitleBarHeight: if (widget && (widget->windowType() == Qt::Tool)) { // MS always use one less than they say @@ -514,13 +516,13 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW ret = QCommonStyle::pixelMetric(pm, opt, widget); } break; -#endif // Q_WS_WIN +#endif // Q_OS_WIN case PM_SplitterWidth: ret = qMax(4, QApplication::globalStrut().width()); break; -#if defined(Q_WS_WIN) +#if defined(Q_OS_WIN) case PM_MdiSubWindowFrameWidth: #if defined(Q_OS_WINCE) ret = GetSystemMetrics(SM_CYDLGFRAME); @@ -926,7 +928,7 @@ static const char *const question_xpm[] = { #endif //QT_NO_IMAGEFORMAT_XPM -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN static QPixmap loadIconFromShell32( int resourceId, int size ) { #ifdef Q_OS_WINCE @@ -937,7 +939,7 @@ static QPixmap loadIconFromShell32( int resourceId, int size ) if( hmod ) { HICON iconHandle = (HICON)LoadImage(hmod, MAKEINTRESOURCE(resourceId), IMAGE_ICON, size, size, 0); if( iconHandle ) { - QPixmap iconpixmap = QPixmap::fromWinHICON( iconHandle ); + QPixmap iconpixmap = qt_pixmapFromWinHICON(iconHandle); DestroyIcon(iconHandle); return iconpixmap; } @@ -952,7 +954,7 @@ static QPixmap loadIconFromShell32( int resourceId, int size ) QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const { -#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) QPixmap desktopIcon; switch(standardPixmap) { case SP_DriveCDIcon: @@ -1035,28 +1037,28 @@ QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyl case SP_MessageBoxInformation: { HICON iconHandle = LoadIcon(NULL, IDI_INFORMATION); - desktopIcon = QPixmap::fromWinHICON( iconHandle ); + desktopIcon = qt_pixmapFromWinHICON(iconHandle); DestroyIcon(iconHandle); break; } case SP_MessageBoxWarning: { HICON iconHandle = LoadIcon(NULL, IDI_WARNING); - desktopIcon = QPixmap::fromWinHICON( iconHandle ); + desktopIcon = qt_pixmapFromWinHICON(iconHandle); DestroyIcon(iconHandle); break; } case SP_MessageBoxCritical: { HICON iconHandle = LoadIcon(NULL, IDI_ERROR); - desktopIcon = QPixmap::fromWinHICON( iconHandle ); + desktopIcon = qt_pixmapFromWinHICON(iconHandle); DestroyIcon(iconHandle); break; } case SP_MessageBoxQuestion: { HICON iconHandle = LoadIcon(NULL, IDI_QUESTION); - desktopIcon = QPixmap::fromWinHICON( iconHandle ); + desktopIcon = qt_pixmapFromWinHICON(iconHandle); DestroyIcon(iconHandle); break; } @@ -1071,7 +1073,7 @@ QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyl memset(&iconInfo, 0, sizeof(iconInfo)); iconInfo.cbSize = sizeof(iconInfo); if (pSHGetStockIconInfo(_SIID_SHIELD, _SHGFI_ICON | _SHGFI_SMALLICON, &iconInfo) == S_OK) { - pixmap = QPixmap::fromWinHICON(iconInfo.hIcon); + pixmap = qt_pixmapFromWinHICON(iconInfo.hIcon); DestroyIcon(iconInfo.hIcon); return pixmap; } @@ -1154,7 +1156,7 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid ret = 0; break; -#if defined(Q_WS_WIN) +#if defined(Q_OS_WIN) case SH_UnderlineShortcut: { ret = 1; @@ -1204,7 +1206,7 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid #endif // QT_NO_RUBBERBAND case SH_LineEdit_PasswordCharacter: { -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN if (widget && (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) { const QFontMetrics &fm = widget->fontMetrics(); if (fm.inFont(QChar(0x25CF))) @@ -3105,7 +3107,7 @@ QIcon QWindowsStyle::standardIconImplementation(StandardPixmap standardIcon, con { QIcon icon; QPixmap pixmap; -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN switch (standardIcon) { case SP_FileDialogNewFolder: { @@ -3216,7 +3218,7 @@ QIcon QWindowsStyle::standardIconImplementation(StandardPixmap standardIcon, con memset(&iconInfo, 0, sizeof(iconInfo)); iconInfo.cbSize = sizeof(iconInfo); if (pSHGetStockIconInfo(_SIID_SHIELD, _SHGFI_ICON | _SHGFI_LARGEICON, &iconInfo) == S_OK) { - icon.addPixmap(QPixmap::fromWinHICON(iconInfo.hIcon)); + icon.addPixmap(qt_pixmapFromWinHICON(iconInfo.hIcon)); DestroyIcon(iconInfo.hIcon); } }