source: trunk/src/gui/util/qsystemtrayicon_pm.cpp@ 277

Last change on this file since 277 was 277, checked in by Dmitry A. Kuminov, 16 years ago

gui: QSystemTrayIcon: Implemented reaction to notification messages from the system tray and emitting them as signals.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 7.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** Copyright (C) 2009 netlabs.org. OS/2 parts.
7**
8** This file is part of the QtGui module of the Qt Toolkit.
9**
10** $QT_BEGIN_LICENSE:LGPL$
11** Commercial Usage
12** Licensees holding valid Qt Commercial licenses may use this file in
13** accordance with the Qt Commercial License Agreement provided with the
14** Software or, alternatively, in accordance with the terms contained in
15** a written agreement between you and Nokia.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Nokia gives you certain
26** additional rights. These rights are described in the Nokia Qt LGPL
27** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
28** package.
29**
30** GNU General Public License Usage
31** Alternatively, this file may be used under the terms of the GNU
32** General Public License version 3.0 as published by the Free Software
33** Foundation and appearing in the file LICENSE.GPL included in the
34** packaging of this file. Please review the following information to
35** ensure the GNU General Public License version 3.0 requirements will be
36** met: http://www.gnu.org/copyleft/gpl.html.
37**
38** If you are unsure which license is appropriate for your use, please
39** contact the sales department at [email protected].
40** $QT_END_LICENSE$
41**
42****************************************************************************/
43
44#include "qsystemtrayicon_p.h"
45
46#ifndef QT_NO_SYSTEMTRAYICON
47
48#include "qapplication.h"
49#include "qdesktopwidget.h"
50#include "qt_os2.h"
51
52#include "xsystray_api.h"
53
54QT_BEGIN_NAMESPACE
55
56#define WM_XST_MYNOTIFY (WM_USER + 1000)
57
58static ULONG WM_XST_CREATED = xstGetSysTrayCreatedMsgId();
59static ULONG MaxTextLen = xstGetSysTrayMaxTextLen();
60
61class QSystemTrayIconSys : QWidget
62{
63public:
64 QSystemTrayIconSys(QSystemTrayIcon *object);
65 ~QSystemTrayIconSys();
66
67 void createIcon();
68
69 void addToTray();
70 void removeFromTray();
71 QRect geometry();
72 void setToolTip();
73 void showMessage(const QString &title, const QString &message,
74 QSystemTrayIcon::MessageIcon type, int timeOut);
75
76protected:
77 bool pmEvent(QMSG *msg, MRESULT *result);
78
79private:
80 HPOINTER hIcon;
81 QPoint globalPos;
82 QSystemTrayIcon *q;
83};
84
85QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object)
86 : hIcon(NULLHANDLE), q(object)
87{
88}
89
90QSystemTrayIconSys::~QSystemTrayIconSys()
91{
92 if (hIcon != NULLHANDLE)
93 WinDestroyPointer(hIcon);
94}
95
96void QSystemTrayIconSys::createIcon()
97{
98 HPOINTER hIconToDestroy = hIcon;
99
100 hIcon = QPixmap::toPmHPOINTER(q->icon());
101
102 if (hIconToDestroy != NULLHANDLE)
103 WinDestroyPointer(hIconToDestroy);
104}
105
106void QSystemTrayIconSys::addToTray()
107{
108 xstAddSysTrayIcon(winId(), 0, hIcon, WM_XST_MYNOTIFY, 0);
109}
110
111void QSystemTrayIconSys::removeFromTray()
112{
113 xstRemoveSysTrayIcon(winId(), 0);
114}
115
116QRect QSystemTrayIconSys::geometry()
117{
118 // @todo use xstQuerySysTrayIconRect()
119 return QRect();
120}
121
122void QSystemTrayIconSys::setToolTip()
123{
124 // @todo use xstSetSysTrayIconToolTip()
125}
126
127void QSystemTrayIconSys::showMessage(const QString &title, const QString &message,
128 QSystemTrayIcon::MessageIcon type, int timeOut)
129{
130 // @todo use xstShowSysTrayIconBalloon()
131}
132
133bool QSystemTrayIconSys::pmEvent(QMSG *msg, MRESULT *result)
134{
135 switch(msg->msg) {
136
137 case WM_XST_MYNOTIFY: {
138 switch (SHORT2FROMMP(msg->mp1)) {
139 case XST_IN_MOUSE: {
140 PXSTMOUSEMSG pMsg = (PXSTMOUSEMSG)msg->mp2;
141 switch (pMsg->ulMouseMsg) {
142 case WM_BUTTON1CLICK:
143 emit q->activated(QSystemTrayIcon::Trigger);
144 break;
145 case WM_BUTTON1DBLCLK:
146 emit q->activated(QSystemTrayIcon::DoubleClick);
147 break;
148 case WM_BUTTON3CLICK:
149 emit q->activated(QSystemTrayIcon::MiddleClick);
150 break;
151 default:
152 break;
153 }
154 break;
155 }
156 case XST_IN_CONTEXT: {
157 PXSTCONTEXTMSG pMsg = (PXSTCONTEXTMSG)msg->mp2;
158 if (q->contextMenu()) {
159 QPoint gpos(pMsg->ptsPointerPos.x,
160 // flip y coordinate
161 QApplication::desktop()->height() -
162 (pMsg->ptsPointerPos.y + 1));
163 q->contextMenu()->popup(gpos);
164 q->contextMenu()->activateWindow();
165 // Must be activated for proper keyboardfocus and
166 // menu closing on OS/2
167 }
168 emit q->activated(QSystemTrayIcon::Context);
169 break;
170 }
171 default:
172 break;
173 }
174 break;
175 }
176
177 default: {
178 if (msg->msg == WM_XST_CREATED) {
179 addToTray();
180 return true;
181 }
182 break;
183 }
184 }
185
186 return QWidget::pmEvent(msg, result);
187}
188
189void QSystemTrayIconPrivate::install_sys()
190{
191 Q_Q(QSystemTrayIcon);
192 if (!sys) {
193 // @todo make QSystemTrayIconSys a singleton and use different icon IDs
194 // to differentiate between icons (this will save us from creating a new
195 // HWND per each icon the application wants to show)
196 sys = new QSystemTrayIconSys(q);
197 sys->createIcon();
198 sys->addToTray();
199 }
200}
201
202void QSystemTrayIconPrivate::
203showMessage_sys(const QString &title, const QString &message,
204 QSystemTrayIcon::MessageIcon type, int timeOut)
205{
206 if (!sys)
207 return;
208
209 sys->showMessage(title, message, type, timeOut);
210}
211
212QRect QSystemTrayIconPrivate::geometry_sys() const
213{
214 if (!sys)
215 return QRect();
216
217 return sys->geometry();
218}
219
220void QSystemTrayIconPrivate::remove_sys()
221{
222 if (!sys)
223 return;
224
225 sys->removeFromTray();
226 delete sys;
227 sys = 0;
228}
229
230void QSystemTrayIconPrivate::updateIcon_sys()
231{
232 if (!sys)
233 return;
234
235 sys->createIcon();
236 sys->addToTray();
237}
238
239void QSystemTrayIconPrivate::updateMenu_sys()
240{
241 // nothing to do
242}
243
244void QSystemTrayIconPrivate::updateToolTip_sys()
245{
246 if (!sys)
247 return;
248
249 sys->setToolTip();
250}
251
252bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys()
253{
254 return xstQuerySysTrayVersion(0, 0, 0);
255}
256
257QT_END_NAMESPACE
258
259#endif // ifndef QT_NO_SYSTEMTRAYICON
260
Note: See TracBrowser for help on using the repository browser.