Minor menu fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5668 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-01-05 16:35:47 +00:00
parent afef91ac71
commit c23e5e2e11
2 changed files with 47 additions and 31 deletions

View file

@ -1,3 +1,9 @@
Wed Jan 5 16:27:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSMenuItem.m: minor fixes and tidying.
* Source/NSMenuView.m: reverted to previous version - last change
broke much more than it fixed.
Mon Jan 3 18:35:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk> Mon Jan 3 18:35:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSBundleAdditions.m: Added ([-awakeWithContext:]) method for * Source/NSBundleAdditions.m: Added ([-awakeWithContext:]) method for

View file

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