author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 11 Jun 2010 14:24:45 +0300 | |
changeset 25 | e24348a560a6 |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
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 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qsystemtrayicon_p.h" |
|
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) |
|
52 |
#endif |
|
53 |
||
54 |
#include <qt_windows.h> |
|
55 |
#include <commctrl.h> |
|
56 |
#include <shlwapi.h> |
|
57 |
#include <QBitmap> |
|
58 |
#include <QLibrary> |
|
59 |
#include <QApplication> |
|
60 |
#include <QToolTip> |
|
61 |
#include <QDesktopWidget> |
|
62 |
#include <QSettings> |
|
63 |
||
64 |
QT_BEGIN_NAMESPACE |
|
65 |
||
66 |
static const UINT q_uNOTIFYICONID = 0; |
|
67 |
||
68 |
static uint MYWM_TASKBARCREATED = 0; |
|
69 |
#define MYWM_NOTIFYICON (WM_APP+101) |
|
70 |
||
71 |
struct Q_NOTIFYICONIDENTIFIER { |
|
72 |
DWORD cbSize; |
|
73 |
HWND hWnd; |
|
74 |
UINT uID; |
|
75 |
GUID guidItem; |
|
76 |
}; |
|
77 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
#define Q_MSGFLT_ALLOW 1 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
|
0 | 80 |
typedef HRESULT (WINAPI *PtrShell_NotifyIconGetRect)(const Q_NOTIFYICONIDENTIFIER* identifier, RECT* iconLocation); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
typedef BOOL (WINAPI *PtrChangeWindowMessageFilter)(UINT message, DWORD dwFlag); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
typedef BOOL (WINAPI *PtrChangeWindowMessageFilterEx)(HWND hWnd, UINT message, DWORD action, void* pChangeFilterStruct); |
0 | 83 |
|
84 |
class QSystemTrayIconSys : QWidget |
|
85 |
{ |
|
86 |
public: |
|
87 |
QSystemTrayIconSys(QSystemTrayIcon *object); |
|
88 |
~QSystemTrayIconSys(); |
|
89 |
bool winEvent( MSG *m, long *result ); |
|
90 |
bool trayMessage(DWORD msg); |
|
91 |
bool iconDrawItem(LPDRAWITEMSTRUCT lpdi); |
|
92 |
void setIconContents(NOTIFYICONDATA &data); |
|
93 |
bool showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs); |
|
94 |
bool allowsMessages(); |
|
95 |
bool supportsMessages(); |
|
96 |
QRect findIconGeometry(const int a_iButtonID); |
|
97 |
void createIcon(); |
|
98 |
HICON hIcon; |
|
99 |
QPoint globalPos; |
|
100 |
QSystemTrayIcon *q; |
|
101 |
private: |
|
102 |
uint notifyIconSize; |
|
103 |
int maxTipLength; |
|
104 |
bool ignoreNextMouseRelease; |
|
105 |
}; |
|
106 |
||
107 |
bool QSystemTrayIconSys::allowsMessages() |
|
108 |
{ |
|
109 |
#ifndef QT_NO_SETTINGS |
|
110 |
QSettings settings(QLatin1String("HKEY_CURRENT_USER\\Software\\Microsoft" |
|
111 |
"\\Windows\\CurrentVersion\\Explorer\\Advanced"), QSettings::NativeFormat); |
|
112 |
return settings.value(QLatin1String("EnableBalloonTips"), true).toBool(); |
|
113 |
#else |
|
114 |
return false; |
|
115 |
#endif |
|
116 |
} |
|
117 |
||
118 |
bool QSystemTrayIconSys::supportsMessages() |
|
119 |
{ |
|
120 |
return allowsMessages(); |
|
121 |
} |
|
122 |
||
123 |
QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object) |
|
124 |
: hIcon(0), q(object), ignoreNextMouseRelease(false) |
|
125 |
||
126 |
{ |
|
127 |
notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, guidItem); // NOTIFYICONDATAW_V2_SIZE; |
|
128 |
maxTipLength = 128; |
|
129 |
||
130 |
// For restoring the tray icon after explorer crashes |
|
131 |
if (!MYWM_TASKBARCREATED) { |
|
132 |
MYWM_TASKBARCREATED = RegisterWindowMessage(L"TaskbarCreated"); |
|
133 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
// Allow the WM_TASKBARCREATED message through the UIPI filter on Windows Vista and higher |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
static PtrChangeWindowMessageFilterEx pChangeWindowMessageFilterEx = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
(PtrChangeWindowMessageFilterEx)QLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilterEx"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
if (pChangeWindowMessageFilterEx) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
// Call the safer ChangeWindowMessageFilterEx API if available |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
pChangeWindowMessageFilterEx(winId(), MYWM_TASKBARCREATED, Q_MSGFLT_ALLOW, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
static PtrChangeWindowMessageFilter pChangeWindowMessageFilter = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
(PtrChangeWindowMessageFilter)QLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilter"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
if (pChangeWindowMessageFilter) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
// Call the deprecated ChangeWindowMessageFilter API otherwise |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
pChangeWindowMessageFilter(MYWM_TASKBARCREATED, Q_MSGFLT_ALLOW); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
} |
0 | 151 |
} |
152 |
||
153 |
QSystemTrayIconSys::~QSystemTrayIconSys() |
|
154 |
{ |
|
155 |
if (hIcon) |
|
156 |
DestroyIcon(hIcon); |
|
157 |
} |
|
158 |
||
159 |
void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd) |
|
160 |
{ |
|
161 |
tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; |
|
162 |
tnd.uCallbackMessage = MYWM_NOTIFYICON; |
|
163 |
tnd.hIcon = hIcon; |
|
164 |
QString tip = q->toolTip(); |
|
165 |
||
166 |
if (!tip.isNull()) { |
|
167 |
tip = tip.left(maxTipLength - 1) + QChar(); |
|
168 |
memcpy(tnd.szTip, tip.utf16(), qMin(tip.length() + 1, maxTipLength) * sizeof(wchar_t)); |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
static int iconFlag( QSystemTrayIcon::MessageIcon icon ) |
|
173 |
{ |
|
174 |
#if NOTIFYICON_VERSION >= 3 |
|
175 |
switch (icon) { |
|
176 |
case QSystemTrayIcon::Information: |
|
177 |
return NIIF_INFO; |
|
178 |
case QSystemTrayIcon::Warning: |
|
179 |
return NIIF_WARNING; |
|
180 |
case QSystemTrayIcon::Critical: |
|
181 |
return NIIF_ERROR; |
|
182 |
case QSystemTrayIcon::NoIcon: |
|
183 |
return NIIF_NONE; |
|
184 |
default: |
|
185 |
Q_ASSERT_X(false, "QSystemTrayIconSys::showMessage", "Invalid QSystemTrayIcon::MessageIcon value"); |
|
186 |
return NIIF_NONE; |
|
187 |
} |
|
188 |
#else |
|
189 |
Q_UNUSED(icon); |
|
190 |
return 0; |
|
191 |
#endif |
|
192 |
} |
|
193 |
||
194 |
bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs) |
|
195 |
{ |
|
196 |
#if NOTIFYICON_VERSION >= 3 |
|
197 |
NOTIFYICONDATA tnd; |
|
198 |
memset(&tnd, 0, notifyIconSize); |
|
199 |
Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
200 |
||
201 |
setIconContents(tnd); |
|
202 |
memcpy(tnd.szInfo, message.utf16(), qMin(message.length() + 1, 256) * sizeof(wchar_t)); |
|
203 |
memcpy(tnd.szInfoTitle, title.utf16(), qMin(title.length() + 1, 64) * sizeof(wchar_t)); |
|
204 |
||
205 |
tnd.uID = q_uNOTIFYICONID; |
|
206 |
tnd.dwInfoFlags = iconFlag(type); |
|
207 |
tnd.cbSize = notifyIconSize; |
|
208 |
tnd.hWnd = winId(); |
|
209 |
tnd.uTimeout = uSecs; |
|
210 |
tnd.uFlags = NIF_INFO; |
|
211 |
||
212 |
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 |
|
220 |
} |
|
221 |
||
222 |
bool QSystemTrayIconSys::trayMessage(DWORD msg) |
|
223 |
{ |
|
224 |
NOTIFYICONDATA tnd; |
|
225 |
memset(&tnd, 0, notifyIconSize); |
|
226 |
tnd.uID = q_uNOTIFYICONID; |
|
227 |
tnd.cbSize = notifyIconSize; |
|
228 |
tnd.hWnd = winId(); |
|
229 |
||
230 |
Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
231 |
||
232 |
if (msg != NIM_DELETE) { |
|
233 |
setIconContents(tnd); |
|
234 |
} |
|
235 |
||
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; |
|
246 |
} |
|
247 |
||
248 |
void QSystemTrayIconSys::createIcon() |
|
249 |
{ |
|
250 |
hIcon = 0; |
|
251 |
QIcon icon = q->icon(); |
|
252 |
if (icon.isNull()) |
|
253 |
return; |
|
254 |
||
255 |
const int iconSizeX = GetSystemMetrics(SM_CXSMICON); |
|
256 |
const int iconSizeY = GetSystemMetrics(SM_CYSMICON); |
|
257 |
QSize size = icon.actualSize(QSize(iconSizeX, iconSizeY)); |
|
258 |
QPixmap pm = icon.pixmap(size); |
|
259 |
if (pm.isNull()) |
|
260 |
return; |
|
261 |
||
262 |
hIcon = pm.toWinHICON(); |
|
263 |
} |
|
264 |
||
265 |
bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) |
|
266 |
{ |
|
267 |
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 |
||
279 |
case MYWM_NOTIFYICON: |
|
280 |
{ |
|
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: |
|
289 |
if (ignoreNextMouseRelease) |
|
290 |
ignoreNextMouseRelease = false; |
|
291 |
else |
|
292 |
emit q->activated(QSystemTrayIcon::Trigger); |
|
293 |
break; |
|
294 |
||
295 |
case WM_LBUTTONDBLCLK: |
|
296 |
ignoreNextMouseRelease = true; // Since DBLCLICK Generates a second mouse |
|
297 |
// release we must ignore it |
|
298 |
emit q->activated(QSystemTrayIcon::DoubleClick); |
|
299 |
break; |
|
300 |
||
301 |
case WM_RBUTTONUP: |
|
302 |
if (q->contextMenu()) { |
|
303 |
q->contextMenu()->popup(gpos); |
|
304 |
q->contextMenu()->activateWindow(); |
|
305 |
//Must be activated for proper keyboardfocus and menu closing on windows: |
|
306 |
} |
|
307 |
emit q->activated(QSystemTrayIcon::Context); |
|
308 |
break; |
|
309 |
||
310 |
case NIN_BALLOONUSERCLICK: |
|
311 |
emit q->messageClicked(); |
|
312 |
break; |
|
313 |
||
314 |
case WM_MBUTTONUP: |
|
315 |
emit q->activated(QSystemTrayIcon::MiddleClick); |
|
316 |
break; |
|
317 |
default: |
|
318 |
break; |
|
319 |
} |
|
320 |
if (e) { |
|
321 |
bool res = QApplication::sendEvent(q, e); |
|
322 |
delete e; |
|
323 |
return res; |
|
324 |
} |
|
325 |
break; |
|
326 |
} |
|
327 |
default: |
|
328 |
if (m->message == MYWM_TASKBARCREATED) |
|
329 |
trayMessage(NIM_ADD); |
|
330 |
else |
|
331 |
return QWidget::winEvent(m, result); |
|
332 |
break; |
|
333 |
} |
|
334 |
return 0; |
|
335 |
} |
|
336 |
||
337 |
void QSystemTrayIconPrivate::install_sys() |
|
338 |
{ |
|
339 |
Q_Q(QSystemTrayIcon); |
|
340 |
if (!sys) { |
|
341 |
sys = new QSystemTrayIconSys(q); |
|
342 |
sys->createIcon(); |
|
343 |
sys->trayMessage(NIM_ADD); |
|
344 |
} |
|
345 |
} |
|
346 |
||
347 |
/* |
|
348 |
* This function tries to determine the icon geometry from the tray |
|
349 |
* |
|
350 |
* If it fails an invalid rect is returned. |
|
351 |
*/ |
|
352 |
QRect QSystemTrayIconSys::findIconGeometry(const int iconId) |
|
353 |
{ |
|
354 |
static PtrShell_NotifyIconGetRect Shell_NotifyIconGetRect = |
|
355 |
(PtrShell_NotifyIconGetRect)QLibrary::resolve(QLatin1String("shell32"), "Shell_NotifyIconGetRect"); |
|
356 |
||
357 |
if (Shell_NotifyIconGetRect) { |
|
358 |
Q_NOTIFYICONIDENTIFIER nid; |
|
359 |
memset(&nid, 0, sizeof(nid)); |
|
360 |
nid.cbSize = sizeof(nid); |
|
361 |
nid.hWnd = winId(); |
|
362 |
nid.uID = iconId; |
|
363 |
||
364 |
RECT rect; |
|
365 |
HRESULT hr = Shell_NotifyIconGetRect(&nid, &rect); |
|
366 |
if (SUCCEEDED(hr)) { |
|
367 |
return QRect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
QRect ret; |
|
372 |
||
373 |
TBBUTTON buttonData; |
|
374 |
DWORD processID = 0; |
|
375 |
HWND trayHandle = FindWindow(L"Shell_TrayWnd", NULL); |
|
376 |
||
377 |
//find the toolbar used in the notification area |
|
378 |
if (trayHandle) { |
|
379 |
trayHandle = FindWindowEx(trayHandle, NULL, L"TrayNotifyWnd", NULL); |
|
380 |
if (trayHandle) { |
|
381 |
HWND hwnd = FindWindowEx(trayHandle, NULL, L"SysPager", NULL); |
|
382 |
if (hwnd) { |
|
383 |
hwnd = FindWindowEx(hwnd, NULL, L"ToolbarWindow32", NULL); |
|
384 |
if (hwnd) |
|
385 |
trayHandle = hwnd; |
|
386 |
} |
|
387 |
} |
|
388 |
} |
|
389 |
||
390 |
if (!trayHandle) |
|
391 |
return ret; |
|
392 |
||
393 |
GetWindowThreadProcessId(trayHandle, &processID); |
|
394 |
if (processID <= 0) |
|
395 |
return ret; |
|
396 |
||
397 |
HANDLE trayProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ, 0, processID); |
|
398 |
if (!trayProcess) |
|
399 |
return ret; |
|
400 |
||
401 |
int buttonCount = SendMessage(trayHandle, TB_BUTTONCOUNT, 0, 0); |
|
402 |
LPVOID data = VirtualAllocEx(trayProcess, NULL, sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE); |
|
403 |
||
404 |
if ( buttonCount < 1 || !data ) { |
|
405 |
CloseHandle(trayProcess); |
|
406 |
return ret; |
|
407 |
} |
|
408 |
||
409 |
//search for our icon among all toolbar buttons |
|
410 |
for (int toolbarButton = 0; toolbarButton < buttonCount; ++toolbarButton ) { |
|
411 |
SIZE_T numBytes = 0; |
|
412 |
DWORD appData[2] = { 0, 0 }; |
|
413 |
SendMessage(trayHandle, TB_GETBUTTON, toolbarButton , (LPARAM)data); |
|
414 |
||
415 |
if (!ReadProcessMemory(trayProcess, data, &buttonData, sizeof(TBBUTTON), &numBytes)) |
|
416 |
continue; |
|
417 |
||
418 |
if (!ReadProcessMemory(trayProcess, (LPVOID) buttonData.dwData, appData, sizeof(appData), &numBytes)) |
|
419 |
continue; |
|
420 |
||
421 |
int currentIconId = appData[1]; |
|
422 |
HWND currentIconHandle = (HWND) appData[0]; |
|
423 |
bool isHidden = buttonData.fsState & TBSTATE_HIDDEN; |
|
424 |
||
425 |
if (currentIconHandle == winId() && |
|
426 |
currentIconId == iconId && !isHidden) { |
|
427 |
SendMessage(trayHandle, TB_GETITEMRECT, toolbarButton , (LPARAM)data); |
|
428 |
RECT iconRect = {0, 0}; |
|
429 |
if(ReadProcessMemory(trayProcess, data, &iconRect, sizeof(RECT), &numBytes)) { |
|
430 |
MapWindowPoints(trayHandle, NULL, (LPPOINT)&iconRect, 2); |
|
431 |
QRect geometry(iconRect.left + 1, iconRect.top + 1, |
|
432 |
iconRect.right - iconRect.left - 2, |
|
433 |
iconRect.bottom - iconRect.top - 2); |
|
434 |
if (geometry.isValid()) |
|
435 |
ret = geometry; |
|
436 |
break; |
|
437 |
} |
|
438 |
} |
|
439 |
} |
|
440 |
VirtualFreeEx(trayProcess, data, 0, MEM_RELEASE); |
|
441 |
CloseHandle(trayProcess); |
|
442 |
return ret; |
|
443 |
} |
|
444 |
||
445 |
void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, int timeOut) |
|
446 |
{ |
|
447 |
if (!sys || !sys->allowsMessages()) |
|
448 |
return; |
|
449 |
||
450 |
uint uSecs = 0; |
|
451 |
if ( timeOut < 0) |
|
452 |
uSecs = 10000; //10 sec default |
|
453 |
else uSecs = (int)timeOut; |
|
454 |
||
455 |
//message is limited to 255 chars + NULL |
|
456 |
QString messageString; |
|
457 |
if (message.isEmpty() && !title.isEmpty()) |
|
458 |
messageString = QLatin1Char(' '); //ensures that the message shows when only title is set |
|
459 |
else |
|
460 |
messageString = message.left(255) + QChar(); |
|
461 |
||
462 |
//title is limited to 63 chars + NULL |
|
463 |
QString titleString = title.left(63) + QChar(); |
|
464 |
||
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 |
} |
|
474 |
} |
|
475 |
||
476 |
QRect QSystemTrayIconPrivate::geometry_sys() const |
|
477 |
{ |
|
478 |
if (!sys) |
|
479 |
return QRect(); |
|
480 |
return sys->findIconGeometry(q_uNOTIFYICONID); |
|
481 |
} |
|
482 |
||
483 |
void QSystemTrayIconPrivate::remove_sys() |
|
484 |
{ |
|
485 |
if (!sys) |
|
486 |
return; |
|
487 |
||
488 |
sys->trayMessage(NIM_DELETE); |
|
489 |
delete sys; |
|
490 |
sys = 0; |
|
491 |
} |
|
492 |
||
493 |
void QSystemTrayIconPrivate::updateIcon_sys() |
|
494 |
{ |
|
495 |
if (!sys) |
|
496 |
return; |
|
497 |
||
498 |
HICON hIconToDestroy = sys->hIcon; |
|
499 |
||
500 |
sys->createIcon(); |
|
501 |
sys->trayMessage(NIM_MODIFY); |
|
502 |
||
503 |
if (hIconToDestroy) |
|
504 |
DestroyIcon(hIconToDestroy); |
|
505 |
} |
|
506 |
||
507 |
void QSystemTrayIconPrivate::updateMenu_sys() |
|
508 |
{ |
|
509 |
||
510 |
} |
|
511 |
||
512 |
void QSystemTrayIconPrivate::updateToolTip_sys() |
|
513 |
{ |
|
514 |
if (!sys) |
|
515 |
return; |
|
516 |
||
517 |
sys->trayMessage(NIM_MODIFY); |
|
518 |
} |
|
519 |
||
520 |
bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() |
|
521 |
{ |
|
522 |
return true; |
|
523 |
} |
|
524 |
||
525 |
QT_END_NAMESPACE |
|
526 |
||
527 |
#endif |