mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 20:50:38 +00:00
further refinements to behavior of performKeyEquivalent: methods
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30828 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e5236628c8
commit
ceb0f17569
4 changed files with 49 additions and 18 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
2010-06-22 Doug Simons <doug.simons@testplant.com>
|
||||||
|
|
||||||
|
* Source/NSButton.m:
|
||||||
|
* Source/NSMatrix.m:
|
||||||
|
* Source/NSMenu.m:
|
||||||
|
Further change to performKeyEquivalent: methods to take Shift key
|
||||||
|
into account for control keys (such as Return and Tab) as well as
|
||||||
|
function keys, and to honor keyEquivalentModifierMask for cells in
|
||||||
|
a matrix that implement that method. Also, ignore key events with
|
||||||
|
zero length (such as the Windows key) which was previously triggering
|
||||||
|
actions on objects with no keyEquivalent.
|
||||||
|
|
||||||
2010-06-22 Wolfgang Lux <wolfgang.lux@gmail.com>
|
2010-06-22 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
* Source/NSPopUpButtonCell.m (-initTextCell:pullsDown:, -initWithCoder:,
|
* Source/NSPopUpButtonCell.m (-initTextCell:pullsDown:, -initWithCoder:,
|
||||||
|
|
|
@ -515,15 +515,19 @@ static id buttonCellClass = nil;
|
||||||
|
|
||||||
if ([self isEnabled] && (mw == nil || [w worksWhenModal] || mw == w))
|
if ([self isEnabled] && (mw == nil || [w worksWhenModal] || mw == w))
|
||||||
{
|
{
|
||||||
NSString *key = [self keyEquivalent];
|
NSString *keyEquivalent = [self keyEquivalent];
|
||||||
|
|
||||||
if (key != nil && [key isEqual: [anEvent charactersIgnoringModifiers]])
|
if ([keyEquivalent length] > 0 && [keyEquivalent isEqualToString: [anEvent charactersIgnoringModifiers]])
|
||||||
{
|
{
|
||||||
const unsigned int relevantMask =
|
|
||||||
NSCommandKeyMask | NSAlternateKeyMask | NSControlKeyMask;
|
|
||||||
unsigned int mask = [self keyEquivalentModifierMask];
|
unsigned int mask = [self keyEquivalentModifierMask];
|
||||||
|
unsigned int modifiers = [anEvent modifierFlags];
|
||||||
if (([anEvent modifierFlags] & relevantMask) == (mask & relevantMask))
|
unsigned int relevantModifiersMask = NSCommandKeyMask | NSAlternateKeyMask | NSControlKeyMask;
|
||||||
|
/* Take shift key into account only for control keys and arrow and function keys */
|
||||||
|
if ((modifiers & NSFunctionKeyMask)
|
||||||
|
|| [[NSCharacterSet controlCharacterSet] characterIsMember:[keyEquivalent characterAtIndex:0]])
|
||||||
|
relevantModifiersMask |= NSShiftKeyMask;
|
||||||
|
|
||||||
|
if ((modifiers & relevantModifiersMask) == (mask & relevantModifiersMask))
|
||||||
{
|
{
|
||||||
[self performClick: self];
|
[self performClick: self];
|
||||||
return YES;
|
return YES;
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
#include <Foundation/NSValue.h>
|
#include <Foundation/NSValue.h>
|
||||||
#include <Foundation/NSArray.h>
|
#include <Foundation/NSArray.h>
|
||||||
#include <Foundation/NSAutoreleasePool.h>
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
|
#include <Foundation/NSCharacterSet.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSKeyedArchiver.h>
|
#include <Foundation/NSKeyedArchiver.h>
|
||||||
#include <Foundation/NSNotification.h>
|
#include <Foundation/NSNotification.h>
|
||||||
|
@ -63,8 +64,8 @@
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSZone.h>
|
#include <Foundation/NSZone.h>
|
||||||
|
|
||||||
#include "AppKit/NSActionCell.h"
|
|
||||||
#include "AppKit/NSApplication.h"
|
#include "AppKit/NSApplication.h"
|
||||||
|
#include "AppKit/NSButtonCell.h"
|
||||||
#include "AppKit/NSColor.h"
|
#include "AppKit/NSColor.h"
|
||||||
#include "AppKit/NSCursor.h"
|
#include "AppKit/NSCursor.h"
|
||||||
#include "AppKit/NSEvent.h"
|
#include "AppKit/NSEvent.h"
|
||||||
|
@ -2580,8 +2581,18 @@ static SEL getSel;
|
||||||
*/
|
*/
|
||||||
- (BOOL) performKeyEquivalent: (NSEvent*)theEvent
|
- (BOOL) performKeyEquivalent: (NSEvent*)theEvent
|
||||||
{
|
{
|
||||||
NSString *key = [theEvent charactersIgnoringModifiers];
|
NSString *keyEquivalent = [theEvent charactersIgnoringModifiers];
|
||||||
|
unsigned int modifiers = [theEvent modifierFlags];
|
||||||
int i;
|
int i;
|
||||||
|
unsigned int relevantModifiersMask = NSCommandKeyMask | NSAlternateKeyMask | NSControlKeyMask;
|
||||||
|
unichar key = ([keyEquivalent length] > 0 ? [keyEquivalent characterAtIndex:0] : 0);
|
||||||
|
/* Take shift key into account only for control keys and arrow and function keys */
|
||||||
|
if ((modifiers & NSFunctionKeyMask)
|
||||||
|
|| ([keyEquivalent length] > 0 && [[NSCharacterSet controlCharacterSet] characterIsMember:[keyEquivalent characterAtIndex:0]]))
|
||||||
|
relevantModifiersMask |= NSShiftKeyMask;
|
||||||
|
|
||||||
|
if ([keyEquivalent length] == 0)
|
||||||
|
return NO; // don't respond to zero-length string (such as the Windows key)
|
||||||
|
|
||||||
for (i = 0; i < _numRows; i++)
|
for (i = 0; i < _numRows; i++)
|
||||||
{
|
{
|
||||||
|
@ -2590,9 +2601,13 @@ static SEL getSel;
|
||||||
for (j = 0; j < _numCols; j++)
|
for (j = 0; j < _numCols; j++)
|
||||||
{
|
{
|
||||||
NSCell *aCell = _cells[i][j];;
|
NSCell *aCell = _cells[i][j];;
|
||||||
|
unsigned int mask = 0;
|
||||||
|
if ([aCell respondsToSelector:@selector(keyEquivalentModifierMask)])
|
||||||
|
mask = [(NSButtonCell *)aCell keyEquivalentModifierMask];
|
||||||
|
|
||||||
if ([aCell isEnabled]
|
if ([aCell isEnabled]
|
||||||
&& [[aCell keyEquivalent] isEqualToString: key])
|
&& [[aCell keyEquivalent] isEqualToString: keyEquivalent]
|
||||||
|
&& (mask & relevantModifiersMask) == (modifiers & relevantModifiersMask))
|
||||||
{
|
{
|
||||||
NSCell *oldSelectedCell = _selectedCell;
|
NSCell *oldSelectedCell = _selectedCell;
|
||||||
int oldSelectedRow = _selectedRow;
|
int oldSelectedRow = _selectedRow;
|
||||||
|
|
|
@ -1226,10 +1226,15 @@ static BOOL menuBarVisible = YES;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
unsigned count = [_items count];
|
unsigned count = [_items count];
|
||||||
NSEventType type = [theEvent type];
|
NSEventType type = [theEvent type];
|
||||||
unsigned modifiers = [theEvent modifierFlags];
|
unsigned int modifiers = [theEvent modifierFlags];
|
||||||
NSString *keyEquivalent = [theEvent charactersIgnoringModifiers];
|
NSString *keyEquivalent = [theEvent charactersIgnoringModifiers];
|
||||||
|
unsigned int relevantModifiersMask = NSCommandKeyMask | NSAlternateKeyMask | NSControlKeyMask;
|
||||||
|
/* Take shift key into account only for control keys and arrow and function keys */
|
||||||
|
if ((modifiers & NSFunctionKeyMask)
|
||||||
|
|| ([keyEquivalent length] > 0 && [[NSCharacterSet controlCharacterSet] characterIsMember:[keyEquivalent characterAtIndex:0]]))
|
||||||
|
relevantModifiersMask |= NSShiftKeyMask;
|
||||||
|
|
||||||
if (type != NSKeyDown && type != NSKeyUp)
|
if ((type != NSKeyDown && type != NSKeyUp) || [keyEquivalent length] == 0)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
|
@ -1239,6 +1244,7 @@ static BOOL menuBarVisible = YES;
|
||||||
if ([item hasSubmenu])
|
if ([item hasSubmenu])
|
||||||
{
|
{
|
||||||
// Recurse through submenus whether active or not.
|
// Recurse through submenus whether active or not.
|
||||||
|
// Recurse through submenus whether active or not.
|
||||||
if ([[item submenu] performKeyEquivalent: theEvent])
|
if ([[item submenu] performKeyEquivalent: theEvent])
|
||||||
{
|
{
|
||||||
// The event has been handled by an item in the submenu.
|
// The event has been handled by an item in the submenu.
|
||||||
|
@ -1247,16 +1253,10 @@ static BOOL menuBarVisible = YES;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned int relevantMask =
|
|
||||||
NSCommandKeyMask | NSAlternateKeyMask | NSControlKeyMask;
|
|
||||||
unsigned int mask = [item keyEquivalentModifierMask];
|
unsigned int mask = [item keyEquivalentModifierMask];
|
||||||
|
|
||||||
if (modifiers & NSFunctionKeyMask)
|
|
||||||
{
|
|
||||||
relevantMask |= NSShiftKeyMask;
|
|
||||||
}
|
|
||||||
if ([[item keyEquivalent] isEqualToString: keyEquivalent]
|
if ([[item keyEquivalent] isEqualToString: keyEquivalent]
|
||||||
&& (modifiers & relevantMask) == (mask & relevantMask))
|
&& (modifiers & relevantModifiersMask) == (mask & relevantModifiersMask))
|
||||||
{
|
{
|
||||||
if ([item isEnabled])
|
if ([item isEnabled])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue