Changeset 846 for trunk/src/gui/util/qsystemtrayicon_win.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/util/qsystemtrayicon_win.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 42 42 #include "qsystemtrayicon_p.h" 43 43 #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 52 51 #endif 53 52 54 53 #include <qt_windows.h> 54 #include <windowsx.h> 55 55 #include <commctrl.h> 56 #include <shlwapi.h> 57 #include <QBitmap> 58 #include <QLibrary> 56 57 #include <private/qsystemlibrary_p.h> 59 58 #include <QApplication> 60 #include <QToolTip>61 #include <QDesktopWidget>62 59 #include <QSettings> 63 60 … … 76 73 }; 77 74 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 78 99 #define Q_MSGFLT_ALLOW 1 79 100 … … 89 110 bool winEvent( MSG *m, long *result ); 90 111 bool trayMessage(DWORD msg); 91 bool iconDrawItem(LPDRAWITEMSTRUCT lpdi);92 112 void setIconContents(NOTIFYICONDATA &data); 93 113 bool showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs); 94 bool allowsMessages();95 bool supportsMessages();96 114 QRect findIconGeometry(const int a_iButtonID); 97 115 void createIcon(); … … 102 120 uint notifyIconSize; 103 121 int maxTipLength; 122 int version; 104 123 bool ignoreNextMouseRelease; 105 124 }; 106 125 107 bool QSystemTrayIconSys::allowsMessages()126 static bool allowsMessages() 108 127 { 109 128 #ifndef QT_NO_SETTINGS … … 116 135 } 117 136 118 bool QSystemTrayIconSys::supportsMessages()119 {120 return allowsMessages();121 }122 123 137 QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object) 124 138 : hIcon(0), q(object), ignoreNextMouseRelease(false) 125 139 126 140 { 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 128 149 maxTipLength = 128; 129 150 … … 135 156 // Allow the WM_TASKBARCREATED message through the UIPI filter on Windows Vista and higher 136 157 static PtrChangeWindowMessageFilterEx pChangeWindowMessageFilterEx = 137 (PtrChangeWindowMessageFilterEx)Q Library::resolve(QLatin1String("user32"), "ChangeWindowMessageFilterEx");158 (PtrChangeWindowMessageFilterEx)QSystemLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilterEx"); 138 159 139 160 if (pChangeWindowMessageFilterEx) { … … 142 163 } else { 143 164 static PtrChangeWindowMessageFilter pChangeWindowMessageFilter = 144 (PtrChangeWindowMessageFilter)Q Library::resolve(QLatin1String("user32"), "ChangeWindowMessageFilter");165 (PtrChangeWindowMessageFilter)QSystemLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilter"); 145 166 146 167 if (pChangeWindowMessageFilter) { … … 159 180 void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd) 160 181 { 161 tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;182 tnd.uFlags |= NIF_MESSAGE | NIF_ICON | NIF_TIP; 162 183 tnd.uCallbackMessage = MYWM_NOTIFYICON; 163 184 tnd.hIcon = hIcon; … … 172 193 static int iconFlag( QSystemTrayIcon::MessageIcon icon ) 173 194 { 174 #if NOTIFYICON_VERSION >= 3175 195 switch (icon) { 176 196 case QSystemTrayIcon::Information: … … 186 206 return NIIF_NONE; 187 207 } 188 #else189 Q_UNUSED(icon);190 return 0;191 #endif192 208 } 193 209 194 210 bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs) 195 211 { 196 #if NOTIFYICON_VERSION >= 3197 212 NOTIFYICONDATA tnd; 198 213 memset(&tnd, 0, notifyIconSize); 199 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); 200 201 setIconContents(tnd); 214 202 215 memcpy(tnd.szInfo, message.utf16(), qMin(message.length() + 1, 256) * sizeof(wchar_t)); 203 216 memcpy(tnd.szInfoTitle, title.utf16(), qMin(title.length() + 1, 64) * sizeof(wchar_t)); … … 208 221 tnd.hWnd = winId(); 209 222 tnd.uTimeout = uSecs; 210 tnd.uFlags = NIF_INFO; 223 tnd.uFlags = NIF_INFO | NIF_SHOWTIP; 224 225 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); 211 226 212 227 return Shell_NotifyIcon(NIM_MODIFY, &tnd); 213 #else214 Q_UNUSED(title);215 Q_UNUSED(message);216 Q_UNUSED(type);217 Q_UNUSED(uSecs);218 return false;219 #endif220 228 } 221 229 … … 224 232 NOTIFYICONDATA tnd; 225 233 memset(&tnd, 0, notifyIconSize); 234 226 235 tnd.uID = q_uNOTIFYICONID; 227 236 tnd.cbSize = notifyIconSize; 228 237 tnd.hWnd = winId(); 238 tnd.uFlags = NIF_SHOWTIP; 239 tnd.uVersion = version; 229 240 230 241 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); 231 242 232 if (msg != NIM_DELETE) {243 if (msg == NIM_ADD || msg == NIM_MODIFY) { 233 244 setIconContents(tnd); 234 245 } 235 246 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; 246 253 } 247 254 … … 266 273 { 267 274 switch(m->message) { 268 case WM_CREATE:269 #ifdef GWLP_USERDATA270 SetWindowLongPtr(winId(), GWLP_USERDATA, (LONG_PTR)((CREATESTRUCTW*)m->lParam)->lpCreateParams);271 #else272 SetWindowLong(winId(), GWL_USERDATA, (LONG)((CREATESTRUCTW*)m->lParam)->lpCreateParams);273 #endif274 break;275 276 case WM_DRAWITEM:277 return iconDrawItem((LPDRAWITEMSTRUCT)m->lParam);278 279 275 case MYWM_NOTIFYICON: 280 276 { 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: 289 293 if (ignoreNextMouseRelease) 290 294 ignoreNextMouseRelease = false; … … 299 303 break; 300 304 301 case WM_ RBUTTONUP:305 case WM_CONTEXTMENU: 302 306 if (q->contextMenu()) { 303 307 q->contextMenu()->popup(gpos); 304 q->contextMenu()->activateWindow();305 //Must be activated for proper keyboardfocus and menu closing on windows:306 308 } 307 309 emit q->activated(QSystemTrayIcon::Context); … … 315 317 emit q->activated(QSystemTrayIcon::MiddleClick); 316 318 break; 319 317 320 default: 318 break; 319 } 320 if (e) { 321 bool res = QApplication::sendEvent(q, e); 322 delete e; 323 return res; 321 break; 324 322 } 325 323 break; … … 353 351 { 354 352 static PtrShell_NotifyIconGetRect Shell_NotifyIconGetRect = 355 (PtrShell_NotifyIconGetRect)Q Library::resolve(QLatin1String("shell32"), "Shell_NotifyIconGetRect");353 (PtrShell_NotifyIconGetRect)QSystemLibrary::resolve(QLatin1String("shell32"), "Shell_NotifyIconGetRect"); 356 354 357 355 if (Shell_NotifyIconGetRect) { … … 445 443 void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, int timeOut) 446 444 { 447 if (!sys || ! sys->allowsMessages())445 if (!sys || !allowsMessages()) 448 446 return; 449 447 … … 463 461 QString titleString = title.left(63) + QChar(); 464 462 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); 474 464 } 475 465 … … 478 468 if (!sys) 479 469 return QRect(); 470 480 471 return sys->findIconGeometry(q_uNOTIFYICONID); 481 472 } … … 523 514 } 524 515 516 bool QSystemTrayIconPrivate::supportsMessages_sys() 517 { 518 return allowsMessages(); 519 } 520 525 521 QT_END_NAMESPACE 526 522
Note:
See TracChangeset
for help on using the changeset viewer.