Added hysteresis to the item selection code.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5620 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
dlazaro 1999-12-23 23:31:59 +00:00
parent 0ac6a19348
commit fc1dab4d2c
2 changed files with 36 additions and 41 deletions

View file

@ -1,3 +1,8 @@
1999-12-24 David Lazaro <khelekir@encomix.es>
* Source/NSMenuView.m ([NSMenuView -trackWithEvent:]): Added hysteresis
to the item selection code.
Wed Dec 22 12:04:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Wed Dec 22 12:04:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSImage.m: When creating an off-screen cache, fill with * Source/NSImage.m: When creating an off-screen cache, fill with

View file

@ -708,8 +708,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[targetMenuView setHighlightedItemIndex: -1]; [targetMenuView setHighlightedItemIndex: -1];
} }
#define MOVE_THRESHOLD_DELTA 1.0 #define MENU_SELECT_DELAY 4
#define DELAY_MULTIPLIER 12
- (BOOL)trackWithEvent: (NSEvent *)event - (BOOL)trackWithEvent: (NSEvent *)event
{ {
@ -721,82 +720,73 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
int index; int index;
NSPoint location; NSPoint location;
NSPoint lastLocation = {0,0}; float lastX = [window mouseLocationOutsideOfEventStream].x;
NSMenu *alreadyAttachedMenu = NO; NSMenu *alreadyAttachedMenu = NO;
BOOL delayedSelect = NO; BOOL delayedSelect = NO;
int delayCount = DELAY_MULTIPLIER; int delayCount = 0;
do do
{ {
location = [window mouseLocationOutsideOfEventStream]; lastX = location.x;
index = [self indexOfItemAtPoint: location]; location = [window mouseLocationOutsideOfEventStream];
index = [self indexOfItemAtPoint: location];
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];
} }
else if (delayedSelect && !--delayCount)
if ([event type] == NSPeriodic && delayedSelect && !delayCount)
{ {
if (location.x - lastLocation.x < MOVE_THRESHOLD_DELTA || delayedSelect = NO;
abs(location.y - lastLocation.y) < MOVE_THRESHOLD_DELTA)
delayedSelect = NO;
lastLocation = location;
} }
delayCount = delayCount ? --delayCount : DELAY_MULTIPLIER;
} }
if (index == -1) if (index == -1)
{ {
if (delayedSelect)
{
delayedSelect = NO;
}
if ([menuv_menu attachedMenu]) if ([menuv_menu attachedMenu])
{ {
if ([[self attachedMenuView] trackWithEvent: event]) if ([[self attachedMenuView] trackWithEvent: event])
return YES; return YES;
} }
else else if (index != menuv_highlightedItemIndex)
{ {
if (index != menuv_highlightedItemIndex) [self setHighlightedItemIndex: index];
[self setHighlightedItemIndex: index];
} }
if (([menuv_menu supermenu] && ![menuv_menu isTornOff]) if (([menuv_menu supermenu] && ![menuv_menu isTornOff])
|| [menuv_menu isFollowTransient]) || [menuv_menu isFollowTransient])
return NO; return NO;
} }
else else if (index != menuv_highlightedItemIndex && !delayedSelect)
{ {
if (index != menuv_highlightedItemIndex) if (location.x - lastX > 0 && [menuv_menu attachedMenu])
{ {
if (![menuv_menu attachedMenu] || !delayedSelect) delayCount = MENU_SELECT_DELAY;
{ delayedSelect = YES;
[self setHighlightedItemIndex: index]; }
if ([menuv_menu attachedMenu]) if (!delayedSelect)
[self detachSubmenu]; {
[self setHighlightedItemIndex: index];
if ((alreadyAttachedMenu = if ([menuv_menu attachedMenu])
[[menuv_items_link objectAtIndex: index] submenu])) [self detachSubmenu];
{
[self attachSubmenuForItemAtIndex: index]; if ((alreadyAttachedMenu =
delayedSelect = YES; [[menuv_items_link objectAtIndex: index] submenu]))
delayCount = DELAY_MULTIPLIER; [self attachSubmenuForItemAtIndex: index];
}
else
{
delayedSelect = NO;
}
}
} }
} }