Changeset 561 for trunk/src/gui/image/qpixmap_win.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/image/qpixmap_win.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 60 60 #include "qt_windows.h" 61 61 62 #if defined(Q_ OS_WINCE)62 #if defined(Q_S_WINCE) 63 63 #include <winbase.h> 64 64 #include "qguifunctions_wince.h" … … 81 81 if (h < 0) h = r.bottom - r.top; 82 82 83 #ifdef Q_ OS_WINCE_WM83 #ifdef Q_S_WINCE_WM 84 84 if (qt_wince_is_pocket_pc()) { 85 85 QWidget *widget = QWidget::find(winId); … … 102 102 HDC window_dc = GetDC(winId); 103 103 BitBlt(bitmap_dc, 0, 0, w, h, window_dc, x, y, SRCCOPY 104 #ifndef Q_ OS_WINCE104 #ifndef Q_S_WINCE 105 105 | CAPTUREBLT 106 106 #endif … … 120 120 } 121 121 122 123 124 /*!125 \enum QPixmap::HBitmapFormat126 127 This enum defines how the conversion between \c HBITMAP128 and QPixmap is performed.129 130 \warning This enum is only available on Windows.131 132 \value NoAlpha The alpha channel is ignored and always treated as133 being set to fully opaque. This is preferred if the \c HBITMAP is134 used with standard GDI calls, such as \c BitBlt().135 136 \value PremultipliedAlpha The \c HBITMAP is treated as having an137 alpha channel and premultiplied colors. This is preferred if the138 \c HBITMAP is accessed through the \c AlphaBlend() GDI function.139 140 \value Alpha The \c HBITMAP is treated as having a plain alpha141 channel. This is the preferred format if the \c HBITMAP is going142 to be used as an application icon or systray icon.143 144 \sa fromWinHBITMAP(), toWinHBITMAP()145 */146 147 /*!148 Creates a \c HBITMAP equivalent to the QPixmap, based on the given149 \a format. Returns the \c HBITMAP handle.150 151 It is the caller's responsibility to free the \c HBITMAP data152 after use.153 154 \warning This function is only available on Windows.155 156 \sa fromWinHBITMAP()157 */158 122 HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const 159 123 { 124 125 126 160 127 HBITMAP bitmap = 0; 161 128 if (data->classId() == QPixmapData::RasterClass) { 162 QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data );129 QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data); 163 130 int w = d->image.width(); 164 131 int h = d->image.height(); … … 210 177 } 211 178 212 /*!213 Returns a QPixmap that is equivalent to the given \a bitmap. The214 conversion is based on the specified \a format.215 216 \warning This function is only available on Windows.217 218 \sa toWinHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion}219 220 */221 179 QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format) 222 180 { … … 225 183 memset(&bitmap_info, 0, sizeof(BITMAP)); 226 184 227 int res; 228 QT_WA({ 229 res = GetObjectW(bitmap, sizeof(BITMAP), &bitmap_info); 230 } , { 231 res = GetObjectA(bitmap, sizeof(BITMAP), &bitmap_info); 232 }); 233 185 int res = GetObject(bitmap, sizeof(BITMAP), &bitmap_info); 234 186 if (!res) { 235 187 qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info"); … … 288 240 } 289 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 290 280 #ifdef Q_WS_WIN 291 #ifndef Q_ OS_WINCE281 #ifndef Q_S_WINCE 292 282 293 283 static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h) … … 320 310 qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits"); 321 311 } 312 322 313 323 314 return image; 324 315 } 325 316 326 QPixmap convertHIconToPixmap( constHICON icon)317 QPixmap HICON icon) 327 318 { 328 319 bool foundAlpha = false; … … 334 325 bool result = GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center 335 326 if (!result) 336 qWarning(" convertHIconToPixmap(), failed to GetIconInfo()");327 qWarning("(), failed to GetIconInfo()"); 337 328 338 329 int w = iconinfo.xHotspot * 2; … … 392 383 return QPixmap::fromImage(image); 393 384 } 394 #else //ifndef Q_ OS_WINCE395 QPixmap convertHIconToPixmap( const HICON icon, bool large)385 #else //ifndef Q_S_WINCE 386 QPixmap ) 396 387 { 397 388 HDC screenDevice = GetDC(0); … … 399 390 ReleaseDC(0, screenDevice); 400 391 401 int size = large ? 64 : 32; 392 ICONINFO iconinfo; 393 bool result = GetIconInfo(icon, &iconinfo); 394 if (!result) 395 qWarning("QPixmap::fromWinHICON(), failed to GetIconInfo()"); 396 397 int w = 0; 398 int h = 0; 399 if (!iconinfo.xHotspot || !iconinfo.yHotspot) { 400 // We could not retrieve the icon size via GetIconInfo, 401 // so we try again using the icon bitmap. 402 BITMAP bm; 403 int result = GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bm); 404 if (!result) result = GetObject(iconinfo.hbmMask, sizeof(BITMAP), &bm); 405 if (!result) { 406 qWarning("QPixmap::fromWinHICON(), failed to retrieve icon size"); 407 return QPixmap(); 408 } 409 w = bm.bmWidth; 410 h = bm.bmHeight; 411 } else { 412 // x and y Hotspot describes the icon center 413 w = iconinfo.xHotspot * 2; 414 h = iconinfo.yHotspot * 2; 415 } 416 const DWORD dwImageSize = w * h * 4; 402 417 403 418 BITMAPINFO bmi; 404 419 memset(&bmi, 0, sizeof(bmi)); 405 420 bmi.bmiHeader.biSize = sizeof(BITMAPINFO); 406 bmi.bmiHeader.biWidth = size;407 bmi.bmiHeader.biHeight = - size;421 bmi.bmiHeader.biWidth = ; 422 bmi.bmiHeader.biHeight = -; 408 423 bmi.bmiHeader.biPlanes = 1; 409 424 bmi.bmiHeader.biBitCount = 32; 410 425 bmi.bmiHeader.biCompression = BI_RGB; 411 bmi.bmiHeader.biSizeImage = size*size*4;426 bmi.bmiHeader.biSizeImage = ; 412 427 413 428 uchar* bits; … … 415 430 HBITMAP winBitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**) &bits, 0, 0); 416 431 if (winBitmap ) 417 memset(bits, 0xff, size*size*4);432 memset(bits, 0xff, ); 418 433 if (!winBitmap) { 419 qWarning(" convertHIconToPixmap(), failed to CreateDIBSection()");434 qWarning("(), failed to CreateDIBSection()"); 420 435 return QPixmap(); 421 436 } 422 437 423 438 HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap); 424 if (!DrawIconEx( hdc, 0, 0, icon, size, size, 0, 0, DI_NORMAL))425 qWarning(" convertHIconToPixmap(), failed to DrawIcon()");439 if (!DrawIconEx( hdc, 0, 0, icon, , 0, 0, DI_NORMAL)) 440 qWarning("(), failed to DrawIcon()"); 426 441 427 442 uint mask = 0xff000000; 428 443 // Create image and copy data into image. 429 QImage image( size, size, QImage::Format_ARGB32);444 QImage image(, QImage::Format_ARGB32); 430 445 431 446 if (!image.isNull()) { // failed to alloc? 432 int bytes_per_line = size* sizeof(QRgb);433 for (int y=0; y <size; ++y) {447 int bytes_per_line = * sizeof(QRgb); 448 for (int y=0; y; ++y) { 434 449 QRgb *dest = (QRgb *) image.scanLine(y); 435 450 const QRgb *src = (const QRgb *) (bits + y * bytes_per_line); 436 for (int x=0; x <size; ++x) {451 for (int x=0; x; ++x) { 437 452 dest[x] = src[x]; 438 453 } 439 454 } 440 455 } 441 if (!DrawIconEx( hdc, 0, 0, icon, size, size, 0, 0, DI_MASK))442 qWarning(" convertHIconToPixmap(), failed to DrawIcon()");456 if (!DrawIconEx( hdc, 0, 0, icon, , 0, 0, DI_MASK)) 457 qWarning("(), failed to DrawIcon()"); 443 458 if (!image.isNull()) { // failed to alloc? 444 int bytes_per_line = size* sizeof(QRgb);445 for (int y=0; y <size; ++y) {459 int bytes_per_line = * sizeof(QRgb); 460 for (int y=0; y; ++y) { 446 461 QRgb *dest = (QRgb *) image.scanLine(y); 447 462 const QRgb *src = (const QRgb *) (bits + y * bytes_per_line); 448 for (int x=0; x <size; ++x) {463 for (int x=0; x; ++x) { 449 464 if (!src[x]) 450 465 dest[x] = dest[x] | mask; … … 457 472 return QPixmap::fromImage(image); 458 473 } 459 #endif //ifndef Q_OS_WINCE 460 461 QPixmap loadIconFromShell32( int resourceId, int size ) 462 { 463 #ifdef Q_OS_WINCE 464 HMODULE hmod = LoadLibrary((const wchar_t *) QString::fromLatin1("ceshell.dll").utf16()); 465 #else 466 HMODULE hmod = LoadLibraryA("shell32.dll"); 467 #endif 468 if( hmod ) { 469 HICON iconHandle = (HICON)LoadImage(hmod, MAKEINTRESOURCE(resourceId), IMAGE_ICON, size, size, 0); 470 if( iconHandle ) { 471 QPixmap iconpixmap = convertHIconToPixmap( iconHandle ); 472 DestroyIcon(iconHandle); 473 return iconpixmap; 474 } 475 } 476 return QPixmap(); 477 } 478 479 #endif 474 #endif //ifndef Q_WS_WINCE 475 #endif //ifdef Q_WS_WIN 480 476 481 477 QT_END_NAMESPACE
Note:
See TracChangeset
for help on using the changeset viewer.