|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 @class QNSMenu; |
|
79 |
|
80 #include <private/qt_cocoa_helpers_mac_p.h> |
|
81 #include <private/qsystemtrayicon_p.h> |
|
82 #include <qtemporaryfile.h> |
|
83 #include <qimagewriter.h> |
|
84 #include <qapplication.h> |
|
85 #include <qdebug.h> |
|
86 #include <qstyle.h> |
|
87 |
|
88 #include <private/qt_mac_p.h> |
|
89 #import <AppKit/AppKit.h> |
|
90 |
|
91 QT_BEGIN_NAMESPACE |
|
92 extern bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret); //qapplication_mac.cpp |
|
93 extern void qtsystray_sendActivated(QSystemTrayIcon *i, int r); //qsystemtrayicon.cpp |
|
94 extern NSString *keySequenceToKeyEqivalent(const QKeySequence &accel); // qmenu_mac.mm |
|
95 extern NSUInteger keySequenceModifierMask(const QKeySequence &accel); // qmenu_mac.mm |
|
96 QT_END_NAMESPACE |
|
97 |
|
98 QT_USE_NAMESPACE |
|
99 |
|
100 @class QNSImageView; |
|
101 |
|
102 @interface QNSStatusItem : NSObject { |
|
103 NSStatusItem *item; |
|
104 QSystemTrayIcon *icon; |
|
105 QSystemTrayIconPrivate *iconPrivate; |
|
106 QNSImageView *imageCell; |
|
107 } |
|
108 -(id)initWithIcon:(QSystemTrayIcon*)icon iconPrivate:(QSystemTrayIconPrivate *)iprivate; |
|
109 -(void)dealloc; |
|
110 -(QSystemTrayIcon*)icon; |
|
111 -(NSStatusItem*)item; |
|
112 -(QRectF)geometry; |
|
113 - (void)triggerSelector:(id)sender; |
|
114 - (void)doubleClickSelector:(id)sender; |
|
115 @end |
|
116 |
|
117 @interface QNSImageView : NSImageView { |
|
118 BOOL down; |
|
119 QNSStatusItem *parent; |
|
120 } |
|
121 -(id)initWithParent:(QNSStatusItem*)myParent; |
|
122 -(QSystemTrayIcon*)icon; |
|
123 -(void)menuTrackingDone:(NSNotification*)notification; |
|
124 -(void)mousePressed:(NSEvent *)mouseEvent; |
|
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 |
|
136 @interface QNSMenu : NSMenu <NSMenuDelegate> { |
|
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; |
|
150 item = [[QNSStatusItem alloc] initWithIcon:icon iconPrivate:d]; |
|
151 } |
|
152 ~QSystemTrayIconSys() { |
|
153 QMacCocoaAutoReleasePool pool; |
|
154 [[[item item] view] setHidden: YES]; |
|
155 [item release]; |
|
156 } |
|
157 QNSStatusItem *item; |
|
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 |
|
229 void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon icon, int) |
|
230 { |
|
231 |
|
232 if(sys) { |
|
233 #ifdef QT_MAC_SYSTEMTRAY_USE_GROWL |
|
234 // Make sure that we have Growl installed on the machine we are running on. |
|
235 QCFType<CFURLRef> cfurl; |
|
236 OSStatus status = LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, |
|
237 CFSTR("growlTicket"), kLSRolesAll, 0, &cfurl); |
|
238 if (status == kLSApplicationNotFoundErr) |
|
239 return; |
|
240 QCFType<CFBundleRef> bundle = CFBundleCreate(0, cfurl); |
|
241 |
|
242 if (CFStringCompare(CFBundleGetIdentifier(bundle), CFSTR("com.Growl.GrowlHelperApp"), |
|
243 kCFCompareCaseInsensitive | kCFCompareBackwards) != kCFCompareEqualTo) |
|
244 return; |
|
245 QPixmap notificationIconPixmap; |
|
246 if(icon == QSystemTrayIcon::Information) |
|
247 notificationIconPixmap = QApplication::style()->standardPixmap(QStyle::SP_MessageBoxInformation); |
|
248 else if(icon == QSystemTrayIcon::Warning) |
|
249 notificationIconPixmap = QApplication::style()->standardPixmap(QStyle::SP_MessageBoxWarning); |
|
250 else if(icon == QSystemTrayIcon::Critical) |
|
251 notificationIconPixmap = QApplication::style()->standardPixmap(QStyle::SP_MessageBoxCritical); |
|
252 QTemporaryFile notificationIconFile; |
|
253 QString notificationType(QLatin1String("Notification")), notificationIcon, notificationApp(QApplication::applicationName()); |
|
254 if(notificationApp.isEmpty()) |
|
255 notificationApp = QLatin1String("Application"); |
|
256 if(!notificationIconPixmap.isNull() && notificationIconFile.open()) { |
|
257 QImageWriter writer(¬ificationIconFile, "PNG"); |
|
258 if(writer.write(notificationIconPixmap.toImage())) |
|
259 notificationIcon = QLatin1String("image from location \"file://") + notificationIconFile.fileName() + QLatin1String("\""); |
|
260 } |
|
261 const QString script(QLatin1String( |
|
262 "tell application \"GrowlHelperApp\"\n" |
|
263 "-- Make a list of all the notification types (all)\n" |
|
264 "set the allNotificationsList to {\"") + notificationType + QLatin1String("\"}\n" |
|
265 |
|
266 "-- Make a list of the notifications (enabled)\n" |
|
267 "set the enabledNotificationsList to {\"") + notificationType + QLatin1String("\"}\n" |
|
268 |
|
269 "-- Register our script with growl.\n" |
|
270 "register as application \"") + notificationApp + QLatin1String("\" all notifications allNotificationsList default notifications enabledNotificationsList\n" |
|
271 |
|
272 "-- Send a Notification...\n") + |
|
273 QLatin1String("notify with name \"") + notificationType + |
|
274 QLatin1String("\" title \"") + title + |
|
275 QLatin1String("\" description \"") + message + |
|
276 QLatin1String("\" application name \"") + notificationApp + |
|
277 QLatin1String("\" ") + notificationIcon + |
|
278 QLatin1String("\nend tell")); |
|
279 qt_mac_execute_apple_script(script, 0); |
|
280 #elif 0 |
|
281 Q_Q(QSystemTrayIcon); |
|
282 NSView *v = [[sys->item item] view]; |
|
283 NSWindow *w = [v window]; |
|
284 w = [[sys->item item] window]; |
|
285 qDebug() << w << v; |
|
286 QPoint p(qRound([w frame].origin.x), qRound([w frame].origin.y)); |
|
287 qDebug() << p; |
|
288 QBalloonTip::showBalloon(icon, message, title, q, QPoint(0, 0), msecs); |
|
289 #else |
|
290 Q_UNUSED(icon); |
|
291 Q_UNUSED(title); |
|
292 Q_UNUSED(message); |
|
293 #endif |
|
294 } |
|
295 } |
|
296 QT_END_NAMESPACE |
|
297 |
|
298 @implementation NSStatusItem (Qt) |
|
299 @end |
|
300 |
|
301 @implementation QNSImageView |
|
302 -(id)initWithParent:(QNSStatusItem*)myParent { |
|
303 self = [super init]; |
|
304 parent = myParent; |
|
305 down = NO; |
|
306 return self; |
|
307 } |
|
308 |
|
309 -(QSystemTrayIcon*)icon { |
|
310 return [parent icon]; |
|
311 } |
|
312 |
|
313 -(void)menuTrackingDone:(NSNotification*)notification |
|
314 { |
|
315 Q_UNUSED(notification); |
|
316 down = NO; |
|
317 if([self icon]->contextMenu()) |
|
318 [self icon]->contextMenu()->hide(); |
|
319 [self setNeedsDisplay:YES]; |
|
320 } |
|
321 |
|
322 -(void)mousePressed:(NSEvent *)mouseEvent |
|
323 { |
|
324 int clickCount = [mouseEvent clickCount]; |
|
325 down = !down; |
|
326 if(!down && [self icon]->contextMenu()) |
|
327 [self icon]->contextMenu()->hide(); |
|
328 [self setNeedsDisplay:YES]; |
|
329 |
|
330 if (down) |
|
331 [parent triggerSelector:self]; |
|
332 else if ((clickCount%2)) |
|
333 [parent doubleClickSelector:self]; |
|
334 while (down) { |
|
335 mouseEvent = [[self window] nextEventMatchingMask:NSLeftMouseDownMask | NSLeftMouseUpMask |
|
336 | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseUpMask |
|
337 | NSRightMouseDraggedMask]; |
|
338 switch ([mouseEvent type]) { |
|
339 case NSRightMouseDown: |
|
340 case NSRightMouseUp: |
|
341 case NSLeftMouseDown: |
|
342 case NSLeftMouseUp: |
|
343 [self menuTrackingDone:nil]; |
|
344 break; |
|
345 case NSRightMouseDragged: |
|
346 case NSLeftMouseDragged: |
|
347 default: |
|
348 /* Ignore any other kind of event. */ |
|
349 break; |
|
350 } |
|
351 }; |
|
352 } |
|
353 |
|
354 -(void)mouseDown:(NSEvent *)mouseEvent |
|
355 { |
|
356 [self mousePressed:mouseEvent]; |
|
357 } |
|
358 |
|
359 - (void)rightMouseDown:(NSEvent *)mouseEvent |
|
360 { |
|
361 [self mousePressed:mouseEvent]; |
|
362 } |
|
363 |
|
364 |
|
365 -(void)drawRect:(NSRect)rect { |
|
366 [[parent item] drawStatusBarBackgroundInRect:rect withHighlight:down]; |
|
367 [super drawRect:rect]; |
|
368 } |
|
369 @end |
|
370 |
|
371 @implementation QNSStatusItem |
|
372 |
|
373 -(id)initWithIcon:(QSystemTrayIcon*)i iconPrivate:(QSystemTrayIconPrivate *)iPrivate |
|
374 { |
|
375 self = [super init]; |
|
376 if(self) { |
|
377 icon = i; |
|
378 iconPrivate = iPrivate; |
|
379 item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; |
|
380 imageCell = [[QNSImageView alloc] initWithParent:self]; |
|
381 [item setView: imageCell]; |
|
382 } |
|
383 return self; |
|
384 } |
|
385 -(void)dealloc { |
|
386 [[NSStatusBar systemStatusBar] removeStatusItem:item]; |
|
387 [imageCell release]; |
|
388 [item release]; |
|
389 [super dealloc]; |
|
390 |
|
391 } |
|
392 |
|
393 -(QSystemTrayIcon*)icon { |
|
394 return icon; |
|
395 } |
|
396 |
|
397 -(NSStatusItem*)item { |
|
398 return item; |
|
399 } |
|
400 -(QRectF)geometry { |
|
401 if(NSWindow *window = [[item view] window]) { |
|
402 NSRect screenRect = [[window screen] frame]; |
|
403 NSRect windowRect = [window frame]; |
|
404 return QRectF(windowRect.origin.x, screenRect.size.height-windowRect.origin.y-windowRect.size.height, windowRect.size.width, windowRect.size.height); |
|
405 } |
|
406 return QRectF(); |
|
407 } |
|
408 - (void)triggerSelector:(id)sender { |
|
409 Q_UNUSED(sender); |
|
410 if(!icon) |
|
411 return; |
|
412 qtsystray_sendActivated(icon, QSystemTrayIcon::Trigger); |
|
413 if (icon->contextMenu()) { |
|
414 #if 0 |
|
415 const QRectF geom = [self geometry]; |
|
416 if(!geom.isNull()) { |
|
417 [[NSNotificationCenter defaultCenter] addObserver:imageCell |
|
418 selector:@selector(menuTrackingDone:) |
|
419 name:nil |
|
420 object:self]; |
|
421 icon->contextMenu()->exec(geom.topLeft().toPoint(), 0); |
|
422 [imageCell menuTrackingDone:nil]; |
|
423 } else |
|
424 #endif |
|
425 { |
|
426 #ifndef QT_MAC_USE_COCOA |
|
427 [[[self item] view] removeAllToolTips]; |
|
428 iconPrivate->updateToolTip_sys(); |
|
429 #endif |
|
430 NSMenu *m = [[QNSMenu alloc] initWithQMenu:icon->contextMenu()]; |
|
431 [m setAutoenablesItems: NO]; |
|
432 [[NSNotificationCenter defaultCenter] addObserver:imageCell |
|
433 selector:@selector(menuTrackingDone:) |
|
434 name:NSMenuDidEndTrackingNotification |
|
435 object:m]; |
|
436 [item popUpStatusItemMenu: m]; |
|
437 [m release]; |
|
438 } |
|
439 } |
|
440 } |
|
441 - (void)doubleClickSelector:(id)sender { |
|
442 Q_UNUSED(sender); |
|
443 if(!icon) |
|
444 return; |
|
445 qtsystray_sendActivated(icon, QSystemTrayIcon::DoubleClick); |
|
446 } |
|
447 @end |
|
448 |
|
449 class QSystemTrayIconQMenu : public QMenu |
|
450 { |
|
451 public: |
|
452 void doAboutToShow() { emit aboutToShow(); } |
|
453 private: |
|
454 QSystemTrayIconQMenu(); |
|
455 }; |
|
456 |
|
457 @implementation QNSMenu |
|
458 -(id)initWithQMenu:(QMenu*)qm { |
|
459 self = [super init]; |
|
460 if(self) { |
|
461 self->qmenu = qm; |
|
462 [self setDelegate:self]; |
|
463 } |
|
464 return self; |
|
465 } |
|
466 -(QMenu*)menu { |
|
467 return qmenu; |
|
468 } |
|
469 -(void)menuNeedsUpdate:(NSMenu*)nsmenu { |
|
470 QNSMenu *menu = static_cast<QNSMenu *>(nsmenu); |
|
471 emit static_cast<QSystemTrayIconQMenu*>(menu->qmenu)->doAboutToShow(); |
|
472 for(int i = [menu numberOfItems]-1; i >= 0; --i) |
|
473 [menu removeItemAtIndex:i]; |
|
474 QList<QAction*> actions = menu->qmenu->actions();; |
|
475 for(int i = 0; i < actions.size(); ++i) { |
|
476 const QAction *action = actions[i]; |
|
477 if(!action->isVisible()) |
|
478 continue; |
|
479 |
|
480 NSMenuItem *item = 0; |
|
481 bool needRelease = false; |
|
482 if(action->isSeparator()) { |
|
483 item = [NSMenuItem separatorItem]; |
|
484 } else { |
|
485 item = [[NSMenuItem alloc] init]; |
|
486 needRelease = true; |
|
487 QString text = action->text(); |
|
488 QKeySequence accel = action->shortcut(); |
|
489 { |
|
490 int st = text.lastIndexOf(QLatin1Char('\t')); |
|
491 if(st != -1) { |
|
492 accel = QKeySequence(text.right(text.length()-(st+1))); |
|
493 text.remove(st, text.length()-st); |
|
494 } |
|
495 } |
|
496 if(accel.count() > 1) |
|
497 text += QLatin1String(" (****)"); //just to denote a multi stroke shortcut |
|
498 |
|
499 [item setTitle:(NSString*)QCFString::toCFStringRef(qt_mac_removeMnemonics(text))]; |
|
500 [item setEnabled:menu->qmenu->isEnabled() && action->isEnabled()]; |
|
501 [item setState:action->isChecked() ? NSOnState : NSOffState]; |
|
502 [item setToolTip:(NSString*)QCFString::toCFStringRef(action->toolTip())]; |
|
503 const QIcon icon = action->icon(); |
|
504 if(!icon.isNull()) { |
|
505 const short scale = [[NSApp mainMenu] menuBarHeight]; |
|
506 NSImage *nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(icon.pixmap(QSize(scale, scale)))); |
|
507 [item setImage: nsimage]; |
|
508 [nsimage release]; |
|
509 } |
|
510 if(action->menu()) { |
|
511 QNSMenu *sub = [[QNSMenu alloc] initWithQMenu:action->menu()]; |
|
512 [item setSubmenu:sub]; |
|
513 } else { |
|
514 [item setAction:@selector(selectedAction:)]; |
|
515 [item setTarget:self]; |
|
516 } |
|
517 if(!accel.isEmpty()) { |
|
518 [item setKeyEquivalent:keySequenceToKeyEqivalent(accel)]; |
|
519 [item setKeyEquivalentModifierMask:keySequenceModifierMask(accel)]; |
|
520 } |
|
521 } |
|
522 if(item) |
|
523 [menu addItem:item]; |
|
524 if (needRelease) |
|
525 [item release]; |
|
526 } |
|
527 } |
|
528 -(void)selectedAction:(id)a { |
|
529 const int activated = [self indexOfItem:a]; |
|
530 QAction *action = 0; |
|
531 QList<QAction*> actions = qmenu->actions(); |
|
532 for(int i = 0, cnt = 0; i < actions.size(); ++i) { |
|
533 if(actions.at(i)->isVisible() && (cnt++) == activated) { |
|
534 action = actions.at(i); |
|
535 break; |
|
536 } |
|
537 } |
|
538 if(action) { |
|
539 action->activate(QAction::Trigger); |
|
540 } |
|
541 } |
|
542 @end |
|
543 |
|
544 |
|
545 /* Done here because this is the only .mm for now! -Sam */ |
|
546 QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool() |
|
547 { |
|
548 NSApplicationLoad(); |
|
549 pool = (void*)[[NSAutoreleasePool alloc] init]; |
|
550 } |
|
551 |
|
552 QMacCocoaAutoReleasePool::~QMacCocoaAutoReleasePool() |
|
553 { |
|
554 [(NSAutoreleasePool*)pool release]; |
|
555 } |
|
556 |