mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 19:10:48 +00:00
Menu behavior tinkering
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5674 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
623f5da51a
commit
26e56d11cf
3 changed files with 108 additions and 56 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Wed Jan 5 20:04:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
* Source/NSMenuView.m: Changes to mouse tracking loop to provide more
|
||||||
|
sophisticated handling of opening/closing of submenus in an attempt to
|
||||||
|
mimic the behavior of NeXTstep.
|
||||||
|
|
||||||
Wed Jan 5 16:27:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Wed Jan 5 16:27:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
* Source/NSMenuItem.m: minor fixes and tidying.
|
* Source/NSMenuItem.m: minor fixes and tidying.
|
||||||
|
|
|
@ -51,15 +51,15 @@
|
||||||
#include <AppKit/NSPopUpButtonCell.h>
|
#include <AppKit/NSPopUpButtonCell.h>
|
||||||
#include <AppKit/NSScreen.h>
|
#include <AppKit/NSScreen.h>
|
||||||
|
|
||||||
static NSZone *menuZone = NULL;
|
static NSZone *menuZone = NULL;
|
||||||
|
|
||||||
static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
static NSString *NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
|
|
||||||
@implementation NSMenu
|
@implementation NSMenu
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Class Methods
|
* Class Methods
|
||||||
//
|
*/
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [NSMenu class])
|
if (self == [NSMenu class])
|
||||||
|
@ -68,19 +68,19 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void) setMenuZone: (NSZone *)zone
|
+ (void) setMenuZone: (NSZone*)zone
|
||||||
{
|
{
|
||||||
menuZone = zone;
|
menuZone = zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSZone *) menuZone
|
+ (NSZone*) menuZone
|
||||||
{
|
{
|
||||||
return menuZone;
|
return menuZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Initializing a New NSMenu
|
* Initializing a New NSMenu
|
||||||
//
|
*/
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
return [self initWithTitle: @"Menu"];
|
return [self initWithTitle: @"Menu"];
|
||||||
|
@ -116,7 +116,7 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithTitle: (NSString *)aTitle
|
- (id) initWithTitle: (NSString*)aTitle
|
||||||
{
|
{
|
||||||
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
|
||||||
NSApplication *theApp = [NSApplication sharedApplication];
|
NSApplication *theApp = [NSApplication sharedApplication];
|
||||||
|
@ -172,9 +172,9 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Setting Up the Menu Commands
|
* Setting Up the Menu Commands
|
||||||
//
|
*/
|
||||||
- (void) insertItem: (id <NSMenuItem>)newItem
|
- (void) insertItem: (id <NSMenuItem>)newItem
|
||||||
atIndex: (int)index
|
atIndex: (int)index
|
||||||
{
|
{
|
||||||
|
@ -185,8 +185,10 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
{
|
{
|
||||||
if ([(id)newItem isKindOfClass: [NSMenuItem class]])
|
if ([(id)newItem isKindOfClass: [NSMenuItem class]])
|
||||||
{
|
{
|
||||||
// If the item is already attached to another menu it
|
/*
|
||||||
// isn't added.
|
* If the item is already attached to another menu it
|
||||||
|
* isn't added.
|
||||||
|
*/
|
||||||
if ([(NSMenuItem *)newItem menu] != nil)
|
if ([(NSMenuItem *)newItem menu] != nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -222,9 +224,9 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
menu_changed = YES;
|
menu_changed = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id <NSMenuItem>) insertItemWithTitle: (NSString *)aString
|
- (id <NSMenuItem>) insertItemWithTitle: (NSString*)aString
|
||||||
action: (SEL)aSelector
|
action: (SEL)aSelector
|
||||||
keyEquivalent: (NSString *)charCode
|
keyEquivalent: (NSString*)charCode
|
||||||
atIndex: (unsigned int)index
|
atIndex: (unsigned int)index
|
||||||
{
|
{
|
||||||
id anItem = [NSMenuItem new];
|
id anItem = [NSMenuItem new];
|
||||||
|
@ -247,9 +249,9 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
[self insertItem: newItem atIndex: [menu_items count]];
|
[self insertItem: newItem atIndex: [menu_items count]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id <NSMenuItem>) addItemWithTitle: (NSString *)aString
|
- (id <NSMenuItem>) addItemWithTitle: (NSString*)aString
|
||||||
action: (SEL)aSelector
|
action: (SEL)aSelector
|
||||||
keyEquivalent: (NSString *)keyEquiv
|
keyEquivalent: (NSString*)keyEquiv
|
||||||
{
|
{
|
||||||
return [self insertItemWithTitle: aString
|
return [self insertItemWithTitle: aString
|
||||||
action: aSelector
|
action: aSelector
|
||||||
|
@ -321,9 +323,9 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
[self update];
|
[self update];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Finding Menu Items
|
* Finding Menu Items
|
||||||
//
|
*/
|
||||||
- (id <NSMenuItem>) itemWithTag: (int)aTag
|
- (id <NSMenuItem>) itemWithTag: (int)aTag
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
@ -368,20 +370,20 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
return [menu_items count];
|
return [menu_items count];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *) itemArray
|
- (NSArray*) itemArray
|
||||||
{
|
{
|
||||||
return (NSArray *)menu_items;
|
return (NSArray*)menu_items;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Finding Indices of Menu Items
|
* Finding Indices of Menu Items
|
||||||
//
|
*/
|
||||||
- (int) indexOfItem: (id <NSMenuItem>)anObject
|
- (int) indexOfItem: (id <NSMenuItem>)anObject
|
||||||
{
|
{
|
||||||
return [menu_items indexOfObjectIdenticalTo: anObject];
|
return [menu_items indexOfObjectIdenticalTo: anObject];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int) indexOfItemWithTitle: (NSString *)aTitle
|
- (int) indexOfItemWithTitle: (NSString*)aTitle
|
||||||
{
|
{
|
||||||
id anItem;
|
id anItem;
|
||||||
|
|
||||||
|
@ -411,9 +413,13 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
||||||
{
|
{
|
||||||
NSMenuItem *menuItem = [menu_items objectAtIndex: i];
|
NSMenuItem *menuItem = [menu_items objectAtIndex: i];
|
||||||
|
|
||||||
if ([[menuItem target] isEqual: anObject]
|
if (actionSelector == 0 || sel_eq([menuItem action], actionSelector))
|
||||||
&& (!actionSelector || [menuItem action] == actionSelector))
|
{
|
||||||
return i;
|
if ([[menuItem target] isEqual: anObject])
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -409,9 +409,9 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
|
||||||
float howHigh = (howMany * cellSize.height);
|
float howHigh = (howMany * cellSize.height);
|
||||||
float neededImageAndTitleWidth = [[NSFont boldSystemFontOfSize: 12]
|
float neededImageAndTitleWidth = [[NSFont boldSystemFontOfSize: 12]
|
||||||
widthOfString: [menuv_menu title]] + 17;
|
widthOfString: [menuv_menu title]] + 17;
|
||||||
float neededKeyEquivalentWidth = 0.;
|
float neededKeyEquivalentWidth = 0.0;
|
||||||
float neededStateImageWidth = 0.;
|
float neededStateImageWidth = 0.0;
|
||||||
float accumulatedOffset = 0.;
|
float accumulatedOffset = 0.0;
|
||||||
|
|
||||||
// TODO: Optimize this loop.
|
// TODO: Optimize this loop.
|
||||||
for (i = 0; i < howMany; i++)
|
for (i = 0; i < howMany; i++)
|
||||||
|
@ -710,7 +710,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MOVE_THRESHOLD_DELTA 1.0
|
#define MOVE_THRESHOLD_DELTA 1.0
|
||||||
#define DELAY_MULTIPLIER 12
|
#define DELAY_MULTIPLIER 6
|
||||||
|
|
||||||
- (BOOL) trackWithEvent: (NSEvent *)event
|
- (BOOL) trackWithEvent: (NSEvent *)event
|
||||||
{
|
{
|
||||||
|
@ -719,43 +719,81 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
|
||||||
| NSLeftMouseDraggedMask
|
| NSLeftMouseDraggedMask
|
||||||
| NSPeriodicMask;
|
| NSPeriodicMask;
|
||||||
NSDate *theDistantFuture = [NSDate distantFuture];
|
NSDate *theDistantFuture = [NSDate distantFuture];
|
||||||
|
int index;
|
||||||
int index;
|
NSPoint location;
|
||||||
NSPoint location;
|
NSPoint lastLocation = {0,0};
|
||||||
NSPoint lastLocation = {0,0};
|
NSMenu *alreadyAttachedMenu = NO;
|
||||||
NSMenu *alreadyAttachedMenu = NO;
|
BOOL mouseMoved = NO;
|
||||||
BOOL delayedSelect = NO;
|
BOOL delayedSelect = NO;
|
||||||
int delayCount = DELAY_MULTIPLIER;
|
int delayCount = 0;
|
||||||
|
float xDelta = MOVE_THRESHOLD_DELTA;
|
||||||
|
float yDelta = 0.0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
location = [window mouseLocationOutsideOfEventStream];
|
location = [window mouseLocationOutsideOfEventStream];
|
||||||
index = [self indexOfItemAtPoint: location];
|
index = [self indexOfItemAtPoint: location];
|
||||||
|
|
||||||
|
if (index != menuv_highlightedItemIndex)
|
||||||
|
{
|
||||||
|
mouseMoved = YES; /* Ok - had an initial movement. */
|
||||||
|
}
|
||||||
if ([event type] == NSPeriodic)
|
if ([event type] == NSPeriodic)
|
||||||
{
|
{
|
||||||
if ([menuv_menu isPartlyOffScreen])
|
if ([menuv_menu isPartlyOffScreen])
|
||||||
{
|
{
|
||||||
NSPoint pointerLoc = [window convertBaseToScreen:
|
NSPoint pointerLoc = [window convertBaseToScreen: location];
|
||||||
location];
|
|
||||||
|
|
||||||
// TODO: Why 1 in the Y axis?
|
// TODO: Why 1 in the Y axis?
|
||||||
if (pointerLoc.x == 0 || pointerLoc.y == 1 ||
|
if (pointerLoc.x == 0 || pointerLoc.y == 1
|
||||||
pointerLoc.x == [[window screen] frame].size.width
|
|| pointerLoc.x == [[window screen] frame].size.width - 1)
|
||||||
- 1)
|
|
||||||
[menuv_menu shiftOnScreen];
|
[menuv_menu shiftOnScreen];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([event type] == NSPeriodic && delayedSelect && !delayCount)
|
if (delayedSelect && mouseMoved && [event type] == NSPeriodic)
|
||||||
{
|
{
|
||||||
if (location.x - lastLocation.x < MOVE_THRESHOLD_DELTA ||
|
float xDiff = location.x - lastLocation.x;
|
||||||
abs(location.y - lastLocation.y) < MOVE_THRESHOLD_DELTA)
|
float yDiff = location.y - lastLocation.y;
|
||||||
delayedSelect = NO;
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Once the mouse movement has started in one vertical
|
||||||
|
* direction, it must continue in the same direction if
|
||||||
|
* selection is to be delayed.
|
||||||
|
*/
|
||||||
|
if (yDelta == 0.0)
|
||||||
|
{
|
||||||
|
if (yDiff < 0.0)
|
||||||
|
yDelta = -MOVE_THRESHOLD_DELTA;
|
||||||
|
else if (yDiff > 0.0)
|
||||||
|
yDelta = MOVE_THRESHOLD_DELTA;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Check to see if movement is less than the threshold.
|
||||||
|
*/
|
||||||
|
if (xDiff < xDelta
|
||||||
|
|| (yDelta < 0.0 && yDiff > yDelta)
|
||||||
|
|| (yDelta > 0.0 && yDiff < yDelta))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* if we have had too many successive small movements, or
|
||||||
|
* a single movement too far in the wrong direction, we
|
||||||
|
* leave 'delayedSelect' mode.
|
||||||
|
*/
|
||||||
|
delayCount++;
|
||||||
|
if (delayCount >= DELAY_MULTIPLIER
|
||||||
|
|| (xDiff < -xDelta)
|
||||||
|
|| (yDelta < 0.0 && yDiff > -yDelta)
|
||||||
|
|| (yDelta > 0.0 && yDiff < -yDelta))
|
||||||
|
{
|
||||||
|
delayedSelect = NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delayCount = 0;
|
||||||
|
}
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
delayCount = delayCount ? --delayCount : DELAY_MULTIPLIER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
|
@ -790,8 +828,10 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
|
||||||
[[menuv_items_link objectAtIndex: index] submenu]))
|
[[menuv_items_link objectAtIndex: index] submenu]))
|
||||||
{
|
{
|
||||||
[self attachSubmenuForItemAtIndex: index];
|
[self attachSubmenuForItemAtIndex: index];
|
||||||
|
mouseMoved = NO;
|
||||||
delayedSelect = YES;
|
delayedSelect = YES;
|
||||||
delayCount = DELAY_MULTIPLIER;
|
delayCount = 0;
|
||||||
|
yDelta = 0.0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -863,7 +903,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
|
||||||
|
|
||||||
masterMenuView->menuv_keepAttachedMenus = YES;
|
masterMenuView->menuv_keepAttachedMenus = YES;
|
||||||
|
|
||||||
[NSEvent startPeriodicEventsAfterDelay: 0.2 withPeriod: 0.05];
|
[NSEvent startPeriodicEventsAfterDelay: 0.1 withPeriod: 0.05];
|
||||||
|
|
||||||
[masterMenuView trackWithEvent: theEvent];
|
[masterMenuView trackWithEvent: theEvent];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue