Tidying window list management

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3495 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-12-20 06:19:06 +00:00
parent fbab6c3769
commit ca8037b919
4 changed files with 32 additions and 116 deletions

View file

@ -1,3 +1,11 @@
Sun Dec 20 6:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
NSApplication.h: Removed windows_menu_count again - and removed
window_list ivar - backend should return window list in ([-windows]).
NSApplication.m: Removed window_list ivar - use calls to ([-windows])
instead. Remove code dealing with adding/removing windows - done in
backend instead.
Fri Dec 18 10:32300 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Fri Dec 18 10:32300 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
NSApplication.h: New instance variable to give reasonable perfomance NSApplication.h: New instance variable to give reasonable perfomance

View file

@ -61,7 +61,6 @@ extern NSString *NSEventTrackingRunLoopMode;
@interface NSApplication : NSResponder <NSCoding> @interface NSApplication : NSResponder <NSCoding>
{ {
// Attributes // Attributes
NSMutableArray *window_list;
NSMutableArray *event_queue; NSMutableArray *event_queue;
NSEvent *current_event; NSEvent *current_event;
NSModalSession session; NSModalSession session;
@ -69,10 +68,8 @@ extern NSString *NSEventTrackingRunLoopMode;
id main_window; id main_window;
id delegate; id delegate;
id listener; id listener;
int window_count;
NSMenu *main_menu; NSMenu *main_menu;
NSMenuItem *windows_menu; NSMenuItem *windows_menu;
int windows_menu_count;
unsigned int current_mod; unsigned int current_mod;
BOOL app_is_running; BOOL app_is_running;
BOOL app_should_quit; BOOL app_should_quit;

View file

@ -97,12 +97,6 @@ static id NSApp;
static NSString *NSAbortModalException = @"NSAbortModalException"; static NSString *NSAbortModalException = @"NSAbortModalException";
@interface NSApplication (Private)
- (BOOL) validateMenuItem: (id<NSMenuItem>)item;
- (void) _windowWillClose: (NSNotification*)n;
- (void) _windowWillOpen: (NSWindow*)win;
@end
@implementation NSApplication @implementation NSApplication
// //
@ -141,8 +135,6 @@ static NSString *NSAbortModalException = @"NSAbortModalException";
NSDebugLog(@"Begin of NSApplication -init\n"); NSDebugLog(@"Begin of NSApplication -init\n");
listener = [GSServicesManager newWithApplication: self]; listener = [GSServicesManager newWithApplication: self];
window_list = [NSMutableArray new]; // allocate window list
window_count = 1;
main_menu = nil; main_menu = nil;
windows_need_update = YES; windows_need_update = YES;
@ -207,7 +199,6 @@ NSString* mainModelFile;
gnustep_gui_app_is_in_dealloc = YES; // are within dealloc gnustep_gui_app_is_in_dealloc = YES; // are within dealloc
[listener release]; [listener release];
[window_list release];
[event_queue release]; [event_queue release];
[current_event release]; [current_event release];
@ -475,7 +466,7 @@ NSAutoreleasePool* pool;
/* /*
* Check to see if the window has gone away - if so, end session. * Check to see if the window has gone away - if so, end session.
*/ */
if ([window_list indexOfObjectIdenticalTo: session->window] == if ([[self windows] indexOfObjectIdenticalTo: session->window] ==
NSNotFound || [session->window isVisible] == NO) NSNotFound || [session->window isVisible] == NO)
[self stopModal]; [self stopModal];
if (windows_need_update) if (windows_need_update)
@ -1127,6 +1118,7 @@ BOOL done = NO;
// //
- (NSWindow*) keyWindow - (NSWindow*) keyWindow
{ {
NSArray *window_list = [self windows];
int i, j; int i, j;
id w; id w;
@ -1143,6 +1135,7 @@ BOOL done = NO;
- (NSWindow*) mainWindow - (NSWindow*) mainWindow
{ {
NSArray *window_list = [self windows];
int i, j; int i, j;
id w; id w;
@ -1159,6 +1152,7 @@ BOOL done = NO;
- (NSWindow*) makeWindowsPerform: (SEL)aSelector inOrder: (BOOL)flag - (NSWindow*) makeWindowsPerform: (SEL)aSelector inOrder: (BOOL)flag
{ {
NSArray *window_list = [self windows];
unsigned i; unsigned i;
if (flag) if (flag)
@ -1193,6 +1187,7 @@ BOOL done = NO;
- (void)miniaturizeAll:sender - (void)miniaturizeAll:sender
{ {
NSArray *window_list = [self windows];
unsigned i, count; unsigned i, count;
for (i = 0, count = [window_list count]; i < count; i++) for (i = 0, count = [window_list count]; i < count; i++)
@ -1212,6 +1207,7 @@ BOOL done = NO;
{ // to all visible windows { // to all visible windows
int i, count; int i, count;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSArray *window_list = [self windows];
// notify that an update is // notify that an update is
// imminent // imminent
[nc postNotificationName:NSApplicationWillUpdateNotification object:self]; [nc postNotificationName:NSApplicationWillUpdateNotification object:self];
@ -1226,25 +1222,27 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:NSApplicationDidUpdateNotification object:self]; [nc postNotificationName:NSApplicationDidUpdateNotification object:self];
} }
- (NSArray *)windows - (NSArray*) windows
{ {
return window_list; // Implemented by backend.
return nil;
} }
- (NSWindow *)windowWithWindowNumber:(int)windowNum - (NSWindow *)windowWithWindowNumber:(int)windowNum
{ {
unsigned i, j; NSArray *window_list = [self windows];
NSWindow *w; unsigned i, j;
NSWindow *w;
j = [window_list count]; j = [window_list count];
for (i = 0;i < j; ++i) for (i = 0; i < j; ++i)
{ {
w = [window_list objectAtIndex:i]; w = [window_list objectAtIndex: i];
if ([w windowNumber] == windowNum) if ([w windowNumber] == windowNum)
return w; return w;
} }
return nil; return nil;
} }
// //
@ -1323,15 +1321,6 @@ NSWindow *w;
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"Object of bad type passed as window"]; format: @"Object of bad type passed as window"];
/*
* If this window is new to us, we add it to the main menu list and
* do any necessary bookkeeping.
*/
if ([window_list indexOfObjectIdenticalTo: aWindow] == NSNotFound)
{
[self _windowWillOpen: aWindow];
}
/* /*
* If Menus are implemented as a subclass of window we must make sure * If Menus are implemented as a subclass of window we must make sure
* to exclude them from the windows menu. * to exclude them from the windows menu.
@ -1339,16 +1328,6 @@ NSWindow *w;
if ([aWindow isKindOfClass: [NSMenu class]]) if ([aWindow isKindOfClass: [NSMenu class]])
return; return;
/*
* FIXME - the following five lines shouldn't be here - but the X stuff
* terminates if I take them out!
*/
if ([window_list count] == 1)
{
[aWindow becomeKeyWindow];
[aWindow becomeMainWindow];
}
/* /*
* Can't permit an untitled window in the window menu. * Can't permit an untitled window in the window menu.
*/ */
@ -1378,7 +1357,6 @@ if ([window_list count] == 1)
if ([item target] == aWindow) if ([item target] == aWindow)
{ {
[menu removeItem: item]; [menu removeItem: item];
windows_menu_count--;
break; break;
} }
} }
@ -1422,7 +1400,6 @@ if ([window_list count] == 1)
action: @selector(makeKeyAndOrderFront:) action: @selector(makeKeyAndOrderFront:)
keyEquivalent: @"" keyEquivalent: @""
atIndex: i]; atIndex: i];
windows_menu_count++;
[item setTarget: aWindow]; [item setTarget: aWindow];
[menu sizeToFit]; [menu sizeToFit];
[menu update]; [menu update];
@ -1448,7 +1425,6 @@ if ([window_list count] == 1)
if ([item target] == aWindow) if ([item target] == aWindow)
{ {
[menu removeItem: item]; [menu removeItem: item];
windows_menu_count--;
[menu sizeToFit]; [menu sizeToFit];
[menu update]; [menu update];
break; break;
@ -1473,7 +1449,7 @@ if ([window_list count] == 1)
* Remove all the windows from the old windows menu and store * Remove all the windows from the old windows menu and store
* them in a temporary array for insertion into the new menu. * them in a temporary array for insertion into the new menu.
*/ */
windows = [NSMutableArray arrayWithCapacity: windows_menu_count]; windows = [NSMutableArray arrayWithCapacity: 10];
if (menu) if (menu)
{ {
NSArray *itemArray; NSArray *itemArray;
@ -1491,7 +1467,6 @@ if ([window_list count] == 1)
{ {
[windows addObject: win]; [windows addObject: win];
[menu removeItem: item]; [menu removeItem: item];
windows_menu_count--;
} }
} }
} }
@ -1499,7 +1474,6 @@ if ([window_list count] == 1)
/* /*
* Now use [-changeWindowsItem:title:filename:] to build the new menu. * Now use [-changeWindowsItem:title:filename:] to build the new menu.
*/ */
windows_menu_count = 0;
[main_menu setSubmenu: aMenu forItem: (id<NSMenuItem>)windows_menu]; [main_menu setSubmenu: aMenu forItem: (id<NSMenuItem>)windows_menu];
while ((win = [windows lastObject]) != nil) while ((win = [windows lastObject]) != nil)
{ {
@ -1809,7 +1783,6 @@ BOOL result = YES;
{ {
[super encodeWithCoder:aCoder]; [super encodeWithCoder:aCoder];
[aCoder encodeObject: window_list];
[aCoder encodeConditionalObject:key_window]; [aCoder encodeConditionalObject:key_window];
[aCoder encodeConditionalObject:main_window]; [aCoder encodeConditionalObject:main_window];
[aCoder encodeConditionalObject:delegate]; [aCoder encodeConditionalObject:delegate];
@ -1821,7 +1794,6 @@ BOOL result = YES;
{ {
[super initWithCoder:aDecoder]; [super initWithCoder:aDecoder];
window_list = [aDecoder decodeObject];
key_window = [aDecoder decodeObject]; key_window = [aDecoder decodeObject];
main_window = [aDecoder decodeObject]; main_window = [aDecoder decodeObject];
delegate = [aDecoder decodeObject]; delegate = [aDecoder decodeObject];
@ -1850,65 +1822,3 @@ BOOL result = YES;
@end /* NSApplication */ @end /* NSApplication */
@implementation NSApplication (Private)
/*
* Method for automatically enabling or disabling menu items
* 'arrangeInFront:' is only valid if we have something in the windows menu.
*/
- (BOOL) validateMenuItem: (id<NSMenuItem>)item
{
SEL action = [item action];
if (action)
{
if (sel_eq(action, @selector(arrangeinFront:)))
{
if (windows_menu_count)
return YES;
}
else if ([self respondsToSelector: action])
return YES;
}
return NO;
}
- (void) _windowWillClose: (NSNotification*)n
{
NSWindow *win = [n object];
if ([win isReleasedWhenClosed])
{
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc removeObserver: self
name: NSWindowWillCloseNotification
object: win];
[window_list removeObjectIdenticalTo: win];
/*
* Horrible kludge to handle case where an application has no menu - we
* assume that this is the only window in the application and terminate.
* We only do this for windows that release when closed - any other
* window may be intended to re-open.
*/
if (main_menu == nil)
[self terminate: nil];
}
}
- (void) _windowWillOpen: (NSWindow*)win
{
if ([window_list indexOfObjectIdenticalTo: win] == NSNotFound)
{
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[window_list addObject: win];
[win setWindowNumber: window_count++];
[nc addObserver: self
selector: @selector(_windowWillClose:)
name: NSWindowWillCloseNotification
object: win];
}
}
@end

View file

@ -632,8 +632,9 @@ NSView *v;
/* /*
* If 'is_released_when_closed' then the window will be removed from the * If 'is_released_when_closed' then the window will be removed from the
* applications list of windows (causing it to be released) - so we must * global list of windows (causing it to be released) - so we must
* bracket any work we do in a retain/release sequence. * bracket any work we do in a retain/release sequence in case that
* removal takes place when we post the notification.
*/ */
if (is_released_when_closed) if (is_released_when_closed)
[self retain]; [self retain];