143 NSMenu *appMenu = [appMenuItem submenu];
144 itemCount = [appMenu numberOfItems];
145
146 for (i = 0; i < itemCount; i++) {
147 NSMenuItem *anItem = [appMenu itemAtIndex:i];
148 NSString *oldTitle = [anItem title];
149 [anItem setTitle:[NSString stringWithFormat:oldTitle, fApplicationName]];
150 }
151 }
152
153 if (applicationDelegate) {
154 [self setDelegate:applicationDelegate];
155 } else {
156 qad = [QueuingApplicationDelegate sharedDelegate];
157 [self setDelegate:qad];
158 }
159
160 [super finishLaunching];
161
162 [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
163
164 // inform any interested parties that the AWT has arrived and is pumping
165 [[NSNotificationCenter defaultCenter] postNotificationName:JNFRunLoopDidStartNotification object:self];
166 }
167
168 - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
169 shouldPresentNotification:(NSUserNotification *)notification
170 {
171 return YES; // We always show notifications to the user
172 }
173
174 - (void) registerWithProcessManager
175 {
176 // Headless: NO
177 // Embedded: NO
178 // Multiple Calls: NO
179 // Caller: -[NSApplicationAWT init]
180
181 AWT_ASSERT_APPKIT_THREAD;
182 JNIEnv *env = [ThreadUtilities getJNIEnv];
183
184 char envVar[80];
185
254
255 NSString *backgroundOnlyProp = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.BackgroundOnly" withEnv:env];
256 if ([@"true" isCaseInsensitiveLike:backgroundOnlyProp]) {
257 [registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsBackgroundOnlyKey"];
258 }
259
260 // TODO replace with direct call
261 // [JRSAppKitAWT registerAWTAppWithOptions:registrationOptions];
262 // and remove below transform/activate/run hack
263
264 id jrsAppKitAWTClass = objc_getClass("JRSAppKitAWT");
265 SEL registerSel = @selector(registerAWTAppWithOptions:);
266 if ([jrsAppKitAWTClass respondsToSelector:registerSel]) {
267 [jrsAppKitAWTClass performSelector:registerSel withObject:registrationOptions];
268 return;
269 }
270
271 // HACK BEGIN
272 // The following is necessary to make the java process behave like a
273 // proper foreground application...
274 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
275 ProcessSerialNumber psn;
276 GetCurrentProcess(&psn);
277 TransformProcessType(&psn, kProcessTransformToForegroundApplication);
278
279 [NSApp activateIgnoringOtherApps:YES];
280 [NSApp run];
281 }];
282 // HACK END
283 }
284
285 - (void) setDockIconWithEnv:(JNIEnv *)env {
286 NSString *theIconPath = nil;
287
288 // The following environment variable is set in java.c. It is probably UTF8.
289 char envVar[80];
290 snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
291 char *appIcon = getenv(envVar);
292 if (appIcon != NULL) {
293 theIconPath = [NSString stringWithUTF8String:appIcon];
294 unsetenv(envVar);
309 if (iconImage == nil) {
310 NSString* bundleIcon = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"];
311 if (bundleIcon == nil) {
312 NSData* iconData;
313 iconData = [[NSData alloc] initWithBytesNoCopy: sAWTIconData length: sizeof(sAWTIconData) freeWhenDone: NO];
314 iconImage = [[NSImage alloc] initWithData: iconData];
315 [iconData release];
316 }
317 }
318
319 // Set up the dock icon if we have an icon image.
320 if (iconImage != nil) {
321 [NSApp setApplicationIconImage:iconImage];
322 [iconImage release];
323 }
324 }
325
326 + (void) runAWTLoopWithApp:(NSApplication*)app {
327 NSAutoreleasePool *pool = [NSAutoreleasePool new];
328
329 // Make sure that when we run in AWTRunLoopMode we don't exit randomly
330 [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:[JNFRunLoop javaRunLoopMode]];
331
332 do {
333 @try {
334 [app run];
335 } @catch (NSException* e) {
336 NSLog(@"Apple AWT Startup Exception: %@", [e description]);
337 NSLog(@"Apple AWT Startup Exception callstack: %@", [e callStackSymbols]);
338 NSLog(@"Apple AWT Restarting Native Event Thread");
339
340 [app stop:app];
341 }
342 } while (YES);
343
344 [pool drain];
345 }
346
347 - (BOOL)usingDefaultNib {
348 return sUsingDefaultNIB;
349 }
350
|
143 NSMenu *appMenu = [appMenuItem submenu];
144 itemCount = [appMenu numberOfItems];
145
146 for (i = 0; i < itemCount; i++) {
147 NSMenuItem *anItem = [appMenu itemAtIndex:i];
148 NSString *oldTitle = [anItem title];
149 [anItem setTitle:[NSString stringWithFormat:oldTitle, fApplicationName]];
150 }
151 }
152
153 if (applicationDelegate) {
154 [self setDelegate:applicationDelegate];
155 } else {
156 qad = [QueuingApplicationDelegate sharedDelegate];
157 [self setDelegate:qad];
158 }
159
160 [super finishLaunching];
161
162 [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
163 }
164
165 - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
166 shouldPresentNotification:(NSUserNotification *)notification
167 {
168 return YES; // We always show notifications to the user
169 }
170
171 - (void) registerWithProcessManager
172 {
173 // Headless: NO
174 // Embedded: NO
175 // Multiple Calls: NO
176 // Caller: -[NSApplicationAWT init]
177
178 AWT_ASSERT_APPKIT_THREAD;
179 JNIEnv *env = [ThreadUtilities getJNIEnv];
180
181 char envVar[80];
182
251
252 NSString *backgroundOnlyProp = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.BackgroundOnly" withEnv:env];
253 if ([@"true" isCaseInsensitiveLike:backgroundOnlyProp]) {
254 [registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsBackgroundOnlyKey"];
255 }
256
257 // TODO replace with direct call
258 // [JRSAppKitAWT registerAWTAppWithOptions:registrationOptions];
259 // and remove below transform/activate/run hack
260
261 id jrsAppKitAWTClass = objc_getClass("JRSAppKitAWT");
262 SEL registerSel = @selector(registerAWTAppWithOptions:);
263 if ([jrsAppKitAWTClass respondsToSelector:registerSel]) {
264 [jrsAppKitAWTClass performSelector:registerSel withObject:registrationOptions];
265 return;
266 }
267
268 // HACK BEGIN
269 // The following is necessary to make the java process behave like a
270 // proper foreground application...
271 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
272 ProcessSerialNumber psn;
273 GetCurrentProcess(&psn);
274 TransformProcessType(&psn, kProcessTransformToForegroundApplication);
275
276 [NSApp activateIgnoringOtherApps:YES];
277 [NSApp run];
278 }];
279 // HACK END
280 }
281
282 - (void) setDockIconWithEnv:(JNIEnv *)env {
283 NSString *theIconPath = nil;
284
285 // The following environment variable is set in java.c. It is probably UTF8.
286 char envVar[80];
287 snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
288 char *appIcon = getenv(envVar);
289 if (appIcon != NULL) {
290 theIconPath = [NSString stringWithUTF8String:appIcon];
291 unsetenv(envVar);
306 if (iconImage == nil) {
307 NSString* bundleIcon = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"];
308 if (bundleIcon == nil) {
309 NSData* iconData;
310 iconData = [[NSData alloc] initWithBytesNoCopy: sAWTIconData length: sizeof(sAWTIconData) freeWhenDone: NO];
311 iconImage = [[NSImage alloc] initWithData: iconData];
312 [iconData release];
313 }
314 }
315
316 // Set up the dock icon if we have an icon image.
317 if (iconImage != nil) {
318 [NSApp setApplicationIconImage:iconImage];
319 [iconImage release];
320 }
321 }
322
323 + (void) runAWTLoopWithApp:(NSApplication*)app {
324 NSAutoreleasePool *pool = [NSAutoreleasePool new];
325
326 // Make sure that when we run in javaRunLoopMode we don't exit randomly
327 [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:[ThreadUtilities javaRunLoopMode]];
328
329 do {
330 @try {
331 [app run];
332 } @catch (NSException* e) {
333 NSLog(@"Apple AWT Startup Exception: %@", [e description]);
334 NSLog(@"Apple AWT Startup Exception callstack: %@", [e callStackSymbols]);
335 NSLog(@"Apple AWT Restarting Native Event Thread");
336
337 [app stop:app];
338 }
339 } while (YES);
340
341 [pool drain];
342 }
343
344 - (BOOL)usingDefaultNib {
345 return sUsingDefaultNIB;
346 }
347
|