Some window fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5250 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-11-22 07:31:01 +00:00
parent 94bb4d75c1
commit ae30b120ff
4 changed files with 125 additions and 89 deletions

View file

@ -1,3 +1,8 @@
Mon Nov 22 7:33:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* 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 <richard@brainstorm.co.uk> Sat Nov 20 6:56:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSMenu.m: Implemented ([-initDefaults]) to set window level * Source/NSMenu.m: Implemented ([-initDefaults]) to set window level

View file

@ -136,6 +136,8 @@ extern NSSize NSTokenSize;
unsigned menu_exclude:1; unsigned menu_exclude:1;
unsigned hides_on_deactivate:1; unsigned hides_on_deactivate:1;
unsigned accepts_mouse_moved:1; unsigned accepts_mouse_moved:1;
unsigned is_closed:1;
unsigned is_deactivated:1;
} _f; } _f;
/* Reserved for back-end use */ /* Reserved for back-end use */

View file

@ -464,6 +464,9 @@ static NSCell* tileCell = nil;
DPSsetinputfocus(context, [kw windowNumber]); DPSsetinputfocus(context, [kw windowNumber]);
NSDebugLog(@"activateIgnoringOtherApps end."); NSDebugLog(@"activateIgnoringOtherApps end.");
[main_menu update];
[main_menu display];
[nc postNotificationName: NSApplicationDidBecomeActiveNotification [nc postNotificationName: NSApplicationDidBecomeActiveNotification
object: self]; object: self];
} }
@ -1104,13 +1107,10 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
if (win != key && [win isKindOfClass: [NSWindow class]] if (win != key && [win isKindOfClass: [NSWindow class]]
&& ![win isKindOfClass: [NSMenuWindow class]] && ![win isKindOfClass: [NSMenuWindow class]]
&& ![win isKindOfClass: [NSIconWindow class]]) && ![win isKindOfClass: [NSIconWindow class]])
{
if (win != key && [win isKindOfClass: [NSWindow class]])
{ {
[win orderFrontRegardless]; [win orderFrontRegardless];
} }
} }
}
app_is_hidden = NO; app_is_hidden = NO;
[nc postNotificationName: NSApplicationDidUnhideNotification [nc postNotificationName: NSApplicationDidUnhideNotification
@ -1464,13 +1464,37 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
- (void) setWindowsMenu: (NSMenu*)aMenu - (void) setWindowsMenu: (NSMenu*)aMenu
{ {
if (windows_menu) NSMenuItem *anItem;
{
NSArray *windows; NSArray *windows;
NSArray *itemArray;
NSMenu *menu; NSMenu *menu;
unsigned count; unsigned count;
unsigned i; unsigned i;
if (windows_menu == nil)
{
itemArray = [main_menu itemArray];
count = [itemArray count];
for (i = 0; i < count; ++i)
{
anItem = [itemArray objectAtIndex: i];
if ([[anItem title] compare: @"Windows"] == NSOrderedSame)
{
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];
}
}
menu = [self windowsMenu]; menu = [self windowsMenu];
if (menu == aMenu) if (menu == aMenu)
return; return;
@ -1480,17 +1504,18 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
*/ */
if (menu) if (menu)
{ {
NSArray *itemArray = [menu itemArray]; id win;
itemArray = [menu itemArray];
count = [itemArray count]; count = [itemArray count];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
id item = [itemArray objectAtIndex: i]; anItem = [itemArray objectAtIndex: i];
id win = [item target]; win = [anItem target];
if ([win isKindOfClass: [NSWindow class]]) if ([win isKindOfClass: [NSWindow class]])
{ {
[menu removeItem: item]; [menu removeItem: anItem];
} }
} }
} }
@ -1517,7 +1542,6 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
} }
[aMenu sizeToFit]; [aMenu sizeToFit];
[aMenu update]; [aMenu update];
}
} }
- (void) updateWindowsItem: (NSWindow*)aWindow - (void) updateWindowsItem: (NSWindow*)aWindow
@ -1607,7 +1631,7 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
- (NSMenu*) windowsMenu - (NSMenu*) windowsMenu
{ {
if (windows_menu) if (windows_menu)
return [windows_menu target]; return [windows_menu submenu];
else else
return nil; return nil;
} }

View file

@ -192,6 +192,31 @@ static NSMapTable* windowmaps = NULL;
return 8; 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 * Instance methods
*/ */
@ -213,6 +238,9 @@ static NSMapTable* windowmaps = NULL;
- (void) dealloc - (void) dealloc
{ {
NSGraphicsContext *context = GSCurrentContext(); NSGraphicsContext *context = GSCurrentContext();
[[NSNotificationCenter defaultCenter] removeObserver: self];
if (content_view) if (content_view)
{ {
RELEASE([content_view superview]); /* Release the window view */ RELEASE([content_view superview]); /* Release the window view */
@ -265,6 +293,7 @@ static NSMapTable* windowmaps = NULL;
screen: (NSScreen*)aScreen screen: (NSScreen*)aScreen
{ {
NSGraphicsContext *context = GSCurrentContext(); NSGraphicsContext *context = GSCurrentContext();
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSRect r = [[NSScreen mainScreen] frame]; NSRect r = [[NSScreen mainScreen] frame];
NSRect cframe; NSRect cframe;
@ -325,6 +354,16 @@ static NSMapTable* windowmaps = NULL;
title: window_title title: window_title
filename: isDoc]; 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"); NSDebugLog(@"NSWindow end of init\n");
return self; return self;
} }
@ -663,6 +702,11 @@ static NSMapTable* windowmaps = NULL;
- (void) orderWindow: (NSWindowOrderingMode)place relativeTo: (int)otherWin - (void) orderWindow: (NSWindowOrderingMode)place relativeTo: (int)otherWin
{ {
DPSorderwindow(GSCurrentContext(), place, otherWin, [self windowNumber]); DPSorderwindow(GSCurrentContext(), place, otherWin, [self windowNumber]);
if (place != NSWindowOut)
{
_f.is_deactivated = NO;
_f.is_closed = NO;
}
} }
- (void) resignKeyWindow - (void) resignKeyWindow
@ -682,49 +726,10 @@ static NSMapTable* windowmaps = NULL;
[nc postNotificationName: NSWindowDidResignMainNotification object: self]; [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 - (void) setHidesOnDeactivate: (BOOL)flag
{ {
if (flag != _f.hides_on_deactivate) 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; _f.hides_on_deactivate = flag;
} }
} }