src/macosx/native/sun/osxapp/NSApplicationAWT.m

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #import "NSApplicationAWT.h"
  27 
  28 #import <objc/runtime.h>
  29 #import <JavaRuntimeSupport/JavaRuntimeSupport.h>
  30 
  31 #import "PropertiesUtilities.h"
  32 #import "ThreadUtilities.h"
  33 #import "QueuingApplicationDelegate.h"

  34 
  35 
  36 static BOOL sUsingDefaultNIB = YES;
  37 static NSString *SHARED_FRAMEWORK_BUNDLE = @"/System/Library/Frameworks/JavaVM.framework";
  38 static id <NSApplicationDelegate> applicationDelegate = nil;
  39 static QueuingApplicationDelegate * qad = nil;
  40 
  41 // Flag used to indicate to the Plugin2 event synthesis code to do a postEvent instead of sendEvent
  42 BOOL postEventDuringEventSynthesis = NO;
  43 
  44 @implementation NSApplicationAWT
  45 
  46 - (id) init
  47 {
  48     // Headless: NO
  49     // Embedded: NO
  50     // Multiple Calls: NO
  51     //  Caller: +[NSApplication sharedApplication]
  52 
  53 AWT_ASSERT_APPKIT_THREAD;


 238     }];
 239 // HACK END
 240 }
 241 
 242 - (void) setDockIconWithEnv:(JNIEnv *)env {
 243     NSString *theIconPath = nil;
 244 
 245     // The following environment variable is set in java.c. It is probably UTF8.
 246     char envVar[80];
 247     snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
 248     char *appIcon = getenv(envVar);
 249     if (appIcon != NULL) {
 250         theIconPath = [NSString stringWithUTF8String:appIcon];
 251         unsetenv(envVar);
 252     }
 253 
 254     if (theIconPath == nil) {
 255         theIconPath = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.icon" withEnv:env];
 256     }
 257 
 258     // If the icon file wasn't specified as an argument and we need to get an icon
 259     // we'll use the generic java app icon.
 260     NSString *defaultIconPath = [NSString stringWithFormat:@"%@%@", SHARED_FRAMEWORK_BUNDLE, @"/Resources/GenericApp.icns"];
 261     if (theIconPath == nil) {
 262         NSString* bundleIcon = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"];
 263         if (bundleIcon == nil) {
 264             theIconPath = defaultIconPath;
 265         }
 266     }
 267 
 268     // Set up the dock icon if we have an icon name.
 269     if (theIconPath != nil) {
 270         NSImage *iconImage = [[NSImage alloc] initWithContentsOfFile:theIconPath];

 271 
 272         // If we failed for some reason fall back to the default icon.

 273         if (iconImage == nil) {
 274             iconImage = [[NSImage alloc] initWithContentsOfFile:defaultIconPath];






 275         }
 276 


 277         [NSApp setApplicationIconImage:iconImage];
 278         [iconImage release];
 279     }
 280 }
 281 
 282 + (void) runAWTLoopWithApp:(NSApplication*)app {
 283     NSAutoreleasePool *pool = [NSAutoreleasePool new];
 284 
 285     // Make sure that when we run in AWTRunLoopMode we don't exit randomly
 286     [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:[JNFRunLoop javaRunLoopMode]];
 287 
 288     do {
 289         @try {
 290             [app run];
 291         } @catch (NSException* e) {
 292             NSLog(@"Apple AWT Startup Exception: %@", [e description]);
 293             NSLog(@"Apple AWT Restarting Native Event Thread");
 294 
 295             [app stop:app];
 296         }




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #import "NSApplicationAWT.h"
  27 
  28 #import <objc/runtime.h>
  29 #import <JavaRuntimeSupport/JavaRuntimeSupport.h>
  30 
  31 #import "PropertiesUtilities.h"
  32 #import "ThreadUtilities.h"
  33 #import "QueuingApplicationDelegate.h"
  34 #import "AWTIconData.h"
  35 
  36 
  37 static BOOL sUsingDefaultNIB = YES;
  38 static NSString *SHARED_FRAMEWORK_BUNDLE = @"/System/Library/Frameworks/JavaVM.framework";
  39 static id <NSApplicationDelegate> applicationDelegate = nil;
  40 static QueuingApplicationDelegate * qad = nil;
  41 
  42 // Flag used to indicate to the Plugin2 event synthesis code to do a postEvent instead of sendEvent
  43 BOOL postEventDuringEventSynthesis = NO;
  44 
  45 @implementation NSApplicationAWT
  46 
  47 - (id) init
  48 {
  49     // Headless: NO
  50     // Embedded: NO
  51     // Multiple Calls: NO
  52     //  Caller: +[NSApplication sharedApplication]
  53 
  54 AWT_ASSERT_APPKIT_THREAD;


 239     }];
 240 // HACK END
 241 }
 242 
 243 - (void) setDockIconWithEnv:(JNIEnv *)env {
 244     NSString *theIconPath = nil;
 245 
 246     // The following environment variable is set in java.c. It is probably UTF8.
 247     char envVar[80];
 248     snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
 249     char *appIcon = getenv(envVar);
 250     if (appIcon != NULL) {
 251         theIconPath = [NSString stringWithUTF8String:appIcon];
 252         unsetenv(envVar);
 253     }
 254 
 255     if (theIconPath == nil) {
 256         theIconPath = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.icon" withEnv:env];
 257     }
 258 
 259     // Use the path specified to get the icon image
 260     NSImage* iconImage = nil;









 261     if (theIconPath != nil) {
 262         iconImage = [[NSImage alloc] initWithContentsOfFile:theIconPath];
 263     } 
 264 
 265     // If no icon file was specified or we failed to get the icon image
 266     // and we need to get an icon, then use the default icon
 267     if (iconImage == nil) {
 268         NSString* bundleIcon = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"];
 269         if (bundleIcon == nil) {
 270             NSData* iconData;
 271             iconData = [[NSData alloc] initWithBytesNoCopy: sAWTIconData length: sizeof(sAWTIconData) freeWhenDone: NO];
 272             iconImage = [[NSImage alloc] initWithData: iconData];
 273             [iconData release];
 274         }
 275     }
 276 
 277     // Set up the dock icon if we have an icon image.
 278     if (iconImage != nil) {
 279         [NSApp setApplicationIconImage:iconImage];
 280         [iconImage release];
 281     }
 282 }
 283 
 284 + (void) runAWTLoopWithApp:(NSApplication*)app {
 285     NSAutoreleasePool *pool = [NSAutoreleasePool new];
 286 
 287     // Make sure that when we run in AWTRunLoopMode we don't exit randomly
 288     [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:[JNFRunLoop javaRunLoopMode]];
 289 
 290     do {
 291         @try {
 292             [app run];
 293         } @catch (NSException* e) {
 294             NSLog(@"Apple AWT Startup Exception: %@", [e description]);
 295             NSLog(@"Apple AWT Restarting Native Event Thread");
 296 
 297             [app stop:app];
 298         }