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

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

gui: Removed QT_NO_SYSTEMTRAYICON. Prototyped QSystemTrayIcon for OS/2. Many new xsystray plugin code (mostly public API).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 5.6 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 "qt_os2.h"
49
50#include "xsystray_api.h"
51
52QT_BEGIN_NAMESPACE
53
54#define WM_XST_MYNOTIFY (WM_USER + 1000)
55
56static ULONG WM_XST_CREATED = xstGetSysTrayCreatedMsgId();
57static ULONG MaxTextLen = xstGetSysTrayMaxTextLen();
58
59class QSystemTrayIconSys : QWidget
60{
61public:
62 QSystemTrayIconSys(QSystemTrayIcon *object);
63 ~QSystemTrayIconSys();
64
65 HBITMAP createIconMask(const QBitmap &bitmap);
66 void createIcon();
67
68 void addToTray();
69 void removeFromTray();
70 QRect geometry();
71 void setToolTip();
72 void showMessage(const QString &title, const QString &message,
73 QSystemTrayIcon::MessageIcon type, int timeOut);
74
75protected:
76 bool pmEvent(QMSG *msg, MRESULT *result);
77
78private:
79 HPOINTER hIcon;
80 QPoint globalPos;
81 QSystemTrayIcon *q;
82};
83
84QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object)
85 : hIcon(NULLHANDLE), q(object)
86{
87}
88
89QSystemTrayIconSys::~QSystemTrayIconSys()
90{
91 if (hIcon != NULLHANDLE)
92 WinDestroyPointer(hIcon);
93}
94
95HBITMAP QSystemTrayIconSys::createIconMask(const QBitmap &bitmap)
96{
97 // @todo
98 return NULL;
99}
100
101void QSystemTrayIconSys::createIcon()
102{
103 HPOINTER hIconToDestroy = hIcon;
104
105 // @todo
106
107 if (hIconToDestroy != NULLHANDLE)
108 WinDestroyPointer(hIconToDestroy);
109}
110
111void QSystemTrayIconSys::addToTray()
112{
113 xstAddSysTrayIcon(winId(), 0, hIcon, WM_XST_MYNOTIFY, 0);
114}
115
116void QSystemTrayIconSys::removeFromTray()
117{
118 xstRemoveSysTrayIcon(winId(), 0);
119}
120
121QRect QSystemTrayIconSys::geometry()
122{
123 // @todo use xstQuerySysTrayIconRect()
124 return QRect();
125}
126
127void QSystemTrayIconSys::setToolTip()
128{
129 // @todo use xstSetSysTrayIconToolTip()
130}
131
132void QSystemTrayIconSys::showMessage(const QString &title, const QString &message,
133 QSystemTrayIcon::MessageIcon type, int timeOut)
134{
135 // @todo use xstShowSysTrayIconBalloon()
136}
137
138bool QSystemTrayIconSys::pmEvent(QMSG *msg, MRESULT *result)
139{
140 switch(msg->msg) {
141
142 case WM_XST_MYNOTIFY:
143 {
144 // @todo
145 break;
146 }
147
148 default:
149 {
150 if (msg->msg == WM_XST_CREATED)
151 {
152 addToTray();
153 return true;
154 }
155 break;
156 }
157 }
158
159 return QWidget::pmEvent(msg, result);
160}
161
162void QSystemTrayIconPrivate::install_sys()
163{
164 Q_Q(QSystemTrayIcon);
165 if (!sys) {
166 // @todo make QSystemTrayIconSys a singleton and use different icon IDs
167 // to differentiate between icons (this will save us from creating a new
168 // HWND per each icon the application wants to show)
169 sys = new QSystemTrayIconSys(q);
170 sys->createIcon();
171 sys->addToTray();
172 }
173}
174
175void QSystemTrayIconPrivate::
176showMessage_sys(const QString &title, const QString &message,
177 QSystemTrayIcon::MessageIcon type, int timeOut)
178{
179 if (!sys)
180 return;
181
182 sys->showMessage(title, message, type, timeOut);
183}
184
185QRect QSystemTrayIconPrivate::geometry_sys() const
186{
187 if (!sys)
188 return QRect();
189
190 return sys->geometry();
191}
192
193void QSystemTrayIconPrivate::remove_sys()
194{
195 if (!sys)
196 return;
197
198 sys->removeFromTray();
199 delete sys;
200 sys = 0;
201}
202
203void QSystemTrayIconPrivate::updateIcon_sys()
204{
205 if (!sys)
206 return;
207
208 sys->createIcon();
209 sys->addToTray();
210}
211
212void QSystemTrayIconPrivate::updateMenu_sys()
213{
214
215}
216
217void QSystemTrayIconPrivate::updateToolTip_sys()
218{
219 if (!sys)
220 return;
221
222 sys->setToolTip();
223}
224
225bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys()
226{
227 return xstQuerySysTrayVersion(0, 0, 0);
228}
229
230QT_END_NAMESPACE
231
232#endif // ifndef QT_NO_SYSTEMTRAYICON
233
Note: See TracBrowser for help on using the repository browser.