From e689e41ad1baad65d90866eefe88a96f5e16fa04 Mon Sep 17 00:00:00 2001 From: miniak Date: Tue, 22 Sep 2009 10:33:30 +0200 Subject: Cleanup convertHIconToPixmap() & loadIconFromShell32() Replace convertHIconToPixmap() by QPixmap::fromWinHICON() Move loadIconFromShell32() to qwindowsstyle.cpp Merge-request: 1570 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/image/qpixmap_win.cpp | 50 +++++++++++---------------------- src/gui/image/qpixmapdata_p.h | 9 ------ src/gui/itemviews/qfileiconprovider.cpp | 9 +++--- src/gui/styles/qwindowsstyle.cpp | 31 +++++++++++++++----- 4 files changed, 44 insertions(+), 55 deletions(-) diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp index 7f0c8e3..a9bcca2 100644 --- a/src/gui/image/qpixmap_win.cpp +++ b/src/gui/image/qpixmap_win.cpp @@ -274,11 +274,6 @@ HICON QPixmap::toWinHICON() const return hIcon; } -QPixmap QPixmap::fromWinHICON(HICON icon) -{ - return convertHIconToPixmap(icon); -} - #ifdef Q_WS_WIN #ifndef Q_WS_WINCE @@ -316,7 +311,7 @@ static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h) return image; } -QPixmap convertHIconToPixmap( const HICON icon) +QPixmap QPixmap::fromWinHICON(HICON icon) { bool foundAlpha = false; HDC screenDevice = GetDC(0); @@ -326,7 +321,7 @@ QPixmap convertHIconToPixmap( const HICON icon) ICONINFO iconinfo; bool result = GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center if (!result) - qWarning("convertHIconToPixmap(), failed to GetIconInfo()"); + qWarning("QPixmap::fromWinHICON(), failed to GetIconInfo()"); int w = iconinfo.xHotspot * 2; int h = iconinfo.yHotspot * 2; @@ -385,19 +380,25 @@ QPixmap convertHIconToPixmap( const HICON icon) return QPixmap::fromImage(image); } #else //ifndef Q_WS_WINCE -QPixmap convertHIconToPixmap( const HICON icon, bool large) +QPixmap QPixmap::fromWinHICON(HICON icon) { HDC screenDevice = GetDC(0); HDC hdc = CreateCompatibleDC(screenDevice); ReleaseDC(0, screenDevice); - int size = large ? 64 : 32; + ICONINFO iconinfo; + bool result = GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center + if (!result) + qWarning("QPixmap::fromWinHICON(), failed to GetIconInfo()"); + + int w = iconinfo.xHotspot * 2; + int h = iconinfo.yHotspot * 2; BITMAPINFO bmi; memset(&bmi, 0, sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFO); - bmi.bmiHeader.biWidth = size; - bmi.bmiHeader.biHeight = -size; + bmi.bmiHeader.biWidth = w; + bmi.bmiHeader.biHeight = -h; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; @@ -409,13 +410,13 @@ QPixmap convertHIconToPixmap( const HICON icon, bool large) if (winBitmap ) memset(bits, 0xff, size*size*4); if (!winBitmap) { - qWarning("convertHIconToPixmap(), failed to CreateDIBSection()"); + qWarning("QPixmap::fromWinHICON(), failed to CreateDIBSection()"); return QPixmap(); } HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap); if (!DrawIconEx( hdc, 0, 0, icon, size, size, 0, 0, DI_NORMAL)) - qWarning("convertHIconToPixmap(), failed to DrawIcon()"); + qWarning("QPixmap::fromWinHICON(), failed to DrawIcon()"); uint mask = 0xff000000; // Create image and copy data into image. @@ -432,7 +433,7 @@ QPixmap convertHIconToPixmap( const HICON icon, bool large) } } if (!DrawIconEx( hdc, 0, 0, icon, size, size, 0, 0, DI_MASK)) - qWarning("convertHIconToPixmap(), failed to DrawIcon()"); + qWarning("QPixmap::fromWinHICON(), failed to DrawIcon()"); if (!image.isNull()) { // failed to alloc? int bytes_per_line = size * sizeof(QRgb); for (int y=0; y #include #include -#include #elif defined(Q_WS_MAC) #include #endif @@ -262,9 +261,9 @@ QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const } if (pixmap.isNull()) { #ifndef Q_OS_WINCE - pixmap = convertHIconToPixmap(info.hIcon); + pixmap = QPixmap::fromWinHICON(info.hIcon); #else - pixmap = convertHIconToPixmap(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL)); + pixmap = QPixmap::fromWinHICON(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL)); #endif if (!pixmap.isNull()) { retIcon.addPixmap(pixmap); @@ -292,9 +291,9 @@ QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const key = QString::fromLatin1("qt_dir_%1").arg(info.iIcon); } #ifndef Q_OS_WINCE - pixmap = convertHIconToPixmap(info.hIcon); + pixmap = QPixmap::fromWinHICON(info.hIcon); #else - pixmap = convertHIconToPixmap(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL), true); + pixmap = QPixmap::fromWinHICON(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL)); #endif if (!pixmap.isNull()) { retIcon.addPixmap(pixmap); diff --git a/src/gui/styles/qwindowsstyle.cpp b/src/gui/styles/qwindowsstyle.cpp index 742b5b0..f5aadb8 100644 --- a/src/gui/styles/qwindowsstyle.cpp +++ b/src/gui/styles/qwindowsstyle.cpp @@ -41,7 +41,6 @@ #include "qwindowsstyle.h" #include "qwindowsstyle_p.h" -#include #include #if !defined(QT_NO_STYLE_WINDOWS) || defined(QT_PLUGIN) @@ -927,6 +926,24 @@ static const char *const question_xpm[] = { #endif //QT_NO_IMAGEFORMAT_XPM +static QPixmap loadIconFromShell32( int resourceId, int size ) +{ +#ifdef Q_OS_WINCE + HMODULE hmod = LoadLibrary(L"ceshell.dll"); +#else + HMODULE hmod = LoadLibrary(L"shell32.dll"); +#endif + if( hmod ) { + HICON iconHandle = (HICON)LoadImage(hmod, MAKEINTRESOURCE(resourceId), IMAGE_ICON, size, size, 0); + if( iconHandle ) { + QPixmap iconpixmap = QPixmap::fromWinHICON( iconHandle ); + DestroyIcon(iconHandle); + return iconpixmap; + } + } + return QPixmap(); +} + /*! \reimp */ @@ -1016,28 +1033,28 @@ QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyl case SP_MessageBoxInformation: { HICON iconHandle = LoadIcon(NULL, IDI_INFORMATION); - desktopIcon = convertHIconToPixmap( iconHandle ); + desktopIcon = QPixmap::fromWinHICON( iconHandle ); DestroyIcon(iconHandle); break; } case SP_MessageBoxWarning: { HICON iconHandle = LoadIcon(NULL, IDI_WARNING); - desktopIcon = convertHIconToPixmap( iconHandle ); + desktopIcon = QPixmap::fromWinHICON( iconHandle ); DestroyIcon(iconHandle); break; } case SP_MessageBoxCritical: { HICON iconHandle = LoadIcon(NULL, IDI_ERROR); - desktopIcon = convertHIconToPixmap( iconHandle ); + desktopIcon = QPixmap::fromWinHICON( iconHandle ); DestroyIcon(iconHandle); break; } case SP_MessageBoxQuestion: { HICON iconHandle = LoadIcon(NULL, IDI_QUESTION); - desktopIcon = convertHIconToPixmap( iconHandle ); + desktopIcon = QPixmap::fromWinHICON( iconHandle ); DestroyIcon(iconHandle); break; } @@ -1052,7 +1069,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 = convertHIconToPixmap(iconInfo.hIcon); + pixmap = QPixmap::fromWinHICON(iconInfo.hIcon); DestroyIcon(iconInfo.hIcon); return pixmap; } @@ -3346,7 +3363,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(convertHIconToPixmap(iconInfo.hIcon)); + icon.addPixmap(QPixmap::fromWinHICON(iconInfo.hIcon)); DestroyIcon(iconInfo.hIcon); } } -- cgit v0.12