Changeset 561 for trunk/src/gui/util/qsystemtrayicon_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/util/qsystemtrayicon_win.cpp
r2 r561 2 2 ** 3 3 ** 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) 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 have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 42 42 #include "qsystemtrayicon_p.h" 43 43 #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 46 45 47 46 //missing defines for MINGW : … … 63 62 #include <QSettings> 64 63 65 #if defined(Q_ OS_WINCE) && !defined(STANDARDSHELL_UI_MODEL)64 #if defined(Q_WS_WINCE) && !defined(STANDARDSHELL_UI_MODEL) 66 65 # include <streams.h> 67 66 #endif … … 69 68 QT_BEGIN_NAMESPACE 70 69 71 #if defined(Q_ OS_WINCE)70 #if defined(Q_WS_WINCE) 72 71 static const UINT q_uNOTIFYICONID = 13; // IDs from 0 to 12 are reserved on WinCE. 73 72 #else … … 78 77 #define MYWM_NOTIFYICON (WM_APP+101) 79 78 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 } 79 struct Q_NOTIFYICONIDENTIFIER { 80 DWORD cbSize; 81 HWND hWnd; 82 UINT uID; 83 GUID guidItem; 84 }; 85 86 #define Q_MSGFLT_ALLOW 1 87 88 typedef HRESULT (WINAPI *PtrShell_NotifyIconGetRect)(const Q_NOTIFYICONIDENTIFIER* identifier, RECT* iconLocation); 89 typedef BOOL (WINAPI *PtrChangeWindowMessageFilter)(UINT message, DWORD dwFlag); 90 typedef BOOL (WINAPI *PtrChangeWindowMessageFilterEx)(HWND hWnd, UINT message, DWORD action, void* pChangeFilterStruct); 99 91 100 92 class QSystemTrayIconSys : QWidget … … 104 96 ~QSystemTrayIconSys(); 105 97 bool winEvent( MSG *m, long *result ); 106 bool trayMessageA(DWORD msg);107 bool trayMessageW(DWORD msg);108 98 bool trayMessage(DWORD msg); 109 99 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); 114 102 bool allowsMessages(); 115 103 bool supportsMessages(); 116 104 QRect findIconGeometry(const int a_iButtonID); 117 QRect findTrayGeometry();118 HBITMAP createIconMask(const QBitmap &bitmap);119 105 void createIcon(); 120 int detectShellVersion() const;121 106 HICON hIcon; 122 107 QPoint globalPos; 123 108 QSystemTrayIcon *q; 124 109 private: 125 uint notifyIconSizeW; 126 uint notifyIconSizeA; 127 int currentShellVersion; 110 uint notifyIconSize; 128 111 int maxTipLength; 112 bool ignoreNextMouseRelease; 129 113 }; 130 114 131 // Checks for the shell32 dll version number, since only version132 // 5 or later of supports ballon messages133 115 bool QSystemTrayIconSys::allowsMessages() 134 116 { 135 117 #ifndef QT_NO_SETTINGS 136 137 118 QSettings settings(QLatin1String("HKEY_CURRENT_USER\\Software\\Microsoft" 138 119 "\\Windows\\CurrentVersion\\Explorer\\Advanced"), QSettings::NativeFormat); … … 143 124 } 144 125 145 // Checks for the shell32 dll version number, since only version146 // 5 or later of supports ballon messages147 126 bool QSystemTrayIconSys::supportsMessages() 148 127 { 149 #if NOTIFYICON_VERSION >= 3150 if (currentShellVersion >= 5)151 return allowsMessages();152 else153 #endif154 return false;155 }156 157 //Returns the runtime major version of the shell32 dll158 int QSystemTrayIconSys::detectShellVersion() const159 {160 128 #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; 181 132 } 182 133 183 134 QSystemTrayIconSys::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; 189 143 maxTipLength = 64; 190 191 #if NOTIFYICON_VERSION >= 3192 if (currentShellVersion >=5) {193 notifyIconSizeA = FIELD_OFFSET(NOTIFYICONDATAA, guidItem); // NOTIFYICONDATAA_V2_SIZE194 notifyIconSizeW = FIELD_OFFSET(NOTIFYICONDATAW, guidItem); // NOTIFYICONDATAW_V2_SIZE;195 maxTipLength = 128;196 }197 144 #endif 198 145 199 146 // For restoring the tray icon after explorer crashes 200 147 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 } 202 166 } 203 167 } … … 209 173 } 210 174 211 void QSystemTrayIconSys::setIconContents W(NOTIFYICONDATAW&tnd)212 { 213 tnd.uFlags = NIF_MESSAGE |NIF_ICON|NIF_TIP;175 void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd) 176 { 177 tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; 214 178 tnd.uCallbackMessage = MYWM_NOTIFYICON; 215 179 tnd.hIcon = hIcon; … … 217 181 218 182 if (!tip.isNull()) { 219 // Tip is limited to maxTipLength - NULL; lstrcpyn appends a NULL terminator.220 183 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 188 static int iconFlag( QSystemTrayIcon::MessageIcon icon ) 189 { 250 190 #if NOTIFYICON_VERSION >= 3 251 191 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; 252 198 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; 263 203 } 264 204 #else 265 205 Q_UNUSED(icon); 266 #endif 267 return flag; 268 } 269 270 bool QSystemTrayIconSys::showMessage W(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs)271 { 272 #if NOTIFYICON_VERSION >=3206 return 0; 207 #endif 208 } 209 210 bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs) 211 { 212 #if NOTIFYICON_VERSION >= 3 273 213 NOTIFYICONDATA tnd; 274 memset(&tnd, 0, notifyIconSize W);214 memset(&tnd, 0, notifyIconSize); 275 215 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); 276 216 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 285 221 tnd.uID = q_uNOTIFYICONID; 286 222 tnd.dwInfoFlags = iconFlag(type); 287 tnd.cbSize = notifyIconSize W;223 tnd.cbSize = notifyIconSize; 288 224 tnd.hWnd = winId(); 289 225 tnd.uTimeout = uSecs; 290 226 tnd.uFlags = NIF_INFO; 291 return ptrShell_NotifyIcon(NIM_MODIFY, &tnd); 227 228 return Shell_NotifyIcon(NIM_MODIFY, &tnd); 292 229 #else 293 230 Q_UNUSED(title); … … 299 236 } 300 237 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); 238 bool 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 306 246 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); 307 247 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 #else313 lstrcpynA(tnd.szInfo, message.toLocal8Bit().constData(), qMin(message.length() + 1, 256));314 lstrcpynA(tnd.szInfoTitle, title.toLocal8Bit().constData(), qMin(title.length() + 1, 64));315 #endif316 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 #else324 Q_UNUSED(title);325 Q_UNUSED(message);326 Q_UNUSED(type);327 Q_UNUSED(uSecs);328 return false;329 #endif330 }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 342 248 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); 379 253 } 380 254 … … 386 260 DrawIconEx(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, hIcon, 0, 0, 0, 0, DI_NORMAL); 387 261 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 alignment396 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;403 262 } 404 263 … … 417 276 return; 418 277 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(); 436 279 } 437 280 … … 460 303 switch (m->lParam) { 461 304 case WM_LBUTTONUP: 462 emit q->activated(QSystemTrayIcon::Trigger); 305 if (ignoreNextMouseRelease) 306 ignoreNextMouseRelease = false; 307 else 308 emit q->activated(QSystemTrayIcon::Trigger); 463 309 break; 464 310 465 #if !defined(Q_OS_WINCE)466 311 case WM_LBUTTONDBLCLK: 312 ignoreNextMouseRelease = true; // Since DBLCLICK Generates a second mouse 313 // release we must ignore it 467 314 emit q->activated(QSystemTrayIcon::DoubleClick); 468 315 break; … … 471 318 if (q->contextMenu()) { 472 319 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 473 329 q->contextMenu()->activateWindow(); 474 330 //Must be activated for proper keyboardfocus and menu closing on windows: … … 477 333 break; 478 334 335 #if !defined(Q_WS_WINCE) 479 336 case NIN_BALLOONUSERCLICK: 480 337 emit q->messageClicked(); 481 338 break; 339 #endif 482 340 483 341 case WM_MBUTTONUP: 484 342 emit q->activated(QSystemTrayIcon::MiddleClick); 485 343 break; 486 #endif487 344 default: 488 345 break; … … 515 372 } 516 373 517 //fallback on win 95/98518 QRect QSystemTrayIconSys::findTrayGeometry()519 {520 //Use lower right corner as fallback521 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 #else526 HWND trayHandle = FindWindowA("Shell_TrayWnd", NULL);527 #endif528 if (trayHandle) {529 #if defined(Q_OS_WINCE)530 trayHandle = FindWindowW(L"TrayNotifyWnd", NULL);531 #else532 trayHandle = FindWindowExA(trayHandle, NULL, "TrayNotifyWnd", NULL);533 #endif534 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 544 374 /* 545 375 * This function tries to determine the icon geometry from the tray … … 549 379 QRect QSystemTrayIconSys::findIconGeometry(const int iconId) 550 380 { 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 551 398 QRect ret; 552 399 553 400 TBBUTTON buttonData; 554 401 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); 560 403 561 404 //find the toolbar used in the notification area 562 405 if (trayHandle) { 563 406 #if defined(Q_OS_WINCE) 564 trayHandle = FindWindow W(L"TrayNotifyWnd", NULL);565 #else 566 trayHandle = FindWindowEx A(trayHandle, NULL,"TrayNotifyWnd", NULL);407 trayHandle = FindWindow(L"TrayNotifyWnd", NULL); 408 #else 409 trayHandle = FindWindowEx(trayHandle, NULL, L"TrayNotifyWnd", NULL); 567 410 #endif 568 411 if (trayHandle) { 569 412 #if defined(Q_OS_WINCE) 570 HWND hwnd = FindWindow W(L"SysPager", NULL);413 HWND hwnd = FindWindow(L"SysPager", NULL); 571 414 #else 572 415 HWND hwnd = FindWindowEx(trayHandle, NULL, L"SysPager", NULL); … … 613 456 SendMessage(trayHandle, TB_GETBUTTON, toolbarButton , (LPARAM)data); 614 457 615 if (!ReadProcessMemory(trayProcess, data, &buttonData, sizeof(TBBUTTON), &numBytes))458 if (!ReadProcessMemory(trayProcess, data, &buttonData, sizeof(TBBUTTON), &numBytes)) 616 459 continue; 617 460 618 if (!ReadProcessMemory(trayProcess, (LPVOID) buttonData.dwData, appData, sizeof(appData), &numBytes))461 if (!ReadProcessMemory(trayProcess, (LPVOID) buttonData.dwData, appData, sizeof(appData), &numBytes)) 619 462 continue; 620 463 … … 647 490 } 648 491 649 650 492 void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, int timeOut) 651 493 { … … 658 500 else uSecs = (int)timeOut; 659 501 660 resolveLibs();661 662 502 //message is limited to 255 chars + NULL 663 503 QString messageString; 664 504 if (message.isEmpty() && !title.isEmpty()) 665 messageString = QLatin1 String(" "); //ensures that the message shows when only title is set505 messageString = QLatin1Char(' '); //ensures that the message shows when only title is set 666 506 else 667 507 messageString = message.left(255) + QChar(); … … 671 511 672 512 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); 678 514 } else { 679 //use fallback s680 QRect iconPos = sys->findIconGeometry( 0);515 //use fallback 516 QRect iconPos = sys->findIconGeometry(q_uNOTIFYICONID); 681 517 if (iconPos.isValid()) { 682 518 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);687 519 } 688 520 } … … 693 525 if (!sys) 694 526 return QRect(); 695 return sys->findIconGeometry( 0);527 return sys->findIconGeometry(q_uNOTIFYICONID); 696 528 } 697 529 … … 727 559 void QSystemTrayIconPrivate::updateToolTip_sys() 728 560 { 729 #ifdef Q_ OS_WINCE561 #ifdef Q_WS_WINCE 730 562 // Calling sys->trayMessage(NIM_MODIFY) on an existing icon is broken on Windows CE. 731 563 // So we need to call updateIcon_sys() which creates a new icon handle.
Note:
See TracChangeset
for help on using the changeset viewer.