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/util/qsystemtrayicon_win.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    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 have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4242#include "qsystemtrayicon_p.h"
    4343#ifndef QT_NO_SYSTEMTRAYICON
    44 //#define _WIN32_IE 0x0500
    45 #define _WIN32_IE 0x0600 //required for NOTIFYICONDATAW_V2_SIZE
     44#define _WIN32_IE 0x0600 //required for NOTIFYICONDATA_V2_SIZE
    4645
    4746//missing defines for MINGW :
     
    6362#include <QSettings>
    6463
    65 #if defined(Q_OS_WINCE) && !defined(STANDARDSHELL_UI_MODEL)
     64#if defined(Q_WS_WINCE) && !defined(STANDARDSHELL_UI_MODEL)
    6665#   include <streams.h>
    6766#endif
     
    6968QT_BEGIN_NAMESPACE
    7069
    71 #if defined(Q_OS_WINCE)
     70#if defined(Q_WS_WINCE)
    7271static const UINT q_uNOTIFYICONID = 13;     // IDs from 0 to 12 are reserved on WinCE.
    7372#else
     
    7877#define MYWM_NOTIFYICON (WM_APP+101)
    7978
    80 typedef BOOL (WINAPI *PtrShell_NotifyIcon)(DWORD,PNOTIFYICONDATA);
    81 static PtrShell_NotifyIcon ptrShell_NotifyIcon = 0;
    82 
    83 static void resolveLibs()
    84 {
    85     static bool triedResolve = false;
    86 #if defined Q_OS_WINCE
    87     QString libName(QLatin1String("coredll"));
    88     const char* funcName = "Shell_NotifyIcon";
    89 #else
    90     QString libName(QLatin1String("shell32"));
    91     const char* funcName = "Shell_NotifyIconW";
    92 #endif
    93     if (!triedResolve) {
    94         QLibrary lib(libName);
    95             triedResolve = true;
    96             ptrShell_NotifyIcon = (PtrShell_NotifyIcon) lib.resolve(funcName);
    97     }
    98 }
     79struct Q_NOTIFYICONIDENTIFIER {
     80    DWORD cbSize;
     81    HWND hWnd;
     82    UINT uID;
     83    GUID guidItem;
     84};
     85
     86#define Q_MSGFLT_ALLOW 1
     87
     88typedef HRESULT (WINAPI *PtrShell_NotifyIconGetRect)(const Q_NOTIFYICONIDENTIFIER* identifier, RECT* iconLocation);
     89typedef BOOL (WINAPI *PtrChangeWindowMessageFilter)(UINT message, DWORD dwFlag);
     90typedef BOOL (WINAPI *PtrChangeWindowMessageFilterEx)(HWND hWnd, UINT message, DWORD action, void* pChangeFilterStruct);
    9991
    10092class QSystemTrayIconSys : QWidget
     
    10496    ~QSystemTrayIconSys();
    10597    bool winEvent( MSG *m, long *result );
    106     bool trayMessageA(DWORD msg);
    107     bool trayMessageW(DWORD msg);
    10898    bool trayMessage(DWORD msg);
    10999    bool iconDrawItem(LPDRAWITEMSTRUCT lpdi);
    110     void setIconContentsW(NOTIFYICONDATAW &data);
    111     void setIconContentsA(NOTIFYICONDATAA &data);
    112     bool showMessageW(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs);
    113     bool showMessageA(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs);
     100    void setIconContents(NOTIFYICONDATA &data);
     101    bool showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs);
    114102    bool allowsMessages();
    115103    bool supportsMessages();
    116104    QRect findIconGeometry(const int a_iButtonID);
    117     QRect findTrayGeometry();
    118     HBITMAP createIconMask(const QBitmap &bitmap);
    119105    void createIcon();
    120     int detectShellVersion() const;
    121106    HICON hIcon;
    122107    QPoint globalPos;
    123108    QSystemTrayIcon *q;
    124109private:
    125     uint notifyIconSizeW;
    126     uint notifyIconSizeA;
    127     int currentShellVersion;
     110    uint notifyIconSize;
    128111    int maxTipLength;
     112    bool ignoreNextMouseRelease;
    129113};
    130114
    131 // Checks for the shell32 dll version number, since only version
    132 // 5 or later of supports ballon messages
    133115bool QSystemTrayIconSys::allowsMessages()
    134116{
    135117#ifndef QT_NO_SETTINGS
    136 
    137118    QSettings settings(QLatin1String("HKEY_CURRENT_USER\\Software\\Microsoft"
    138119                                      "\\Windows\\CurrentVersion\\Explorer\\Advanced"), QSettings::NativeFormat);
     
    143124}
    144125
    145 // Checks for the shell32 dll version number, since only version
    146 // 5 or later of supports ballon messages
    147126bool QSystemTrayIconSys::supportsMessages()
    148127{
    149 #if NOTIFYICON_VERSION >= 3
    150     if (currentShellVersion >= 5)
    151         return allowsMessages();
    152     else
    153 #endif
    154         return false;
    155 }
    156 
    157 //Returns the runtime major version of the shell32 dll
    158 int QSystemTrayIconSys::detectShellVersion() const
    159 {
    160128#ifndef Q_OS_WINCE
    161     int shellVersion = 4; //NT 4.0 and W95
    162     DLLGETVERSIONPROC pDllGetVersion = (DLLGETVERSIONPROC)QLibrary::resolve(
    163             QLatin1String("shell32"), "DllGetVersion");
    164     if (pDllGetVersion)
    165     {
    166         DLLVERSIONINFO dvi;
    167         HRESULT hr;
    168         ZeroMemory(&dvi, sizeof(dvi));
    169         dvi.cbSize = sizeof(dvi);
    170         hr = (*pDllGetVersion)(&dvi);
    171         if (SUCCEEDED(hr)) {
    172             if (dvi.dwMajorVersion >= 5)
    173             {
    174                 shellVersion = dvi.dwMajorVersion;
    175             }
    176         }
    177     }
    178     return shellVersion;
    179 #endif
    180     return 4; //No ballonMessages and MaxTipLength = 64 for WindowsCE
     129    return allowsMessages();
     130#endif
     131    return false;
    181132}
    182133
    183134QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object)
    184     : hIcon(0), q(object)
    185 {
    186     currentShellVersion = detectShellVersion();
    187     notifyIconSizeA = FIELD_OFFSET(NOTIFYICONDATAA, szTip[64]); // NOTIFYICONDATAA_V1_SIZE
    188     notifyIconSizeW = FIELD_OFFSET(NOTIFYICONDATAW, szTip[64]); // NOTIFYICONDATAW_V1_SIZE;
     135    : hIcon(0), q(object), ignoreNextMouseRelease(false)
     136
     137{
     138#ifndef Q_OS_WINCE
     139    notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, guidItem); // NOTIFYICONDATAW_V2_SIZE;
     140    maxTipLength = 128;
     141#else
     142    notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, szTip[64]); // NOTIFYICONDATAW_V1_SIZE;
    189143    maxTipLength = 64;
    190 
    191 #if NOTIFYICON_VERSION >= 3
    192     if (currentShellVersion >=5) {
    193         notifyIconSizeA = FIELD_OFFSET(NOTIFYICONDATAA, guidItem); // NOTIFYICONDATAA_V2_SIZE
    194         notifyIconSizeW = FIELD_OFFSET(NOTIFYICONDATAW, guidItem); // NOTIFYICONDATAW_V2_SIZE;
    195         maxTipLength = 128;
    196     }
    197144#endif
    198145
    199146    // For restoring the tray icon after explorer crashes
    200147    if (!MYWM_TASKBARCREATED) {
    201         MYWM_TASKBARCREATED = QT_WA_INLINE(RegisterWindowMessageW(L"TaskbarCreated"),RegisterWindowMessageA("TaskbarCreated"));
     148        MYWM_TASKBARCREATED = RegisterWindowMessage(L"TaskbarCreated");
     149    }
     150
     151    // Allow the WM_TASKBARCREATED message through the UIPI filter on Windows Vista and higher
     152    static PtrChangeWindowMessageFilterEx pChangeWindowMessageFilterEx =
     153        (PtrChangeWindowMessageFilterEx)QLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilterEx");
     154
     155    if (pChangeWindowMessageFilterEx) {
     156        // Call the safer ChangeWindowMessageFilterEx API if available
     157        pChangeWindowMessageFilterEx(winId(), MYWM_TASKBARCREATED, Q_MSGFLT_ALLOW, 0);
     158    } else {
     159        static PtrChangeWindowMessageFilter pChangeWindowMessageFilter =
     160            (PtrChangeWindowMessageFilter)QLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilter");
     161
     162        if (pChangeWindowMessageFilter) {
     163            // Call the deprecated ChangeWindowMessageFilter API otherwise
     164            pChangeWindowMessageFilter(MYWM_TASKBARCREATED, Q_MSGFLT_ALLOW);
     165        }
    202166    }
    203167}
     
    209173}
    210174
    211 void QSystemTrayIconSys::setIconContentsW(NOTIFYICONDATAW &tnd)
    212 {
    213     tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
     175void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd)
     176{
     177    tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    214178    tnd.uCallbackMessage = MYWM_NOTIFYICON;
    215179    tnd.hIcon = hIcon;
     
    217181
    218182    if (!tip.isNull()) {
    219         // Tip is limited to maxTipLength - NULL; lstrcpyn appends a NULL terminator.
    220183        tip = tip.left(maxTipLength - 1) + QChar();
    221 #if defined(Q_OS_WINCE)
    222         wcsncpy(tnd.szTip, reinterpret_cast<const wchar_t *> (tip.utf16()), qMin(tip.length()+1, maxTipLength));
    223 #else
    224         lstrcpynW(tnd.szTip, (TCHAR*)tip.utf16(), qMin(tip.length()+1, maxTipLength));
    225 #endif
    226     }
    227 }
    228 
    229 void QSystemTrayIconSys::setIconContentsA(NOTIFYICONDATAA &tnd)
    230 {
    231     tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
    232     tnd.uCallbackMessage = MYWM_NOTIFYICON;
    233     tnd.hIcon = hIcon;
    234     QString tip = q->toolTip();
    235 
    236     if (!tip.isNull()) {
    237         // Tip is limited to maxTipLength - NULL; lstrcpyn appends a NULL terminator.
    238         tip = tip.left(maxTipLength - 1) + QChar();
    239 #if defined(Q_OS_WINCE)
    240         strncpy(tnd.szTip, tip.toLocal8Bit().constData(), qMin(tip.length()+1, maxTipLength));
    241 #else
    242         lstrcpynA(tnd.szTip, tip.toLocal8Bit().constData(), qMin(tip.length()+1, maxTipLength));
    243 #endif
    244     }
    245 }
    246 
    247 int iconFlag( QSystemTrayIcon::MessageIcon icon )
    248 {
    249     int flag = 0;
     184        memcpy(tnd.szTip, tip.utf16(), qMin(tip.length() + 1, maxTipLength) * sizeof(wchar_t));
     185    }
     186}
     187
     188static int iconFlag( QSystemTrayIcon::MessageIcon icon )
     189{
    250190#if NOTIFYICON_VERSION >= 3
    251191    switch (icon) {
     192        case QSystemTrayIcon::Information:
     193            return NIIF_INFO;
     194        case QSystemTrayIcon::Warning:
     195            return NIIF_WARNING;
     196        case QSystemTrayIcon::Critical:
     197            return NIIF_ERROR;
    252198        case QSystemTrayIcon::NoIcon:
    253             break;
    254         case QSystemTrayIcon::Critical:
    255             flag = NIIF_ERROR;
    256             break;
    257         case QSystemTrayIcon::Warning:
    258             flag = NIIF_WARNING;
    259             break;
    260         case QSystemTrayIcon::Information:
    261         default : // fall through
    262             flag = NIIF_INFO;
     199            return NIIF_NONE;
     200        default:
     201            Q_ASSERT_X(false, "QSystemTrayIconSys::showMessage", "Invalid QSystemTrayIcon::MessageIcon value");
     202            return NIIF_NONE;
    263203    }
    264204#else
    265205    Q_UNUSED(icon);
    266 #endif
    267     return flag;
    268 }
    269 
    270 bool QSystemTrayIconSys::showMessageW(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs)
    271 {
    272 #if NOTIFYICON_VERSION>=3
     206    return 0;
     207#endif
     208}
     209
     210bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs)
     211{
     212#if NOTIFYICON_VERSION >= 3
    273213    NOTIFYICONDATA tnd;
    274     memset(&tnd, 0, notifyIconSizeW);
     214    memset(&tnd, 0, notifyIconSize);
    275215    Q_ASSERT(testAttribute(Qt::WA_WState_Created));
    276216
    277     setIconContentsW(tnd);
    278 #if defined(Q_OS_WINCE)
    279     wcsncpy(tnd.szInfo, message.utf16(), qMin(message.length() + 1, 256));
    280     wcsncpy(tnd.szInfoTitle, title.utf16(), qMin(title.length()+1, 64));
    281 #else
    282     lstrcpynW(tnd.szInfo, (TCHAR*)message.utf16(), qMin(message.length() + 1, 256));
    283     lstrcpynW(tnd.szInfoTitle, (TCHAR*)title.utf16(), qMin(title.length() + 1, 64));
    284 #endif
     217    setIconContents(tnd);
     218    memcpy(tnd.szInfo, message.utf16(), qMin(message.length() + 1, 256) * sizeof(wchar_t));
     219    memcpy(tnd.szInfoTitle, title.utf16(), qMin(title.length() + 1, 64) * sizeof(wchar_t));
     220
    285221    tnd.uID = q_uNOTIFYICONID;
    286222    tnd.dwInfoFlags = iconFlag(type);
    287     tnd.cbSize = notifyIconSizeW;
     223    tnd.cbSize = notifyIconSize;
    288224    tnd.hWnd = winId();
    289225    tnd.uTimeout = uSecs;
    290226    tnd.uFlags = NIF_INFO;
    291     return ptrShell_NotifyIcon(NIM_MODIFY, &tnd);
     227
     228    return Shell_NotifyIcon(NIM_MODIFY, &tnd);
    292229#else
    293230    Q_UNUSED(title);
     
    299236}
    300237
    301 bool QSystemTrayIconSys::showMessageA(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs)
    302 {
    303 #if NOTIFYICON_VERSION>=3
    304     NOTIFYICONDATAA tnd;
    305     memset(&tnd, 0, notifyIconSizeA);
     238bool QSystemTrayIconSys::trayMessage(DWORD msg)
     239{
     240    NOTIFYICONDATA tnd;
     241    memset(&tnd, 0, notifyIconSize);
     242    tnd.uID = q_uNOTIFYICONID;
     243    tnd.cbSize = notifyIconSize;
     244    tnd.hWnd = winId();
     245
    306246    Q_ASSERT(testAttribute(Qt::WA_WState_Created));
    307247
    308     setIconContentsA(tnd);
    309 #if defined(Q_OS_WINCE)
    310     strncpy(tnd.szInfo, message.toLocal8Bit().constData(), qMin(message.length() + 1, 256));
    311     strncpy(tnd.szInfoTitle, title.toLocal8Bit().constData(), qMin(title.length()+1, 64));
    312 #else
    313     lstrcpynA(tnd.szInfo, message.toLocal8Bit().constData(), qMin(message.length() + 1, 256));
    314     lstrcpynA(tnd.szInfoTitle, title.toLocal8Bit().constData(), qMin(title.length() + 1, 64));
    315 #endif
    316     tnd.uID = q_uNOTIFYICONID;
    317     tnd.dwInfoFlags = iconFlag(type);
    318     tnd.cbSize = notifyIconSizeA;
    319     tnd.hWnd = winId();
    320     tnd.uTimeout = uSecs;
    321     tnd.uFlags = NIF_INFO;
    322     return Shell_NotifyIconA(NIM_MODIFY, &tnd);
    323 #else
    324     Q_UNUSED(title);
    325     Q_UNUSED(message);
    326     Q_UNUSED(type);
    327     Q_UNUSED(uSecs);
    328     return false;
    329 #endif
    330 }
    331 
    332 bool QSystemTrayIconSys::trayMessageA(DWORD msg)
    333 {
    334 #if !defined(Q_OS_WINCE)
    335     NOTIFYICONDATAA tnd;
    336     memset(&tnd, 0, notifyIconSizeA);
    337     tnd.uID = q_uNOTIFYICONID;
    338     tnd.cbSize = notifyIconSizeA;
    339     tnd.hWnd = winId();
    340     Q_ASSERT(testAttribute(Qt::WA_WState_Created));
    341 
    342248    if (msg != NIM_DELETE) {
    343         setIconContentsA(tnd);
    344     }
    345     return Shell_NotifyIconA(msg, &tnd);
    346 #else
    347     Q_UNUSED(msg);
    348     return false;
    349 #endif
    350 }
    351 
    352 bool QSystemTrayIconSys::trayMessageW(DWORD msg)
    353 {
    354     NOTIFYICONDATAW tnd;
    355     memset(&tnd, 0, notifyIconSizeW);
    356     tnd.uID = q_uNOTIFYICONID;
    357     tnd.cbSize = notifyIconSizeW;
    358     tnd.hWnd = winId();
    359     Q_ASSERT(testAttribute(Qt::WA_WState_Created));
    360 
    361     if (msg != NIM_DELETE) {
    362         setIconContentsW(tnd);
    363     }
    364     return ptrShell_NotifyIcon(msg, &tnd);
    365 }
    366 
    367 bool QSystemTrayIconSys::trayMessage(DWORD msg)
    368 {
    369     resolveLibs();
    370     if (!(ptrShell_NotifyIcon))
    371         return false;
    372 
    373     QT_WA({
    374         return trayMessageW(msg);
    375     },
    376     {
    377         return trayMessageA(msg);
    378     });
     249        setIconContents(tnd);
     250    }
     251
     252    return Shell_NotifyIcon(msg, &tnd);
    379253}
    380254
     
    386260    DrawIconEx(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, hIcon, 0, 0, 0, 0, DI_NORMAL);
    387261    return true;
    388 }
    389 
    390 HBITMAP QSystemTrayIconSys::createIconMask(const QBitmap &bitmap)
    391 {
    392     QImage bm = bitmap.toImage().convertToFormat(QImage::Format_Mono);
    393     int w = bm.width();
    394     int h = bm.height();
    395     int bpl = ((w+15)/16)*2;                        // bpl, 16 bit alignment
    396     uchar *bits = new uchar[bpl*h];
    397     bm.invertPixels();
    398     for (int y=0; y<h; y++)
    399         memcpy(bits+y*bpl, bm.scanLine(y), bpl);
    400     HBITMAP hbm = CreateBitmap(w, h, 1, 1, bits);
    401     delete [] bits;
    402     return hbm;
    403262}
    404263
     
    417276        return;
    418277
    419     QBitmap mask = pm.mask();
    420     if (mask.isNull()) {
    421         mask = QBitmap(pm.size());
    422         mask.fill(Qt::color1);
    423     }
    424 
    425     HBITMAP im = createIconMask(mask);
    426     ICONINFO ii;
    427     ii.fIcon    = true;
    428     ii.hbmMask  = im;
    429     ii.hbmColor = pm.toWinHBITMAP(QPixmap::Alpha);
    430     ii.xHotspot = 0;
    431     ii.yHotspot = 0;
    432     hIcon = CreateIconIndirect(&ii);
    433 
    434     DeleteObject(ii.hbmColor);
    435     DeleteObject(im);
     278    hIcon = pm.toWinHICON();
    436279}
    437280
     
    460303            switch (m->lParam) {
    461304            case WM_LBUTTONUP:
    462                 emit q->activated(QSystemTrayIcon::Trigger);
     305                if (ignoreNextMouseRelease)
     306                    ignoreNextMouseRelease = false;
     307                else
     308                    emit q->activated(QSystemTrayIcon::Trigger);
    463309                break;
    464310
    465 #if !defined(Q_OS_WINCE)
    466311            case WM_LBUTTONDBLCLK:
     312                ignoreNextMouseRelease = true; // Since DBLCLICK Generates a second mouse
     313                                               // release we must ignore it
    467314                emit q->activated(QSystemTrayIcon::DoubleClick);
    468315                break;
     
    471318                if (q->contextMenu()) {
    472319                    q->contextMenu()->popup(gpos);
     320#if defined(Q_WS_WINCE)
     321                    // We must ensure that the popup menu doesn't show up behind the task bar.
     322                    QRect desktopRect = qApp->desktop()->availableGeometry();
     323                    int maxY = desktopRect.y() + desktopRect.height() - q->contextMenu()->height();
     324                    if (gpos.y() > maxY) {
     325                        gpos.ry() = maxY;
     326                        q->contextMenu()->move(gpos);
     327                    }
     328#endif
    473329                    q->contextMenu()->activateWindow();
    474330                    //Must be activated for proper keyboardfocus and menu closing on windows:
     
    477333                break;
    478334
     335#if !defined(Q_WS_WINCE)
    479336            case NIN_BALLOONUSERCLICK:
    480337                emit q->messageClicked();
    481338                break;
     339#endif
    482340
    483341            case WM_MBUTTONUP:
    484342                emit q->activated(QSystemTrayIcon::MiddleClick);
    485343                break;
    486 #endif
    487344            default:
    488345                        break;
     
    515372}
    516373
    517 //fallback on win 95/98
    518 QRect QSystemTrayIconSys::findTrayGeometry()
    519 {
    520     //Use lower right corner as fallback
    521     QPoint brCorner = qApp->desktop()->screenGeometry().bottomRight();
    522     QRect ret(brCorner.x() - 10, brCorner.y() - 10, 10, 10);
    523 #if defined(Q_OS_WINCE)
    524     HWND trayHandle = FindWindowW(L"Shell_TrayWnd", NULL);
    525 #else
    526     HWND trayHandle = FindWindowA("Shell_TrayWnd", NULL);
    527 #endif
    528     if (trayHandle) {
    529 #if defined(Q_OS_WINCE)
    530         trayHandle = FindWindowW(L"TrayNotifyWnd", NULL);
    531 #else
    532         trayHandle = FindWindowExA(trayHandle, NULL, "TrayNotifyWnd", NULL);
    533 #endif
    534         if (trayHandle) {
    535             RECT r;
    536             if (GetWindowRect(trayHandle, &r)) {
    537                 ret = QRect(r.left, r.top, r.right- r.left, r.bottom - r.top);
    538             }
    539         }
    540     }
    541     return ret;
    542 }
    543 
    544374/*
    545375* This function tries to determine the icon geometry from the tray
     
    549379QRect QSystemTrayIconSys::findIconGeometry(const int iconId)
    550380{
     381    static PtrShell_NotifyIconGetRect Shell_NotifyIconGetRect =
     382        (PtrShell_NotifyIconGetRect)QLibrary::resolve(QLatin1String("shell32"), "Shell_NotifyIconGetRect");
     383
     384    if (Shell_NotifyIconGetRect) {
     385        Q_NOTIFYICONIDENTIFIER nid;
     386        memset(&nid, 0, sizeof(nid));
     387        nid.cbSize = sizeof(nid);
     388        nid.hWnd = winId();
     389        nid.uID = iconId;
     390
     391        RECT rect;
     392        HRESULT hr = Shell_NotifyIconGetRect(&nid, &rect);
     393        if (SUCCEEDED(hr)) {
     394            return QRect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
     395        }
     396    }
     397
    551398    QRect ret;
    552399
    553400    TBBUTTON buttonData;
    554401    DWORD processID = 0;
    555 #if defined(Q_OS_WINCE)
    556     HWND trayHandle = FindWindowW(L"Shell_TrayWnd", NULL);
    557 #else
    558     HWND trayHandle = FindWindowA("Shell_TrayWnd", NULL);
    559 #endif
     402    HWND trayHandle = FindWindow(L"Shell_TrayWnd", NULL);
    560403
    561404    //find the toolbar used in the notification area
    562405    if (trayHandle) {
    563406#if defined(Q_OS_WINCE)
    564         trayHandle = FindWindowW(L"TrayNotifyWnd", NULL);
    565 #else
    566         trayHandle = FindWindowExA(trayHandle, NULL, "TrayNotifyWnd", NULL);
     407        trayHandle = FindWindow(L"TrayNotifyWnd", NULL);
     408#else
     409        trayHandle = FindWindowEx(trayHandle, NULL, L"TrayNotifyWnd", NULL);
    567410#endif
    568411        if (trayHandle) {
    569412#if defined(Q_OS_WINCE)
    570             HWND hwnd = FindWindowW(L"SysPager", NULL);
     413            HWND hwnd = FindWindow(L"SysPager", NULL);
    571414#else
    572415            HWND hwnd = FindWindowEx(trayHandle, NULL, L"SysPager", NULL);
     
    613456        SendMessage(trayHandle, TB_GETBUTTON, toolbarButton , (LPARAM)data);
    614457
    615         if(!ReadProcessMemory(trayProcess, data, &buttonData, sizeof(TBBUTTON), &numBytes))
     458        if (!ReadProcessMemory(trayProcess, data, &buttonData, sizeof(TBBUTTON), &numBytes))
    616459            continue;
    617460
    618         if(!ReadProcessMemory(trayProcess, (LPVOID) buttonData.dwData, appData, sizeof(appData), &numBytes))
     461        if (!ReadProcessMemory(trayProcess, (LPVOID) buttonData.dwData, appData, sizeof(appData), &numBytes))
    619462            continue;
    620463
     
    647490}
    648491
    649 
    650492void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, int timeOut)
    651493{
     
    658500    else uSecs = (int)timeOut;
    659501
    660     resolveLibs();
    661 
    662502    //message is limited to 255 chars + NULL
    663503    QString messageString;
    664504    if (message.isEmpty() && !title.isEmpty())
    665         messageString = QLatin1String(" "); //ensures that the message shows when only title is set
     505        messageString = QLatin1Char(' '); //ensures that the message shows when only title is set
    666506    else
    667507        messageString = message.left(255) + QChar();
     
    671511
    672512    if (sys->supportsMessages()) {
    673         QT_WA({
    674             sys->showMessageW(titleString, messageString, type, (unsigned int)uSecs);
    675         }, {
    676             sys->showMessageA(titleString, messageString, type, (unsigned int)uSecs);
    677         });
     513        sys->showMessage(titleString, messageString, type, (unsigned int)uSecs);
    678514    } else {
    679         //use fallbacks
    680         QRect iconPos = sys->findIconGeometry(0);
     515        //use fallback
     516        QRect iconPos = sys->findIconGeometry(q_uNOTIFYICONID);
    681517        if (iconPos.isValid()) {
    682518            QBalloonTip::showBalloon(type, title, message, sys->q, iconPos.center(), uSecs, true);
    683         } else {
    684             QRect trayRect = sys->findTrayGeometry();
    685             QBalloonTip::showBalloon(type, title, message, sys->q, QPoint(trayRect.left(),
    686                                      trayRect.center().y()), uSecs, false);
    687519        }
    688520    }
     
    693525    if (!sys)
    694526        return QRect();
    695     return sys->findIconGeometry(0);
     527    return sys->findIconGeometry(q_uNOTIFYICONID);
    696528}
    697529
     
    727559void QSystemTrayIconPrivate::updateToolTip_sys()
    728560{
    729 #ifdef Q_OS_WINCE
     561#ifdef Q_WS_WINCE
    730562    // Calling sys->trayMessage(NIM_MODIFY) on an existing icon is broken on Windows CE.
    731563    // So we need to call updateIcon_sys() which creates a new icon handle.
Note: See TracChangeset for help on using the changeset viewer.