mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 19:10:48 +00:00
More windows menu improvements.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3487 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
cce58064d6
commit
1f26059c40
3 changed files with 157 additions and 98 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Thu Dec 17 22:55:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
* NSMenu.m: ([-update]) removed code to search responder chain -
|
||||||
|
get NSApplication to do it for us.
|
||||||
|
* NSApplication.m: Implemented more of the windows menu stuff.
|
||||||
|
Almost complete barring wierd glitches due to the menu implementation.
|
||||||
|
|
||||||
1998-12-17 Matthias Klose <doko@cs.tu-berlin.de>
|
1998-12-17 Matthias Klose <doko@cs.tu-berlin.de>
|
||||||
|
|
||||||
* {,*}/GNUmakefile: Include Version and GNUmakefile.local.
|
* {,*}/GNUmakefile: Include Version and GNUmakefile.local.
|
||||||
|
|
|
@ -98,6 +98,7 @@ static NSString *NSAbortModalException = @"NSAbortModalException";
|
||||||
|
|
||||||
|
|
||||||
@interface NSApplication (Private)
|
@interface NSApplication (Private)
|
||||||
|
- (BOOL) validateMenuItem: (id<NSMenuItem>)item;
|
||||||
- (void) _windowWillClose: (NSNotification*)n;
|
- (void) _windowWillClose: (NSNotification*)n;
|
||||||
- (void) _windowWillOpen: (NSWindow*)win;
|
- (void) _windowWillOpen: (NSWindow*)win;
|
||||||
@end
|
@end
|
||||||
|
@ -1338,14 +1339,15 @@ NSWindow *w;
|
||||||
if ([aWindow isKindOfClass: [NSMenu class]])
|
if ([aWindow isKindOfClass: [NSMenu class]])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this was the first window then make it the main and key window.
|
* FIXME - the following five lines shouldn't be here - but the X stuff
|
||||||
*/
|
* terminates if I take them out!
|
||||||
if ([window_list count] == 1)
|
*/
|
||||||
{
|
if ([window_list count] == 1)
|
||||||
[aWindow becomeMainWindow];
|
{
|
||||||
[aWindow becomeKeyWindow];
|
[aWindow becomeKeyWindow];
|
||||||
}
|
[aWindow becomeMainWindow];
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Can't permit an untitled window in the window menu.
|
* Can't permit an untitled window in the window menu.
|
||||||
|
@ -1376,6 +1378,7 @@ NSWindow *w;
|
||||||
if ([item target] == aWindow)
|
if ([item target] == aWindow)
|
||||||
{
|
{
|
||||||
[menu removeItem: item];
|
[menu removeItem: item];
|
||||||
|
windows_menu_count--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1419,6 +1422,7 @@ NSWindow *w;
|
||||||
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];
|
||||||
|
@ -1444,6 +1448,7 @@ NSWindow *w;
|
||||||
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;
|
||||||
|
@ -1455,11 +1460,123 @@ NSWindow *w;
|
||||||
- (void) setWindowsMenu: (NSMenu*)aMenu
|
- (void) setWindowsMenu: (NSMenu*)aMenu
|
||||||
{
|
{
|
||||||
if (windows_menu)
|
if (windows_menu)
|
||||||
[main_menu setSubmenu: aMenu forItem: (id<NSMenuItem>)windows_menu];
|
{
|
||||||
|
NSMutableArray *windows;
|
||||||
|
NSMenu *menu;
|
||||||
|
id win;
|
||||||
|
|
||||||
|
menu = [self windowsMenu];
|
||||||
|
if (menu == aMenu)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove all the windows from the old windows menu and store
|
||||||
|
* them in a temporary array for insertion into the new menu.
|
||||||
|
*/
|
||||||
|
windows = [NSMutableArray arrayWithCapacity: windows_menu_count];
|
||||||
|
if (menu)
|
||||||
|
{
|
||||||
|
NSArray *itemArray;
|
||||||
|
unsigned count;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
itemArray = [menu itemArray];
|
||||||
|
count = [itemArray count];
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
id item = [itemArray objectAtIndex: i];
|
||||||
|
|
||||||
|
win = [item target];
|
||||||
|
if ([win isKindOfClass: [NSWindow class]])
|
||||||
|
{
|
||||||
|
[windows addObject: win];
|
||||||
|
[menu removeItem: item];
|
||||||
|
windows_menu_count--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now use [-changeWindowsItem:title:filename:] to build the new menu.
|
||||||
|
*/
|
||||||
|
windows_menu_count = 0;
|
||||||
|
[main_menu setSubmenu: aMenu forItem: (id<NSMenuItem>)windows_menu];
|
||||||
|
while ((win = [windows lastObject]) != nil)
|
||||||
|
{
|
||||||
|
[self changeWindowsItem: win
|
||||||
|
title: [win title]
|
||||||
|
filename: [win representedFilename] != nil];
|
||||||
|
[windows removeLastObject];
|
||||||
|
}
|
||||||
|
[aMenu sizeToFit];
|
||||||
|
[aMenu update];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) updateWindowsItem: aWindow
|
- (void) updateWindowsItem: aWindow
|
||||||
{
|
{
|
||||||
|
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 item = [itemArray objectAtIndex: i];
|
||||||
|
|
||||||
|
if ([item target] == aWindow)
|
||||||
|
{
|
||||||
|
NSCellImagePosition oldPos = [item imagePosition];
|
||||||
|
NSImage *oldImage = [item image];
|
||||||
|
BOOL changed = NO;
|
||||||
|
|
||||||
|
if ([aWindow representedFilename] == nil)
|
||||||
|
{
|
||||||
|
if (oldPos != NSNoImage)
|
||||||
|
{
|
||||||
|
[item setImagePosition: NSNoImage];
|
||||||
|
changed = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSImage *newImage = oldImage;
|
||||||
|
|
||||||
|
if (oldPos != NSImageLeft)
|
||||||
|
{
|
||||||
|
[item setImagePosition: NSImageLeft];
|
||||||
|
changed = YES;
|
||||||
|
}
|
||||||
|
if ([aWindow isDocumentEdited])
|
||||||
|
{
|
||||||
|
newImage = [NSImage imageNamed: @"common_CloseBroken"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newImage = [NSImage imageNamed: @"common_Close"];
|
||||||
|
}
|
||||||
|
if (newImage != oldImage)
|
||||||
|
{
|
||||||
|
[item setImage: newImage];
|
||||||
|
changed = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
[item sizeToFit];
|
||||||
|
[menu sizeToFit];
|
||||||
|
[menu update];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSMenu*) windowsMenu
|
- (NSMenu*) windowsMenu
|
||||||
|
@ -1715,7 +1832,7 @@ BOOL result = YES;
|
||||||
|
|
||||||
+ (void)setNullEvent:(NSEvent *)e
|
+ (void)setNullEvent:(NSEvent *)e
|
||||||
{
|
{
|
||||||
ASSIGN(null_event, e);
|
ASSIGN(null_event, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSEvent *)getNullEvent;
|
+ (NSEvent *)getNullEvent;
|
||||||
|
@ -1734,6 +1851,28 @@ BOOL result = YES;
|
||||||
@end /* NSApplication */
|
@end /* NSApplication */
|
||||||
|
|
||||||
@implementation NSApplication (Private)
|
@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
|
- (void) _windowWillClose: (NSNotification*)n
|
||||||
{
|
{
|
||||||
NSWindow *win = [n object];
|
NSWindow *win = [n object];
|
||||||
|
|
|
@ -485,94 +485,7 @@ static Class menuCellClass = nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Search the key window's responder chain */
|
validator = [theApp targetForAction: action];
|
||||||
keyWindow = [theApp keyWindow];
|
|
||||||
responder = [keyWindow firstResponder];
|
|
||||||
while (responder)
|
|
||||||
{
|
|
||||||
if ([responder respondsToSelector: action])
|
|
||||||
{
|
|
||||||
validator = responder;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
responder = [responder nextResponder];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validator == nil)
|
|
||||||
{
|
|
||||||
/* Search the key window */
|
|
||||||
if ([keyWindow respondsToSelector: action])
|
|
||||||
{
|
|
||||||
validator = keyWindow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validator == nil)
|
|
||||||
{
|
|
||||||
/* Search the key window's delegate */
|
|
||||||
delegate = [keyWindow delegate];
|
|
||||||
if ([delegate respondsToSelector: action])
|
|
||||||
{
|
|
||||||
validator = delegate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validator == nil)
|
|
||||||
{
|
|
||||||
mainWindow = [theApp mainWindow];
|
|
||||||
if (mainWindow != keyWindow)
|
|
||||||
{
|
|
||||||
/* Search the main window's responder chain */
|
|
||||||
responder = [mainWindow firstResponder];
|
|
||||||
while (responder)
|
|
||||||
{
|
|
||||||
if ([responder respondsToSelector: action])
|
|
||||||
{
|
|
||||||
validator = responder;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
responder = [responder nextResponder];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validator == nil)
|
|
||||||
{
|
|
||||||
/* Search the main window */
|
|
||||||
if ([mainWindow respondsToSelector: action])
|
|
||||||
{
|
|
||||||
validator = mainWindow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validator == nil)
|
|
||||||
{
|
|
||||||
/* Search the main window's delegate */
|
|
||||||
delegate = [mainWindow delegate];
|
|
||||||
if ([delegate respondsToSelector: action])
|
|
||||||
{
|
|
||||||
validator = delegate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validator == nil)
|
|
||||||
{
|
|
||||||
/* Search the NSApplication object */
|
|
||||||
if ([theApp respondsToSelector: action])
|
|
||||||
{
|
|
||||||
validator = theApp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validator == nil)
|
|
||||||
{
|
|
||||||
/* Search the NSApplication object's delegate */
|
|
||||||
delegate = [theApp delegate];
|
|
||||||
if ([delegate respondsToSelector: action])
|
|
||||||
{
|
|
||||||
validator = theApp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue