2 * MACDRV Cocoa application 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
27 @implementation WineApplication
34 eventQueues = [[NSMutableArray alloc] init];
35 eventQueuesLock = [[NSLock alloc] init];
37 if (!eventQueues || !eventQueuesLock)
48 [eventQueues release];
49 [eventQueuesLock release];
53 - (void) transformProcessToForeground
55 if ([self activationPolicy] != NSApplicationActivationPolicyRegular)
63 [self setActivationPolicy:NSApplicationActivationPolicyRegular];
64 [self activateIgnoringOtherApps:YES];
66 mainMenu = [[[NSMenu alloc] init] autorelease];
68 submenu = [[[NSMenu alloc] initWithTitle:@"Wine"] autorelease];
69 bundleName = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleNameKey];
70 if ([bundleName length])
71 title = [NSString stringWithFormat:@"Quit %@", bundleName];
74 item = [submenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
75 [item setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
76 item = [[[NSMenuItem alloc] init] autorelease];
77 [item setTitle:@"Wine"];
78 [item setSubmenu:submenu];
79 [mainMenu addItem:item];
81 submenu = [[[NSMenu alloc] initWithTitle:@"Window"] autorelease];
82 [submenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@""];
83 [submenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
84 [submenu addItem:[NSMenuItem separatorItem]];
85 [submenu addItemWithTitle:@"Bring All to Front" action:@selector(arrangeInFront:) keyEquivalent:@""];
86 item = [[[NSMenuItem alloc] init] autorelease];
87 [item setTitle:@"Window"];
88 [item setSubmenu:submenu];
89 [mainMenu addItem:item];
91 [self setMainMenu:mainMenu];
92 [self setWindowsMenu:submenu];
96 - (BOOL) registerEventQueue:(WineEventQueue*)queue
98 [eventQueuesLock lock];
99 [eventQueues addObject:queue];
100 [eventQueuesLock unlock];
104 - (void) unregisterEventQueue:(WineEventQueue*)queue
106 [eventQueuesLock lock];
107 [eventQueues removeObjectIdenticalTo:queue];
108 [eventQueuesLock unlock];
113 /***********************************************************************
116 * Run a block on the main thread synchronously.
118 void OnMainThread(dispatch_block_t block)
120 dispatch_sync(dispatch_get_main_queue(), block);
123 /***********************************************************************
126 * Run a block on the main thread asynchronously.
128 void OnMainThreadAsync(dispatch_block_t block)
130 dispatch_async(dispatch_get_main_queue(), block);
133 /***********************************************************************
136 void LogError(const char* func, NSString* format, ...)
139 va_start(args, format);
140 LogErrorv(func, format, args);
144 /***********************************************************************
147 void LogErrorv(const char* func, NSString* format, va_list args)
149 NSString* message = [[NSString alloc] initWithFormat:format arguments:args];
150 fprintf(stderr, "err:%s:%s", func, [message UTF8String]);