Various updates to get keyboard equivalents for buttons working (especially

for panels).


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3461 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-12-15 16:20:22 +00:00
parent 958d1bf294
commit bf5137b858
7 changed files with 357 additions and 233 deletions

View file

@ -1,3 +1,13 @@
Tue Dec 15 16:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* NSApplication.m: Terminate modal loop if the window goes away.
* NSButton.m: Handle key equivalents.
* NSButtonCell.m: Handle key equivalents.
* NSCell.m: implement ([-performClick:]) method.
* NSPanel.m: Close closable panels when user hits escape key.
handle keyboard shortcut for default option.
* NSWindow.m: Fix bug causing app to terminate when it shouldn't.
Mon Dec 14 16:15:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* GSServicesMnager.m: Added alert panels to display error messages

View file

@ -358,9 +358,13 @@ unsigned i;
[theSession->window display];
[theSession->window makeKeyAndOrderFront: self];
do { // First we make sure
count = [event_queue count]; // that there is an
for (i = 0; i < count; i++) // event.
// First we make sure
// that there is an
// event.
do
{
count = [event_queue count];
for (i = 0; i < count; i++)
{
event = [event_queue objectAtIndex: 0];
if ([event window] == theSession->window)
@ -368,8 +372,12 @@ unsigned i;
found = YES;
break;
}
else // dump events not for
[event_queue removeObjectAtIndex:0]; // the modal window
else
{
// dump events not for
// the modal window
[event_queue removeObjectAtIndex: 0];
}
}
if (found == NO)
@ -407,10 +415,14 @@ unsigned i;
{
[self sendEvent: current_event];
/*
* Check to see if the window has gone away - if so, end session.
*/
if ([window_list indexOfObjectIdenticalTo: session->window] ==
NSNotFound || [session->window isVisible] == NO)
[self stopModal];
if (windows_need_update)
[self updateWindows];
/* xxx should we update the services menu? */
[listener updateServicesMenu];
}
[pool release];
@ -1093,7 +1105,7 @@ int i;
{
}
- (void)removeWindowsItem:aWindow
- (void) removeWindowsItem: (NSWindow*)aWindow
{
if (aWindow == key_window) // This should be different
key_window = nil;

View file

@ -265,23 +265,38 @@ id gnustep_gui_nsbutton_class = nil;
//
- (NSString*) keyEquivalent
{
return nil;
return [cell keyEquivalent];
}
- (unsigned int) keyEquivalentModifierMask
{
return 0;
return [cell keyEquivalentModifierMask];
}
- (void) setKeyEquivalent: (NSString*)aKeyEquivalent
{}
{
[cell setKeyEquivalent: aKeyEquivalent];
}
- (void) setKeyEquivalentModifierMask: (unsigned int)mask
{}
{
[cell setKeyEquivalentModifierMask: mask];
}
//
// Handling Events and Action Messages
//
- (BOOL)acceptsFirstResponder
{
return [self keyEquivalent] != nil;;
}
- (void) keyDown: (NSEvent*)theEvent
{
if ([self performKeyEquivalent: theEvent] == NO)
[super keyDown: theEvent];
}
- (void) performClick: (id)sender
{
[cell performClick: sender];
@ -289,6 +304,21 @@ id gnustep_gui_nsbutton_class = nil;
- (BOOL) performKeyEquivalent: (NSEvent *)anEvent
{
if ([self isEnabled])
{
NSString *key = [self keyEquivalent];
if (key != nil && [key isEqual: [anEvent charactersIgnoringModifiers]])
{
unsigned int mask = [self keyEquivalentModifierMask];
if (([anEvent modifierFlags] & mask) == mask)
{
[self performClick: self];
return YES;
}
}
}
return NO;
}

View file

@ -33,6 +33,7 @@
#include <Foundation/NSLock.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSString.h>
#include <Foundation/NSException.h>
#include <AppKit/NSButtonCell.h>
#include <AppKit/NSButton.h>
@ -154,11 +155,39 @@ NSString* _string = [aString copy];
[self setContinuous:YES];
}
- (void) performClick: (id)sender
{
NSView *cv = [self controlView];
[self highlight: YES withFrame: [cv frame] inView: cv];
if (action && target)
{
NS_DURING
{
[(NSControl*)cv sendAction: action to: target];
}
NS_HANDLER
{
[self highlight: NO withFrame: [cv frame] inView: cv];
[localException raise];
}
NS_ENDHANDLER
}
[self highlight: NO withFrame: [cv frame] inView: cv];
}
//
// Setting the Key Equivalent
//
- (NSString *)keyEquivalent { return keyEquivalent; }
- (NSFont *)keyEquivalentFont { return keyEquivalentFont; }
- (NSString*) keyEquivalent
{
return keyEquivalent;
}
- (NSFont*) keyEquivalentFont
{
return keyEquivalentFont;
}
- (unsigned int) keyEquivalentModifierMask
{
@ -167,7 +196,11 @@ NSString* _string = [aString copy];
- (void) setKeyEquivalent: (NSString*)key
{
ASSIGN(keyEquivalent, [key copy]);
if (keyEquivalent != key)
{
[keyEquivalent release];
keyEquivalent = [key copy];
}
}
- (void) setKeyEquivalentModifierMask: (unsigned int)mask
@ -272,13 +305,6 @@ NSString* _string = [aString copy];
control_view = controlView; // Save last view cell was drawn to
}
//
// Simulating a Click
//
- (void)performClick:(id)sender
{
}
- (id)copyWithZone:(NSZone*)zone
{
NSButtonCell* c = [super copyWithZone:zone];

View file

@ -30,6 +30,7 @@
#include <gnustep/gui/config.h>
#include <Foundation/NSString.h>
#include <Foundation/NSException.h>
#include <Foundation/NSValue.h>
#include <AppKit/NSApplication.h>
@ -527,6 +528,23 @@ unsigned int previousMask = action_mask;
- (void) performClick: (id)sender
{
NSView *cv = [self controlView];
[self highlight: YES withFrame: [cv frame] inView: cv];
if ([self action] && [self target])
{
NS_DURING
{
[(NSControl*)cv sendAction: [self action] to: [self target]];
}
NS_HANDLER
{
[self highlight: NO withFrame: [cv frame] inView: cv];
[localException raise];
}
NS_ENDHANDLER
}
[self highlight: NO withFrame: [cv frame] inView: cv];
}
//

View file

@ -83,6 +83,18 @@
defer: NO];
}
//
// If we receive an escape, close.
//
- (void) keyDown: (NSEvent*)theEvent
{
if ([@"\e" isEqual: [theEvent charactersIgnoringModifiers]] &&
([self styleMask] & NSClosableWindowMask) == NSClosableWindowMask)
[self close];
else
[super keyDown: theEvent];
}
//
// Determining the Panel's Behavior
//
@ -410,6 +422,7 @@ static GSAlertPanel *gmodelAlertPanel = nil;
[defButton setTitle: defaultButton];
if ([defButton superview] == nil)
[content addSubview: defButton];
[self makeFirstResponder: defButton];
}
else
{

View file

@ -619,15 +619,10 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName: NSWindowWillCloseNotification object: self];
[self orderOut: self];
visible = NO;
// if app has no
if(![[NSApplication sharedApplication] mainMenu]) // menu terminate
[[NSApplication sharedApplication] terminate:self];
else
{ // else if should
if (is_released_when_closed) // release do so
[self autorelease]; // default is YES
} // for windows and
} // NO for panels
if (is_released_when_closed)
[self autorelease];
}
- (void)deminiaturize:sender
{
@ -708,12 +703,32 @@ NSApplication *theApp = [NSApplication sharedApplication];
- (NSResponder *)firstResponder { return first_responder; }
- (void)keyDown:(NSEvent *)theEvent // save the first responder
{ // so that the key up goes
original_responder = first_responder; // to it and not a possible
// new first responder
[first_responder keyDown:theEvent]; // Send the first responder
} // the key down
- (void) keyDown: (NSEvent*)theEvent
{
static NSEvent *inProgress = nil;
if (theEvent == inProgress)
{
/*
* There was a loop in the responser chain - nothin handled the event
* so we make a warning beep.
*/
inProgress = nil;
NSBeep();
}
else
{
/*
* Save the first responder so that the key up goes to it and not a
* possible new first responder.
* Save the event so we can detect a loop in the responder chain.
*/
original_responder = first_responder;
inProgress = theEvent;
[first_responder keyDown: theEvent];
inProgress = nil;
}
}
- (BOOL)makeFirstResponder:(NSResponder *)aResponder
{