From 285febd6c48a6d339181df6e2c11a1bd73f306d2 Mon Sep 17 00:00:00 2001 From: espectador Date: Sat, 8 Jan 2011 07:04:57 +0000 Subject: [PATCH] Improvements for menu in window git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@31857 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/NSMenuView.m | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e85a6966..d21441996 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-08 German Arias + + * Source/NSMenuView.m (-trackWithEvent:): + Close the menu in window if user press a modifier key. + And improvements for don't lose the mouse tracking + in a menu in window. + 2011-01-06 German Arias * Source/NSMenuView.m (-locationForSubmenu:, -trackWithEvent:): diff --git a/Source/NSMenuView.m b/Source/NSMenuView.m index c330461a4..762078d13 100644 --- a/Source/NSMenuView.m +++ b/Source/NSMenuView.m @@ -1427,6 +1427,7 @@ static NSMapTable *viewInfo = 0; int delayCount = 0; int indexOfActionToExecute = -1; int firstIndex = -1; + int space = 0; NSEvent *original; NSEventType type; NSEventType end; @@ -1458,6 +1459,14 @@ static NSMapTable *viewInfo = 0; end = NSLeftMouseUp; eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask; eventMask |= NSLeftMouseDownMask; + + /*We need know if the user press a modifier key to close the menu + when the menu is in a window*/ + if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self) == + NSWindows95InterfaceStyle) + { + eventMask |= NSFlagsChangedMask; + } } else { @@ -1484,6 +1493,17 @@ static NSMapTable *viewInfo = 0; } do { + /*Close the menu if the user press a modifier key and menu + is in a window*/ + if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self) == + NSWindows95InterfaceStyle && type == NSFlagsChanged) + { + [self setHighlightedItemIndex: -1]; + [[[[NSApp mainWindow] menu] attachedMenu] close]; + shouldFinish = YES; + return NO; + } + if (type == end) { shouldFinish = YES; @@ -1628,9 +1648,17 @@ static NSMapTable *viewInfo = 0; { if ([self hitTest: location] == nil) { - [[[[NSApp mainWindow] menu] attachedMenu] close]; - shouldFinish = YES; - return NO; + /*This gives us time to move the cursor between a menu and + its submenu (or vice versa) without lose the mouse + tracking*/ + space += 1; + + if (space == 2) + { + [[[[NSApp mainWindow] menu] attachedMenu] close]; + shouldFinish = YES; + return NO; + } } if (self != [[[NSApp mainWindow] menu] menuRepresentation])