ApplicationDelegate.m revision 4632
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#import "ApplicationDelegate.h"
#import "com_apple_eawt_Application.h"
#import "com_apple_eawt__AppDockIconHandler.h"
#import "com_apple_eawt__AppEventHandler.h"
#import "com_apple_eawt__AppMenuBarHandler.h"
#import "com_apple_eawt__AppMenuBarHandler.h"
#import "com_apple_eawt__AppMiscHandlers.h"
#import "CPopupMenu.h"
#import "ThreadUtilities.h"
#import "NSApplicationAWT.h"
// The following is a AWT convention?
}
}
@interface NSBundle (EAWTOverrides)
@end
return [[[[self objectForInfoDictionaryKey:@"Java"] objectForKey:@"EAWTOverride"] objectForKey:key] boolValue];
}
@end
// used by JavaRuntimeSupport.framework's [JRSAppKitAWT awtAppDelegate]
// to expose our app delegate to the SWT or other apps that have knoledge
// of Java's AWT and want to install their own app delegate that will delegate
// to the AWT for some operations
@interface JavaAWTAppDelegateLoader : NSObject { }
@end
+ (ApplicationDelegate *) awtAppDelegate {
return [ApplicationDelegate sharedDelegate];
}
@end
// don't install the EAWT delegate if another kind of NSApplication is installed, like say, Safari
}
if (!shouldInstall) return nil;
return sApplicationDelegate;
}
if (prefsAvailable) {
// Make sure Prefs is around
// Position of Prefs depends upon About availability.
}
if (prefsEnabled) {
} else {
}
} else {
// Remove the preferences item
}
}
if (aboutAvailable) {
// Make sure About is around
}
if (aboutEnabled) {
} else {
}
} else {
// Remove About item.
}
}
// Prep for about and preferences menu
}
if (!usingDefaultNib) return self;
// If the java application has a bundle with an Info.plist file with
// a CFBundleDocumentTypes entry, then it is set up to handle Open Doc
// and Print Doc commands for these files. Therefore java AWT will
// cache Open Doc and Print Doc events that are sent prior to a
// listener being installed by the client java application.
fHandlesDocumentTypes = [bundle objectForInfoDictionaryKey:@"CFBundleDocumentTypes"] != nil || [bundle _hasEAWTOverride:@"DocumentHandler"];
fHandlesURLTypes = [bundle objectForInfoDictionaryKey:@"CFBundleURLTypes"] != nil || [bundle _hasEAWTOverride:@"URLHandler"];
if (fHandlesURLTypes) {
}
// By HIG, Preferences are not available unless there is a handler. By default in Mac OS X,
// there is not a handler, but it is in the nib file for convenience.
// Now that the AppKit objects are known and set up, initialize the model data
BOOL aboutEnabled = (aboutAvailable && [self.fAboutMenu isEnabled] && ([self.fAboutMenu target] != nil));
BOOL prefsEnabled = (prefsAvailable && [self.fPreferencesMenu isEnabled] && ([self.fPreferencesMenu target] != nil));
static JNF_STATIC_MEMBER_CACHE(sjm_initMenuStates, sjc_AppMenuBarHandler, "initMenuStates", "(ZZZZ)V");
JNFCallStaticVoidMethod(env, sjm_initMenuStates, aboutAvailable, aboutEnabled, prefsAvailable, prefsEnabled);
// register for the finish launching and system power off notifications by default
[ctr addObserver:clz selector:@selector(_willFinishLaunching) name:NSApplicationWillFinishLaunchingNotification object:nil];
[ctr addObserver:clz selector:@selector(_systemWillPowerOff) name:NSWorkspaceWillPowerOffNotification object:nil];
[ctr addObserver:clz selector:@selector(_appDidActivate) name:NSApplicationDidBecomeActiveNotification object:nil];
[ctr addObserver:clz selector:@selector(_appDidDeactivate) name:NSApplicationDidResignActiveNotification object:nil];
[ctr addObserver:clz selector:@selector(_appDidHide) name:NSApplicationDidHideNotification object:nil];
[ctr addObserver:clz selector:@selector(_appDidUnhide) name:NSApplicationDidUnhideNotification object:nil];
return self;
}
- (void)dealloc {
[super dealloc];
}
//- (void)finalize { [super finalize]; } // GC
- (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
if (!fHandlesURLTypes) return;
//fprintf(stderr,"jm_handleOpenURL\n");
static JNF_STATIC_MEMBER_CACHE(jm_handleOpenURI, sjc_AppEventHandler, "handleOpenURI", "(Ljava/lang/String;)V");
}
// Helper for both open file and print file methods
// Creates a Java list of files from a native list of files
jobject jFileNamesArray = JNFNewObject(env, jm_ArrayList_ctor, (jint)[filenames count]); // AWT_THREADING Safe (known object)
}
return jFileNamesArray;
}
// Open file handler
if (!fHandlesDocumentTypes) {
return;
}
//fprintf(stderr,"jm_handleOpenFile\n");
// if these files were opened from a Spotlight query, try to get the search text from the current AppleEvent
NSAppleEventDescriptor *currentEvent = [[NSAppleEventManager sharedAppleEventManager] currentAppleEvent];
// convert the file names array
static JNF_STATIC_MEMBER_CACHE(jm_handleOpenFiles, sjc_AppEventHandler, "handleOpenFiles", "(Ljava/util/List;Ljava/lang/String;)V");
}
// Print handler
- (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(NSArray *)fileNames withSettings:(NSDictionary *)printSettings showPrintPanels:(BOOL)showPrintPanels {
if (!fHandlesDocumentTypes) return NSPrintingCancelled;
//fprintf(stderr,"jm_handlePrintFile\n");
static JNF_STATIC_MEMBER_CACHE(jm_handlePrintFile, sjc_AppEventHandler, "handlePrintFiles", "(Ljava/util/List;)V");
return NSPrintingSuccess;
}
// Open app handler, registered in -init
//fprintf(stderr,"jm_handleOpenApplication\n");
static JNF_STATIC_MEMBER_CACHE(jm_handleNativeNotification, sjc_AppEventHandler, "handleNativeNotification", "(I)V");
JNFCallStaticVoidMethod(env, jm_handleNativeNotification, notificationType); // AWT_THREADING Safe (event)
}
// About menu handler
- (void)_aboutMenuHandler {
}
// Preferences handler
- (void)_preferencesMenuHandler {
}
// Open app handler, registered in -init
+ (void)_willFinishLaunching {
}
// ReOpen app handler
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {
return YES;
}
// Quit handler
return NSTerminateLater;
}
+ (void)_systemWillPowerOff {
}
+ (void)_appDidActivate {
}
+ (void)_appDidDeactivate {
}
+ (void)_appDidHide {
}
+ (void)_appDidUnhide {
}
+ (void)_sessionDidActivate {
}
+ (void)_sessionDidDeactivate {
}
+ (void)_screenDidSleep {
}
+ (void)_screenDidWake {
}
+ (void)_systemDidSleep {
}
+ (void)_systemDidWake {
}
switch (notificationType) {
[ctr addObserver:clz selector:@selector(_sessionDidActivate) name:NSWorkspaceSessionDidBecomeActiveNotification object:nil];
[ctr addObserver:clz selector:@selector(_sessionDidDeactivate) name:NSWorkspaceSessionDidResignActiveNotification object:nil];
break;
[ctr addObserver:clz selector:@selector(_screenDidSleep) name:NSWorkspaceScreensDidSleepNotification object:nil];
[ctr addObserver:clz selector:@selector(_screenDidWake) name:NSWorkspaceScreensDidWakeNotification object:nil];
break;
[ctr addObserver:clz selector:@selector(_systemDidSleep) name:NSWorkspaceWillSleepNotification object:nil];
[ctr addObserver:clz selector:@selector(_systemDidWake) name:NSWorkspaceDidWakeNotification object:nil];
break;
default:
break;
}
}
// Retrieves the menu to be attached to the Dock icon (AppKit callback)
}
- (CMenuBar *)defaultMenuBar {
}
// Sets a new NSImageView on the Dock tile
return;
}
// setup an image view for the dock tile
// add it to the NSDockTile
}
// Obtains the image of the Dock icon, either manually set, a drawn copy, or the default NSApplicationIcon
+ (NSImage *)_dockIconImage {
}
}
[image unlockFocus];
[image autorelease];
return image;
}
@end
/*
* Class: com_apple_eawt_Application
* Method: nativeInitializeApplicationDelegate
* Signature: ()V
*/
{
// Force initialization to happen on AppKit thread!
}];
}
/*
* Class: com_apple_eawt__AppEventHandler
* Method: nativeOpenCocoaAboutWindow
* Signature: ()V
*/
{
}];
}
/*
* Class: com_apple_eawt__AppEventHandler
* Method: nativeReplyToAppShouldTerminate
* Signature: (Z)V
*/
{
}];
}
/*
* Class: com_apple_eawt__AppEventHandler
* Method: nativeRegisterForNotification
* Signature: (I)V
*/
{
onObject:[ApplicationDelegate class]
}
/*
* Class: com_apple_eawt__AppDockIconHandler
* Method: nativeSetDockMenu
* Signature: (J)V
*/
{
}];
}
/*
* Class: com_apple_eawt__AppDockIconHandler
* Method: nativeSetDockIconImage
* Signature: (J)V
*/
{
on:[ApplicationDelegate class]
}
/*
* Class: com_apple_eawt__AppDockIconHandler
* Method: nativeGetDockIconImage
* Signature: ()J
*/
{
}];
return ptr_to_jlong(image);
}
/*
* Class: com_apple_eawt__AppDockIconHandler
* Method: nativeSetDockIconBadge
*/
{
}];
}
/*
* Class: com_apple_eawt__AppMiscHandlers
* Method: nativeRequestActivation
* Signature: (Z)V
*/
{
}];
}
/*
* Class: com_apple_eawt__AppMiscHandlers
* Method: nativeRequestUserAttention
* Signature: (Z)V
*/
{
}];
}
/*
* Class: com_apple_eawt__AppMiscHandlers
* Method: nativeOpenHelpViewer
* Signature: ()V
*/
{
}
/*
* Class: com_apple_eawt__AppMiscHandlers
* Method: nativeEnableSuddenTermination
* Signature: ()V
*/
{
}
/*
* Class: com_apple_eawt__AppMiscHandlers
* Method: nativeDisableSuddenTermination
* Signature: ()V
*/
{
}
/*
* Class: com_apple_eawt__AppMenuBarHandler
* Method: nativeSetMenuState
* Signature: (IZZ)V
*/
{
switch (menuID) {
break;
break;
}
}];
}
/*
* Class: com_apple_eawt__AppMenuBarHandler
* Method: nativeSetDefaultMenuBar
* Signature: (J)V
*/
{
}];
}