1 /* gtkstatusicon-quartz.c:
3 * Copyright (C) 2006 Imendio AB
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 * GCC on Mac OS X handles inlined objective C in C-files.
21 * Mikael Hallendal <micke@imendio.com>
24 #import <Cocoa/Cocoa.h>
25 #include <quartz/gdkquartz.h>
27 #define QUARTZ_POOL_ALLOC NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]
28 #define QUARTZ_POOL_RELEASE [pool release]
30 @interface GtkQuartzStatusIcon : NSObject
32 GtkStatusIcon *status_icon;
34 NSStatusItem *ns_item;
35 NSImage *current_image;
38 - (id) initWithStatusIcon:(GtkStatusIcon *)status_icon;
40 - (void) actionCb:(NSObject *)button;
41 - (void) setImage:(GdkPixbuf *)pixbuf;
42 - (void) setVisible:(gboolean)visible;
43 - (void) setToolTip:(const gchar *)tooltip_text;
48 @implementation GtkQuartzStatusIcon : NSObject
49 - (id) initWithStatusIcon:(GtkStatusIcon *)icon
53 ns_bar = [NSStatusBar systemStatusBar];
63 ns_item = [ns_bar statusItemWithLength:NSVariableStatusItemLength];
64 [ns_item setAction:@selector(actionCb:)];
65 [ns_item setTarget:self];
71 g_print ("Deallocating GtkQuartzStatusIcon\n");
72 [current_image release];
79 - (void) actionCb:(NSObject *)button
81 NSEvent *event = [NSApp currentEvent];
82 double time = [event timestamp];
84 g_signal_emit (status_icon,
85 status_icon_signals [POPUP_MENU_SIGNAL], 0,
90 - (void) setImage:(GdkPixbuf *)pixbuf
95 if (current_image != nil) {
96 [current_image release];
106 current_image = gdk_quartz_pixbuf_to_ns_image_libgtk_only (pixbuf);
107 [current_image retain];
109 [ns_item setImage:current_image];
112 - (void) setVisible:(gboolean)visible
117 [ns_item setImage:current_image];
118 if (ns_tooltip != nil)
119 [ns_item setToolTip:ns_tooltip];
126 - (void) setToolTip:(const gchar *)tooltip_text
128 [ns_tooltip release];
129 ns_tooltip = [[NSString stringWithUTF8String:tooltip_text] retain];
131 [ns_item setToolTip:ns_tooltip];
136 return [ns_bar thickness];
141 return [ns_bar thickness];