From ae30b120ff94e127dddb5d11cca31ac34ad73471 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Mon, 22 Nov 1999 07:31:01 +0000 Subject: [PATCH] Some window fixes git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5250 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 ++ Headers/gnustep/gui/NSWindow.h | 2 + Source/NSApplication.m | 116 ++++++++++++++++++++------------- Source/NSWindow.m | 91 ++++++++++++++------------ 4 files changed, 125 insertions(+), 89 deletions(-) diff --git a/ChangeLog b/ChangeLog index a65d2eb0e..dfbaf6bee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Nov 22 7:33:00 1999 Richard Frith-Macdonald + + * Source/NSWindow.m: Tidied activation/deactivation code. + * Source/NSApplication.m: Fixed Windows menu for new menu API. + Sat Nov 20 6:56:00 1999 Richard Frith-Macdonald * Source/NSMenu.m: Implemented ([-initDefaults]) to set window level diff --git a/Headers/gnustep/gui/NSWindow.h b/Headers/gnustep/gui/NSWindow.h index 2d411d960..d1b86e0e9 100644 --- a/Headers/gnustep/gui/NSWindow.h +++ b/Headers/gnustep/gui/NSWindow.h @@ -136,6 +136,8 @@ extern NSSize NSTokenSize; unsigned menu_exclude:1; unsigned hides_on_deactivate:1; unsigned accepts_mouse_moved:1; + unsigned is_closed:1; + unsigned is_deactivated:1; } _f; /* Reserved for back-end use */ diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 7e12421d3..0dd731a2c 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -464,6 +464,9 @@ static NSCell* tileCell = nil; DPSsetinputfocus(context, [kw windowNumber]); NSDebugLog(@"activateIgnoringOtherApps end."); + [main_menu update]; + [main_menu display]; + [nc postNotificationName: NSApplicationDidBecomeActiveNotification object: self]; } @@ -1105,10 +1108,7 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException); && ![win isKindOfClass: [NSMenuWindow class]] && ![win isKindOfClass: [NSIconWindow class]]) { - if (win != key && [win isKindOfClass: [NSWindow class]]) - { - [win orderFrontRegardless]; - } + [win orderFrontRegardless]; } } app_is_hidden = NO; @@ -1464,60 +1464,84 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException); - (void) setWindowsMenu: (NSMenu*)aMenu { - if (windows_menu) + NSMenuItem *anItem; + NSArray *windows; + NSArray *itemArray; + NSMenu *menu; + unsigned count; + unsigned i; + + if (windows_menu == nil) { - NSArray *windows; - NSMenu *menu; - unsigned count; - unsigned i; - - menu = [self windowsMenu]; - if (menu == aMenu) - return; - - /* - * Remove all the windows from the old windows menu. - */ - if (menu) + itemArray = [main_menu itemArray]; + count = [itemArray count]; + for (i = 0; i < count; ++i) { - NSArray *itemArray = [menu itemArray]; - - count = [itemArray count]; - for (i = 0; i < count; i++) + anItem = [itemArray objectAtIndex: i]; + if ([[anItem title] compare: @"Windows"] == NSOrderedSame) { - id item = [itemArray objectAtIndex: i]; - id win = [item target]; - - if ([win isKindOfClass: [NSWindow class]]) - { - [menu removeItem: item]; - } + windows_menu = anItem; + break; } } + if (windows_menu == nil) + { + windows_menu = [main_menu insertItemWithTitle: @"Windows" + action: 0 + keyEquivalent: @"" + atIndex: count]; + [main_menu sizeToFit]; + [main_menu update]; + } + } - /* - * Now use [-changeWindowsItem:title:filename:] to build the new menu. - */ - [main_menu setSubmenu: aMenu forItem: (id)windows_menu]; - windows = [self windows]; - count = [windows count]; + menu = [self windowsMenu]; + if (menu == aMenu) + return; + + /* + * Remove all the windows from the old windows menu. + */ + if (menu) + { + id win; + + itemArray = [menu itemArray]; + count = [itemArray count]; for (i = 0; i < count; i++) { - NSWindow *win = [windows objectAtIndex: i]; + anItem = [itemArray objectAtIndex: i]; + win = [anItem target]; - if ([win isExcludedFromWindowsMenu] == NO) + if ([win isKindOfClass: [NSWindow class]]) { - NSString *t = [win title]; - NSString *f = [win representedFilename]; - - [self changeWindowsItem: win - title: t - filename: [t isEqual: f]]; + [menu removeItem: anItem]; } } - [aMenu sizeToFit]; - [aMenu update]; } + + /* + * Now use [-changeWindowsItem:title:filename:] to build the new menu. + */ + [main_menu setSubmenu: aMenu forItem: (id)windows_menu]; + windows = [self windows]; + count = [windows count]; + for (i = 0; i < count; i++) + { + NSWindow *win = [windows objectAtIndex: i]; + + if ([win isExcludedFromWindowsMenu] == NO) + { + NSString *t = [win title]; + NSString *f = [win representedFilename]; + + [self changeWindowsItem: win + title: t + filename: [t isEqual: f]]; + } + } + [aMenu sizeToFit]; + [aMenu update]; } - (void) updateWindowsItem: (NSWindow*)aWindow @@ -1607,7 +1631,7 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException); - (NSMenu*) windowsMenu { if (windows_menu) - return [windows_menu target]; + return [windows_menu submenu]; else return nil; } diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 8f974d444..5c277335c 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -192,6 +192,31 @@ static NSMapTable* windowmaps = NULL; return 8; } +- (void) _appNotification: (NSNotification*)aNotification +{ + NSString *name = [aNotification name]; + + if ([name isEqualToString: NSApplicationWillBecomeActiveNotification]) + { + if (_f.is_deactivated == YES && _f.is_closed == NO) + { + [self orderFrontRegardless]; + } + } + else if ([name isEqualToString: NSApplicationWillResignActiveNotification]) + { + if (_f.hides_on_deactivate == YES && _f.visible == YES) + { + _f.is_deactivated = YES; + [self orderOut: self]; + } + } + else + { + NSLog(@"Unexpected notification - %@", aNotification); + } +} + /* * Instance methods */ @@ -212,7 +237,10 @@ static NSMapTable* windowmaps = NULL; - (void) dealloc { - NSGraphicsContext *context = GSCurrentContext(); + NSGraphicsContext *context = GSCurrentContext(); + + [[NSNotificationCenter defaultCenter] removeObserver: self]; + if (content_view) { RELEASE([content_view superview]); /* Release the window view */ @@ -264,9 +292,10 @@ static NSMapTable* windowmaps = NULL; defer: (BOOL)flag screen: (NSScreen*)aScreen { - NSGraphicsContext *context = GSCurrentContext(); - NSRect r = [[NSScreen mainScreen] frame]; - NSRect cframe; + NSGraphicsContext *context = GSCurrentContext(); + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + NSRect r = [[NSScreen mainScreen] frame]; + NSRect cframe; NSDebugLog(@"NSWindow default initializer\n"); if (!NSApp) @@ -325,6 +354,16 @@ static NSMapTable* windowmaps = NULL; title: window_title filename: isDoc]; } + + [nc addObserver: self + selector: @selector(_appNotification:) + name: NSApplicationWillBecomeActiveNotification + object: NSApp]; + [nc addObserver: self + selector: @selector(_appNotification:) + name: NSApplicationWillResignActiveNotification + object: NSApp]; + NSDebugLog(@"NSWindow end of init\n"); return self; } @@ -663,6 +702,11 @@ static NSMapTable* windowmaps = NULL; - (void) orderWindow: (NSWindowOrderingMode)place relativeTo: (int)otherWin { DPSorderwindow(GSCurrentContext(), place, otherWin, [self windowNumber]); + if (place != NSWindowOut) + { + _f.is_deactivated = NO; + _f.is_closed = NO; + } } - (void) resignKeyWindow @@ -682,49 +726,10 @@ static NSMapTable* windowmaps = NULL; [nc postNotificationName: NSWindowDidResignMainNotification object: self]; } -- (void) _appWillBecomeActive: (NSNotification*)aNotification -{ - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - - [nc removeObserver: self - name: NSApplicationWillBecomeActiveNotification - object: NSApp]; - [self orderFrontRegardless]; -} - -- (void) _appWillResignActive: (NSNotification*)aNotification -{ - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - - if (_f.visible) - { - [nc addObserver: self - selector: @selector(_appWillBecomeActive:) - name: NSApplicationWillBecomeActiveNotification - object: NSApp]; - [self orderOut: self]; - } -} - - (void) setHidesOnDeactivate: (BOOL)flag { if (flag != _f.hides_on_deactivate) { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - - if (flag == YES) - { - [nc addObserver: self - selector: @selector(_appWillResignActive:) - name: NSApplicationWillResignActiveNotification - object: NSApp]; - } - else - { - [nc removeObserver: self - name: NSApplicationWillResignActiveNotification - object: NSApp]; - } _f.hides_on_deactivate = flag; } }