diff --git a/ChangeLog b/ChangeLog index 6a12cf82c..c4108468b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1999-12-24 David Lazaro + + * Source/NSMenuView.m ([NSMenuView -trackWithEvent:]): Added hysteresis + to the item selection code. + Wed Dec 22 12:04:00 1999 Richard Frith-Macdonald * Source/NSImage.m: When creating an off-screen cache, fill with diff --git a/Source/NSMenuView.m b/Source/NSMenuView.m index 6d206edd3..191de4465 100644 --- a/Source/NSMenuView.m +++ b/Source/NSMenuView.m @@ -708,8 +708,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess. [targetMenuView setHighlightedItemIndex: -1]; } -#define MOVE_THRESHOLD_DELTA 1.0 -#define DELAY_MULTIPLIER 12 +#define MENU_SELECT_DELAY 4 - (BOOL)trackWithEvent: (NSEvent *)event { @@ -721,82 +720,73 @@ static float GSMenuBarHeight = 25.0; // A wild guess. int index; NSPoint location; - NSPoint lastLocation = {0,0}; + float lastX = [window mouseLocationOutsideOfEventStream].x; NSMenu *alreadyAttachedMenu = NO; BOOL delayedSelect = NO; - int delayCount = DELAY_MULTIPLIER; + int delayCount = 0; do { - location = [window mouseLocationOutsideOfEventStream]; - index = [self indexOfItemAtPoint: location]; + lastX = location.x; + location = [window mouseLocationOutsideOfEventStream]; + index = [self indexOfItemAtPoint: location]; if ([event type] == NSPeriodic) { if ([menuv_menu isPartlyOffScreen]) { - NSPoint pointerLoc = [window convertBaseToScreen: - location]; + NSPoint pointerLoc = [window convertBaseToScreen: location]; // TODO: Why 1 in the Y axis? if (pointerLoc.x == 0 || pointerLoc.y == 1 || - pointerLoc.x == [[window screen] frame].size.width - - 1) + pointerLoc.x == [[window screen] frame].size.width - 1) [menuv_menu shiftOnScreen]; } - - if ([event type] == NSPeriodic && delayedSelect && !delayCount) + else if (delayedSelect && !--delayCount) { - if (location.x - lastLocation.x < MOVE_THRESHOLD_DELTA || - abs(location.y - lastLocation.y) < MOVE_THRESHOLD_DELTA) - delayedSelect = NO; - - lastLocation = location; + delayedSelect = NO; } - - delayCount = delayCount ? --delayCount : DELAY_MULTIPLIER; } if (index == -1) { + if (delayedSelect) + { + delayedSelect = NO; + } + if ([menuv_menu attachedMenu]) { if ([[self attachedMenuView] trackWithEvent: event]) 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]) || [menuv_menu isFollowTransient]) 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) - { - [self setHighlightedItemIndex: index]; + delayCount = MENU_SELECT_DELAY; + delayedSelect = YES; + } - if ([menuv_menu attachedMenu]) - [self detachSubmenu]; + if (!delayedSelect) + { + [self setHighlightedItemIndex: index]; - if ((alreadyAttachedMenu = - [[menuv_items_link objectAtIndex: index] submenu])) - { - [self attachSubmenuForItemAtIndex: index]; - delayedSelect = YES; - delayCount = DELAY_MULTIPLIER; - } - else - { - delayedSelect = NO; - } - } + if ([menuv_menu attachedMenu]) + [self detachSubmenu]; + + if ((alreadyAttachedMenu = + [[menuv_items_link objectAtIndex: index] submenu])) + [self attachSubmenuForItemAtIndex: index]; } }