Commit 9714e6ee authored by Ken Thomases's avatar Ken Thomases Committed by Alexandre Julliard

winemac: Implement rudimentary support for system tray icons as Mac status items.

parent b1de5323
......@@ -16,6 +16,7 @@ C_SRCS = \
opengl.c \
scroll.c \
surface.c \
systray.c \
window.c
OBJC_SRCS = \
......@@ -25,6 +26,7 @@ OBJC_SRCS = \
cocoa_event.m \
cocoa_main.m \
cocoa_opengl.m \
cocoa_status_item.m \
cocoa_window.m
@MAKE_DLL_RULES@
/*
* MACDRV Cocoa status item class
*
* Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#import <Cocoa/Cocoa.h>
#include "macdrv_cocoa.h"
#import "cocoa_app.h"
#import "cocoa_event.h"
@interface WineStatusItem : NSObject
{
NSStatusItem* item;
WineEventQueue* queue;
}
@property (retain, nonatomic) NSStatusItem* item;
@property (assign, nonatomic) WineEventQueue* queue;
@end
@implementation WineStatusItem
@synthesize item, queue;
- (id) initWithEventQueue:(WineEventQueue*)inQueue
{
self = [super init];
if (self)
{
NSStatusBar* statusBar = [NSStatusBar systemStatusBar];
item = [[statusBar statusItemWithLength:NSSquareStatusItemLength] retain];
[item setTarget:self];
[item setAction:@selector(clicked:)];
[item setDoubleAction:@selector(doubleClicked:)];
queue = inQueue;
}
return self;
}
- (void) dealloc
{
if (item)
{
NSStatusBar* statusBar = [NSStatusBar systemStatusBar];
[statusBar removeStatusItem:item];
[item release];
}
[super dealloc];
}
- (void) removeFromStatusBar
{
if (item)
{
NSStatusBar* statusBar = [NSStatusBar systemStatusBar];
[statusBar removeStatusItem:item];
self.item = nil;
}
}
- (void) postClickedEventWithCount:(int)count
{
macdrv_event event;
event.type = STATUS_ITEM_CLICKED;
event.window = NULL;
event.status_item_clicked.item = (macdrv_status_item)self;
event.status_item_clicked.count = count;
[queue postEvent:&event];
}
- (void) clicked:(id)sender
{
[self postClickedEventWithCount:1];
}
- (void) doubleClicked:(id)sender
{
[self postClickedEventWithCount:2];
}
@end
/***********************************************************************
* macdrv_create_status_item
*
* Creates a new status item in the status bar.
*/
macdrv_status_item macdrv_create_status_item(macdrv_event_queue q)
{
WineEventQueue* queue = (WineEventQueue*)q;
__block WineStatusItem* statusItem;
OnMainThread(^{
statusItem = [[WineStatusItem alloc] initWithEventQueue:queue];
});
return (macdrv_status_item)statusItem;
}
/***********************************************************************
* macdrv_destroy_status_item
*
* Removes a status item previously returned by
* macdrv_create_status_item() from the status bar and destroys it.
*/
void macdrv_destroy_status_item(macdrv_status_item s)
{
WineStatusItem* statusItem = (WineStatusItem*)s;
OnMainThreadAsync(^{
[statusItem removeFromStatusBar];
[statusItem release];
});
}
/***********************************************************************
* macdrv_set_status_item_image
*
* Sets the image for a status item. If cgimage is NULL, clears the
* image of the status item (leaving it a blank spot on the menu bar).
*/
void macdrv_set_status_item_image(macdrv_status_item s, CGImageRef cgimage)
{
WineStatusItem* statusItem = (WineStatusItem*)s;
CGImageRetain(cgimage);
OnMainThreadAsync(^{
NSImage* image = nil;
if (cgimage)
{
image = [[NSImage alloc] initWithCGImage:cgimage size:NSZeroSize];
CGImageRelease(cgimage);
}
[statusItem.item setImage:image];
[image release];
});
}
/***********************************************************************
* macdrv_set_status_item_tooltip
*
* Sets the tooltip string for a status item. If cftip is NULL, clears
* the tooltip string for the status item.
*/
void macdrv_set_status_item_tooltip(macdrv_status_item s, CFStringRef cftip)
{
WineStatusItem* statusItem = (WineStatusItem*)s;
NSString* tip = (NSString*)cftip;
if (![tip length]) tip = nil;
OnMainThreadAsync(^{
[statusItem.item setToolTip:tip];
});
}
......@@ -42,6 +42,7 @@ static const char *dbgstr_event(int type)
"MOUSE_MOVED_ABSOLUTE",
"MOUSE_SCROLL",
"QUERY_EVENT",
"STATUS_ITEM_CLICKED",
"WINDOW_CLOSE_REQUESTED",
"WINDOW_DID_MINIMIZE",
"WINDOW_DID_UNMINIMIZE",
......@@ -87,6 +88,7 @@ static macdrv_event_mask get_event_mask(DWORD mask)
{
event_mask |= event_mask_for_type(APP_DEACTIVATED);
event_mask |= event_mask_for_type(DISPLAYS_CHANGED);
event_mask |= event_mask_for_type(STATUS_ITEM_CLICKED);
event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
event_mask |= event_mask_for_type(WINDOW_DID_MINIMIZE);
event_mask |= event_mask_for_type(WINDOW_DID_UNMINIMIZE);
......@@ -186,6 +188,9 @@ void macdrv_handle_event(macdrv_event *event)
case QUERY_EVENT:
macdrv_query_event(hwnd, event);
break;
case STATUS_ITEM_CLICKED:
macdrv_status_item_clicked(event);
break;
case WINDOW_CLOSE_REQUESTED:
macdrv_window_close_requested(hwnd);
break;
......
......@@ -181,7 +181,7 @@ CGImageRef create_cgimage_from_icon_bitmaps(HDC hdc, HANDLE icon, HBITMAP hbmCol
*
* Create a CGImage from a Windows icon.
*/
static CGImageRef create_cgimage_from_icon(HANDLE icon, int width, int height)
CGImageRef create_cgimage_from_icon(HANDLE icon, int width, int height)
{
CGImageRef ret = NULL;
HDC hdc;
......
......@@ -177,6 +177,9 @@ extern CGImageRef create_cgimage_from_icon_bitmaps(HDC hdc, HANDLE icon, HBITMAP
unsigned char *color_bits, int color_size, HBITMAP hbmMask,
unsigned char *mask_bits, int mask_size, int width,
int height, int istep) DECLSPEC_HIDDEN;
extern CGImageRef create_cgimage_from_icon(HANDLE icon, int width, int height) DECLSPEC_HIDDEN;
extern CFArrayRef create_app_icon_images(void) DECLSPEC_HIDDEN;
extern void macdrv_status_item_clicked(const macdrv_event *event) DECLSPEC_HIDDEN;
#endif /* __WINE_MACDRV_H */
......@@ -116,6 +116,7 @@ typedef struct macdrv_opaque_window* macdrv_window;
typedef struct macdrv_opaque_event_queue* macdrv_event_queue;
typedef struct macdrv_opaque_view* macdrv_view;
typedef struct macdrv_opaque_opengl_context* macdrv_opengl_context;
typedef struct macdrv_opaque_status_item* macdrv_status_item;
struct macdrv_event;
struct macdrv_query;
......@@ -161,6 +162,7 @@ enum {
MOUSE_MOVED_ABSOLUTE,
MOUSE_SCROLL,
QUERY_EVENT,
STATUS_ITEM_CLICKED,
WINDOW_CLOSE_REQUESTED,
WINDOW_DID_MINIMIZE,
WINDOW_DID_UNMINIMIZE,
......@@ -212,6 +214,10 @@ typedef struct macdrv_event {
struct macdrv_query *query;
} query_event;
struct {
macdrv_status_item item;
int count;
} status_item_clicked;
struct {
CGRect frame;
} window_frame_changed;
struct {
......@@ -348,4 +354,11 @@ extern void macdrv_make_context_current(macdrv_opengl_context c, macdrv_view v)
extern void macdrv_update_opengl_context(macdrv_opengl_context c) DECLSPEC_HIDDEN;
extern void macdrv_flush_opengl_context(macdrv_opengl_context c) DECLSPEC_HIDDEN;
/* systray / status item */
extern macdrv_status_item macdrv_create_status_item(macdrv_event_queue q) DECLSPEC_HIDDEN;
extern void macdrv_destroy_status_item(macdrv_status_item s) DECLSPEC_HIDDEN;
extern void macdrv_set_status_item_image(macdrv_status_item s, CGImageRef cgimage) DECLSPEC_HIDDEN;
extern void macdrv_set_status_item_tooltip(macdrv_status_item s, CFStringRef cftip) DECLSPEC_HIDDEN;
#endif /* __WINE_MACDRV_COCOA_H */
......@@ -46,3 +46,6 @@
@ cdecl WindowMessage(long long long long) macdrv_WindowMessage
@ cdecl WindowPosChanged(long long long ptr ptr ptr ptr ptr) macdrv_WindowPosChanged
@ cdecl WindowPosChanging(long long long ptr ptr ptr ptr) macdrv_WindowPosChanging
# System tray
@ cdecl wine_notify_icon(long ptr)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment