Index: Source/UIApplication.m =================================================================== --- Source/UIApplication.m (revision 33949) +++ Source/UIApplication.m (working copy) @@ -1,8 +1,8 @@ -/** NSApplication +/** UIApplication The one and only application class. - Copyright (C) 1996,1999 Free Software Foundation, Inc. + Copyright (C) 1996,1999,2011 Free Software Foundation, Inc. Author: Scott Christley Date: 1996 @@ -10,8 +10,10 @@ Date: August 1998 Author: Richard Frith-Macdonald Date: December 1998 + Author: Ivan Vucica + Date: November 2011 - This file is part of the GNUstep GUI Library. + This file is part of the GNUstep UIKit Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -60,314 +62,36 @@ #import #endif -#import "AppKit/AppKitExceptions.h" -#import "AppKit/NSAlert.h" -#import "AppKit/NSApplication.h" -#import "AppKit/NSCell.h" -#import "AppKit/NSCursor.h" -#import "AppKit/NSDocumentController.h" -#import "AppKit/NSEvent.h" -#import "AppKit/NSFontManager.h" -#import "AppKit/NSImage.h" -#import "AppKit/NSMenu.h" -#import "AppKit/NSMenuItem.h" -#import "AppKit/NSNibLoading.h" -#import "AppKit/NSPageLayout.h" -#import "AppKit/NSPanel.h" -#import "AppKit/NSPasteboard.h" -#import "AppKit/NSToolbarItem.h" -#import "AppKit/NSWorkspace.h" -#import "AppKit/NSScreen.h" -#import "AppKit/PSOperators.h" +#import "UIKit/UIApplication.h" -#import "GSIconManager.h" -#import "GNUstepGUI/GSDisplayServer.h" -#import "GNUstepGUI/GSServicesManager.h" -#import "GSGuiPrivate.h" -#import "GNUstepGUI/GSInfoPanel.h" -#import "GNUstepGUI/GSVersion.h" -#import "NSDocumentFrameworkPrivate.h" -#import "NSToolbarFrameworkPrivate.h" - -// minimize icon when suppressed? -#define MINI_ICON 0 - /* The -gui thread. See the comment in initialize_gnustep_backend. */ -NSThread *GSAppKitThread; +NSThread *GSUIKitThread; -/* Notifications used to implement hide and unhide functionality. */ -static NSString *GSHideOtherApplicationsNotification - = @"GSHideOtherApplicationsNotification"; -static NSString *GSUnhideAllApplicationsNotification - = @"GSUnhideAllApplicationsNotification"; - /* * Base library exception handler */ static NSUncaughtExceptionHandler *defaultUncaughtExceptionHandler; -/* - * Gui library user friendly exception handler - */ -static void -_NSAppKitUncaughtExceptionHandler (NSException *exception) -{ - int retVal; - /* Reset the exception handler to the Base library's one, to prevent - recursive calls to the gui one. */ - NSSetUncaughtExceptionHandler(defaultUncaughtExceptionHandler); - - /* - * If there is no graphics context to run the alert panel in or - * its a severe error, use a non-graphical exception handler - */ - if (GSCurrentContext() == nil - || [[exception name] isEqual: NSWindowServerCommunicationException] - || [[exception name] isEqual: GSWindowServerInternalException]) - { - /* The following will raise again the exception using the base - library exception handler */ - [exception raise]; - } - - retVal = GSRunExceptionPanel - ([NSString stringWithFormat: _(@"Critical Error in %@"), - [[NSProcessInfo processInfo] processName]], - exception, - _(@"Abort"), - nil, -#ifdef DEBUG - _(@"Debug")); -#else - nil); -#endif - - /* The user wants to abort */ - if (retVal == NSAlertDefault) - { - /* The following will raise again the exception using the base - library exception handler */ - [exception raise]; - } - else - { - /* Debug button: abort so we can trace the error in gdb */ - abort(); - } -} - /* Get the bundle. */ NSBundle * -GSGuiBundle(void) +GSUIKitBundle(void) { /* This is the bundle from where we load localization of messages. */ - static NSBundle *guiBundle = nil; + static NSBundle *uikitBundle = nil; - if (!guiBundle) + if (!uikitBundle) { /* Create the gui bundle we use to localize messages. */ - guiBundle = [NSBundle bundleForLibrary: @"gnustep-gui" - version: OBJC_STRINGIFY(GNUSTEP_GUI_MAJOR_VERSION.GNUSTEP_GUI_MINOR_VERSION)]; - RETAIN(guiBundle); + uikitBundle = [NSBundle bundleForLibrary: @"gnustep-uikit" + version: OBJC_STRINGIFY(GNUSTEP_UIKIT_MAJOR_VERSION.GNUSTEP_UIKIT_MINOR_VERSION)]; + RETAIN(uikitBundle); } - return guiBundle; + return uikitBundle; } -@interface GSBackend : NSObject -{} -+ (void) initializeBackend; -@end - -static NSString * -gnustep_backend_path(NSString *dir, NSString *name) -{ - NSString *path; - NSEnumerator *benum; - - NSDebugFLLog(@"BackendBundle", @"Looking for %@", name); - - /* Find the backend framework */ - benum = [NSStandardLibraryPaths() objectEnumerator]; - while ((path = [benum nextObject])) - { - path = [path stringByAppendingPathComponent: dir]; - path = [path stringByAppendingPathComponent: name]; - if ([[NSFileManager defaultManager] fileExistsAtPath: path]) - { - break; - } - } - return path; -} - -/* Find and load the backend framework, if there is one. The name is - taken from a user default containing the name of the backend framework, - such as 'GNUstep-back', or simply 'back', or for historical reasons, - 'libgnustep-back'. */ -static NSString * -gnustep_backend_framework(NSString *bundleName) -{ - if (bundleName == nil) - bundleName = @"GNUstep_back.framework"; - else - { - if ([bundleName hasPrefix: @"GNUstep-"]) - bundleName = [bundleName stringByAppendingString: @".framework"]; - else - { - if ([bundleName hasPrefix: @"libgnustep-"]) - { - bundleName = [bundleName substringFromIndex: [@"libgnustep-" length]]; - } - bundleName = [NSString stringWithFormat: @"GNUstep-%@.framework", - bundleName]; - } - } - - return gnustep_backend_path(@"Frameworks", bundleName); -} - -/* Find and load the backend bundle, if there is one. The name is - taken from a user default containing the name of the backend bundle, - such as 'back', or for historical reasons, 'libgnustep-back'. New - versions may also have a version number associated with it. */ -static NSString * -gnustep_backend_bundle(NSString *bundleName) -{ - NSString *path, *bundleWithVersion; - int version = GNUSTEP_GUI_MAJOR_VERSION * 100 + GNUSTEP_GUI_MINOR_VERSION; - - if (bundleName == nil) - { - bundleName = @"libgnustep-back"; - } - else - { - if ([bundleName hasPrefix: @"libgnustep-"] == NO) - { - bundleName = [NSString stringWithFormat: @"libgnustep-%@", - bundleName]; - } - } - bundleWithVersion = [NSString stringWithFormat: @"%@-%03d.bundle", - bundleName, version]; - bundleName = [bundleName stringByAppendingString: @".bundle"]; - path = gnustep_backend_path(@"Bundles", bundleWithVersion); - if (path == nil) - { - NSLog(@"Did not find correct version of backend (%@), " - @"falling back to std (%@).", bundleWithVersion, bundleName); - path = gnustep_backend_path(@"Bundles", bundleName); - } - return path; -} - -BOOL -initialize_gnustep_backend(void) -{ - static int first = 1; - - if (first) - { - Class backend; - - /* - Remember which thread we are running in. This thread will be the - -gui thread, ie. the only thread that may do any rendering. With - the exception of a few methods explicitly marked as thread-safe, - other threads should not call any methods in -gui. - */ - GSAppKitThread = [NSThread currentThread]; - - first = 0; -#ifdef BACKEND_BUNDLE - { - NSBundle *theBundle; - NSString *path, *bundleName; - NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; - - /* What backend ? */ - bundleName = [defs stringForKey: @"GSBackend"]; - path = gnustep_backend_framework (bundleName); - if (path == nil) - { - NSDebugLLog(@"BackendBundle", @"Did not find backend framework."); - path = gnustep_backend_bundle (bundleName); - } - - /* FIXME/TODO - update localized error messages. */ - - /* Backend found ? */ - if (bundleName == nil) - bundleName = @"back"; - NSCAssert1(path != nil, _(@"Unable to find backend %@"), bundleName); - NSDebugLog(@"Loading Backend from %@", path); - NSDebugFLLog(@"BackendBundle", @"Loading Backend from %@", path); - - /* Create a bundle object. (Should normally succeed). */ - theBundle = [NSBundle bundleWithPath: path]; - NSCAssert1(theBundle != nil, - _(@"Can't create NSBundle object for backend at path %@"), - path); - - /* Now load the object file from the bundle. */ - NSCAssert1 ([theBundle load], - _(@"Can't load object file from backend at path %@"), - path); - - /* Now get the GSBackend class, which should have just been loaded - * from the bundle. */ - backend = NSClassFromString (@"GSBackend"); - NSCAssert1 (backend != Nil, - _(@"Backend at path %@ doesn't contain the GSBackend class"), path); - [backend initializeBackend]; - } - -#else - /* GSBackend will be in a separate library linked in with the app. - This would be cleaner with ...classNamed: @"GSBackend", but that - doesn't work in some cases (Mac OS X for instance). */ - [GSBackend initializeBackend]; -#endif - } - return YES; -} - -void -gsapp_user_bundles(void) -{ - NSUserDefaults *defs=[NSUserDefaults standardUserDefaults]; - NSArray *a=[defs arrayForKey: @"GSAppKitUserBundles"]; - int i, c; - c = [a count]; - if (a == nil || c == 0) - return; - NSLog(@"Loading %d user defined AppKit bundles", c); - for (i = 0; i < c; i++) - { - NSBundle *b = [NSBundle bundleWithPath: [a objectAtIndex: i]]; - if (!b) - { - NSLog(@"* Unable to load '%@'", [a objectAtIndex: i]); - continue; - } - NSLog(@"Loaded '%@'\n", [a objectAtIndex: i]); - [[[b principalClass] alloc] init]; - } -} - -/* - * Types - */ -struct _NSModalSession { - int runState; - int entryLevel; - NSWindow *window; - NSModalSession previous; -}; -@interface NSApplication (Private) +@interface UIApplication (Private) - (void) _appIconInit; - (NSDictionary*) _notificationUserInfo; - (void) _openDocument: (NSString*)name; @@ -383,363 +107,26 @@ - (NSMenu *) _dockMenu; @end -@interface NSWindow (ApplicationPrivate) -- (void) setAttachedSheet: (id) sheet; -@end - -@implementation NSWindow (ApplicationPrivate) -/** - * Associate sheet with the window it's attached to. The window is not retained. - */ -- (void) setAttachedSheet: (id) sheet -{ - _attachedSheet = sheet; -} -@end - -@interface NSIconWindow : NSWindow -@end - -@interface NSAppIconView : NSView -- (void) setImage: (NSImage *)anImage; -@end - -@interface NSMenu (HorizontalPrivate) -- (void) _organizeMenu; -@end - /* * Class variables */ static NSEvent *null_event; static Class arpClass; static NSNotificationCenter *nc; - -NSApplication *NSApp = nil; - -@implementation NSIconWindow - -- (BOOL) canBecomeMainWindow -{ - return NO; -} - -- (BOOL) canBecomeKeyWindow -{ - return NO; -} - -- (BOOL) worksWhenModal -{ - return YES; -} - - -- (void) orderWindow: (NSWindowOrderingMode)place relativeTo: (int)otherWin -{ - if ([[NSUserDefaults standardUserDefaults] - boolForKey: @"GSSuppressAppIcon"] == NO) - { - [super orderWindow: place relativeTo: otherWin]; - } -} - -- (void) _initDefaults -{ - [super _initDefaults]; - /* Set the title of the window to the process name. Even as the - window shows no title bar, the window manager may show it. */ - [self setTitle: [[NSProcessInfo processInfo] processName]]; - [self setExcludedFromWindowsMenu: YES]; - [self setReleasedWhenClosed: NO]; - -#if MINI_ICON - /* Hack ... - * At least one window manager won't miniaturize a window unless - * it's at the standard level. If the app icon is suppressed, we - * may still want a miniaturised version while the app is hidden. - */ - if (YES == [[NSUserDefaults standardUserDefaults] - boolForKey: @"GSSuppressAppIcon"]) - { - return; - } -#endif - /* App icons and mini windows are displayed at dock level by default. Yet, - with the current window level mapping in -back, some window managers - will order pop up and context menus behind app icons and mini windows. - Therefore, it is possible to have app icons and mini windows displayed - at normal window level under control of a user preference. */ - // See also NSMiniWindow -_initDefaults in NSWindow.m - if ([[NSUserDefaults standardUserDefaults] - boolForKey: @"GSAllowWindowsOverIcons"] == YES) - _windowLevel = NSDockWindowLevel; -} - -- (void) rightMouseDown: (NSEvent *)theEvent -{ - NSMenu *menu = nil; - NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil); - - if (style == NSMacintoshInterfaceStyle || style == NSWindows95InterfaceStyle) - { - menu = [NSApp _dockMenu]; - } - if (menu) - { - [NSMenu popUpContextMenu: menu - withEvent: theEvent - forView: [self contentView]]; - } - else - { - [super rightMouseDown: theEvent]; - } -} - -@end - -@implementation NSAppIconView - -// Class variables -static NSCell* dragCell = nil; -static NSCell* tileCell = nil; - -static NSSize scaledIconSizeForSize(NSSize imageSize) -{ - NSSize iconSize, retSize; - - iconSize = GSGetIconSize(); - retSize.width = imageSize.width * iconSize.width / 64; - retSize.height = imageSize.height * iconSize.height / 64; - return retSize; -} - -+ (void) initialize -{ - NSImage *tileImage; - NSSize iconSize; - - iconSize = GSGetIconSize(); - /* _appIconInit will set our image */ - dragCell = [[NSCell alloc] initImageCell: nil]; - [dragCell setBordered: NO]; - - tileImage = [[GSCurrentServer() iconTileImage] copy]; - [tileImage setScalesWhenResized: YES]; - [tileImage setSize: iconSize]; - tileCell = [[NSCell alloc] initImageCell: tileImage]; - RELEASE(tileImage); - [tileCell setBordered: NO]; -} - -- (BOOL) acceptsFirstMouse: (NSEvent*)theEvent -{ - return YES; -} - -- (void) concludeDragOperation: (id)sender -{ -} - -- (NSDragOperation) draggingEntered: (id)sender -{ - return NSDragOperationGeneric; -} - -- (void) draggingExited: (id)sender -{ -} - -- (NSDragOperation) draggingUpdated: (id)sender -{ - return NSDragOperationGeneric; -} - -- (void) drawRect: (NSRect)rect -{ - NSSize iconSize = GSGetIconSize(); - - [tileCell drawWithFrame: NSMakeRect(0, 0, iconSize.width, iconSize.height) - inView: self]; - [dragCell drawWithFrame: NSMakeRect(0, 0, iconSize.width, iconSize.height) - inView: self]; - - if ([NSApp isHidden]) - { - NSRectEdge mySides[] = {NSMinXEdge, NSMinYEdge, NSMaxXEdge, NSMaxYEdge}; - float myGrays[] = {NSBlack, NSWhite, NSWhite, NSBlack}; - NSDrawTiledRects(NSMakeRect(4, 4, 3, 2), rect, mySides, myGrays, 4); - } -} - -- (id) initWithFrame: (NSRect)frame -{ - self = [super initWithFrame: frame]; - [self registerForDraggedTypes: [NSArray arrayWithObjects: - NSFilenamesPboardType, nil]]; - return self; -} - -- (void) mouseDown: (NSEvent*)theEvent -{ - if ([theEvent clickCount] >= 2) - { - /* if not hidden raise windows which are possibly obscured. */ - if ([NSApp isHidden] == NO) - { - NSArray *windows = RETAIN(GSOrderedWindows()); - NSWindow *aWin; - NSEnumerator *iter = [windows reverseObjectEnumerator]; - - while ((aWin = [iter nextObject])) - { - if ([aWin isVisible] == YES && [aWin isMiniaturized] == NO - && aWin != [NSApp keyWindow] && aWin != [NSApp mainWindow] - && aWin != [self window] - && ([aWin styleMask] & NSMiniWindowMask) == 0) - { - [aWin orderFrontRegardless]; - } - } - - if ([NSApp isActive] == YES) - { - if ([NSApp keyWindow] != nil) - { - [[NSApp keyWindow] orderFront: self]; - } - else if ([NSApp mainWindow] != nil) - { - [[NSApp mainWindow] makeKeyAndOrderFront: self]; - } - else - { - /* We need give input focus to some window otherwise we'll - never get keyboard events. FIXME: doesn't work. */ - NSWindow *menu_window= [[NSApp mainMenu] window]; - NSDebugLLog(@"Focus", - @"No key on activation - make menu key"); - [GSServerForWindow(menu_window) setinputfocus: - [menu_window windowNumber]]; - } - } - - RELEASE(windows); - } - [NSApp unhide: self]; // or activate or do nothing. - } - else - { - NSPoint lastLocation; - NSPoint location; - unsigned eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask - | NSPeriodicMask | NSOtherMouseUpMask | NSRightMouseUpMask; - NSDate *theDistantFuture = [NSDate distantFuture]; - BOOL done = NO; - - lastLocation = [theEvent locationInWindow]; - [NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.02]; - - while (!done) - { - theEvent = [NSApp nextEventMatchingMask: eventMask - untilDate: theDistantFuture - inMode: NSEventTrackingRunLoopMode - dequeue: YES]; - - switch ([theEvent type]) - { - case NSRightMouseUp: - case NSOtherMouseUp: - case NSLeftMouseUp: - /* any mouse up means we're done */ - done = YES; - break; - case NSPeriodic: - location = [_window mouseLocationOutsideOfEventStream]; - if (NSEqualPoints(location, lastLocation) == NO) - { - NSPoint origin = [_window frame].origin; - - origin.x += (location.x - lastLocation.x); - origin.y += (location.y - lastLocation.y); - [_window setFrameOrigin: origin]; - } - break; - - default: - break; - } - } - [NSEvent stopPeriodicEvents]; - } -} - -- (BOOL) prepareForDragOperation: (id)sender -{ - return YES; -} - -- (BOOL) performDragOperation: (id)sender -{ - NSArray *types; - NSPasteboard *dragPb; - - dragPb = [sender draggingPasteboard]; - types = [dragPb types]; - if ([types containsObject: NSFilenamesPboardType] == YES) - { - NSArray *names = [dragPb propertyListForType: NSFilenamesPboardType]; - unsigned index; - - [NSApp activateIgnoringOtherApps: YES]; - for (index = 0; index < [names count]; index++) - { - [NSApp _openDocument: [names objectAtIndex: index]]; - } - return YES; - } - return NO; -} - -- (void) setImage: (NSImage *)anImage -{ - NSImage *imgCopy = [anImage copy]; - - if (imgCopy) - { - NSSize imageSize = [imgCopy size]; - - [imgCopy setScalesWhenResized: YES]; - [imgCopy setSize: scaledIconSizeForSize(imageSize)]; - } - [dragCell setImage: imgCopy]; - RELEASE(imgCopy); - [self setNeedsDisplay: YES]; -} - -@end - +static UIApplication *uikitApp=nil; /** - *

Every graphical GNUstep application has exactly one instance of - * NSApplication (or a subclass) instantiated. Usually this is + *

Every graphical GNUstep UIKit application has exactly one instance of + * UIApplication (or a subclass) instantiated. Usually this is * created through the +sharedApplication method. Once created, this instance - * is always accessible through the global variable 'NSApp'.

+ * is always accessible through that same method.

* - *

The NSApplication instance manages the main run loop, dispatches + *

The UIApplication instance manages the main run loop, dispatches * events, and manages resources. It sets up the connection to the window - * server and provides special methods for putting up "modal" (always on top) - * windows.

+ * server.

* - *

Typically, -run is called by an application's main method - * after the NSApplication instance is created, which never returns. However, - * applications needing to integrate other event loops may strategically call - * the -stop: method, followed by -run later on.

- * - *

To avoid most common needs for subclassing, NSApplication allows you to + *

To avoid most common needs for subclassing, UIApplication allows you to * specify a delegate that is messaged in particular situations. - * See -delegate , -setDelegate: , and [(GSAppDelegateProtocol)].

+ * See -delegate , -setDelegate: , and [(UIApplicationDelegate)].

* *

Subclassing should be a last resort, and delegate * methods should be used in most cases. However, subclassing is most @@ -747,14 +134,14 @@ * -run when the method described above is not sufficient, or to intercept * events by overriding -sendEvent: .

*/ -@implementation NSApplication +@implementation UIApplication /* * Class methods */ + (void) initialize { - if (self == [NSApplication class]) + if (self == [UIApplication class]) { CREATE_AUTORELEASE_POOL(pool); /* @@ -783,27 +170,7 @@ [pool drain]; } -/** - * Calls [NSThread+detachNewThreadSelector:toTarget:withObject:] with the - * invocation wrapped by an autorelease pool. - */ -+ (void) detachDrawingThread: (SEL)selector - toTarget: (id)target - withObject: (id)argument -{ - NSInvocation *inv; - inv = [NSInvocation - invocationWithMethodSignature: - [target methodSignatureForSelector: selector]]; - [inv setTarget: target]; - [inv setSelector: selector]; - [inv setArgument: argument atIndex: 2]; - [NSThread detachNewThreadSelector: @selector(_invokeWithAutoreleasePool:) - toTarget: self - withObject: inv]; -} - /** *

Return the shared application instance, creating one (of the * receiver class) if needed. There is (and must always be) only a @@ -813,21 +180,21 @@ * the shared application instance is created, it is also automatically * initialized (that is, its init method is called), which * connects to the window server and prepares the gui library for actual - * operation. For this reason, you must always call [NSApplication + * operation. For this reason, you must always call [UIApplication * sharedApplication] before using any functionality of the gui * library - so, normally, this should be one of the first commands in - * your program (if you use NSApplicationMain(), this is + * your program (if you use UIApplicationMain(), this is * automatically done).

* *

The shared application instance is normally an instance of - * NSApplication; but you can subclass NSApplication, and have an + * UIApplication; but you can subclass UIApplication, and have an * instance of your own subclass be created and used as the shared * application instance. If you want to get this result, you need to * make sure the first time you call +sharedApplication is on your - * custom NSApplication subclass (rather than on NSApplication). + * custom UIApplication subclass (rather than on UIApplication). * Putting [MyApplicationClass sharedApplication]; as the first * command in your program is the recommended way. :-) If you use - * NSApplicationMain(), it automatically creates the appropriate + * UIApplicationMain(), it automatically creates the appropriate * instance (which you can control by editing the info dictionary of * the application).

* @@ -838,15 +205,15 @@ * application, make sure only one of them uses the gui [the 'drawing' * thread], and the other ones do not).

*/ -+ (NSApplication *) sharedApplication ++ (UIApplication *) sharedApplication { /* If the global application does not yet exist then create it. */ - if (NSApp == nil) + if (uikitApp == nil) { /* -init sets NSApp. */ [[self alloc] init]; } - return NSApp; + return uikitApp; } /* @@ -865,47 +232,47 @@ /* * Set NSApp as soon as possible, since other gui classes (which - * we refer or use in this method) might be calling [NSApplication + * we refer or use in this method) might be calling [UIApplication * sharedApplication] during their initialization, and we want * those calls to succeed. */ - NSApp = self; + uikitApp = self; - /* Initialize the backend here. */ - initialize_gnustep_backend(); - - /* Load user-defined bundles */ - gsapp_user_bundles(); - /* Connect to our window server. */ srv = [GSDisplayServer serverWithAttributes: nil]; RETAIN(srv); [GSDisplayServer setCurrentServer: srv]; /* Create a default context with the attributes of the main screen. */ +/* attributes = [[NSScreen mainScreen] deviceDescription]; _default_context = [NSGraphicsContext graphicsContextWithAttributes: attributes]; RETAIN(_default_context); [NSGraphicsContext setCurrentContext: _default_context]; - +*/ /* Initialize font manager. */ +/* [NSFontManager sharedFontManager]; _hidden = [[NSMutableArray alloc] init]; _inactive = [[NSMutableArray alloc] init]; _unhide_on_activation = YES; _app_is_hidden = NO; +*/ /* Ivar already automatically initialized to NO when the app is created. */ //_app_is_active = NO; //_main_menu = nil; +/* _windows_need_update = YES; +*/ /* Save the base library exception handler */ defaultUncaughtExceptionHandler = NSGetUncaughtExceptionHandler(); /* Set a new exception handler for the gui library. */ +/* NSSetUncaughtExceptionHandler(_NSAppKitUncaughtExceptionHandler); - + */ _listener = [GSServicesManager newWithApplication: self]; /* NSEvent doesn't use -init so we use +alloc instead of +new. */ @@ -915,17 +282,12 @@ /* We are the end of responder chain. */ [self setNextResponder: nil]; - /* Create our app icon. - NB We are doing this here because WindowMaker will not map the app icon - window unless it is the very first window being mapped. */ - [self _appIconInit]; - [_app_init_pool drain]; } /** - * This method initializes an NSApplication instance. It sets the + * This method initializes an UIApplication instance. It sets the * shared application instance to be the receiver, and then connects * to the window server and performs the actual gui library * initialization. @@ -935,7 +297,7 @@ * * It is recommended that you /never/ call this method directly from * your code! It's called automatically (and only once) by - * [NSApplication sharedApplication]. You might override this method + * [UIApplication sharedApplication]. You might override this method * in subclasses (make sure to call super's :-), then your overridden * method will automatically be called (guaranteed once in the * lifetime of the application) when you call [MyApplicationClass @@ -951,8 +313,8 @@ - (id) init { /* - * As per openstep specification, calling -init twice is a bug in - * the program. +sharedApplication automatically makes sure it + * Calling -init twice is a bug in the program. + * +sharedApplication automatically makes sure it * never calls -init more than once, and programmers should normally * use +sharedApplication in programs. * @@ -966,7 +328,7 @@ * initialization code behaves always in the same way for this class * and for subclasses. */ - NSAssert (NSApp == nil, _(@"[NSApplication -init] called more than once")); + NSAssert (uikitApp == nil, _(@"[UIApplication -init] called more than once")); /* * The appkit should run in the main thread ... so to be sure we perform @@ -975,14 +337,11 @@ [self performSelectorOnMainThread: @selector(_init) withObject: self waitUntilDone: YES]; - return NSApp; + return uikitApp; } /** - *

Activates the application, sets the application icon, loads the main - * Nib file if NSMainNibFile is set in the application - * property list, posts an - * NSApplicationWillFinishLaunchingNotification, and takes care + *

Activates the application, and takes care * of a few other startup tasks. * If you override this method, be sure to call super.

* @@ -991,7 +350,6 @@ */ - (void) finishLaunching { - NSDocumentController *sdc; NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; NSString *filePath; NSArray *windows_list; @@ -1001,10 +359,8 @@ BOOL didAutoreopen = NO; NSArray *files = nil; - /* post notification that launch will finish */ - [nc postNotificationName: NSApplicationWillFinishLaunchingNotification - object: self]; - +#if 0 +// code disabled until it can be reviewed /* Register our listener to incoming services requests etc. */ [_listener registerAsServiceProvider]; @@ -1174,10 +530,11 @@ } } } +#endif } /* - * Posts NSApplicationDidFinishLaunchingNotification. + * Posts UIApplicationDidFinishLaunchingNotification. * *

The -run method calls this the first time it is called, before starting * the event loop for the first time and after calling finishLaunching.

@@ -1185,9 +542,11 @@ - (void) _didFinishLaunching { /* finish the launching post notification that launching has finished */ - [nc postNotificationName: NSApplicationDidFinishLaunchingNotification + [nc postNotificationName: UIApplicationDidFinishLaunchingNotification object: self]; - +#if 0 +// Workspace/Springboard should be notified. +// Disabled until we have a Workspace/Springboard! NS_DURING { [[[NSWorkspace sharedWorkspace] notificationCenter] @@ -1202,6 +561,7 @@ [localException raise]; } NS_ENDHANDLER +#endif } - (void) dealloc @@ -1212,16 +572,22 @@ { srv = GSCurrentServer(); } +/* [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver: self]; +*/ [nc removeObserver: self]; - +/* RELEASE(_hidden); RELEASE(_inactive); RELEASE(_listener); +*/ RELEASE(null_event); RELEASE(_current_event); +#if 0 +// Disabled until we figure out if we really need modal sessions in UIKit +// Probably not! /* We may need to tidy up nested modal session structures. */ while (_session != 0) { @@ -1230,20 +596,14 @@ _session = tmp->previous; NSZoneFree(NSDefaultMallocZone(), tmp); } +#endif - /* Release the menus, then set them to nil so we don't try updating - them after they have been deallocated. */ - DESTROY(_main_menu); - DESTROY(_windows_menu); - - TEST_RELEASE(_app_icon); - TEST_RELEASE(_app_icon_window); - TEST_RELEASE(_infoPanel); - +#if 0 +// Did not yet figure out gfx. /* Destroy the default context */ [NSGraphicsContext setCurrentContext: nil]; DESTROY(_default_context); - +#endif /* Close the server */ [srv closeServer]; DESTROY(srv); @@ -1252,224 +612,13 @@ } /** - * Activate app unconditionally if flag is YES, otherwise only if no other app - * is active. (Note: this is currently not implemented - * under GNUstep. The app is always activated unconditionally.) Usually - * it is not necessary to manually call this method, except in some - * circumstances of interapplication communication. + * Returns whether this app is the currently active GNUstep UIKit application. */ -- (void) activateIgnoringOtherApps: (BOOL)flag -{ - // TODO: Currently the flag is ignored - if (_app_is_active == NO) - { - unsigned count; - unsigned i; - NSDictionary *info; - - /* - * Menus should observe this notification in order to make themselves - * visible when the application is active. - */ - [nc postNotificationName: NSApplicationWillBecomeActiveNotification - object: self]; - - _app_is_active = YES; - - if ([[NSUserDefaults standardUserDefaults] - boolForKey: @"GSSuppressAppIcon"]) - { - [_app_icon_window orderOut: self]; - } - - /* Make sure to calculate count after the notification, since - inactive status might be changed by a notifiee. */ - count = [_inactive count]; - for (i = 0; i < count; i++) - { - [[_inactive objectAtIndex: i] orderFrontRegardless]; - } - [_inactive removeAllObjects]; - - if (_unhide_on_activation) - { - [self unhide: nil]; - } - - if ([self keyWindow] == nil && _hidden_key != nil - && [[self windows] indexOfObjectIdenticalTo: _hidden_key] != NSNotFound) - { - [_hidden_key makeKeyWindow]; - _hidden_key = nil; - } - - if ([self mainWindow] == nil && _hidden_main != nil - && [[self windows] indexOfObjectIdenticalTo: _hidden_main] != NSNotFound) - { - [_hidden_main makeMainWindow]; - _hidden_main = nil; - } - - if ([self keyWindow] != nil) - { - [[self keyWindow] orderFront: self]; - } - else if ([self mainWindow] != nil) - { - [[self mainWindow] makeKeyAndOrderFront: self]; - } - else - { - /* We need give input focus to some window otherwise we'll never get - keyboard events. FIXME: doesn't work. */ - NSWindow *menu_window= [[self mainMenu] window]; - NSDebugLLog(@"Focus", @"No key on activation - make menu key"); - [GSServerForWindow(menu_window) setinputfocus: - [menu_window windowNumber]]; - } - - info = [self _notificationUserInfo]; - [nc postNotificationName: NSApplicationDidBecomeActiveNotification - object: self - userInfo: info]; - [[[NSWorkspace sharedWorkspace] notificationCenter] - postNotificationName: NSApplicationDidBecomeActiveNotification - object: [NSWorkspace sharedWorkspace] - userInfo: info]; - } -} - -/** - * Forcefully deactivate the app, without activating another. It is rarely - * necessary to use this method. - */ -- (void) deactivate -{ - if (_app_is_active == YES) - { - NSArray *windows_list; - NSDictionary *info; - NSWindow *win; - NSEnumerator *iter; - - [nc postNotificationName: NSApplicationWillResignActiveNotification - object: self]; - - _app_is_active = NO; - - if ([self keyWindow] != nil) - { - _hidden_key = [self keyWindow]; - [_hidden_key resignKeyWindow]; - } - // The main window is saved for when the app is activated again. - // This is necessary for menu in window. - if ([self mainWindow] != nil) - { - _hidden_main = [self mainWindow]; - [_hidden_main resignMainWindow]; - } - - windows_list = GSOrderedWindows(); - iter = [windows_list reverseObjectEnumerator]; - - while ((win = [iter nextObject])) - { - NSModalSession theSession; - - if ([win isVisible] == NO) - { - continue; /* Already invisible */ - } - if ([win canHide] == NO) - { - continue; /* Can't be hidden */ - } - if (win == _app_icon_window) - { - continue; /* can't hide the app icon. */ - } - /* Don't order out modal windows */ - theSession = _session; - while (theSession != 0) - { - if (win == theSession->window) - break; - theSession = theSession->previous; - } - if (theSession) - continue; - - if ([win hidesOnDeactivate] == YES) - { - /* NB Order is important here. When a hide on deactivate window - is ordered out while the application is inactive, it gets - removed from the _inactive list. Therefore, we must first - order out the window and then add it to the _inactive list. */ - [win orderOut: self]; - [_inactive addObject: win]; - } - } - - if (YES == [[NSUserDefaults standardUserDefaults] - boolForKey: @"GSSuppressAppIcon"]) - { -#if MINI_ICON - NSRect f = [[[self mainMenu] window] frame]; - NSPoint p = f.origin; - - p.y += f.size.height; - [_app_icon_window setFrameTopLeftPoint: p]; - [_app_icon_window orderFrontRegardless]; - [_app_icon_window miniaturize: self]; -#else - [_app_icon_window orderFrontRegardless]; -#endif - } - - info = [self _notificationUserInfo]; - [nc postNotificationName: NSApplicationDidResignActiveNotification - object: self - userInfo: info]; - [[[NSWorkspace sharedWorkspace] notificationCenter] - postNotificationName: NSApplicationDidResignActiveNotification - object: [NSWorkspace sharedWorkspace] - userInfo: info]; - } -} - -/** - * Returns whether this app is the currently active GNUstep application. - * Note that on a GNUstep system, unlike OS X, it is possible for NO GNUstep - * app to be active. - */ - (BOOL) isActive { return _app_is_active; } -/** - * Cause all other apps to hide themselves. - */ -- (void) hideOtherApplications: (id)sender -{ - [[[NSWorkspace sharedWorkspace] notificationCenter] - postNotificationName: GSHideOtherApplicationsNotification - object: [NSWorkspace sharedWorkspace] - userInfo: [self _notificationUserInfo]]; -} - -/** - * Cause all apps including this one to unhide themselves. - */ -- (void) unhideAllApplications: (id)sender -{ - [[[NSWorkspace sharedWorkspace] notificationCenter] - postNotificationName: GSUnhideAllApplicationsNotification - object: [NSWorkspace sharedWorkspace] - userInfo: [self _notificationUserInfo]]; -} - #define NSLogUncaughtExceptionMask 1 #define NSHandleUncaughtExceptionMask 2 #define NSLogUncaughtSystemExceptionMask 4 @@ -1540,8 +689,6 @@ [self finishLaunching]; [self _didFinishLaunching]; - [_listener updateServicesMenu]; - [_main_menu update]; DESTROY(_runLoopPool); } @@ -1597,333 +744,11 @@ return _app_is_running; } -/* - * Running modal event loops - */ - /** - * Halts a currently running modal event loop started by -runModalForWindow: - * or -runModalSession: . If you wish to halt the session in response to - * user interaction with the modal window, use -stopModalWithCode: or - * -stopModal instead; only use this to halt the loop from elsewhere, such as - * another thread. - */ -- (void) abortModal -{ -/* FIXME: The previous, now commented out, code here did only work from within the modal loop, - which is contrary to the purpose of this method. Calling stopModalWithCode: works a bit better, - but still relies on the modal loop to cooperate. Calling that method via performSelectorOnMainThread:... - and moving the exception into stopModalWithCode:, looks like another option. Still this would - rely on the loop getting executed. - - if (_session == 0) - { - [NSException raise: NSAbortModalException - format: @"abortModal called while not in a modal session"]; - } - [NSException raise: NSAbortModalException format: @"abortModal"]; -*/ - [self stopModalWithCode: NSRunAbortedResponse]; -} - -/** - * Set up modal session for theWindow, and, if it is not visible already, - * puts it up on screen, centering it if it is an NSPanel. It is then - * ordered front and made key or main window. - */ -- (NSModalSession) beginModalSessionForWindow: (NSWindow*)theWindow -{ - NSModalSession theSession; - - theSession = (NSModalSession)NSZoneMalloc(NSDefaultMallocZone(), - sizeof(struct _NSModalSession)); - theSession->runState = NSRunContinuesResponse; - theSession->entryLevel = [theWindow level]; - theSession->window = theWindow; - theSession->previous = _session; - _session = theSession; - - /* - * Displaying / raising window but centering panel only if not up - * seems to match the behavior on OS X (Panther). - */ - if ([theWindow isKindOfClass: [NSPanel class]]) - { - if ([theWindow isVisible] == NO) - [theWindow center]; - [theWindow setLevel: NSModalPanelWindowLevel]; - } - [theWindow orderFrontRegardless]; - if ([self isActive] == YES) - { - if ([theWindow canBecomeKeyWindow] == YES) - { - [theWindow makeKeyWindow]; - } - else if ([theWindow canBecomeMainWindow] == YES) - { - [theWindow makeMainWindow]; - } - } - - return theSession; -} - -/** - * Clean up after a modal session has been run. Called with theSession - * returned from a previous call to beginModalSessionForWindow: . - */ -- (void) endModalSession: (NSModalSession)theSession -{ - NSModalSession tmp = _session; - NSArray *windows = [self windows]; - - if (theSession == 0) - { - [NSException raise: NSInvalidArgumentException - format: @"null pointer passed to endModalSession:"]; - } - /* Remove this session from linked list of sessions. */ - while (tmp != 0 && tmp != theSession) - { - tmp = tmp->previous; - } - if (tmp == 0) - { - [NSException raise: NSInvalidArgumentException - format: @"unknown session passed to endModalSession:"]; - } - while (_session != theSession) - { - tmp = _session; - _session = tmp->previous; - if ([windows indexOfObjectIdenticalTo: tmp->window] != NSNotFound) - { - [tmp->window setLevel: tmp->entryLevel]; - } - NSZoneFree(NSDefaultMallocZone(), tmp); - } - _session = _session->previous; - if ([windows indexOfObjectIdenticalTo: theSession->window] != NSNotFound) - { - [theSession->window setLevel: theSession->entryLevel]; - } - NSZoneFree(NSDefaultMallocZone(), theSession); - - // Bring the next modal window to front - if ((_session != 0) && - ([windows indexOfObjectIdenticalTo: _session->window] != NSNotFound)) - { - NSWindow *theWindow = _session->window; - - // Same code as in beginModalSessionForWindow: - [theWindow orderFrontRegardless]; - if ([self isActive] == YES) - { - if ([theWindow canBecomeKeyWindow] == YES) - { - [theWindow makeKeyWindow]; - } - else if ([theWindow canBecomeMainWindow] == YES) - { - [theWindow makeMainWindow]; - } - } - } - else - { - [_main_menu update]; - } -} - -/** - * Starts modal event loop for given window, after calling - * -beginModalSessionForWindow:. Loop is broken only by -stopModal , - * -stopModalWithCode: , or -abortModal , at which time -endModalSession: - * is called automatically. - */ -- (int) runModalForWindow: (NSWindow*)theWindow -{ - NSModalSession theSession = 0; - int code = NSRunContinuesResponse; - - NS_DURING - { - NSDate *limit; - GSDisplayServer *srv; - - theSession = [self beginModalSessionForWindow: theWindow]; - limit = [NSDate distantFuture]; - srv = GSCurrentServer(); - - while (code == NSRunContinuesResponse) - { - /* - * Try to handle events for this session, discarding others. - */ - code = [self runModalSession: theSession]; - if (code == NSRunContinuesResponse) - { - /* - * Wait until there are more events to handle. - */ - DPSPeekEvent(srv, NSAnyEventMask, limit, NSModalPanelRunLoopMode); - } - } - - [self endModalSession: theSession]; - } - NS_HANDLER - { - if (theSession != 0) - { - NSWindow *win_to_close = theSession->window; - - [self endModalSession: theSession]; - [win_to_close close]; - } - if ([[localException name] isEqual: NSAbortModalException] == NO) - { - [localException raise]; - } - code = NSRunAbortedResponse; - } - NS_ENDHANDLER - - return code; -} - -/** -

-Processes any events for a modal session described by the theSession -variable. When finished, it returns the state of the session (i.e. -whether it is still running or has been stopped, etc) -

-

If there are no pending events for the session, this method returns -immediately. -

-

- Although Apple's docs state that, before processing the events, it makes the - session window key and orders the window front, this method does not attempt - to do this, because: 1) we don't want to interfere with use of other apps - during modal session for this app; 2) occasionally other windows are active - and should be usable during modal sessions (e.g., a popup dialog from a modal - window); 3) most of the time -beginModalSessionForWindow: will have been - called in advance. If the latter is not the case, you may need to order the - window front yourself in advance. -

-

-See Also: -runModalForWindow: -

-*/ -- (int) runModalSession: (NSModalSession)theSession -{ - NSAutoreleasePool *pool; - GSDisplayServer *srv; - BOOL done = NO; - NSEvent *event; - NSDate *limit; - - if (theSession != _session) - { - [NSException raise: NSInvalidArgumentException - format: @"runModalSession: with wrong session"]; - } - - // Use the default context for all events. - srv = GSCurrentServer(); - - // Only handle input which is already available. - limit = [NSDate distantPast]; - - /* - * Deal with the events in the queue. - */ - while (done == NO && theSession->runState == NSRunContinuesResponse) - { - IF_NO_GC(pool = [arpClass new]); - - event = DPSGetEvent(srv, NSAnyEventMask, limit, NSModalPanelRunLoopMode); - if (event != nil) - { - NSWindow *eventWindow = [event window]; - - /* - * We handle events for the session window, events for any - * window which works when modal, and any window management - * events. All others are ignored/discarded. - */ - if (eventWindow == theSession->window - || [eventWindow worksWhenModal] == YES - || [event type] == NSAppKitDefined) - { - ASSIGN(_current_event, event); - } - else - { - event = nil; // Ignore/discard this event. - } - } - else - { - done = YES; // No more events pending. - } - - if (event != nil) - { - NSEventType type = [_current_event type]; - - [self sendEvent: _current_event]; - - // update (en/disable) the services menu's items - if (type != NSPeriodic && type != NSMouseMoved) - { - [_listener updateServicesMenu]; - [_main_menu update]; - } - - /* - * Check to see if the window has gone away - if so, end session. - */ - if ([[self windows] indexOfObjectIdenticalTo: _session->window] - == NSNotFound - || ![_session->window isVisible]) - { - [self stopModal]; - } - } - [pool drain]; - } - - NSAssert(_session == theSession, @"Session was changed while running"); - - return theSession->runState; -} - -/** -

- Returns the window that is part of the current modal session, if any. -

-

-See -runModalForWindow: -

-*/ -- (NSWindow *) modalWindow -{ - if (_session != 0) - return (_session->window); - else - return nil; -} - -/** * Stops the main run loop, as well as a modal session if it is running. */ - (void) stop: (id)sender { - if (_session != 0) - [self stopModal]; - else { _app_is_running = NO; /* @@ -1934,114 +759,7 @@ } } -/**

Stops a running modal session causing -runModalForWindow: or - * -runModalSession: to return NSRunStoppedResponse. Use this - * or -stopModalWithCode: to end a modal session in response to user input.

- *

See Also: -stopModalWithCode:

- */ -- (void) stopModal -{ - [self stopModalWithCode: NSRunStoppedResponse]; -} -/** - * Stops a running modal session causing -runModalForWindow: or - * -runModalSession: to return the specified integer code. Use this - * or -stopModal to end a modal session in response to user input. - */ -- (void) stopModalWithCode: (int)returnCode -{ - /* According to the spec, there is no exception which is thrown - * if we are not currently in a modal session. While it is not - * good practice to call this when we're not, we shouldn't throw - * an exception. - */ - if (_session != 0 && _session->runState == NSRunContinuesResponse) - { - if (returnCode == NSRunContinuesResponse) - { - [NSException raise: NSInvalidArgumentException - format: @"stopModalWithCode: with NSRunContinuesResponse"]; - } - _session->runState = returnCode; - } -} - -/** - * Put up a modal window centered relative to docWindow. On OS X this is - * deprecated in favor of - * -beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo: . - * Not implemented under GNUstep. Currently just centers window on the - * screen. - */ -- (int) runModalForWindow: (NSWindow *)theWindow - relativeToWindow: (NSWindow *)docWindow -{ - // FIXME - [theWindow orderWindow: NSWindowAbove - relativeTo: [docWindow windowNumber]]; - return [self runModalForWindow: theWindow]; -} - -/** - * Put up a modal sheet sliding down from top of docWindow. If modalDelegate - * is non-nil and responds to didEndSelector (this is optional), it is invoked - * after the session ends. The selector should take three arguments: - * NSWindow *, int, void *. It is passed the sheet window, the return code, - * and the contextInfo passed in here. - - * Under GNUstep, the sheet aspect is not implemented (just centers - * window on the screen), but modalDelegate didEndSelector is called if - * both non-nil. - */ -- (void) beginSheet: (NSWindow *)sheet - modalForWindow: (NSWindow *)docWindow - modalDelegate: (id)modalDelegate - didEndSelector: (SEL)didEndSelector - contextInfo: (void *)contextInfo -{ - // FIXME - int ret; - - [sheet setParentWindow: docWindow]; - [docWindow setAttachedSheet: sheet]; - - ret = [self runModalForWindow: sheet - relativeToWindow: docWindow]; - - if (modalDelegate && [modalDelegate respondsToSelector: didEndSelector]) - { - void (*didEnd)(id, SEL, id, int, void*); - - didEnd = (void (*)(id, SEL, id, int, void*))[modalDelegate methodForSelector: - didEndSelector]; - didEnd(modalDelegate, didEndSelector, sheet, ret, contextInfo); - } - - [docWindow setAttachedSheet: nil]; - [sheet setParentWindow: nil]; -} - -/** - * Analogous to -stopModal for sheets. - */ -- (void) endSheet: (NSWindow *)sheet -{ - // FIXME - [self stopModal]; -} - -/** - * Analogous to -stopModalWithCode: for sheets. - */ -- (void) endSheet: (NSWindow *)sheet - returnCode: (int)returnCode -{ - // FIXME - [self stopModalWithCode: returnCode]; -} - - /* * Getting, removing, and posting events */ @@ -2058,9 +776,12 @@ * forwarding conventions. You rarely need to invoke this directly. If you * want to synthesize an event for processing, call -postEvent:atStart: . */ -- (void) sendEvent: (NSEvent *)theEvent +- (void) sendEvent: (UIEvent *)theEvent { - NSEventType type; +#if 0 +// None of these are types of UIEvent! +// Figure out what to do. + UIEventType type; type = [theEvent type]; switch (type) @@ -2109,6 +830,7 @@ [self rightMouseDown: theEvent]; } } +#endif } /** @@ -2119,12 +841,6 @@ return _current_event; } -/* Utility for pen-device input. See NSResponder. */ -- (BOOL) shouldBeTreatedAsInkEvent: (NSEvent *)theEvent -{ - return [[theEvent window] shouldBeTreatedAsInkEvent: theEvent]; -} - /** * Drop events matching mask from the queue, before but not including * lastEvent. The mask is a bitwise AND of event mask constants. @@ -2178,6 +894,7 @@ if (mode != NSEventTrackingRunLoopMode) { _windows_need_update = YES; +/* if ([NSCursor isHiddenUntilMouseMoves]) { NSEventType type = [event type]; @@ -2190,6 +907,7 @@ [NSCursor setHiddenUntilMouseMoves: NO]; } } + */ } if (flag) @@ -2221,6 +939,9 @@ */ - (BOOL) sendAction: (SEL)aSelector to: (id)aTarget from: (id)sender { +#if 0 +// targetForAction:to:from: is not used on the fruity implementation. +// We'll probably use it, but let's leave this commented out for now. id resp = [self targetForAction: aSelector to: aTarget from: sender]; if (resp != nil) @@ -2233,10 +954,14 @@ return YES; } } - +#endif return NO; } +#if 0 +// The fruity implementation does not have this. +// Commented out until it is studied. + /** * If theTarget responds to theAction it is returned, otherwise * the application searches for an object which will handle @@ -2291,8 +1016,10 @@ keyWindow: [self keyWindow] mainWindow: [self mainWindow]]; } +#endif - +#if 0 +// Not in fruity implementation, commented out for now. /** * Attempts to perform aSelector using [NSResponder-tryToPerform:with:] * and if that is not possible, attempts to get the application @@ -2316,296 +1043,8 @@ } return NO; } - -/**

Sets the application's icon. Any windows that use the old application -icon image as their mini window image will be updated to use the new -image.

See Also: -applicationIconImage

-*/ -- (void) setApplicationIconImage: (NSImage*)anImage -{ - NSEnumerator *iterator; - NSWindow *current; - NSImage *old_app_icon = _app_icon; - NSSize miniWindowSize; - NSSize imageSize; - - // Ignore attempts to set nil as the icon image. - if (nil == anImage) - return; - - RETAIN(old_app_icon); - - // Use a copy as we change the name and size - ASSIGNCOPY(_app_icon, anImage); - - [_app_icon setScalesWhenResized: YES]; - - miniWindowSize = [GSCurrentServer() iconSize]; - if (miniWindowSize.width <= 0 || miniWindowSize.height <= 0) - { - miniWindowSize = NSMakeSize(48, 48); - } - - // restrict size when the icon is larger than the mini window. - imageSize = [_app_icon size]; - if (imageSize.width > miniWindowSize.width - || imageSize.height > miniWindowSize.height) - { - [_app_icon setSize: miniWindowSize]; - } - - // Let horizontal menu change icon - [_main_menu _organizeMenu]; - - if (_app_icon_window != nil) - { - [(NSAppIconView *)[_app_icon_window contentView] setImage: _app_icon]; - } - - // Swap the old image for the new one wherever it's used - iterator = [[self windows] objectEnumerator]; - while ((current = [iterator nextObject]) != nil) - { - if ([current miniwindowImage] == old_app_icon) - [current setMiniwindowImage: _app_icon]; - } - - DESTROY(old_app_icon); -} - -/**

Returns the current icon be used for the application.

-

See Also: -setApplicationIconImage:

- */ -- (NSImage*) applicationIconImage -{ - return _app_icon; -} - -/** - * Returns the actual window object being used to display the application - * icon (usually in the dock). - */ -- (NSWindow*) iconWindow -{ - return _app_icon_window; -} - -/* - * Hiding and arranging windows - */ - -/**

Request this application to "hide" (unmap all windows from the screen - * except the icon window). Posts - * NSApplicationWillHideNotification and - * NSApplicationDidHideNotification. On OS X this activates - * the next app that is running, however on GNUstep this is up to the window - * manager.

See Also: -unhide: -isHidden

- */ -- (void) hide: (id)sender -{ -#ifdef __MINGW32__ - [self miniaturizeAll: sender]; -#else - if (_app_is_hidden == NO) - { - if (![[NSUserDefaults standardUserDefaults] - boolForKey: @"GSSuppressAppIcon"]) - { - NSArray *windows_list; - NSDictionary *info; - NSWindow *win; - NSEnumerator *iter; - - [nc postNotificationName: NSApplicationWillHideNotification - object: self]; - - if ([self keyWindow] != nil) - { - _hidden_key = [self keyWindow]; - [_hidden_key resignKeyWindow]; - } - - // The main window is saved for when the app is activated again. - // This is necessary for menu in window. - if ([self mainWindow] != nil) - { - _hidden_main = [self mainWindow]; - [_hidden_main resignMainWindow]; - } - - windows_list = GSOrderedWindows(); - iter = [windows_list reverseObjectEnumerator]; - - while ((win = [iter nextObject])) - { - if ([win isVisible] == NO && ![win isMiniaturized]) - { - continue; /* Already invisible */ - } - if ([win canHide] == NO) - { - continue; /* Not hideable */ - } - if (win == _app_icon_window) - { - continue; /* can't hide the app icon. */ - } - if (_app_is_active == YES && [win hidesOnDeactivate] == YES) - { - continue; /* Will be hidden by deactivation */ - } - [_hidden addObject: win]; - [win orderOut: self]; - } - _app_is_hidden = YES; - - if (YES == [[NSUserDefaults standardUserDefaults] - boolForKey: @"GSSuppressAppIcon"]) - { -#if MINI_ICON - NSRect f = [[[self mainMenu] window] frame]; - NSPoint p = f.origin; - - p.y += f.size.height; - [_app_icon_window setFrameTopLeftPoint: p]; - [_app_icon_window orderFrontRegardless]; - [_app_icon_window miniaturize: self]; -#else - [_app_icon_window orderFrontRegardless]; #endif - } - else - { - [[_app_icon_window contentView] setNeedsDisplay: YES]; - } - - /* - * On hiding we also deactivate the application which will make the menus - * go away too. - */ - [self deactivate]; - _unhide_on_activation = YES; - - info = [self _notificationUserInfo]; - [nc postNotificationName: NSApplicationDidHideNotification - object: self - userInfo: info]; - [[[NSWorkspace sharedWorkspace] notificationCenter] - postNotificationName: NSApplicationDidHideNotification - object: [NSWorkspace sharedWorkspace] - userInfo: info]; - } - else - { - /*Minimize all windows if there isn't an AppIcon. This isn't the - most elegant solution, but avoids to loss the app if the user - hide it. */ - [self miniaturizeAll: sender]; - } - } -#endif -} -/**

Returns whether app is currently in hidden state.

-

See Also: -hide: -unhide:

- */ -- (BOOL) isHidden -{ - return _app_is_hidden; -} - -/**

Unhides and activates this application.

-

See Also: -unhideWithoutActivation -hide: -isHidden

- */ -- (void) unhide: (id)sender -{ - if (_app_is_hidden) - { - [self unhideWithoutActivation]; - _unhide_on_activation = NO; - } - if (_app_is_active == NO) - { - /* - * Activation should make the applications menus visible. - */ - [self activateIgnoringOtherApps: YES]; - } -} - -/** - * Unhides this app (displays its windows) but does not activate it. - */ -- (void) unhideWithoutActivation -{ - if (_app_is_hidden == YES) - { - NSDictionary *info; - unsigned count; - unsigned i; - - [nc postNotificationName: NSApplicationWillUnhideNotification - object: self]; - - /* Make sure we set this before ordering windows to avoid possible - recursive loops (some methods window/backend methods check if - the app is hidden before ordering a window). */ - _app_is_hidden = NO; - - count = [_hidden count]; - for (i = 0; i < count; i++) - { - NSWindow *win = [_hidden objectAtIndex: i]; - [win orderFrontRegardless]; - if ([win isMiniaturized]) - { - [GSServerForWindow(win) miniwindow: [win windowNumber]]; - } - } - [_hidden removeAllObjects]; - [[_app_icon_window contentView] setNeedsDisplay: YES]; - - info = [self _notificationUserInfo]; - [nc postNotificationName: NSApplicationDidUnhideNotification - object: self - userInfo: info]; - [[[NSWorkspace sharedWorkspace] notificationCenter] - postNotificationName: NSApplicationDidUnhideNotification - object: [NSWorkspace sharedWorkspace] - userInfo: info]; - } -} - -/** - * Arranges all non-miniaturized app's windows in front by successively calling - * [NSWindow-orderFront:] on each window in the app's Windows menu. - */ -- (void) arrangeInFront: (id)sender -{ - NSMenu *menu; - - menu = [self windowsMenu]; - if (menu) - { - NSArray *itemArray; - unsigned count; - unsigned i; - - itemArray = [menu itemArray]; - count = [itemArray count]; - for (i = 0; i < count; i++) - { - id win = [(NSMenuItem*)[itemArray objectAtIndex: i] target]; - - if ([win isKindOfClass: [NSWindow class]] && - [win isVisible] && ![win isMiniaturized]) - { - [win orderFront: sender]; - } - } - } -} - /* * Managing windows */ @@ -2615,669 +1054,24 @@ * key. If this app is not active, nil should be returned. The key window * is the one that will receive keyboard input. */ -- (NSWindow*) keyWindow +- (UIWindow*) keyWindow { return _key_window; } -/** - * Returns current main window of this application. There need not necessarily - * be a main window, even if app is active, and this should return nil if the - * app is inactive. - */ -- (NSWindow*) mainWindow -{ - return _main_window; -} /** - * Sends aSelector to each window, either in the app's internal window list - * (flag = NO) or their stacking order from front to back on the screen - * (flag = YES, currently not implemented under GNUstep). - */ -- (NSWindow*) makeWindowsPerform: (SEL)aSelector inOrder: (BOOL)flag -{ - NSArray *window_list; - unsigned i, c; - - // so i suppose when flag is YES it only runs on visible windows - if (flag) - { - window_list = GSOrderedWindows(); - } - else - { - window_list = [self windows]; - } - - for (i = 0, c = [window_list count]; i < c; i++) - { - NSWindow *window = [window_list objectAtIndex: i]; - - if ([window performSelector: aSelector] != nil) - { - return window; - } - } - return nil; -} - -/** - * Iconify all windows in the app. - */ -- (void) miniaturizeAll: sender -{ - NSArray *window_list = [self windows]; - unsigned i, count; - - for (i = 0, count = [window_list count]; i < count; i++) - [[window_list objectAtIndex: i] miniaturize: sender]; -} - -/** - * Prevent window reordering in response to most recent mouse down (useful to - * prevent raise-on-mouse-click). Not implemented under GNUstep. - */ -- (void) preventWindowOrdering -{ - //TODO -} - -/** - * Set whether the main run loop will request all visible windows update - * themselves after the current or next event is processed. (Update occurs - * after event dispatch in the loop.) - * This is needed when in NSEventTrackingRunLoopMode. When the application - * is using NSDefaultRunLoopMode or NSModalPanelRunLoopMode windows are updated - * after each loop iteration irrespective of this setting. - */ -- (void) setWindowsNeedUpdate: (BOOL)flag -{ - _windows_need_update = flag; -} - -/** - * Sends each of the app's visible windows an [NSWindow-update] message. - * This method is called automatically for every iteration of the run loop - * in NSDefaultRunLoopMode or NSModalPanelRunLoopMode, but is only called during - * NSEventTrackingRunLoopMode if -setWindowsNeedUpdate: is set to YES. - */ -- (void) updateWindows -{ - NSArray *window_list = [self windows]; - unsigned count = [window_list count]; - unsigned i; - - _windows_need_update = NO; - [nc postNotificationName: NSApplicationWillUpdateNotification object: self]; - - for (i = 0; i < count; i++) - { - NSWindow *win = [window_list objectAtIndex: i]; - if ([win isVisible]) - [win update]; - } - [nc postNotificationName: NSApplicationDidUpdateNotification object: self]; -} - -/** * Returns array of app's visible and invisible windows. */ - (NSArray*) windows { + // TODO we cannot use gnustep-gui method here +#if 0 return GSAllWindows(); +#endif } /** - * Returns window for windowNum. Note the window number can be obtained for - * a window from [NSWindow-windowNumber]. - */ -- (NSWindow *) windowWithWindowNumber: (int)windowNum -{ - return GSWindowWithNumber(windowNum); -} - -/* - * Showing Standard Panels - */ - -/** Calls -orderFrontStandardAboutPanelWithOptions: with nil passed as - the options dictionary. -*/ -- (void) orderFrontStandardAboutPanel: sender -{ - [self orderFrontStandardAboutPanelWithOptions: nil]; -} - -/** OS X compatibility: Calls -orderFrontStandardInfoPanelWithOptions: . -*/ -- (void) orderFrontStandardAboutPanelWithOptions: (NSDictionary *)dictionary -{ - [self orderFrontStandardInfoPanelWithOptions: dictionary]; -} - -/* infoPanel, GNUstep API */ -/** Calls -orderFrontStandardInfoPanelWithOptions: with nil passed as - the options dictionary. -*/ -- (void) orderFrontStandardInfoPanel: sender -{ - [self orderFrontStandardInfoPanelWithOptions: nil]; -} - -/** -

- Orders front the standard info panel for the application, - taking the needed information from the dictionary - argument. There is a single standard info panel per application; - it is created the first time that this method is invoked, and then - reused in all subsequent calls. The application standard info - panel is immutable and can not be changed after creation. Useful - keys for the dictionary are: -

- - - ApplicationName - A string with the name of the - application (eg, "Gorm"). If not available, the - Info-gnustep.plist file is searched for the value of - ApplicationName followed by - NSHumanReadableShortName. If this also fails, the - string returned by [NSProcessInfo-processName] is used. - - - ApplicationDescription - A string with a very short - description of the application (eg, "GNUstep Graphics - Objects Relationship Modeller"). If not available, - Info-gnustep.plist is searched for that key; if this - fails, no application description is shown. - - - ApplicationIcon - An image to be shown near the title. - If not available, Info-gnustep.plist is searched for - ApplicationIcon; if this fails, NSApp's -applicationIconImage - method is used instead. - - - ApplicationRelease - A string with the name of the - application, release included (eg, "Gorm 0.1"). If - not available, the value for ApplicationVersion is - used instead. If this fails, Info-gnustep.plist is - searched for ApplicationRelease or - NSAppVersion, otherwise, "Unknown" is - used. - - - FullVersionID - A string with the full version of the - application (eg, "0.1.2b" or - "snap011100"). If not available, - Version is used instead. If this fails, - Info-gnustep.plist is looked for - NSBuildVersion. If all fails, no full version is - shown. - - - Authors - An array of strings, each one with the name - of an author (eg, [NSArray arrayWithObject: "Nicola Pero - <n.pero\@mi.flashnet.it>"]). If not found, - Info-gnustep.plist is searched for Authors, - if this fails, "Unknown" is displayed. - - - URL - [This field is still under work, so it might be - changed] A string with an URL (eg, "See - http://www.gnustep.org"). - - - Copyright - A string with copyright owners (eg, - "Copyright (C) 2000 The Free Software Foundation, - Inc."). Support for multiple line strings is planned but - not yet available. If not found, Info-gnustep.plist - is searched for Copyright and then (failing this) for - NSHumanReadableCopyright. If all fails, - "Copyright Information Not Available" is used. - - - CopyrightDescription - A string describing the kind of - copyright (eg, "Released under the GNU General Public - License 2.0"). If not available, - Info-gnustep.plist is searched for - CopyrightDescription. If this fails, no copyright - description is shown. - - - */ -- (void) orderFrontStandardInfoPanelWithOptions: (NSDictionary *)dictionary -{ - if (_infoPanel == nil) - _infoPanel = [[GSInfoPanel alloc] initWithDictionary: dictionary]; - - [_infoPanel setTitle: NSLocalizedString (@"Info", - @"Title of the Info Panel")]; - [_infoPanel orderFront: self]; -} - -/* - * Getting the main menu - */ - -/** - * Returns the main menu of the receiver. - */ -- (NSMenu*) mainMenu -{ - return _main_menu; -} - -/** - * Sets the main menu of the receiver. This is sent update messages by the - * main event loop. - */ -- (void) setMainMenu: (NSMenu*)aMenu -{ - if (_main_menu == aMenu) - { - return; - } - - if (_main_menu != nil) - { - [_main_menu setMain: NO]; - } - - ASSIGN(_main_menu, aMenu); - - if (_main_menu != nil) - { - [_main_menu setMain: YES]; - } -} - -/* - Overrides to show transient version of main menu as in NeXTstep. -*/ -- (void) rightMouseDown: (NSEvent*)theEvent -{ - // On right mouse down display the main menu transient - if (_main_menu != nil) - [NSMenu popUpContextMenu: _main_menu - withEvent: theEvent - forView: nil]; - else - [super rightMouseDown: theEvent]; -} - -/** - * Here for compatibility with OS X, but currently a no-op. - */ -- (void) setAppleMenu: (NSMenu*)aMenu -{ - //TODO: Unclear, what this should do. -} - -/* - * Managing the Windows menu - */ - -/** - * Adds an item to the app's Windows menu. This is usually done automatically - * so you don't need to call this method. - */ -- (void) addWindowsItem: (NSWindow*)aWindow - title: (NSString*)aString - filename: (BOOL)isFilename -{ - [self changeWindowsItem: aWindow title: aString filename: isFilename]; -} - -/** - * Removes an item from the app's Windows menu. This is usually done - * automatically so you don't need to call this method. - */ -- (void) removeWindowsItem: (NSWindow*)aWindow -{ - if (_windows_menu) - { - NSArray *itemArray; - unsigned count; - - itemArray = [_windows_menu itemArray]; - count = [itemArray count]; - while (count-- > 0) - { - NSMenuItem *item = [itemArray objectAtIndex: count]; - - if ([item target] == aWindow) - { - [_windows_menu removeItemAtIndex: count]; - return; - } - } - } -} - -// this is an internal helper method for changeWindowsItem:title:filename -// when window represents an editable document -- (void) setImageForWindowsItem: (NSMenuItem *)item -{ - NSImage *oldImage = [item image]; - NSImage *newImage; - - if (!([[item target] styleMask] & NSClosableWindowMask)) - return; - - if ([[item target] isDocumentEdited]) - { - newImage = [NSImage imageNamed: @"common_CloseBroken"]; - } - else - { - newImage = [NSImage imageNamed: @"common_Close"]; - } - - if (newImage != oldImage) - { - [item setImage: newImage]; - } -} - -/** Changes the Window menu item associated with aWindow to aString. If no - associated window item exists, one is created. If isFilename is YES, then - aString is assumed to be a filename representation the way - [NSWindow-setTitleWithRepresentedFilename:] would format it, otherwise - the string is displayed literally in the menu item. - */ -- (void) changeWindowsItem: (NSWindow*)aWindow - title: (NSString*)aString - filename: (BOOL)isFilename -{ - NSArray *itemArray; - unsigned count; - unsigned i; - id item; - - if (![aWindow isKindOfClass: [NSWindow class]]) - [NSException raise: NSInvalidArgumentException - format: @"Object of bad type passed as window"]; - - if (isFilename) - { - NSRange r = [aString rangeOfString: @" -- "]; - - if (r.length > 0) - { - aString = [aString substringToIndex: r.location]; - } - } - - /* - * If there is no menu and nowhere to put one, we can't do anything. - */ - if (_windows_menu == nil) - return; - - /* - * Check if the window is already in the menu. - */ - itemArray = [_windows_menu itemArray]; - count = [itemArray count]; - for (i = 0; i < count; i++) - { - NSMenuItem *item = [itemArray objectAtIndex: i]; - - if ([item target] == aWindow) - { - /* - * If our menu item already exists and with the correct - * title, we need not continue. - */ - if ([[item title] isEqualToString: aString]) - { - return; - } - else - { - /* - * Else, we need to remove the old item and add it again - * with the new title. Then new item might be located - * somewhere else in the menu than the old one (because - * items in the menu are sorted by title) ... this is - * why we remove the old one and then insert it again. - */ - [_windows_menu removeItem: item]; - break; - } - } - } - - /* - * Can't permit an untitled window in the window menu ... so if the - * window has not title, we don't add it to the menu. - */ - if (aString == nil || [aString isEqualToString: @""]) - return; - - /* - * Now we insert a menu item for the window in the correct order. - * Window menu items are inserted in alphabetic order at the bottom - * of the windows menu except for two special items with actions - * 'performMiniaturize: ' and 'performClose: '. If these exist the - * they are kept at the below all window entries in the menu. - */ - itemArray = [_windows_menu itemArray]; - count = [itemArray count]; - - if (count > 0 && sel_isEqual([[itemArray objectAtIndex: count-1] action], - @selector(performClose:))) - count--; - if (count > 0 && sel_isEqual([[itemArray objectAtIndex: count-1] action], - @selector(performMiniaturize:))) - count--; - for (i = 0; i < count; i++) - { - NSMenuItem *item = [itemArray objectAtIndex: i]; - if ([[item target] isKindOfClass: [NSWindow class]] && - sel_isEqual([item action], @selector(makeKeyAndOrderFront:))) - break; - } - - while (i < count) - { - item = [itemArray objectAtIndex: i]; - - if ([[item title] compare: aString] == NSOrderedDescending) - break; - i++; - } - - item = [_windows_menu insertItemWithTitle: aString - action: @selector(makeKeyAndOrderFront:) - keyEquivalent: @"" - atIndex: i]; - [item setTarget: aWindow]; - - // When changing for a window with a file, we should also set the image. - [self setImageForWindowsItem: item]; -} - -/** - * Update Windows menu item for aWindow, to reflect its edited status. This - * is usually done automatically so you don't need to call this. - */ -- (void) updateWindowsItem: (NSWindow*)aWindow -{ - NSMenu *menu; - - menu = [self windowsMenu]; - if (menu != nil) - { - NSArray *itemArray; - unsigned count; - unsigned i; - BOOL found = NO; - - itemArray = [menu itemArray]; - count = [itemArray count]; - for (i = 0; i < count; i++) - { - NSMenuItem *item = [itemArray objectAtIndex: i]; - - if ([item target] == aWindow) - { - [self setImageForWindowsItem: item]; - break; - } - } - - if (found == NO) - { - NSString *t = [aWindow title]; - NSString *f = [aWindow representedFilename]; - - f = [NSString stringWithFormat: @"%@ -- %@", - [f lastPathComponent], - [f stringByDeletingLastPathComponent]]; - [self changeWindowsItem: aWindow - title: t - filename: [t isEqual: f]]; - } - } -} - -/** - * Sets the windows menu of the receiver. The windows menu keeps track of all - * windows open in the application. - */ -- (void) setWindowsMenu: (NSMenu*)aMenu -{ - if (_windows_menu == aMenu) - { - return; - } - - /* - * Remove all the windows from the old windows menu. - */ - if (_windows_menu != nil) - { - NSArray *itemArray = [_windows_menu itemArray]; - unsigned i, count = [itemArray count]; - - for (i = 0; i < count; i++) - { - NSMenuItem *anItem = [itemArray objectAtIndex: i]; - id win = [anItem target]; - - if ([win isKindOfClass: [NSWindow class]]) - { - [_windows_menu removeItem: anItem]; - } - } - } - - /* Set the new _windows_menu. */ - ASSIGN (_windows_menu, aMenu); - - { - /* - * Now use [-changeWindowsItem:title:filename:] to build the new menu. - */ - NSArray * windows = [self windows]; - unsigned i, count = [windows count]; - for (i = 0; i < count; i++) - { - NSWindow *win = [windows objectAtIndex: i]; - - if (([win isExcludedFromWindowsMenu] == NO) - && ([win isVisible] || [win isMiniaturized])) - { - NSString *t = [win title]; - NSString *f = [win representedFilename]; - - f = [NSString stringWithFormat: @"%@ -- %@", - [f lastPathComponent], - [f stringByDeletingLastPathComponent]]; - [self changeWindowsItem: win - title: t - filename: [t isEqual: f]]; - } - } - } -} - -/** - * Returns current Windows menu for the application (whose window contents are - * managed automatically by this class and NSWindow). - */ -- (NSMenu*) windowsMenu -{ - return _windows_menu; -} - -/* - * Managing the Service menu - */ - -/** - * Registers the types this application can send and receive over Services. - * sendTypes represents the pasteboard types this app can receive in Service - * invocation. This is used to set up the services menu of this app -- an - * item is added for each registered service that can accept one of sendTypes - * or return one of returnTypes - */ -- (void) registerServicesMenuSendTypes: (NSArray *)sendTypes - returnTypes: (NSArray *)returnTypes -{ - [_listener registerSendTypes: sendTypes - returnTypes: returnTypes]; -} - -/**

Returns the services menu of the receiver.

-

See Also: -setServicesMenu:

- */ -- (NSMenu *) servicesMenu -{ - return [_listener servicesMenu]; -} - -/**

Returns the services provided previously registered using the - * -setServicesProvider: method.

See Also: -setServicesProvider:

- */ -- (id) servicesProvider -{ - return [_listener servicesProvider]; -} - -/**

ets the services menu for the receiver. This should be called, otherwise - * warnings will be generated by the main event loop, which is in charge of - * updating all menus, including the Services menu.

- *

See Also: -servicesMenu

- */ -- (void) setServicesMenu: (NSMenu *)aMenu -{ - [_listener setServicesMenu: aMenu]; -} - -/** - * Sets the object which provides services to other applications.
- * Passing a nil value for anObject will result in the provision of - * services to other applications by this application being disabled.
- * See [NSPasteboard] for information about providing services. - */ -- (void) setServicesProvider: (id)anObject -{ - [_listener setServicesProvider: anObject]; -} - -/** * Return an object capable of sending and receiving the specified sendType * and returnType in a services interaction. NSApp is generally the last * responder to get this request, and the implementation passes it on to the @@ -3287,7 +1081,7 @@ - (id) validRequestorForSendType: (NSString *)sendType returnType: (NSString *)returnType { - if (_delegate != nil && ![_delegate isKindOfClass: [NSResponder class]] + if (_delegate != nil && ![_delegate isKindOfClass: [UIResponder class]] && [_delegate respondsToSelector: @selector(validRequestorForSendType:returnType:)]) return [_delegate validRequestorForSendType: sendType @@ -3296,6 +1090,8 @@ return nil; } +#if 0 +// TODO no NSGraphicsContext equivalent yet /** * Returns the default drawing context for the app. */ @@ -3303,6 +1099,7 @@ { return _default_context; } +#endif /** * NSLogs an exception without raising it. @@ -3313,219 +1110,8 @@ NSLog (_(@"reported exception - %@"), anException); } -- (BOOL) presentError: (NSError *)error -{ - NSAlert *alert; - int result; - - error = [self willPresentError: error]; - alert = [NSAlert alertWithError: error]; - result = [alert runModal]; - - if (result != NSAlertErrorReturn) - { - // Convert result (1, 0, -1) into index (0, 1, 2) - result = 1 - result; - return [[error recoveryAttempter] attemptRecoveryFromError: error - optionIndex: result]; - } - else - { - return NO; - } -} - -struct _DelegateWrapper -{ - id delegate; - SEL selector; - NSError *error; - void *context; -}; - -- (void) presentError: (NSError*)error - modalForWindow: (NSWindow*)window - delegate: (id)delegate - didPresentSelector: (SEL)sel - contextInfo: (void*)context -{ - NSAlert *alert; - struct _DelegateWrapper *wrapper; - - error = [self willPresentError: error]; - alert = [NSAlert alertWithError: error]; - // FIXME: Who is trying to recover the error? - wrapper = malloc(sizeof(struct _DelegateWrapper)); - wrapper->delegate = delegate; - wrapper->selector = sel; - wrapper->error = error; - wrapper->context = context; - - [alert beginSheetModalForWindow: window - modalDelegate: self - didEndSelector: @selector(_didPresentError:returnCode:contextInfo:) - contextInfo: wrapper]; -} - -- (void) _didPresentError: (NSWindow*)sheet - returnCode: (int)result - contextInfo: (void*)context -{ - struct _DelegateWrapper *wrapper; - id delegate; - SEL sel; - NSError *error; - void *orgContext; - BOOL recover; - - wrapper = (struct _DelegateWrapper*)context; - delegate = wrapper->delegate; - sel = wrapper->selector; - error = wrapper->error; - orgContext = wrapper->context; - free(wrapper); - - if (result != NSAlertErrorReturn) - { - // Convert result (1, 0, -1) into index (0, 1, 2) - result = 1 - result; - recover = [[error recoveryAttempter] attemptRecoveryFromError: error - optionIndex: result]; - } - else - { - recover = NO; - } - - if ([delegate respondsToSelector: sel]) - { - void (*didEnd)(id, SEL, BOOL, void*); - - didEnd = (void (*)(id, SEL, BOOL, void*))[delegate methodForSelector: sel]; - didEnd(delegate, sel, recover, orgContext); - } -} - -- (NSError*) willPresentError: (NSError*)error -{ - if ([_delegate respondsToSelector: @selector(application:willPresentError:)]) - { - return [_delegate application: self willPresentError: error]; - } - else - { - return error; - } -} - /** - * Requests the application terminates the application. First an - * -applicationShouldTerminate: message is sent to the delegate, and only if - * it returns NSTerminateNow will termination be - * carried out.
- * The old version of -applicationShouldTerminate: returned a BOOL, and this - * should still work as YES is - * equivalent to NSTerminateNow and NO is - * equivalent to NSTerminateCancel. - */ -- (void) terminate: (id)sender -{ - NSDocumentController *sdc; - NSApplicationTerminateReply termination; - - /* First ask the shared document controller to save any unsaved changes */ - sdc = [NSDocumentController sharedDocumentController]; - if ([[sdc documentClassNames] count] > 0) - { - if ([sdc reviewUnsavedDocumentsWithAlertTitle: _(@"Quit") - cancellable: YES] == NO) - { - return; - } - } - - /* Now ask the application delegate whether its okay to terminate */ - termination = NSTerminateNow; - if ([_delegate respondsToSelector: @selector(applicationShouldTerminate:)]) - { - /* The old API has applicationShouldTerminate: return a BOOL, - * so if we are linked in to an application which used that - * API, the delegate might return a BOOL rather than an - * NSTerminateNow. That's fine as both NSTerminateNow - * and BOOL are integral types (though potentially of different sizes), - * and NSTerminateNow is defined as YES and NSTerminateCancel as NO. - * So all we need to do is mask the low byte of the return value in - * case there is uninitialised random data in the higher bytes. - */ - termination = ([_delegate applicationShouldTerminate: self] & 0xff); - } - - if (termination == NSTerminateNow) - { - [self replyToApplicationShouldTerminate: YES]; - } - /* - Don't need to do anything on NSTerminateLater, as long as user code - follows the contract (to call replyTo... later). - */ -} - -/** - * Terminates the app if shouldTerminate is YES, otherwise does nothing. - * This should be called by user code if a delegate has returned - * NSTerminateLater to an -applicationShouldTerminate: message. - */ -- (void) replyToApplicationShouldTerminate: (BOOL)shouldTerminate -{ - // Prevent cycles in terminate: call. - if (shouldTerminate && _app_is_running) - { - [nc postNotificationName: NSApplicationWillTerminateNotification - object: self]; - - _app_is_running = NO; - - GSRemoveIcon(_app_icon_window); - [[self windows] makeObjectsPerformSelector: @selector(close)]; - [NSCursor setHiddenUntilMouseMoves: NO]; - - /* Store our user information. */ - [[NSUserDefaults standardUserDefaults] synchronize]; - - /* Tell the Workspace that we really did terminate. */ - [[[NSWorkspace sharedWorkspace] notificationCenter] - postNotificationName: NSWorkspaceDidTerminateApplicationNotification - object: [NSWorkspace sharedWorkspace] - userInfo: [self _notificationUserInfo]]; - - /* Destroy the main run loop pool (this also destroys any nested - pools which might have been created inside this one). */ - DESTROY (_runLoopPool); - - /* Now free the NSApplication object. Enclose the operation - into an autorelease pool, in case some -dealloc method needs - to use any temporary object. */ - { - NSAutoreleasePool *pool; - - IF_NO_GC(pool = [arpClass new]); - - DESTROY(NSApp); - - DESTROY(pool); - } - - /* And finally, stop the program. */ - exit(0); - } -} - -- (void) replyToOpenOrPrint: (NSApplicationDelegateReply)reply -{ - // FIXME -} - -/** + * NOTE: Documentation not updated for UIKit. * Returns the application's delegate, as set by the -setDelegate: method.
*

The application delegate will automatically be sent various * notifications (as long as it implements the appropriate methods) @@ -3599,221 +1185,24 @@ if ([_delegate respondsToSelector: @selector(application##notif_name:)]) \ [nc addObserver: _delegate \ selector: @selector(application##notif_name:) \ - name: NSApplication##notif_name##Notification object: self] + name: UIApplication##notif_name##Notification object: self] - SET_DELEGATE_NOTIFICATION(DidBecomeActive); + SET_DELEGATE_NOTIFICATION(WillEnterForeground); + SET_DELEGATE_NOTIFICATION(DidEnterBackground); SET_DELEGATE_NOTIFICATION(DidFinishLaunching); - SET_DELEGATE_NOTIFICATION(DidHide); - SET_DELEGATE_NOTIFICATION(DidResignActive); - SET_DELEGATE_NOTIFICATION(DidUnhide); - SET_DELEGATE_NOTIFICATION(DidUpdate); - SET_DELEGATE_NOTIFICATION(WillBecomeActive); - SET_DELEGATE_NOTIFICATION(WillFinishLaunching); - SET_DELEGATE_NOTIFICATION(WillHide); - SET_DELEGATE_NOTIFICATION(WillResignActive); SET_DELEGATE_NOTIFICATION(WillTerminate); - SET_DELEGATE_NOTIFICATION(WillUnhide); - SET_DELEGATE_NOTIFICATION(WillUpdate); } /* * Methods for scripting */ -/** - * OS X scripting method to return document objects being handled by - * application. Not implemented yet under GNUstep. - */ -- (NSArray *) orderedDocuments -{ - // FIXME - return nil; -} -/** - * OS X scripting method to return windows in front-to-back on-screen order - * for scriptable windows. - * The GNUstep implementation returns all the windows excluding NSPanels. - * some backends may return an array in an unspecified order. - */ -- (NSArray *) orderedWindows -{ - NSArray *arr = GSOrderedWindows(); - NSMutableArray *ret = [[NSMutableArray alloc] initWithCapacity:[arr count]]; - NSEnumerator *iter = [arr objectEnumerator]; - id win; - while ((win = [iter nextObject])) - { - if (![win isKindOfClass:[NSPanel class]]) - [ret addObject:win]; - } - - return AUTORELEASE(ret); -} +@end /* UIApplication */ -/* - * Methods for user attention requests - */ -/** - * Cancels a request previously made through calling -requestUserAttention: . - * Note that request is cancelled automatically if user activates the app. - */ -- (void) cancelUserAttentionRequest: (int)request -{ - // FIXME -} +@implementation UIApplication (Private) -/** - * Method that on OS X makes the icon jump in the doc. Mercifully, this is - * unimplemented under GNUstep. If it were implemented, requestType - * could be either NSCriticalRequest (bounce endlessly) or - * NSInformationalRequest (bounce for one second). - */ -- (int) requestUserAttention: (NSRequestUserAttentionType)requestType -{ - // FIXME - return 0; -} - -/* - * NSCoding protocol - */ -- (void) encodeWithCoder: (NSCoder*)aCoder -{ - [super encodeWithCoder: aCoder]; - if ([aCoder allowsKeyedCoding]) - { - /* - if (_delegate != nil) - { - [aCoder encodeObject: _delegate forKey: @"NSDelegate"]; - } - [aCoder encodeObject: _main_menu forKey: @"NSMainMenu"]; // ??? - [aCoder encodeObject: _windows_menu forKey: @"NSWindowsMenu"]; // ??? - */ - } - else - { - [aCoder encodeConditionalObject: _delegate]; - [aCoder encodeObject: _main_menu]; - [aCoder encodeConditionalObject: _windows_menu]; - } -} - -- (id) initWithCoder: (NSCoder*)aDecoder -{ - id obj; - - [super initWithCoder: aDecoder]; - if ([aDecoder allowsKeyedCoding]) - { - /* - if ([aDecoder containsValueForKey: @"NSDelegate"]) - { - obj = [aDecoder decodeObjectForKey: @"NSDelegate"]; - [self setDelegate: obj]; - } - obj = [aDecoder decodeObjectForKey: @"NSMainMenu"]; - [self setMainMenu: obj]; - obj = [aDecoder decodeObjectForKey: @"NSWindowsMenu"]; - [self setWindowsMenu: obj]; - */ - } - else - { - obj = [aDecoder decodeObject]; - [self setDelegate: obj]; - obj = [aDecoder decodeObject]; - [self setMainMenu: obj]; - obj = [aDecoder decodeObject]; - [self setWindowsMenu: obj]; - } - return self; -} - -@end /* NSApplication */ - - -@implementation NSApplication (Private) - -- (void) _appIconInit -{ - NSDictionary *infoDict; - NSString *appIconFile; - NSImage *image = nil; - NSAppIconView *iv; - unsigned mask = NSIconWindowMask; - BOOL suppress; - - suppress = [[NSUserDefaults standardUserDefaults] - boolForKey: @"GSSuppressAppIcon"]; -#if MINI_ICON - if (suppress) - { - mask = NSMiniaturizableWindowMask; - } -#endif - - infoDict = [[NSBundle mainBundle] infoDictionary]; - appIconFile = [infoDict objectForKey: @"NSIcon"]; - if (appIconFile && ![appIconFile isEqual: @""]) - { - image = [NSImage imageNamed: appIconFile]; - } - - // Try to look up the icns file. - appIconFile = [infoDict objectForKey: @"CFBundleIconFile"]; - if (appIconFile && ![appIconFile isEqual: @""]) - { - image = [NSImage imageNamed: appIconFile]; - } - - if (image == nil) - { - image = [NSImage imageNamed: @"GNUstep"]; - } - else - { - /* Set the new image to be named 'NSApplicationIcon' ... to do that we - * must first check that any existing image of the same name has its - * name removed. - */ - [(NSImage*)[NSImage imageNamed: @"NSApplicationIcon"] setName: nil]; - // We need to copy the image as we may have a proxy here - image = AUTORELEASE([image copy]); - [image setName: @"NSApplicationIcon"]; - } - [self setApplicationIconImage: image]; - - _app_icon_window = [[NSIconWindow alloc] initWithContentRect: NSZeroRect - styleMask: mask - backing: NSBackingStoreRetained - defer: NO - screen: nil]; - - - - { - NSRect iconContentRect = GSGetIconFrame(_app_icon_window); - NSRect iconFrame = [_app_icon_window frameRectForContentRect: iconContentRect]; - NSRect iconViewFrame = NSMakeRect(0, 0, iconContentRect.size.width, iconContentRect.size.height); - [_app_icon_window setFrame: iconFrame display: YES]; - - iv = [[NSAppIconView alloc] initWithFrame: iconViewFrame]; - [iv setImage: _app_icon]; - [_app_icon_window setContentView: iv]; - RELEASE(iv); - } - - if (NO == suppress) - { - /* The icon window is not suppressed ... display it. - */ - [_app_icon_window orderFrontRegardless]; - } -} - - (NSDictionary*) _notificationUserInfo { NSString *path; @@ -3859,11 +1248,8 @@ return userInfo; } -- (void) _openDocument: (NSString*)filePath -{ - [_listener application: self openFile: filePath]; -} - +#if 0 +/// TODO study what this is used for - (id) _targetForAction: (SEL)aSelector keyWindow: (NSWindow *)keyWindow mainWindow: (NSWindow *)mainWindow @@ -3971,15 +1357,17 @@ /* give up */ return nil; } - +#endif - (void) _windowDidBecomeKey: (NSNotification*) notification { id obj = [notification object]; - if (_key_window == nil && [obj isKindOfClass: [NSWindow class]]) + if (_key_window == nil && [obj isKindOfClass: [UIWindow class]]) { _key_window = obj; +/* [_main_menu update]; +*/ } else if (_key_window != obj) { @@ -3987,21 +1375,6 @@ } } -- (void) _windowDidBecomeMain: (NSNotification*) notification -{ - id obj = [notification object]; - - if (_main_window == nil && [obj isKindOfClass: [NSWindow class]]) - { - _main_window = obj; - [_main_menu update]; - } - else if (_main_window != obj) - { - NSLog(@"Bogus attempt to set main window"); - } -} - - (void) _windowDidResignKey: (NSNotification*) notification { id obj = [notification object]; @@ -4009,7 +1382,9 @@ if (_key_window == obj) { _key_window = nil; +/* [NSCursor setHiddenUntilMouseMoves: NO]; + */ } else { @@ -4017,79 +1392,8 @@ } } -- (void) _windowDidResignMain: (NSNotification*) notification -{ - id obj = [notification object]; - - if (_main_window == obj) - { - _main_window = nil; - } - else - { - NSLog(@"Bogus attempt to resign key window"); - } -} - -- (void) _lastWindowClosed -{ - if ([_delegate respondsToSelector: - @selector(applicationShouldTerminateAfterLastWindowClosed:)]) - { - if ([_delegate - applicationShouldTerminateAfterLastWindowClosed: self]) - { - [self terminate: self]; - } - } - /* wlux 2009-10-17: If we use MS Windows style menus, terminate - the application by default when the last window is closed. */ - else if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil) == - NSWindows95InterfaceStyle) - { - [self terminate: self]; - } -} - -- (void) _windowWillClose: (NSNotification*) notification -{ - NSWindow *win = [notification object]; - - if (_app_is_running) - { - /* FIXME Don't use GSOrderedWindows(), since it may not return all - windows when the application is hidden. E.g., given a hidden - application with a single window with canHide == NO, if the user - closes this window it would appear as if the last window was closed. */ - NSArray *windows_list = GSOrderedWindows(); - NSEnumerator *iter = [windows_list objectEnumerator]; - BOOL wasLast = YES; - NSWindow *tmp; - - while ((tmp = [iter nextObject])) - { - if (tmp != win && [tmp canBecomeMainWindow] == YES) - { - wasLast = NO; - break; - } - } - - /* Perform _lastWindowDidClose at the end of the event loop cycle so - that all interested objects are notified before we terminate the - application. In particular, this means that a modified document - associated with the closed window has been closed before -terminate: - is called and therefore the user isn't asked twice whether she wants - to save that document's unsaved changes. */ - if (wasLast) - { - [self performSelector: @selector(_lastWindowClosed) - withObject: nil - afterDelay: 0.1]; - } - } -} - +#if 0 +// Reenable when we have Springboard/Workspace - (void) _workspaceNotification: (NSNotification*) notification { NSString *name = [notification name]; @@ -4112,109 +1416,18 @@ } } } +#endif -- (NSArray *) _openFiles -{ - NSMutableArray *files = nil; - NSArray *args = [[NSProcessInfo processInfo] arguments]; - NSEnumerator *en = [args objectEnumerator]; - NSString *file = nil; - [en nextObject]; // skip the first element, which is always empty... - while((file = [en nextObject]) != nil) - { - unichar c = [file characterAtIndex: 0]; - if(c != '-') - { - if(files == nil) - { - files = [NSMutableArray array]; - } - [files addObject: file]; - } - else - { - break; - } - } +@end // UIApplication (Private) - return files; -} -- (NSMenu *) _dockMenu -{ - NSUInteger i, j, n; - NSMenu *dockMenu, *windowsMenu; +@implementation UIApplication (GSGUIInternal) - // ask delegate for a dock menu, if none create a new one - dockMenu = nil; - if ([_delegate respondsToSelector: @selector(applicationDockMenu:)]) - { - // NB we make a copy of the menu since we are going to modify it - dockMenu = [[_delegate applicationDockMenu: self] copy]; - } - if (dockMenu == nil) - { - dockMenu = [[NSMenu alloc] initWithTitle:@""]; - } - - // copy window menu entries to the top of the menu - windowsMenu = [NSApp windowsMenu]; - for (i = j = 0, n = [windowsMenu numberOfItems]; i < n; i++) - { - NSMenuItem *item = [windowsMenu itemAtIndex: i]; - if ([[item target] isKindOfClass:[NSWindow class]] && - sel_isEqual([item action], @selector(makeKeyAndOrderFront:))) - { - [[dockMenu insertItemWithTitle: [item title] - action: @selector(makeKeyAndOrderFront:) - keyEquivalent: @"" - atIndex: j++] - setTarget: [item target]]; - } - } - if (j > 0) - { - [dockMenu insertItem: [NSMenuItem separatorItem] atIndex: j++]; - } - - // insert standard entries to show or hide and to quit the application at - // the bottom - if (j < [dockMenu numberOfItems]) - { - [dockMenu addItem: [NSMenuItem separatorItem]]; - } - if ([self isHidden]) - { - [dockMenu addItemWithTitle:_(@"Show") - action:@selector(unhide:) - keyEquivalent:@""]; - } - else - { - [dockMenu addItemWithTitle:_(@"Hide") - action:@selector(hide:) - keyEquivalent:@""]; - } - [dockMenu addItemWithTitle:_(@"Quit") - action:@selector(terminate:) - keyEquivalent:@""]; - - // return the menu - return dockMenu; -} - -@end // NSApplication (Private) - - -@implementation NSApplication (GSGUIInternal) - -- (void) _windowWillDealloc: (NSWindow *)window +- (void) _windowWillDealloc: (UIWindow *)window { if (window == _key_window) _key_window = nil; - if (window == _main_window) - _main_window = nil; } @end Index: GNUmakefile =================================================================== --- GNUmakefile (revision 33949) +++ GNUmakefile (working copy) @@ -1,10 +1,12 @@ -# The main makefile of the GNUstep Core Data framework. -# Copyright (C) 2005 Free Software Foundation, Inc. +# The main makefile of the GNUstep UIKit framework. +# Copyright (C) 2005,2011 Free Software Foundation, Inc. # # Written by: Saso Kiselkov # Date: August 2005 +# Modified by: Ivan Vucica +# Date: November 2011 # -# This file is part of the GNUstep Core Data framework. +# This file is part of the GNUstep UIKit framework. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -40,11 +42,11 @@ include $(GNUSTEP_MAKEFILES)/common.make -PROJECT_NAME=CoreData +PROJECT_NAME=UIKit FRAMEWORK_NAME=$(PROJECT_NAME) $(PROJECT_NAME)_OBJC_FILES=$(wildcard *.m) -$(PROJECT_NAME)_HEADER_FILES=$(filter-out CoreDataUtilities.h, $(wildcard *.h)) +$(PROJECT_NAME)_HEADER_FILES=$(wildcard *.h) #$(filter-out CoreDataUtilities.h, $(wildcard *.h)) $(PROJECT_NAME)_RESOURCE_FILES=$(wildcard Resources/*) Index: Headers/UIApplication.h =================================================================== --- Headers/UIApplication.h (revision 33949) +++ Headers/UIApplication.h (working copy) @@ -1,9 +1,9 @@ /** - NSApplication.h + UIApplication.h - The one and only application class + The "other" application class - Copyright (C) 1996,1999 Free Software Foundation, Inc. + Copyright (C) 1996,1999,2011 Free Software Foundation, Inc. Author: Scott Christley Date: 1996 @@ -11,8 +11,10 @@ Date: August 1998 Author: Richard Frith-Macdonald Date: December 1998 + Author: Ivan Vucica + Date: October 2011 - This file is part of the GNUstep GUI Library. + This file is part of the GNUstep UIKit Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -30,16 +32,15 @@ Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - AutogsdocSource: NSApplication.m - AutogsdocSource: GSServicesManager.m + AutogsdocSource: UIApplication.m */ -#ifndef _GNUstep_H_NSApplication -#define _GNUstep_H_NSApplication +#ifndef _GNUstep_UIKit_H_UIApplication +#define _GNUstep_UIKit_H_UIApplication #import -#import +#import @class NSArray; @class NSAutoreleasePool; @@ -50,103 +51,33 @@ @class NSNotification; @class NSString; @class NSTimer; - +/* @class NSEvent; @class NSGraphicsContext; @class NSImage; @class NSMenu; @class NSMenuItem; +*/ @class NSPasteboard; -@class NSWindow; +@class UIWindow; @class GSInfoPanel; -typedef struct _NSModalSession *NSModalSession; - enum { NSRunStoppedResponse = (-1000), NSRunAbortedResponse = (-1001), NSRunContinuesResponse = (-1002) }; -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -#define NSUpdateWindowsRunLoopOrdering 600000 -/** -* Returned by -applicationShouldTerminate: when -terminate: is called. -* Possible types include: -* -* NSTerminateCancel; -* NSTerminateNow; -* NSTerminateLater. -* -*/ -typedef enum { - NSTerminateCancel = NO, - NSTerminateNow = YES, - NSTerminateLater -} NSApplicationTerminateReply; +UIKIT_EXPORT NSString *NSEventTrackingRunLoopMode; -/** -* Type used by -requestUserAttention: when an applications opened. Possible values are: -* -* NSCriticalRequest; -* NSInformationalRequest; -* -*/ -typedef enum { - NSCriticalRequest, - NSInformationalRequest -} NSRequestUserAttentionType; - -#define NSAppKitVersionNumber10_0 0 -#endif - -#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) -typedef enum _NSApplicationDelegateReply +@interface UIApplication : UIResponder { - NSApplicationDelegateReplySuccess =0, - NSApplicationDelegateReplyCancel =1, - NSApplicationDelegateReplyFailure =2 -} NSApplicationDelegateReply; - -typedef enum _NSApplicationPrintReply -{ - NSPrintingCancelled = NO, - NSPrintingSuccess = YES, - NSPrintingFailure, - NSPrintingReplyLater -} NSApplicationPrintReply; -#endif - -APPKIT_EXPORT NSString *NSModalPanelRunLoopMode; -APPKIT_EXPORT NSString *NSEventTrackingRunLoopMode; - -@interface NSApplication : NSResponder -{ - NSGraphicsContext *_default_context; NSEvent *_current_event; - NSModalSession _session; - NSWindow *_key_window; - NSWindow *_main_window; + UIWindow *_key_window; id _delegate; - id _listener; - NSMenu *_main_menu; - NSMenu *_windows_menu; // 6 bits - BOOL _app_is_launched; - BOOL _app_is_running; - BOOL _app_is_active; - BOOL _app_is_hidden; - BOOL _unhide_on_activation; - BOOL _windows_need_update; - NSImage *_app_icon; - NSWindow *_app_icon_window; - NSMutableArray *_hidden; - NSMutableArray *_inactive; - NSWindow *_hidden_key; - NSWindow *_hidden_main; - GSInfoPanel *_infoPanel; /* This autorelease pool should only be created and used by -run, with a single exception (which is why it is stored here as an ivar): the @@ -166,59 +97,28 @@ #endif /* - * Creating and initializing the NSApplication + * Creating and initializing the UIApplication */ -+ (NSApplication*) sharedApplication; ++ (UIApplication*) sharedApplication; /* * Instance methods */ /* - * Creating and initializing the NSApplication + * Creating and initializing the UIApplication */ - (void) finishLaunching; -/* - * Changing the active application - */ -- (void) activateIgnoringOtherApps: (BOOL)flag; -- (void) deactivate; -- (BOOL) isActive; -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -- (void) hideOtherApplications: (id)sender; -- (void) unhideAllApplications: (id)sender; -#endif /* * Running the event loop */ -- (void) abortModal; -- (NSModalSession) beginModalSessionForWindow: (NSWindow*)theWindow; -- (void) endModalSession: (NSModalSession)theSession; - (BOOL) isRunning; - (void) run; -- (int) runModalForWindow: (NSWindow*)theWindow; -- (int) runModalSession: (NSModalSession)theSession; -- (NSWindow *) modalWindow; - (void) sendEvent: (NSEvent*)theEvent; - (void) stop: (id)sender; -- (void) stopModal; -- (void) stopModalWithCode: (int)returnCode; -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -- (int) runModalForWindow: (NSWindow *)theWindow - relativeToWindow: (NSWindow *)docWindow; -- (void) beginSheet: (NSWindow *)sheet - modalForWindow: (NSWindow *)docWindow - modalDelegate: (id)modalDelegate - didEndSelector: (SEL)didEndSelector - contextInfo: (void *)contextInfo; -- (void) endSheet: (NSWindow *)sheet; -- (void) endSheet: (NSWindow *)sheet - returnCode: (int)returnCode; -#endif - /* * Getting, removing, and posting events */ @@ -237,292 +137,38 @@ - (BOOL) sendAction: (SEL)aSelector to: (id)aTarget from: (id)sender; -- (id) targetForAction: (SEL)aSelector; -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -- (id)targetForAction: (SEL)theAction - to: (id)theTarget - from: (id)sender; -#endif -- (BOOL) tryToPerform: (SEL)aSelector - with: (id)anObject; -/* - * Setting the application's icon - */ -- (void) setApplicationIconImage: (NSImage*)anImage; -- (NSImage*) applicationIconImage; /* - * Hiding all windows - */ -- (void) hide: (id)sender; -- (BOOL) isHidden; -- (void) unhide: (id)sender; -- (void) unhideWithoutActivation; - -/* * Managing windows */ -- (NSWindow*) keyWindow; -- (NSWindow*) mainWindow; -- (NSWindow*) makeWindowsPerform: (SEL)aSelector - inOrder: (BOOL)flag; -- (void) miniaturizeAll: (id)sender; -- (void) preventWindowOrdering; -- (void) setWindowsNeedUpdate: (BOOL)flag; -- (void) updateWindows; +- (UIWindow*) keyWindow; - (NSArray*) windows; -- (NSWindow*) windowWithWindowNumber: (int)windowNum; /* - * Showing Standard Panels - */ -#if OS_API_VERSION(GS_API_NONE, GS_API_NONE) -/* GNUstep extensions displaying an infoPanel, title is 'Info' */ -/* For a list of the useful values in the dictionary, see GSInfoPanel.h. - The entries are mostly compatible with macosx. */ -- (void) orderFrontStandardInfoPanel: (id)sender; -- (void) orderFrontStandardInfoPanelWithOptions: (NSDictionary *)dictionary; -#endif -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -/* macosx extensions displaying an aboutPanel, title is 'About'. - NB: These two methods do exactly the same as the two methods above, - only the title is different. */ -- (void) orderFrontStandardAboutPanel: (id)sender; -- (void) orderFrontStandardAboutPanelWithOptions: (NSDictionary *)dictionary; -#endif - -/* - * Getting the main menu - */ -- (NSMenu*) mainMenu; -- (void) setMainMenu: (NSMenu*)aMenu; -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -- (void) setAppleMenu: (NSMenu*)aMenu; -#endif - -/* - * Managing the Windows menu - */ -- (void) addWindowsItem: (NSWindow*)aWindow - title: (NSString*)aString - filename: (BOOL)isFilename; -- (void) arrangeInFront: (id)sender; -- (void) changeWindowsItem: (NSWindow*)aWindow - title: (NSString*)aString - filename: (BOOL)isFilename; -- (void) removeWindowsItem: (NSWindow*)aWindow; -- (void) setWindowsMenu: (NSMenu*)aMenu; -- (void) updateWindowsItem: (NSWindow*)aWindow; -- (NSMenu*) windowsMenu; - -/* - * Managing the Service menu - */ -- (void) registerServicesMenuSendTypes: (NSArray*)sendTypes - returnTypes: (NSArray*)returnTypes; -- (NSMenu*) servicesMenu; -- (id) servicesProvider; -- (void) setServicesMenu: (NSMenu*)aMenu; -- (void) setServicesProvider: (id)anObject; -- (id) validRequestorForSendType: (NSString*)sendType - returnType: (NSString*)returnType; - -/* - * Getting the display context - */ -- (NSGraphicsContext*) context; - -/* - * Reporting an exception - */ -- (void) reportException: (NSException*)anException; - -/* - * Terminating the application - */ -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -- (void) replyToApplicationShouldTerminate: (BOOL)shouldTerminate; -#endif -#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) -- (void) replyToOpenOrPrint: (NSApplicationDelegateReply)reply; -#endif -- (void) terminate: (id)sender; - -/* * Assigning a delegate */ - (id) delegate; - (void) setDelegate: (id)anObject; -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -/* - * Methods for scripting - */ -- (NSArray *) orderedDocuments; -- (NSArray *) orderedWindows; -/* - * Methods for user attention requests - */ -- (void) cancelUserAttentionRequest: (int)request; -- (int) requestUserAttention: (NSRequestUserAttentionType)requestType; -#endif @end -/** - * Informal protocol declaring methods for sending to and receiving from - * remote services providers. - */ -@interface NSObject (NSServicesRequests) -/* - * Pasteboard Read/Write - */ +@protocol UIApplicationDelegate +@optional /** - * Request to transfer data from given pasteboard to selection (called when - * a called remote service has provided data to this pasteboard). + * Invoked on notification that application has become active. */ -- (BOOL) readSelectionFromPasteboard: (NSPasteboard*)pboard; +- (void) applicationWillEnterForeground: (NSNotification*)aNotification; -/** - * Request to write selection data to given pasteboard (called when a called - * remote service is to be invoked). - */ -- (BOOL) writeSelectionToPasteboard: (NSPasteboard*)pboard - types: (NSArray*)types; -#if OS_API_VERSION(GS_API_NONE, GS_API_NONE) -- (NSWindow*) iconWindow; -#endif -@end - -#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) -@interface NSApplication (CharacterPanel) -- (void) orderFrontCharacterPalette: (id)sender; -@end -#endif - -#if OS_API_VERSION(GS_API_NONE, GS_API_NONE) - -@interface NSApplication (GSGUIInternal) -- (void) _windowWillDealloc: (NSWindow *)window; -@end - /** - * This is a formal protocol that duplicates the informal protocol for - * [NSApplication] delegates. Your delegate does not need to implement the - * formal protocol; it is declared only for documentation purposes. Your - * delegate should just implement the methods it needs to, which will allow - * NSApp to use default implementations in other cases. + * Invoked on notification that application has just been deactivated. */ -@protocol GSAppDelegateProtocol -/** - * Sender app (not necessarily this application) requests application to open - * file without bringing up its normal UI, for programmatic manipulation. - * YES should be returned on success, NO on failure. - */ -- (BOOL) application: (NSApplication*)app - openFileWithoutUI: (NSString*)filename; +- (void) applicationDidEnterBackground: (NSNotification*)aNotification; /** - * Sender requests application to open filename. - * YES should be returned on success, NO on failure. - */ -- (BOOL) application: (NSApplication*)app - openFile: (NSString*)filename; - -#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) -/** - * Sender requests application to open filenames. - * Not sent yet under GNUstep. - */ -- (void) application: (NSApplication*)app openFiles: (NSArray*)filenames; -#endif - -/** - * Sender requests application to open a temporary file. Responsibility - * for eventual deletion lies with this application. - * YES should be returned on success, NO on failure. - */ -- (BOOL) application: (NSApplication*)app - openTempFile: (NSString*)filename; - -/** - * Sender requests application to print filename. This should generally be - * done without presenting a GUI to the user, unless default options are - * likely to be changed. - * YES should be returned on success, NO on failure. - */ -- (BOOL) application: (NSApplication *)theApplication - printFile:(NSString *)filename; - -#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) -/** - * Not sent yet on GNUstep. - */ -#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) -- (NSApplicationPrintReply) application: (NSApplication*)app - printFiles: (NSArray*)files - withSettings: (NSDictionary*)settings - showPrintPanels: (BOOL)flag; - -#else -// Deprecated in 10.4 -- (void) application: (NSApplication*)app printFiles: (NSArray*)filenames; -#endif -#endif - -#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) -/** - * Ask delegate for an error replacement. - */ -- (NSError*) application: (NSApplication*)app willPresentError: (NSError*)error; -#endif - -/** - * Sender requests application to open a fresh document. - * YES should be returned on success, NO on failure. - */ -- (BOOL) applicationOpenUntitledFile: (NSApplication*)app; - -/** - * Sender will request application to open a fresh document, unless NO - * is returned here. - */ -- (BOOL) applicationShouldOpenUntitledFile:(NSApplication *)sender; - -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -/** - * Sent from within the [NSApplication-terminate:]. If - * NSTerminateNow is returned, termination will proceed. If - * NSTerminateCancel is returned, termination will NOT proceed. - * If NSTerminateLater is returned, termination will be halted, - * but the application should call - * [NSApplication-replyToApplicationShouldTerminate:] with a YES or NO. (Used - * if confirmation windows, etc. need to be put up.) - */ -- (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *)sender; -#else -/** - * Sent from within the [NSApplication-terminate:]. If NO is returned - * termination will not proceed. - */ -- (BOOL) applicationShouldTerminate: (id)sender; -#endif - -/** - * Invoked when the last window is closed in an application. If YES is - * returned, -applicationShouldTerminate: is invoked. - */ -- (BOOL) applicationShouldTerminateAfterLastWindowClosed: (id)sender; - -/** - * Invoked on notification that application has become active. - */ -- (void) applicationDidBecomeActive: (NSNotification*)aNotification; - -/** * Invoked on notification that application has finished launching * ([NSApplication-finishLaunching] has completed, but no event dispatching * has begun. @@ -530,159 +176,23 @@ - (void) applicationDidFinishLaunching: (NSNotification*)aNotification; /** - * Invoked on notification that application has just been hidden. - */ -- (void) applicationDidHide: (NSNotification*)aNotification; - -/** - * Invoked on notification that application has just been deactivated. - */ -- (void) applicationDidResignActive: (NSNotification*)aNotification; - -/** - * Invoked on notification that application has just been unhidden. - */ -- (void) applicationDidUnhide: (NSNotification*)aNotification; - -/** - * Invoked on notification that application has updated its windows. - */ -- (void) applicationDidUpdate: (NSNotification*)aNotification; - -/** - * Invoked on notification that application will become active. - */ -- (void) applicationWillBecomeActive: (NSNotification*)aNotification; - -/** - * Invoked on notification that application will become active. - */ -- (void) applicationWillFinishLaunching: (NSNotification*)aNotification; - -/** - * Invoked on notification that application will be hidden. - */ -- (void) applicationWillHide: (NSNotification*)aNotification; - -/** - * Invoked on notification just before application resigns active status. - */ -- (void) applicationWillResignActive: (NSNotification*)aNotification; - -/** * Invoked on notification just before application terminates. (There is * no opportunity to avert it now.) */ - (void) applicationWillTerminate:(NSNotification*)aNotification; -/** - * Invoked on notification that application will be unhidden. - */ -- (void) applicationWillUnhide: (NSNotification*)aNotification; - -/** - * Invoked on notification that application will now update its windows. - * (See [NSApplication-updateWindows]. - */ -- (void) applicationWillUpdate: (NSNotification*)aNotification; - -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -/** - * Method called by scripting framework on OS X. Not implemented (sent) - * yet on GNUstep. - */ -- (BOOL) application: (NSApplication*)sender - delegateHandlesKey: (NSString*)key; - -/** - * Method used on OS X to allow an application to override the standard menu - * obtained by right-clicking on the application's dock icon. Called - * when the application uses Macintosh or Windows95 style menus. - */ -- (NSMenu *) applicationDockMenu: (NSApplication*)sender; - -/** - * Method used on OS X to allow delegate to handle event when user clicks on - * dock icon of an already-open app. If YES is returned, a default - * implementation executes (for example, to create a new untitled document); - * if NO is returned nothing is done (and you can handle it here in this - * method). Not sent yet under GNUstep. - */ -- (BOOL) applicationShouldHandleReopen: (NSApplication*)theApplication - hasVisibleWindows: (BOOL)flag; - -/** - * Called on OS X when the resolution or other characteristics of the display - * have changed (through control panel operation, connecting a new monitor, - * etc.). Not implemented/sent yet under GNUstep. - */ -- (void) applicationDidChangeScreenParameters: (NSNotification*)aNotification; -#endif @end -#endif /* * Notifications */ -APPKIT_EXPORT NSString *NSApplicationDidBecomeActiveNotification; -APPKIT_EXPORT NSString *NSApplicationDidChangeScreenParametersNotification; -APPKIT_EXPORT NSString *NSApplicationDidFinishLaunchingNotification; -APPKIT_EXPORT NSString *NSApplicationDidHideNotification; -APPKIT_EXPORT NSString *NSApplicationDidResignActiveNotification; -APPKIT_EXPORT NSString *NSApplicationDidUnhideNotification; -APPKIT_EXPORT NSString *NSApplicationDidUpdateNotification; -APPKIT_EXPORT NSString *NSApplicationWillBecomeActiveNotification; -APPKIT_EXPORT NSString *NSApplicationWillFinishLaunchingNotification; -APPKIT_EXPORT NSString *NSApplicationWillHideNotification; -APPKIT_EXPORT NSString *NSApplicationWillResignActiveNotification; -APPKIT_EXPORT NSString *NSApplicationWillTerminateNotification; -APPKIT_EXPORT NSString *NSApplicationWillUnhideNotification; -APPKIT_EXPORT NSString *NSApplicationWillUpdateNotification; +UIKIT_EXPORT NSString *UIApplicationWillEnterForegroundNotification; +UIKIT_EXPORT NSString *UIApplicationDidFinishLaunchingNotification; +UIKIT_EXPORT NSString *NSApplicationDidEnterBackgroundNotification; +UIKIT_EXPORT NSString *NSApplicationWillTerminateNotification; -/* - * Determine Whether an Item Is Included in Services Menus - */ -APPKIT_EXPORT int -NSSetShowsServicesMenuItem(NSString *name, BOOL enabled); -APPKIT_EXPORT BOOL -NSShowsServicesMenuItem(NSString *name); +UIKIT_EXPORT int +UIApplicationMain(int argc, const char **argv, NSString *principalClassName, NSString *delegateClassName); -/* - * Programmatically Invoke a Service - */ -APPKIT_EXPORT BOOL -NSPerformService(NSString *serviceItem, NSPasteboard *pboard); - -#if OS_API_VERSION(GS_API_NONE, GS_API_NONE) -APPKIT_EXPORT id -GSContactApplication(NSString *appName, NSString *port, NSDate *expire); -#endif - -/* - * Force Services Menu to Update Based on New Services - */ -APPKIT_EXPORT void -NSUpdateDynamicServices(void); - -/* - * Register object to handle services requests. - */ -APPKIT_EXPORT void -NSRegisterServicesProvider(id provider, NSString *name); - -APPKIT_EXPORT void -NSUnRegisterServicesProvider(NSString *name); - -APPKIT_EXPORT int -NSApplicationMain(int argc, const char **argv); - -APPKIT_EXPORT void -NSShowSystemInfoPanel(NSDictionary *options); - -/* - * The NSApp global variable. - */ -APPKIT_EXPORT NSApplication *NSApp; - -#endif // _GNUstep_H_NSApplication +#endif // _GNUstep_UIKit_H_UIApplication Index: GNUmakefile.preamble =================================================================== --- GNUmakefile.preamble (revision 33949) +++ GNUmakefile.preamble (working copy) @@ -1,10 +1,12 @@ -# GNUmakefile.preamble of the GNUstep Core Data framework. -# Copyright (C) 2005 Free Software Foundation, Inc. +# GNUmakefile.preamble of the GNUstep UIKit framework. +# Copyright (C) 2005,2011 Free Software Foundation, Inc. # # Written by: Saso Kiselkov # Date: August 2005 +# Modified by: Ivan Vucica +# Date: November 2011 # -# This file is part of the GNUstep Core Data framework. +# This file is part of the GNUstep UIKit framework. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public