author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 33 | 3e2da88830cd |
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 |
/**************************************************************************** |
|
43 |
** |
|
44 |
** Copyright (c) 2007-2008, Apple, Inc. |
|
45 |
** |
|
46 |
** All rights reserved. |
|
47 |
** |
|
48 |
** Redistribution and use in source and binary forms, with or without |
|
49 |
** modification, are permitted provided that the following conditions are met: |
|
50 |
** |
|
51 |
** * Redistributions of source code must retain the above copyright notice, |
|
52 |
** this list of conditions and the following disclaimer. |
|
53 |
** |
|
54 |
** * Redistributions in binary form must reproduce the above copyright notice, |
|
55 |
** this list of conditions and the following disclaimer in the documentation |
|
56 |
** and/or other materials provided with the distribution. |
|
57 |
** |
|
58 |
** * Neither the name of Apple, Inc. nor the names of its contributors |
|
59 |
** may be used to endorse or promote products derived from this software |
|
60 |
** without specific prior written permission. |
|
61 |
** |
|
62 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
63 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
64 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
65 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
66 |
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
67 |
** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
68 |
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
69 |
** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
70 |
** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
71 |
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
72 |
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
73 |
** |
|
74 |
****************************************************************************/ |
|
75 |
||
76 |
#define QT_MAC_SYSTEMTRAY_USE_GROWL |
|
77 |
||
78 |
#include <private/qt_cocoa_helpers_mac_p.h> |
|
79 |
#include <private/qsystemtrayicon_p.h> |
|
80 |
#include <qtemporaryfile.h> |
|
81 |
#include <qimagewriter.h> |
|
82 |
#include <qapplication.h> |
|
83 |
#include <qdebug.h> |
|
84 |
#include <qstyle.h> |
|
85 |
||
86 |
#include <private/qt_mac_p.h> |
|
87 |
#import <AppKit/AppKit.h> |
|
88 |
||
89 |
QT_BEGIN_NAMESPACE |
|
90 |
extern bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret); //qapplication_mac.cpp |
|
91 |
extern void qtsystray_sendActivated(QSystemTrayIcon *i, int r); //qsystemtrayicon.cpp |
|
92 |
extern NSString *keySequenceToKeyEqivalent(const QKeySequence &accel); // qmenu_mac.mm |
|
93 |
extern NSUInteger keySequenceModifierMask(const QKeySequence &accel); // qmenu_mac.mm |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
94 |
extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); |
0 | 95 |
QT_END_NAMESPACE |
96 |
||
97 |
QT_USE_NAMESPACE |
|
98 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
99 |
@class QT_MANGLE_NAMESPACE(QNSMenu); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
100 |
@class QT_MANGLE_NAMESPACE(QNSImageView); |
0 | 101 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
102 |
@interface QT_MANGLE_NAMESPACE(QNSStatusItem) : NSObject { |
0 | 103 |
NSStatusItem *item; |
104 |
QSystemTrayIcon *icon; |
|
105 |
QSystemTrayIconPrivate *iconPrivate; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
106 |
QT_MANGLE_NAMESPACE(QNSImageView) *imageCell; |
0 | 107 |
} |
108 |
-(id)initWithIcon:(QSystemTrayIcon*)icon iconPrivate:(QSystemTrayIconPrivate *)iprivate; |
|
109 |
-(void)dealloc; |
|
110 |
-(QSystemTrayIcon*)icon; |
|
111 |
-(NSStatusItem*)item; |
|
112 |
-(QRectF)geometry; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
113 |
- (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton; |
0 | 114 |
- (void)doubleClickSelector:(id)sender; |
115 |
@end |
|
116 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
117 |
@interface QT_MANGLE_NAMESPACE(QNSImageView) : NSImageView { |
0 | 118 |
BOOL down; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
119 |
QT_MANGLE_NAMESPACE(QNSStatusItem) *parent; |
0 | 120 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
121 |
-(id)initWithParent:(QT_MANGLE_NAMESPACE(QNSStatusItem)*)myParent; |
0 | 122 |
-(QSystemTrayIcon*)icon; |
123 |
-(void)menuTrackingDone:(NSNotification*)notification; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
124 |
-(void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton; |
0 | 125 |
@end |
126 |
||
127 |
||
128 |
#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 |
|
129 |
||
130 |
@protocol NSMenuDelegate <NSObject> |
|
131 |
-(void)menuNeedsUpdate:(NSMenu*)menu; |
|
132 |
@end |
|
133 |
#endif |
|
134 |
||
135 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
136 |
@interface QT_MANGLE_NAMESPACE(QNSMenu) : NSMenu <NSMenuDelegate> { |
0 | 137 |
QMenu *qmenu; |
138 |
} |
|
139 |
-(QMenu*)menu; |
|
140 |
-(id)initWithQMenu:(QMenu*)qmenu; |
|
141 |
-(void)selectedAction:(id)item; |
|
142 |
@end |
|
143 |
||
144 |
QT_BEGIN_NAMESPACE |
|
145 |
class QSystemTrayIconSys |
|
146 |
{ |
|
147 |
public: |
|
148 |
QSystemTrayIconSys(QSystemTrayIcon *icon, QSystemTrayIconPrivate *d) { |
|
149 |
QMacCocoaAutoReleasePool pool; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
150 |
item = [[QT_MANGLE_NAMESPACE(QNSStatusItem) alloc] initWithIcon:icon iconPrivate:d]; |
0 | 151 |
} |
152 |
~QSystemTrayIconSys() { |
|
153 |
QMacCocoaAutoReleasePool pool; |
|
154 |
[[[item item] view] setHidden: YES]; |
|
155 |
[item release]; |
|
156 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
157 |
QT_MANGLE_NAMESPACE(QNSStatusItem) *item; |
0 | 158 |
}; |
159 |
||
160 |
void QSystemTrayIconPrivate::install_sys() |
|
161 |
{ |
|
162 |
Q_Q(QSystemTrayIcon); |
|
163 |
if (!sys) { |
|
164 |
sys = new QSystemTrayIconSys(q, this); |
|
165 |
updateIcon_sys(); |
|
166 |
updateMenu_sys(); |
|
167 |
updateToolTip_sys(); |
|
168 |
} |
|
169 |
} |
|
170 |
||
171 |
QRect QSystemTrayIconPrivate::geometry_sys() const |
|
172 |
{ |
|
173 |
if(sys) { |
|
174 |
const QRectF geom = [sys->item geometry]; |
|
175 |
if(!geom.isNull()) |
|
176 |
return geom.toRect(); |
|
177 |
} |
|
178 |
return QRect(); |
|
179 |
} |
|
180 |
||
181 |
void QSystemTrayIconPrivate::remove_sys() |
|
182 |
{ |
|
183 |
delete sys; |
|
184 |
sys = 0; |
|
185 |
} |
|
186 |
||
187 |
void QSystemTrayIconPrivate::updateIcon_sys() |
|
188 |
{ |
|
189 |
if(sys && !icon.isNull()) { |
|
190 |
QMacCocoaAutoReleasePool pool; |
|
191 |
#ifndef QT_MAC_USE_COCOA |
|
192 |
const short scale = GetMBarHeight()-4; |
|
193 |
#else |
|
194 |
CGFloat hgt = [[[NSApplication sharedApplication] mainMenu] menuBarHeight]; |
|
195 |
const short scale = hgt - 4; |
|
196 |
#endif |
|
197 |
NSImage *nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(icon.pixmap(QSize(scale, scale)))); |
|
198 |
[(NSImageView*)[[sys->item item] view] setImage: nsimage]; |
|
199 |
[nsimage release]; |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
void QSystemTrayIconPrivate::updateMenu_sys() |
|
204 |
{ |
|
205 |
if(sys) { |
|
206 |
QMacCocoaAutoReleasePool pool; |
|
207 |
if(menu && !menu->isEmpty()) { |
|
208 |
[[sys->item item] setHighlightMode:YES]; |
|
209 |
} else { |
|
210 |
[[sys->item item] setHighlightMode:NO]; |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
void QSystemTrayIconPrivate::updateToolTip_sys() |
|
216 |
{ |
|
217 |
if(sys) { |
|
218 |
QMacCocoaAutoReleasePool pool; |
|
219 |
QCFString string(toolTip); |
|
220 |
[[[sys->item item] view] setToolTip:(NSString*)static_cast<CFStringRef>(string)]; |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() |
|
225 |
{ |
|
226 |
return true; |
|
227 |
} |
|
228 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
229 |
bool QSystemTrayIconPrivate::supportsMessages_sys() |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
230 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
231 |
return true; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
232 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
233 |
|
0 | 234 |
void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon icon, int) |
235 |
{ |
|
236 |
||
237 |
if(sys) { |
|
238 |
#ifdef QT_MAC_SYSTEMTRAY_USE_GROWL |
|
239 |
// Make sure that we have Growl installed on the machine we are running on. |
|
240 |
QCFType<CFURLRef> cfurl; |
|
241 |
OSStatus status = LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, |
|
242 |
CFSTR("growlTicket"), kLSRolesAll, 0, &cfurl); |
|
243 |
if (status == kLSApplicationNotFoundErr) |
|
244 |
return; |
|
245 |
QCFType<CFBundleRef> bundle = CFBundleCreate(0, cfurl); |
|
246 |
||
247 |
if (CFStringCompare(CFBundleGetIdentifier(bundle), CFSTR("com.Growl.GrowlHelperApp"), |
|
248 |
kCFCompareCaseInsensitive | kCFCompareBackwards) != kCFCompareEqualTo) |
|
249 |
return; |
|
250 |
QPixmap notificationIconPixmap; |
|
251 |
if(icon == QSystemTrayIcon::Information) |
|
252 |
notificationIconPixmap = QApplication::style()->standardPixmap(QStyle::SP_MessageBoxInformation); |
|
253 |
else if(icon == QSystemTrayIcon::Warning) |
|
254 |
notificationIconPixmap = QApplication::style()->standardPixmap(QStyle::SP_MessageBoxWarning); |
|
255 |
else if(icon == QSystemTrayIcon::Critical) |
|
256 |
notificationIconPixmap = QApplication::style()->standardPixmap(QStyle::SP_MessageBoxCritical); |
|
257 |
QTemporaryFile notificationIconFile; |
|
258 |
QString notificationType(QLatin1String("Notification")), notificationIcon, notificationApp(QApplication::applicationName()); |
|
259 |
if(notificationApp.isEmpty()) |
|
260 |
notificationApp = QLatin1String("Application"); |
|
261 |
if(!notificationIconPixmap.isNull() && notificationIconFile.open()) { |
|
262 |
QImageWriter writer(¬ificationIconFile, "PNG"); |
|
263 |
if(writer.write(notificationIconPixmap.toImage())) |
|
264 |
notificationIcon = QLatin1String("image from location \"file://") + notificationIconFile.fileName() + QLatin1String("\""); |
|
265 |
} |
|
266 |
const QString script(QLatin1String( |
|
267 |
"tell application \"GrowlHelperApp\"\n" |
|
268 |
"-- Make a list of all the notification types (all)\n" |
|
269 |
"set the allNotificationsList to {\"") + notificationType + QLatin1String("\"}\n" |
|
270 |
||
271 |
"-- Make a list of the notifications (enabled)\n" |
|
272 |
"set the enabledNotificationsList to {\"") + notificationType + QLatin1String("\"}\n" |
|
273 |
||
274 |
"-- Register our script with growl.\n" |
|
275 |
"register as application \"") + notificationApp + QLatin1String("\" all notifications allNotificationsList default notifications enabledNotificationsList\n" |
|
276 |
||
277 |
"-- Send a Notification...\n") + |
|
278 |
QLatin1String("notify with name \"") + notificationType + |
|
279 |
QLatin1String("\" title \"") + title + |
|
280 |
QLatin1String("\" description \"") + message + |
|
281 |
QLatin1String("\" application name \"") + notificationApp + |
|
282 |
QLatin1String("\" ") + notificationIcon + |
|
283 |
QLatin1String("\nend tell")); |
|
284 |
qt_mac_execute_apple_script(script, 0); |
|
285 |
#elif 0 |
|
286 |
Q_Q(QSystemTrayIcon); |
|
287 |
NSView *v = [[sys->item item] view]; |
|
288 |
NSWindow *w = [v window]; |
|
289 |
w = [[sys->item item] window]; |
|
290 |
qDebug() << w << v; |
|
291 |
QPoint p(qRound([w frame].origin.x), qRound([w frame].origin.y)); |
|
292 |
qDebug() << p; |
|
293 |
QBalloonTip::showBalloon(icon, message, title, q, QPoint(0, 0), msecs); |
|
294 |
#else |
|
295 |
Q_UNUSED(icon); |
|
296 |
Q_UNUSED(title); |
|
297 |
Q_UNUSED(message); |
|
298 |
#endif |
|
299 |
} |
|
300 |
} |
|
301 |
QT_END_NAMESPACE |
|
302 |
||
303 |
@implementation NSStatusItem (Qt) |
|
304 |
@end |
|
305 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
306 |
@implementation QT_MANGLE_NAMESPACE(QNSImageView) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
307 |
-(id)initWithParent:(QT_MANGLE_NAMESPACE(QNSStatusItem)*)myParent { |
0 | 308 |
self = [super init]; |
309 |
parent = myParent; |
|
310 |
down = NO; |
|
311 |
return self; |
|
312 |
} |
|
313 |
||
314 |
-(QSystemTrayIcon*)icon { |
|
315 |
return [parent icon]; |
|
316 |
} |
|
317 |
||
318 |
-(void)menuTrackingDone:(NSNotification*)notification |
|
319 |
{ |
|
320 |
Q_UNUSED(notification); |
|
321 |
down = NO; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
323 |
if( ![self icon]->icon().isNull() ) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
#ifndef QT_MAC_USE_COCOA |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
const short scale = GetMBarHeight()-4; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
326 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
CGFloat hgt = [[[NSApplication sharedApplication] mainMenu] menuBarHeight]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
const short scale = hgt - 4; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
NSImage *nsimage = static_cast<NSImage *>(qt_mac_create_nsimage([self icon]->icon().pixmap(QSize(scale, scale)))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
[self setImage: nsimage]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
[nsimage release]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
334 |
|
0 | 335 |
if([self icon]->contextMenu()) |
336 |
[self icon]->contextMenu()->hide(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
|
0 | 338 |
[self setNeedsDisplay:YES]; |
339 |
} |
|
340 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
341 |
-(void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton |
0 | 342 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
343 |
down = YES; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
344 |
int clickCount = [mouseEvent clickCount]; |
0 | 345 |
[self setNeedsDisplay:YES]; |
346 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
347 |
#ifndef QT_MAC_USE_COCOA |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
const short scale = GetMBarHeight()-4; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
349 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
CGFloat hgt = [[[NSApplication sharedApplication] mainMenu] menuBarHeight]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
const short scale = hgt - 4; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
353 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
354 |
if (![self icon]->icon().isNull() ) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
355 |
NSImage *nsaltimage = static_cast<NSImage *>(qt_mac_create_nsimage([self icon]->icon().pixmap(QSize(scale, scale), QIcon::Selected))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
[self setImage: nsaltimage]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
357 |
[nsaltimage release]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
359 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
360 |
if ((clickCount == 2)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
361 |
[self menuTrackingDone:nil]; |
0 | 362 |
[parent doubleClickSelector:self]; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
363 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
364 |
[parent triggerSelector:self button:mouseButton]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
365 |
} |
0 | 366 |
} |
367 |
||
368 |
-(void)mouseDown:(NSEvent *)mouseEvent |
|
369 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
370 |
[self mousePressed:mouseEvent button:Qt::LeftButton]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
371 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
372 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
373 |
-(void)mouseUp:(NSEvent *)mouseEvent |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
374 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
375 |
Q_UNUSED(mouseEvent); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
376 |
[self menuTrackingDone:nil]; |
0 | 377 |
} |
378 |
||
379 |
- (void)rightMouseDown:(NSEvent *)mouseEvent |
|
380 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
381 |
[self mousePressed:mouseEvent button:Qt::RightButton]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
382 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
383 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
384 |
-(void)rightMouseUp:(NSEvent *)mouseEvent |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
385 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
386 |
Q_UNUSED(mouseEvent); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
387 |
[self menuTrackingDone:nil]; |
0 | 388 |
} |
389 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
390 |
- (void)otherMouseDown:(NSEvent *)mouseEvent |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
391 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
392 |
[self mousePressed:mouseEvent button:cocoaButton2QtButton([mouseEvent buttonNumber])]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
393 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
394 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
395 |
-(void)otherMouseUp:(NSEvent *)mouseEvent |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
396 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
397 |
Q_UNUSED(mouseEvent); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
398 |
[self menuTrackingDone:nil]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
399 |
} |
0 | 400 |
|
401 |
-(void)drawRect:(NSRect)rect { |
|
402 |
[[parent item] drawStatusBarBackgroundInRect:rect withHighlight:down]; |
|
403 |
[super drawRect:rect]; |
|
404 |
} |
|
405 |
@end |
|
406 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
407 |
@implementation QT_MANGLE_NAMESPACE(QNSStatusItem) |
0 | 408 |
|
409 |
-(id)initWithIcon:(QSystemTrayIcon*)i iconPrivate:(QSystemTrayIconPrivate *)iPrivate |
|
410 |
{ |
|
411 |
self = [super init]; |
|
412 |
if(self) { |
|
413 |
icon = i; |
|
414 |
iconPrivate = iPrivate; |
|
415 |
item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
416 |
imageCell = [[QT_MANGLE_NAMESPACE(QNSImageView) alloc] initWithParent:self]; |
0 | 417 |
[item setView: imageCell]; |
418 |
} |
|
419 |
return self; |
|
420 |
} |
|
421 |
-(void)dealloc { |
|
422 |
[[NSStatusBar systemStatusBar] removeStatusItem:item]; |
|
423 |
[imageCell release]; |
|
424 |
[item release]; |
|
425 |
[super dealloc]; |
|
426 |
||
427 |
} |
|
428 |
||
429 |
-(QSystemTrayIcon*)icon { |
|
430 |
return icon; |
|
431 |
} |
|
432 |
||
433 |
-(NSStatusItem*)item { |
|
434 |
return item; |
|
435 |
} |
|
436 |
-(QRectF)geometry { |
|
437 |
if(NSWindow *window = [[item view] window]) { |
|
438 |
NSRect screenRect = [[window screen] frame]; |
|
439 |
NSRect windowRect = [window frame]; |
|
440 |
return QRectF(windowRect.origin.x, screenRect.size.height-windowRect.origin.y-windowRect.size.height, windowRect.size.width, windowRect.size.height); |
|
441 |
} |
|
442 |
return QRectF(); |
|
443 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
444 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
445 |
- (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton { |
0 | 446 |
Q_UNUSED(sender); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
447 |
if (!icon) |
0 | 448 |
return; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
449 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
450 |
if (mouseButton == Qt::MidButton) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
451 |
qtsystray_sendActivated(icon, QSystemTrayIcon::MiddleClick); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
452 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
453 |
qtsystray_sendActivated(icon, QSystemTrayIcon::Trigger); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
454 |
|
0 | 455 |
if (icon->contextMenu()) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
456 |
#ifndef QT_MAC_USE_COCOA |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
457 |
[[[self item] view] removeAllToolTips]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
458 |
iconPrivate->updateToolTip_sys(); |
0 | 459 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
460 |
NSMenu *m = [[QT_MANGLE_NAMESPACE(QNSMenu) alloc] initWithQMenu:icon->contextMenu()]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
461 |
[m setAutoenablesItems: NO]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
462 |
[[NSNotificationCenter defaultCenter] addObserver:imageCell |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
463 |
selector:@selector(menuTrackingDone:) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
464 |
name:NSMenuDidEndTrackingNotification |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
465 |
object:m]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
466 |
[item popUpStatusItemMenu: m]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
467 |
[m release]; |
0 | 468 |
} |
469 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
470 |
|
0 | 471 |
- (void)doubleClickSelector:(id)sender { |
472 |
Q_UNUSED(sender); |
|
473 |
if(!icon) |
|
474 |
return; |
|
475 |
qtsystray_sendActivated(icon, QSystemTrayIcon::DoubleClick); |
|
476 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
477 |
|
0 | 478 |
@end |
479 |
||
480 |
class QSystemTrayIconQMenu : public QMenu |
|
481 |
{ |
|
482 |
public: |
|
483 |
void doAboutToShow() { emit aboutToShow(); } |
|
484 |
private: |
|
485 |
QSystemTrayIconQMenu(); |
|
486 |
}; |
|
487 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
488 |
@implementation QT_MANGLE_NAMESPACE(QNSMenu) |
0 | 489 |
-(id)initWithQMenu:(QMenu*)qm { |
490 |
self = [super init]; |
|
491 |
if(self) { |
|
492 |
self->qmenu = qm; |
|
493 |
[self setDelegate:self]; |
|
494 |
} |
|
495 |
return self; |
|
496 |
} |
|
497 |
-(QMenu*)menu { |
|
498 |
return qmenu; |
|
499 |
} |
|
500 |
-(void)menuNeedsUpdate:(NSMenu*)nsmenu { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
501 |
QT_MANGLE_NAMESPACE(QNSMenu) *menu = static_cast<QT_MANGLE_NAMESPACE(QNSMenu) *>(nsmenu); |
0 | 502 |
emit static_cast<QSystemTrayIconQMenu*>(menu->qmenu)->doAboutToShow(); |
503 |
for(int i = [menu numberOfItems]-1; i >= 0; --i) |
|
504 |
[menu removeItemAtIndex:i]; |
|
505 |
QList<QAction*> actions = menu->qmenu->actions();; |
|
506 |
for(int i = 0; i < actions.size(); ++i) { |
|
507 |
const QAction *action = actions[i]; |
|
508 |
if(!action->isVisible()) |
|
509 |
continue; |
|
510 |
||
511 |
NSMenuItem *item = 0; |
|
512 |
bool needRelease = false; |
|
513 |
if(action->isSeparator()) { |
|
514 |
item = [NSMenuItem separatorItem]; |
|
515 |
} else { |
|
516 |
item = [[NSMenuItem alloc] init]; |
|
517 |
needRelease = true; |
|
518 |
QString text = action->text(); |
|
519 |
QKeySequence accel = action->shortcut(); |
|
520 |
{ |
|
521 |
int st = text.lastIndexOf(QLatin1Char('\t')); |
|
522 |
if(st != -1) { |
|
523 |
accel = QKeySequence(text.right(text.length()-(st+1))); |
|
524 |
text.remove(st, text.length()-st); |
|
525 |
} |
|
526 |
} |
|
527 |
if(accel.count() > 1) |
|
528 |
text += QLatin1String(" (****)"); //just to denote a multi stroke shortcut |
|
529 |
||
530 |
[item setTitle:(NSString*)QCFString::toCFStringRef(qt_mac_removeMnemonics(text))]; |
|
531 |
[item setEnabled:menu->qmenu->isEnabled() && action->isEnabled()]; |
|
532 |
[item setState:action->isChecked() ? NSOnState : NSOffState]; |
|
533 |
[item setToolTip:(NSString*)QCFString::toCFStringRef(action->toolTip())]; |
|
534 |
const QIcon icon = action->icon(); |
|
535 |
if(!icon.isNull()) { |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
536 |
#ifndef QT_MAC_USE_COCOA |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
537 |
const short scale = GetMBarHeight(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
538 |
#else |
0 | 539 |
const short scale = [[NSApp mainMenu] menuBarHeight]; |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
540 |
#endif |
0 | 541 |
NSImage *nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(icon.pixmap(QSize(scale, scale)))); |
542 |
[item setImage: nsimage]; |
|
543 |
[nsimage release]; |
|
544 |
} |
|
545 |
if(action->menu()) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
546 |
QT_MANGLE_NAMESPACE(QNSMenu) *sub = [[QT_MANGLE_NAMESPACE(QNSMenu) alloc] initWithQMenu:action->menu()]; |
0 | 547 |
[item setSubmenu:sub]; |
548 |
} else { |
|
549 |
[item setAction:@selector(selectedAction:)]; |
|
550 |
[item setTarget:self]; |
|
551 |
} |
|
552 |
if(!accel.isEmpty()) { |
|
553 |
[item setKeyEquivalent:keySequenceToKeyEqivalent(accel)]; |
|
554 |
[item setKeyEquivalentModifierMask:keySequenceModifierMask(accel)]; |
|
555 |
} |
|
556 |
} |
|
557 |
if(item) |
|
558 |
[menu addItem:item]; |
|
559 |
if (needRelease) |
|
560 |
[item release]; |
|
561 |
} |
|
562 |
} |
|
563 |
-(void)selectedAction:(id)a { |
|
564 |
const int activated = [self indexOfItem:a]; |
|
565 |
QAction *action = 0; |
|
566 |
QList<QAction*> actions = qmenu->actions(); |
|
567 |
for(int i = 0, cnt = 0; i < actions.size(); ++i) { |
|
568 |
if(actions.at(i)->isVisible() && (cnt++) == activated) { |
|
569 |
action = actions.at(i); |
|
570 |
break; |
|
571 |
} |
|
572 |
} |
|
573 |
if(action) { |
|
574 |
action->activate(QAction::Trigger); |
|
575 |
} |
|
576 |
} |
|
577 |
@end |
|
578 |