76 #define QT_MAC_SYSTEMTRAY_USE_GROWL 78 #include <private/qt_cocoa_helpers_mac_p.h> 79 #include <private/qsystemtrayicon_p.h> 86 #include <private/qt_mac_p.h> 87 #import <AppKit/AppKit.h> 102 @interface QT_MANGLE_NAMESPACE(QNSStatusItem) : NSObject {
111 -(NSStatusItem*)item;
113 - (void)triggerSelector:(
id)sender button:(
Qt::
MouseButton)mouseButton;
114 - (void)doubleClickSelector:(
id)sender;
117 @interface QT_MANGLE_NAMESPACE(QNSImageView) : NSImageView {
123 -(void)menuTrackingDone:(NSNotification*)notification;
124 -(void)mousePressed:(NSEvent *)mouseEvent button:(
Qt::
MouseButton)mouseButton;
128 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 130 @protocol NSMenuDelegate <NSObject>
131 -(void)menuNeedsUpdate:(NSMenu*)menu;
136 @interface QT_MANGLE_NAMESPACE(QNSMenu) : NSMenu <NSMenuDelegate> {
140 -(id)initWithQMenu:(
QMenu*)qmenu;
141 -(void)selectedAction:(
id)item;
150 item = [[QT_MANGLE_NAMESPACE(QNSStatusItem) alloc] initWithIcon:icon iconPrivate:d];
154 [[[
item item] view] setHidden: YES];
189 if(sys && !icon.isNull()) {
191 #ifndef QT_MAC_USE_COCOA 192 const short scale = GetMBarHeight()-4;
194 CGFloat hgt = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
195 const short scale = hgt - 4;
198 [(NSImageView*)[[
sys->item
item] view] setImage: nsimage];
207 if(menu && !menu->isEmpty()) {
208 [[
sys->item
item] setHighlightMode:YES];
210 [[
sys->item
item] setHighlightMode:NO];
220 [[[
sys->item
item] view] setToolTip:(NSString*)static_cast<CFStringRef>(string)];
238 #ifdef QT_MAC_SYSTEMTRAY_USE_GROWL 241 OSStatus status = LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
242 CFSTR(
"growlTicket"), kLSRolesAll, 0, &cfurl);
243 if (status == kLSApplicationNotFoundErr)
247 if (CFStringCompare(CFBundleGetIdentifier(bundle), CFSTR(
"com.Growl.GrowlHelperApp"),
248 kCFCompareCaseInsensitive | kCFCompareBackwards) != kCFCompareEqualTo)
250 QPixmap notificationIconPixmap;
261 if(!notificationIconPixmap.
isNull() && notificationIconFile.
open()) {
267 "tell application \"GrowlHelperApp\"\n" 268 "-- Make a list of all the notification types (all)\n" 269 "set the allNotificationsList to {\"") + notificationType +
QLatin1String(
"\"}\n" 271 "-- Make a list of the notifications (enabled)\n" 272 "set the enabledNotificationsList to {\"") + notificationType +
QLatin1String(
"\"}\n" 274 "-- Register our script with growl.\n" 275 "register as application \"") + notificationApp +
QLatin1String(
"\" all notifications allNotificationsList default notifications enabledNotificationsList\n" 277 "-- Send a Notification...\n") +
287 NSView *v = [[
sys->item
item] view];
288 NSWindow *w = [v window];
306 @implementation QT_MANGLE_NAMESPACE(QNSImageView)
318 -(void)menuTrackingDone:(NSNotification*)notification
323 if( ![
self icon]->icon().
isNull() ) {
324 #ifndef QT_MAC_USE_COCOA 325 const short scale = GetMBarHeight()-4;
327 CGFloat hgt = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
328 const short scale = hgt - 4;
331 [
self setImage: nsimage];
335 if([
self icon]->contextMenu())
336 [
self icon]->contextMenu()->hide();
338 [
self setNeedsDisplay:YES];
341 -(void)mousePressed:(NSEvent *)mouseEvent button:(
Qt::
MouseButton)mouseButton
344 int clickCount = [mouseEvent clickCount];
345 [
self setNeedsDisplay:YES];
347 #ifndef QT_MAC_USE_COCOA 348 const short scale = GetMBarHeight()-4;
350 CGFloat hgt = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
351 const short scale = hgt - 4;
354 if (![
self icon]->icon().
isNull() ) {
356 [
self setImage: nsaltimage];
357 [nsaltimage release];
360 if ((clickCount == 2)) {
370 [
self mousePressed:mouseEvent button:Qt::LeftButton];
381 [
self mousePressed:mouseEvent button:Qt::RightButton];
392 [
self mousePressed:mouseEvent
button:cocoaButton2QtButton([mouseEvent buttonNumber])];
401 -(void)drawRect:(NSRect)rect {
402 [[
parent item] drawStatusBarBackgroundInRect:rect withHighlight:down];
403 [
super drawRect:rect];
407 @implementation QT_MANGLE_NAMESPACE(QNSStatusItem)
414 iconPrivate = iPrivate;
415 item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
416 imageCell = [[QT_MANGLE_NAMESPACE(QNSImageView) alloc] initWithParent:self];
417 [
item setView: imageCell];
422 [[NSStatusBar systemStatusBar] removeStatusItem:item];
433 -(NSStatusItem*)item {
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);
456 #ifndef QT_MAC_USE_COCOA 457 [[[
self item] view] removeAllToolTips];
458 iconPrivate->updateToolTip_sys();
460 NSMenu *m = [[QT_MANGLE_NAMESPACE(QNSMenu) alloc] initWithQMenu:icon->contextMenu()];
461 [m setAutoenablesItems: NO];
462 [[NSNotificationCenter defaultCenter] addObserver:imageCell
463 selector:@selector(menuTrackingDone:)
464 name:NSMenuDidEndTrackingNotification
466 [
item popUpStatusItemMenu: m];
471 - (void)doubleClickSelector:(
id)sender {
488 @implementation QT_MANGLE_NAMESPACE(QNSMenu)
493 [
self setDelegate:self];
500 -(void)menuNeedsUpdate:(NSMenu*)nsmenu {
503 for(
int i = [menu numberOfItems]-1; i >= 0; --i)
504 [menu removeItemAtIndex:i];
506 for(
int i = 0; i < actions.
size(); ++i) {
507 const QAction *action = actions[i];
512 bool needRelease =
false;
516 item = [[NSMenuItem
alloc] init];
527 if(accel.
count() > 1)
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())];
536 #ifndef QT_MAC_USE_COCOA 537 const short scale = GetMBarHeight();
539 const short scale = [[NSApp mainMenu] menuBarHeight];
542 [item setImage: nsimage];
547 [item setSubmenu:sub];
549 [item setAction:@selector(selectedAction:)];
550 [item setTarget:self];
553 [item setKeyEquivalent:keySequenceToKeyEqivalent(accel)];
554 [item setKeyEquivalentModifierMask:keySequenceModifierMask(accel)];
563 -(void)selectedAction:(
id)a {
564 const int activated = [
self indexOfItem:a];
567 for(
int i = 0, cnt = 0; i < actions.
size(); ++i) {
568 if(actions.
at(i)->
isVisible() && (cnt++) == activated) {
569 action = actions.
at(i);
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
QImage toImage() const
Converts the pixmap to a QImage.
void showMessage_sys(const QString &msg, const QString &title, QSystemTrayIcon::MessageIcon icon, int secs)
bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret)
#define QT_END_NAMESPACE
This macro expands to.
QKeySequence shortcut
the action's primary shortcut key
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
int length() const
Returns the number of characters in this string.
The QTemporaryFile class is an I/O device that operates on temporary files.
QString text
the action's descriptive text
void qtsystray_sendActivated(QSystemTrayIcon *i, int r)
QRect geometry_sys() const
static LibLoadStatus status
bool open()
A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, this allows easy access to the d...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void * qt_mac_create_nsimage(const QPixmap &pm)
static QStyle * style()
Returns the application's style object.
void menuTrackingDone:(NSNotification *notification)
The QString class provides a Unicode character string.
static bool supportsMessages_sys()
void mousePressed:button:(NSEvent *mouseEvent, [button] Qt::MouseButton mouseButton)
static void showBalloon(QSystemTrayIcon::MessageIcon icon, const QString &title, const QString &msg, QSystemTrayIcon *trayIcon, const QPoint &pos, int timeout, bool showArrow=true)
Q_CORE_EXPORT void qDebug(const char *,...)
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
The QImageWriter class provides a format independent interface for writing images to files or other d...
static bool isSystemTrayAvailable_sys()
void doubleClickSelector:(id sender)
const T & at(int i) const
Returns the item at index position i in the list.
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
QSystemTrayIconPrivate * iconPrivate
QIcon icon
the action's icon
QMenu * contextMenu() const
Returns the current context menu for the system tray entry.
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
NSUInteger keySequenceModifierMask(const QKeySequence &accel)
bool isEmpty() const
Returns true if the key sequence is empty; otherwise returns false.
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
QMenu * menu() const
Returns the menu contained by this action.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
#define QT_MANGLE_NAMESPACE(name)
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
#define st(var, type, card)
The QPoint class defines a point in the plane using integer precision.
QString fileName() const
Returns the complete unique filename backing the QTemporaryFile object.
int size() const
Returns the number of items in the list.
The QRect class defines a rectangle in the plane using integer precision.
void triggerSelector:button:(id sender, [button] Qt::MouseButton mouseButton)
uint count() const
Returns the number of keys in the key sequence.
NSString * keySequenceToKeyEqivalent(const QKeySequence &accel)
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
The QPixmap class is an off-screen image representation that can be used as a paint device...
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
The QSize class defines the size of a two-dimensional object using integer point precision.
static QString applicationName()
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
MessageIcon
This enum describes the icon that is shown when a balloon message is displayed.
bool write(const QImage &image)
Writes the image image to the assigned device or file name.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QSystemTrayIconSys(QSystemTrayIcon *icon, QSystemTrayIconPrivate *d)
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
virtual QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt=0, const QWidget *widget=0) const =0
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Q_DECL_CONSTEXPR int qRound(qreal d)
The QAction class provides an abstract user interface action that can be inserted into widgets...
static bool isNull(const QVariant::Private *d)
The QSystemTrayIcon class provides an icon for an application in the system tray. ...
The QList class is a template class that provides lists.
The QIcon class provides scalable icons in different modes and states.