Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/util/qsystemtrayicon_win.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4242#include "qsystemtrayicon_p.h"
    4343#ifndef QT_NO_SYSTEMTRAYICON
    44 #define _WIN32_IE 0x0600 //required for NOTIFYICONDATA_V2_SIZE
    45 
    46 //missing defines for MINGW :
    47 #ifndef NIN_BALLOONTIMEOUT
    48 #define NIN_BALLOONTIMEOUT  (WM_USER + 4)
    49 #endif
    50 #ifndef NIN_BALLOONUSERCLICK
    51 #define NIN_BALLOONUSERCLICK (WM_USER + 5)
     44
     45#ifndef _WIN32_WINNT
     46#define _WIN32_WINNT 0x0600
     47#endif
     48
     49#ifndef _WIN32_IE
     50#define _WIN32_IE 0x600
    5251#endif
    5352
    5453#include <qt_windows.h>
     54#include <windowsx.h>
    5555#include <commctrl.h>
    56 #include <shlwapi.h>
    57 #include <QBitmap>
    58 #include <QLibrary>
     56
     57#include <private/qsystemlibrary_p.h>
    5958#include <QApplication>
    60 #include <QToolTip>
    61 #include <QDesktopWidget>
    6259#include <QSettings>
    6360
     
    7673};
    7774
     75#ifndef NOTIFYICON_VERSION_4
     76#define NOTIFYICON_VERSION_4 4
     77#endif
     78
     79#ifndef NIN_SELECT
     80#define NIN_SELECT (WM_USER + 0)
     81#endif
     82
     83#ifndef NIN_KEYSELECT
     84#define NIN_KEYSELECT (WM_USER + 1)
     85#endif
     86
     87#ifndef NIN_BALLOONTIMEOUT
     88#define NIN_BALLOONTIMEOUT (WM_USER + 4)
     89#endif
     90
     91#ifndef NIN_BALLOONUSERCLICK
     92#define NIN_BALLOONUSERCLICK (WM_USER + 5)
     93#endif
     94
     95#ifndef NIF_SHOWTIP
     96#define NIF_SHOWTIP 0x00000080
     97#endif
     98
    7899#define Q_MSGFLT_ALLOW 1
    79100
     
    89110    bool winEvent( MSG *m, long *result );
    90111    bool trayMessage(DWORD msg);
    91     bool iconDrawItem(LPDRAWITEMSTRUCT lpdi);
    92112    void setIconContents(NOTIFYICONDATA &data);
    93113    bool showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs);
    94     bool allowsMessages();
    95     bool supportsMessages();
    96114    QRect findIconGeometry(const int a_iButtonID);
    97115    void createIcon();
     
    102120    uint notifyIconSize;
    103121    int maxTipLength;
     122    int version;
    104123    bool ignoreNextMouseRelease;
    105124};
    106125
    107 bool QSystemTrayIconSys::allowsMessages()
     126static bool allowsMessages()
    108127{
    109128#ifndef QT_NO_SETTINGS
     
    116135}
    117136
    118 bool QSystemTrayIconSys::supportsMessages()
    119 {
    120     return allowsMessages();
    121 }
    122 
    123137QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object)
    124138    : hIcon(0), q(object), ignoreNextMouseRelease(false)
    125139
    126140{
    127     notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, guidItem); // NOTIFYICONDATAW_V2_SIZE;
     141    if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) {
     142        notifyIconSize = sizeof(NOTIFYICONDATA);
     143        version = NOTIFYICON_VERSION_4;
     144    } else {
     145        notifyIconSize = NOTIFYICONDATA_V2_SIZE;
     146        version = NOTIFYICON_VERSION;
     147    }
     148
    128149    maxTipLength = 128;
    129150
     
    135156    // Allow the WM_TASKBARCREATED message through the UIPI filter on Windows Vista and higher
    136157    static PtrChangeWindowMessageFilterEx pChangeWindowMessageFilterEx =
    137         (PtrChangeWindowMessageFilterEx)QLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilterEx");
     158        (PtrChangeWindowMessageFilterEx)QSystemLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilterEx");
    138159
    139160    if (pChangeWindowMessageFilterEx) {
     
    142163    } else {
    143164        static PtrChangeWindowMessageFilter pChangeWindowMessageFilter =
    144             (PtrChangeWindowMessageFilter)QLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilter");
     165            (PtrChangeWindowMessageFilter)QSystemLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilter");
    145166
    146167        if (pChangeWindowMessageFilter) {
     
    159180void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd)
    160181{
    161     tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
     182    tnd.uFlags |= NIF_MESSAGE | NIF_ICON | NIF_TIP;
    162183    tnd.uCallbackMessage = MYWM_NOTIFYICON;
    163184    tnd.hIcon = hIcon;
     
    172193static int iconFlag( QSystemTrayIcon::MessageIcon icon )
    173194{
    174 #if NOTIFYICON_VERSION >= 3
    175195    switch (icon) {
    176196        case QSystemTrayIcon::Information:
     
    186206            return NIIF_NONE;
    187207    }
    188 #else
    189     Q_UNUSED(icon);
    190     return 0;
    191 #endif
    192208}
    193209
    194210bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs)
    195211{
    196 #if NOTIFYICON_VERSION >= 3
    197212    NOTIFYICONDATA tnd;
    198213    memset(&tnd, 0, notifyIconSize);
    199     Q_ASSERT(testAttribute(Qt::WA_WState_Created));
    200 
    201     setIconContents(tnd);
     214
    202215    memcpy(tnd.szInfo, message.utf16(), qMin(message.length() + 1, 256) * sizeof(wchar_t));
    203216    memcpy(tnd.szInfoTitle, title.utf16(), qMin(title.length() + 1, 64) * sizeof(wchar_t));
     
    208221    tnd.hWnd = winId();
    209222    tnd.uTimeout = uSecs;
    210     tnd.uFlags = NIF_INFO;
     223    tnd.uFlags = NIF_INFO | NIF_SHOWTIP;
     224
     225    Q_ASSERT(testAttribute(Qt::WA_WState_Created));
    211226
    212227    return Shell_NotifyIcon(NIM_MODIFY, &tnd);
    213 #else
    214     Q_UNUSED(title);
    215     Q_UNUSED(message);
    216     Q_UNUSED(type);
    217     Q_UNUSED(uSecs);
    218     return false;
    219 #endif
    220228}
    221229
     
    224232    NOTIFYICONDATA tnd;
    225233    memset(&tnd, 0, notifyIconSize);
     234
    226235    tnd.uID = q_uNOTIFYICONID;
    227236    tnd.cbSize = notifyIconSize;
    228237    tnd.hWnd = winId();
     238    tnd.uFlags = NIF_SHOWTIP;
     239    tnd.uVersion = version;
    229240
    230241    Q_ASSERT(testAttribute(Qt::WA_WState_Created));
    231242
    232     if (msg != NIM_DELETE) {
     243    if (msg == NIM_ADD || msg == NIM_MODIFY) {
    233244        setIconContents(tnd);
    234245    }
    235246
    236     return Shell_NotifyIcon(msg, &tnd);
    237 }
    238 
    239 bool QSystemTrayIconSys::iconDrawItem(LPDRAWITEMSTRUCT lpdi)
    240 {
    241     if (!hIcon)
    242         return false;
    243 
    244     DrawIconEx(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, hIcon, 0, 0, 0, 0, DI_NORMAL);
    245     return true;
     247    bool success = Shell_NotifyIcon(msg, &tnd);
     248
     249    if (msg == NIM_ADD)
     250        return success && Shell_NotifyIcon(NIM_SETVERSION, &tnd);
     251    else
     252        return success;
    246253}
    247254
     
    266273{
    267274    switch(m->message) {
    268     case WM_CREATE:
    269 #ifdef GWLP_USERDATA
    270         SetWindowLongPtr(winId(), GWLP_USERDATA, (LONG_PTR)((CREATESTRUCTW*)m->lParam)->lpCreateParams);
    271 #else
    272         SetWindowLong(winId(), GWL_USERDATA, (LONG)((CREATESTRUCTW*)m->lParam)->lpCreateParams);
    273 #endif
    274         break;
    275 
    276     case WM_DRAWITEM:
    277         return iconDrawItem((LPDRAWITEMSTRUCT)m->lParam);
    278 
    279275    case MYWM_NOTIFYICON:
    280276        {
    281             RECT r;
    282             GetWindowRect(winId(), &r);
    283             QEvent *e = 0;
    284             Qt::KeyboardModifiers keys = QApplication::keyboardModifiers();
    285             QPoint gpos = QCursor::pos();
    286 
    287             switch (m->lParam) {
    288             case WM_LBUTTONUP:
     277            int message = 0;
     278            QPoint gpos;
     279
     280            if (version == NOTIFYICON_VERSION_4) {
     281                Q_ASSERT(q_uNOTIFYICONID == HIWORD(m->lParam));
     282                message = LOWORD(m->lParam);
     283                gpos = QPoint(GET_X_LPARAM(m->wParam), GET_Y_LPARAM(m->wParam));
     284            } else {
     285                Q_ASSERT(q_uNOTIFYICONID == m->wParam);
     286                message = m->lParam;
     287                gpos = QCursor::pos();
     288            }
     289
     290            switch (message) {
     291            case NIN_SELECT:
     292            case NIN_KEYSELECT:
    289293                if (ignoreNextMouseRelease)
    290294                    ignoreNextMouseRelease = false;
     
    299303                break;
    300304
    301             case WM_RBUTTONUP:
     305            case WM_CONTEXTMENU:
    302306                if (q->contextMenu()) {
    303307                    q->contextMenu()->popup(gpos);
    304                     q->contextMenu()->activateWindow();
    305                     //Must be activated for proper keyboardfocus and menu closing on windows:
    306308                }
    307309                emit q->activated(QSystemTrayIcon::Context);
     
    315317                emit q->activated(QSystemTrayIcon::MiddleClick);
    316318                break;
     319
    317320            default:
    318                         break;
    319             }
    320             if (e) {
    321                 bool res = QApplication::sendEvent(q, e);
    322                 delete e;
    323                 return res;
     321                break;
    324322            }
    325323            break;
     
    353351{
    354352    static PtrShell_NotifyIconGetRect Shell_NotifyIconGetRect =
    355         (PtrShell_NotifyIconGetRect)QLibrary::resolve(QLatin1String("shell32"), "Shell_NotifyIconGetRect");
     353        (PtrShell_NotifyIconGetRect)QSystemLibrary::resolve(QLatin1String("shell32"), "Shell_NotifyIconGetRect");
    356354
    357355    if (Shell_NotifyIconGetRect) {
     
    445443void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, int timeOut)
    446444{
    447     if (!sys || !sys->allowsMessages())
     445    if (!sys || !allowsMessages())
    448446        return;
    449447
     
    463461    QString titleString = title.left(63) + QChar();
    464462
    465     if (sys->supportsMessages()) {
    466         sys->showMessage(titleString, messageString, type, (unsigned int)uSecs);
    467     } else {
    468         //use fallback
    469         QRect iconPos = sys->findIconGeometry(q_uNOTIFYICONID);
    470         if (iconPos.isValid()) {
    471             QBalloonTip::showBalloon(type, title, message, sys->q, iconPos.center(), uSecs, true);
    472         }
    473     }
     463    sys->showMessage(titleString, messageString, type, uSecs);
    474464}
    475465
     
    478468    if (!sys)
    479469        return QRect();
     470
    480471    return sys->findIconGeometry(q_uNOTIFYICONID);
    481472}
     
    523514}
    524515
     516bool QSystemTrayIconPrivate::supportsMessages_sys()
     517{
     518    return allowsMessages();
     519}
     520
    525521QT_END_NAMESPACE
    526522
Note: See TracChangeset for help on using the changeset viewer.