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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * GCC on Mac OS X handles inlined objective C in C-files.
23 * Mikael Hallendal <micke@imendio.com>
26 #import <Cocoa/Cocoa.h>
27 #include <quartz/gdkquartz.h>
29 #define QUARTZ_POOL_ALLOC NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]
30 #define QUARTZ_POOL_RELEASE [pool release]
32 @interface GtkQuartzStatusIcon : NSObject
34 GtkStatusIcon *status_icon;
36 NSStatusItem *ns_item;
37 NSImage *current_image;
40 - (id) initWithStatusIcon:(GtkStatusIcon *)status_icon;
42 - (void) actionCb:(NSObject *)button;
43 - (void) setImage:(GdkPixbuf *)pixbuf;
44 - (void) setVisible:(gboolean)visible;
45 - (void) setToolTip:(const gchar *)tooltip_text;
50 @implementation GtkQuartzStatusIcon : NSObject
51 - (id) initWithStatusIcon:(GtkStatusIcon *)icon
55 ns_bar = [NSStatusBar systemStatusBar];
65 ns_item = [ns_bar statusItemWithLength:NSVariableStatusItemLength];
66 [ns_item setAction:@selector(actionCb:)];
67 [ns_item setTarget:self];
73 g_print ("Deallocating GtkQuartzStatusIcon\n");
74 [current_image release];
81 - (void) actionCb:(NSObject *)button
83 NSEvent *event = [NSApp currentEvent];
84 double time = [event timestamp];
86 g_signal_emit (status_icon,
87 status_icon_signals [POPUP_MENU_SIGNAL], 0,
92 - (void) setImage:(GdkPixbuf *)pixbuf
97 if (current_image != nil) {
98 [current_image release];
108 current_image = gdk_quartz_pixbuf_to_ns_image_libgtk_only (pixbuf);
109 [current_image retain];
111 [ns_item setImage:current_image];
114 - (void) setVisible:(gboolean)visible
119 [ns_item setImage:current_image];
120 if (ns_tooltip != nil)
121 [ns_item setToolTip:ns_tooltip];
128 - (void) setToolTip:(const gchar *)tooltip_text
130 [ns_tooltip release];
131 ns_tooltip = [[NSString stringWithUTF8String:tooltip_text] retain];
133 [ns_item setToolTip:ns_tooltip];
138 return [ns_bar thickness];
143 return [ns_bar thickness];