2 * MACDRV Cocoa status item class
4 * Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #import <Cocoa/Cocoa.h>
22 #include "macdrv_cocoa.h"
24 #import "cocoa_event.h"
27 @interface WineStatusItem : NSObject
30 WineEventQueue* queue;
33 @property (retain, nonatomic) NSStatusItem* item;
34 @property (assign, nonatomic) WineEventQueue* queue;
39 @implementation WineStatusItem
41 @synthesize item, queue;
43 - (id) initWithEventQueue:(WineEventQueue*)inQueue
48 NSStatusBar* statusBar = [NSStatusBar systemStatusBar];
49 item = [[statusBar statusItemWithLength:NSSquareStatusItemLength] retain];
50 [item setTarget:self];
51 [item setAction:@selector(clicked:)];
52 [item setDoubleAction:@selector(doubleClicked:)];
63 NSStatusBar* statusBar = [NSStatusBar systemStatusBar];
64 [statusBar removeStatusItem:item];
70 - (void) removeFromStatusBar
74 NSStatusBar* statusBar = [NSStatusBar systemStatusBar];
75 [statusBar removeStatusItem:item];
80 - (void) postClickedEventWithCount:(int)count
83 event.type = STATUS_ITEM_CLICKED;
85 event.status_item_clicked.item = (macdrv_status_item)self;
86 event.status_item_clicked.count = count;
87 [queue postEvent:&event];
90 - (void) clicked:(id)sender
92 [self postClickedEventWithCount:1];
95 - (void) doubleClicked:(id)sender
97 [self postClickedEventWithCount:2];
103 /***********************************************************************
104 * macdrv_create_status_item
106 * Creates a new status item in the status bar.
108 macdrv_status_item macdrv_create_status_item(macdrv_event_queue q)
110 WineEventQueue* queue = (WineEventQueue*)q;
111 __block WineStatusItem* statusItem;
114 statusItem = [[WineStatusItem alloc] initWithEventQueue:queue];
117 return (macdrv_status_item)statusItem;
120 /***********************************************************************
121 * macdrv_destroy_status_item
123 * Removes a status item previously returned by
124 * macdrv_create_status_item() from the status bar and destroys it.
126 void macdrv_destroy_status_item(macdrv_status_item s)
128 WineStatusItem* statusItem = (WineStatusItem*)s;
131 [statusItem removeFromStatusBar];
132 [statusItem release];
136 /***********************************************************************
137 * macdrv_set_status_item_image
139 * Sets the image for a status item. If cgimage is NULL, clears the
140 * image of the status item (leaving it a blank spot on the menu bar).
142 void macdrv_set_status_item_image(macdrv_status_item s, CGImageRef cgimage)
144 WineStatusItem* statusItem = (WineStatusItem*)s;
146 CGImageRetain(cgimage);
149 NSImage* image = nil;
152 image = [[NSImage alloc] initWithCGImage:cgimage size:NSZeroSize];
153 CGImageRelease(cgimage);
155 [statusItem.item setImage:image];
160 /***********************************************************************
161 * macdrv_set_status_item_tooltip
163 * Sets the tooltip string for a status item. If cftip is NULL, clears
164 * the tooltip string for the status item.
166 void macdrv_set_status_item_tooltip(macdrv_status_item s, CFStringRef cftip)
168 WineStatusItem* statusItem = (WineStatusItem*)s;
169 NSString* tip = (NSString*)cftip;
171 if (![tip length]) tip = nil;
173 [statusItem.item setToolTip:tip];