diff --git a/ChangeLog b/ChangeLog index c634f825c..f7f5e79b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Mon Nov 29 6:05:00 1999 Richard Frith-Macdonald + + * Source/NSApplication.m: ([-iconWindow]) new (non-standard) method. + * Source/NSWindow.m: ([-orderWindow:relativeTo:]) added code to + resign key/main window status on ordering out. Also, set up a new + key/main window - if no suitable candidates are available, use the + app icon window or the main menu window. + Sun Nov 28 19:37:00 1999 Richard Frith-Macdonald * Source/NSOpenPanel.m: ([-filenames]) fix to handle multiple diff --git a/Headers/gnustep/gui/NSApplication.h b/Headers/gnustep/gui/NSApplication.h index 8c3bd0699..162b6235d 100644 --- a/Headers/gnustep/gui/NSApplication.h +++ b/Headers/gnustep/gui/NSApplication.h @@ -79,7 +79,7 @@ extern NSString *NSEventTrackingRunLoopMode; NSMutableArray *_hidden; NSMutableArray *_inactive; NSWindow *_hidden_key; - + NSWindow *_app_icon_window; BOOL inTrackingLoop; // Reserved for back-end use @@ -256,6 +256,9 @@ extern NSString *NSEventTrackingRunLoopMode; - (BOOL) writeSelectionToPasteboard: (NSPasteboard*)pboard types: (NSArray*)types; +#ifndef NO_GNUSTEP +- (NSWindow*) iconWindow; +#endif @end diff --git a/Headers/gnustep/gui/NSMenu.h b/Headers/gnustep/gui/NSMenu.h index 6fe865d2b..dd028a681 100644 --- a/Headers/gnustep/gui/NSMenu.h +++ b/Headers/gnustep/gui/NSMenu.h @@ -168,7 +168,7 @@ @end - +#ifndef NO_GNUSTEP @interface NSMenu (GNUstepExtra) - (BOOL)isFollowTransient; - (NSWindow *)window; @@ -190,6 +190,7 @@ - (void)shiftOnScreen; @end +#endif /* A menu's title is an instance of this class */ @interface NSMenuWindowTitleView : NSView diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 24395eaf0..8811975ba 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -86,7 +86,6 @@ struct _NSModalSession { * Class variables */ static BOOL gnustep_gui_app_is_in_dealloc; -static NSIconWindow *app_icon_window; static NSEvent *null_event; static NSString *NSAbortModalException = @"NSAbortModalException"; @@ -267,7 +266,7 @@ static NSCell* tileCell = nil; if (app_icon == nil) app_icon = [[NSImage imageNamed: @"GNUstep"] retain]; - app_icon_window = [[NSIconWindow alloc] initWithContentRect: + _app_icon_window = [[NSIconWindow alloc] initWithContentRect: NSMakeRect(0,0,64,64) styleMask: NSBorderlessWindowMask backing: NSBackingStoreRetained @@ -275,11 +274,11 @@ static NSCell* tileCell = nil; screen: nil]; iv = [[NSAppIconView alloc] initWithFrame: NSMakeRect(0,0,64,64)]; - [app_icon_window setContentView: iv]; + [_app_icon_window setContentView: iv]; [iv setImage: app_icon]; - [app_icon_window orderFrontRegardless]; - DPSsetinputfocus(context, [app_icon_window windowNumber]); + [_app_icon_window orderFrontRegardless]; + DPSsetinputfocus(context, [_app_icon_window windowNumber]); return self; } @@ -339,7 +338,6 @@ static NSCell* tileCell = nil; } } - - (void) _windowWillClose: (NSNotification*) notification { NSWindow *win = [notification object]; @@ -490,7 +488,7 @@ static NSCell* tileCell = nil; { NSGraphicsContext *context = GSCurrentContext(); - DPSsetinputfocus(context, [app_icon_window windowNumber]); + DPSsetinputfocus(context, [_app_icon_window windowNumber]); } } } @@ -789,7 +787,7 @@ static NSCell* tileCell = nil; { continue; /* Already invisible */ } - if (win == app_icon_window) + if (win == _app_icon_window) { continue; /* can't hide the app icon. */ } @@ -1345,8 +1343,8 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException); [app_icon setName: nil]; [anImage setName: @"NSApplicationIcon"]; ASSIGN(app_icon, anImage); - [[app_icon_window contentView] setImage: anImage]; - [[app_icon_window contentView] setNeedsDisplay: YES]; + [[_app_icon_window contentView] setImage: anImage]; + [[_app_icon_window contentView] setNeedsDisplay: YES]; } - (NSImage*) applicationIconImage @@ -1354,6 +1352,11 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException); return app_icon; } +- (NSWindow*) iconWindow +{ + return _app_icon_window; +} + /* * Hiding and arranging windows */ @@ -1381,7 +1384,7 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException); { continue; /* Already invisible */ } - if (win == app_icon_window) + if (win == _app_icon_window) { continue; /* can't hide the app icon. */ } diff --git a/Source/NSWindow.m b/Source/NSWindow.m index a4bcd7d3b..2f8631a6b 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -673,6 +674,76 @@ static NSMapTable* windowmaps = NULL; - (void) orderWindow: (NSWindowOrderingMode)place relativeTo: (int)otherWin { + if (place == NSWindowOut) + { + NSArray *windowList = [NSWindow _windowList]; + unsigned pos = [windowList indexOfObjectIdenticalTo: self]; + unsigned c = [windowList count]; + unsigned i; + NSWindow *w; + + if ([self isKeyWindow]) + { + [self resignKeyWindow]; + for (i = pos + 1; i != pos; i++) + { + if (i == c) + { + i = 0; + } + w = [windowList objectAtIndex: i]; + if ([w isVisible] && [w canBecomeKeyWindow]) + { + [w makeKeyWindow]; + break; + } + } + /* + * if we didn't find a possible key window - use tha app icon or, + * failing that, use the menu window. + */ + if (i == pos) + { + w = [NSApp iconWindow]; + if (w != nil && [w isVisible] == YES) + { + [GSCurrentContext() DPSsetinputfocus: [w windowNumber]]; + } + else + { + w = [[NSApp mainMenu] window]; + [GSCurrentContext() DPSsetinputfocus: [w windowNumber]]; + } + } + } + if ([self isMainWindow]) + { + NSWindow *w = [NSApp keyWindow]; + + [self resignMainWindow]; + if (w != nil && [w canBecomeMainWindow]) + { + [w makeKeyWindow]; + } + else + { + for (i = pos + 1; i != pos; i++) + { + if (i == c) + { + i = 0; + } + w = [windowList objectAtIndex: i]; + if ([w isVisible] && [w canBecomeMainWindow]) + { + [w makeMainWindow]; + break; + } + } + } + } + } + DPSorderwindow(GSCurrentContext(), place, otherWin, [self windowNumber]); } @@ -1228,8 +1299,6 @@ resetCursorRectsForView(NSView *theView) RETAIN(self); [nc postNotificationName: NSWindowWillCloseNotification object: self]; - [self resignKeyWindow]; - [self resignMainWindow]; [NSApp removeWindowsItem: self]; [self orderOut: self];