Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/qpixmap_win.cpp

    r2 r561  
    22**
    33** 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])
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    6060#include "qt_windows.h"
    6161
    62 #if defined(Q_OS_WINCE)
     62#if defined(Q_S_WINCE)
    6363#include <winbase.h>
    6464#include "qguifunctions_wince.h"
     
    8181    if (h < 0) h = r.bottom - r.top;
    8282
    83 #ifdef Q_OS_WINCE_WM
     83#ifdef Q_S_WINCE_WM
    8484    if (qt_wince_is_pocket_pc()) {
    8585        QWidget *widget = QWidget::find(winId);
     
    102102    HDC window_dc = GetDC(winId);
    103103    BitBlt(bitmap_dc, 0, 0, w, h, window_dc, x, y, SRCCOPY
    104 #ifndef Q_OS_WINCE
     104#ifndef Q_S_WINCE
    105105                                    | CAPTUREBLT
    106106#endif
     
    120120}
    121121
    122 
    123 
    124 /*!
    125     \enum QPixmap::HBitmapFormat
    126 
    127     This enum defines how the conversion between \c HBITMAP
    128     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 as
    133     being set to fully opaque. This is preferred if the \c HBITMAP is
    134     used with standard GDI calls, such as \c BitBlt().
    135 
    136     \value PremultipliedAlpha The \c HBITMAP is treated as having an
    137     alpha channel and premultiplied colors. This is preferred if the
    138     \c HBITMAP is accessed through the \c AlphaBlend() GDI function.
    139 
    140     \value Alpha The \c HBITMAP is treated as having a plain alpha
    141     channel. This is the preferred format if the \c HBITMAP is going
    142     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 given
    149     \a format. Returns the \c HBITMAP handle.
    150 
    151     It is the caller's responsibility to free the \c HBITMAP data
    152     after use.
    153 
    154     \warning This function is only available on Windows.
    155 
    156     \sa fromWinHBITMAP()
    157 */
    158122HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const
    159123{
     124
     125
     126
    160127    HBITMAP bitmap = 0;
    161128    if (data->classId() == QPixmapData::RasterClass) {
    162         QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data);
     129        QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data);
    163130        int w = d->image.width();
    164131        int h = d->image.height();
     
    210177}
    211178
    212 /*!
    213     Returns a QPixmap that is equivalent to the given \a bitmap. The
    214     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 */
    221179QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
    222180{
     
    225183    memset(&bitmap_info, 0, sizeof(BITMAP));
    226184
    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);
    234186    if (!res) {
    235187        qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info");
     
    288240}
    289241
     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
    290280#ifdef Q_WS_WIN
    291 #ifndef Q_OS_WINCE
     281#ifndef Q_S_WINCE
    292282
    293283static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h)
     
    320310        qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits");
    321311    }
     312
    322313
    323314    return image;
    324315}
    325316
    326 QPixmap convertHIconToPixmap( const HICON icon)
     317QPixmap HICON icon)
    327318{
    328319    bool foundAlpha = false;
     
    334325    bool result = GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center
    335326    if (!result)
    336         qWarning("convertHIconToPixmap(), failed to GetIconInfo()");
     327        qWarning("(), failed to GetIconInfo()");
    337328
    338329    int w = iconinfo.xHotspot * 2;
     
    392383    return QPixmap::fromImage(image);
    393384}
    394 #else //ifndef Q_OS_WINCE
    395 QPixmap convertHIconToPixmap( const HICON icon, bool large)
     385#else //ifndef Q_S_WINCE
     386QPixmap )
    396387{
    397388    HDC screenDevice = GetDC(0);
     
    399390    ReleaseDC(0, screenDevice);
    400391
    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;
    402417
    403418    BITMAPINFO bmi;
    404419    memset(&bmi, 0, sizeof(bmi));
    405420    bmi.bmiHeader.biSize        = sizeof(BITMAPINFO);
    406     bmi.bmiHeader.biWidth       = size;
    407     bmi.bmiHeader.biHeight      = -size;
     421    bmi.bmiHeader.biWidth       = ;
     422    bmi.bmiHeader.biHeight      = -;
    408423    bmi.bmiHeader.biPlanes      = 1;
    409424    bmi.bmiHeader.biBitCount    = 32;
    410425    bmi.bmiHeader.biCompression = BI_RGB;
    411     bmi.bmiHeader.biSizeImage   = size*size*4;
     426    bmi.bmiHeader.biSizeImage   = ;
    412427
    413428    uchar* bits;
     
    415430    HBITMAP winBitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**) &bits, 0, 0);
    416431    if (winBitmap )
    417         memset(bits, 0xff, size*size*4);
     432        memset(bits, 0xff, );
    418433    if (!winBitmap) {
    419         qWarning("convertHIconToPixmap(), failed to CreateDIBSection()");
     434        qWarning("(), failed to CreateDIBSection()");
    420435        return QPixmap();
    421436    }
    422437
    423438    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()");
    426441
    427442    uint mask = 0xff000000;
    428443    // Create image and copy data into image.
    429     QImage image(size, size, QImage::Format_ARGB32);
     444    QImage image(, QImage::Format_ARGB32);
    430445
    431446    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) {
    434449            QRgb *dest = (QRgb *) image.scanLine(y);
    435450            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) {
    437452                dest[x] = src[x];
    438453            }
    439454        }
    440455    }
    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()");
    443458    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) {
    446461            QRgb *dest = (QRgb *) image.scanLine(y);
    447462            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) {
    449464                if (!src[x])
    450465                    dest[x] = dest[x] | mask;
     
    457472    return QPixmap::fromImage(image);
    458473}
    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
    480476
    481477QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.