This attached patch fix the behavior of menu in window. And add code to
display transient menus in a better way. For example, if the transient
menu is displayed at right side of the screen, its submenus are
displayed to left. This avoids have submenus displayed above its
supermenu, and that not respond properly.

Also, I added code to display the transient menus with one of its bottom
corners below the mouse cursor (when transient menus are displayed near
of bottom). With this the transient menus at appicons are more
consistently, and respond correctly. Or I think so.

Try the patch, add changes, discuss the code or apply it. Regards.


On mar, 2011-01-18 at 00:05 -0600, Germán Arias wrote:
> I think:
> 
>  && ![[self menu] isTransient]
>  
> really solve the problem. But in other hand, the transient menus have
> one bug. This bug occurs when transient menu is displayed at bottom. In
> this case the transient menu moves up, to appears entirely at screen.
> When this occurs, the transient menu don't respond to the events
> correctly. You can see this problem with the transient menu at AppIcons,
> when the icons are displayed at bottom. Or in any transient menu
> displayed at bottom. For example, in an Ink document that is near at
> bottom. This bug is independently of the menu style.
> 
> 
> On lun, 2011-01-17 at 14:08 -0500, Gregory Casamento wrote:
> > I'm also not entirely certain how going into that code when the
> > [[[NSApp mainWindow] menu] attachedMenu] method returns nil helps us
> > in the first place.
> > 
> > 
> > GC
> > 
> > On Jan 17, 2011, at 1:25 PM, Germán Arias wrote:
> > 
> > > Maybe:
> > > 
> > > && ![[self menu] isTransient]
> > > 
> > > is better. But even with this, and independently of the menu style,
> > > there are some problems with the transient menu at appicon. Seems
> > > like
> > > don't track correctly the mouse. 
> > > 
> > > On lun, 2011-01-17 at 10:20 -0500, Gregory Casamento wrote:
> > > > The issue I was trying to correct was that pull down menus were
> > > > not
> > > > working with the previous code.
> > > > 
> > > > I will test the situation you describe below as well.
> > > > 
> > > > GC
> > > > 
> > > > On Monday, January 17, 2011, Germán Arias <ger...@xelalug.org>
> > > > wrote:
> > > > > Hi Greg.
> > > > > 
> > > > > The addition at lines 1660 and 1661 in NSMenuView.m:
> > > > > 
> > > > > && anAttachedMenu != nil
> > > > > 
> > > > > added an odd behavior at menu in window. This is because if you
> > > > > move the
> > > > > mouse outside a submenu, the horizontal menu retrieves the mouse
> > > > > tracking. But if the mouse is outside this too, the submenu is
> > > > > closed.
> > > > > Then in next loop,there isn't an attached menu, and the code to
> > > > > handle
> > > > > the menu in window is not executed, and variable "space" never
> > > > > arrive to
> > > > > 2. Then we can't break the loop. We need add 1 to variable
> > > > > "space" even
> > > > > when there isn't an attached menu. Or I think so, I will test
> > > > > this
> > > > > tomorrow.
> > > > > 
> > > > > 
> > > > > _______________________________________________
> > > > > Gnustep-dev mailing list
> > > > > Gnustep-dev@gnu.org
> > > > > http://lists.gnu.org/mailman/listinfo/gnustep-dev
> > > > > 
> > > > 
> > > 
> > > 
> > > _______________________________________________
> > > Gnustep-dev mailing list
> > > Gnustep-dev@gnu.org
> > > http://lists.gnu.org/mailman/listinfo/gnustep-dev
> > > 
> > 
> > Gregory Casamento - GNUstep Lead/Principal Consultant, OLC, Inc.
> > yahoo/skype: greg_casamento, aol: gjcasa
> > (240)274-9630 (Cell)
> > 
> > 
Index: Source/NSMenu.m
===================================================================
--- Source/NSMenu.m	(revision 31909)
+++ Source/NSMenu.m	(working copy)
@@ -647,6 +647,8 @@
   _menu.needsSizing = YES;
   // According to the spec, menus do autoenable by default.
   _menu.autoenable = YES;
+  //By default we display transient menus from left to right.
+  _submenusToLeft = NO;
 
 
   /* Please note that we own all this menu network of objects.  So, 
@@ -1045,7 +1047,27 @@
 
 - (NSPoint) locationForSubmenu: (NSMenu*)aSubmenu
 {
-  return [_view locationForSubmenu: aSubmenu];
+  NSPoint location;
+  
+  location = [_view locationForSubmenu: aSubmenu];
+  /* If there isn't enough space at right, we display the submenus from
+     right to left. */
+  if (_submenusToLeft || [_superMenu _displayToLeft])
+    {
+      NSRect submenuFrame = [[aSubmenu window] frame];
+      NSRect frame = [_aWindow frame];
+      
+      location.x = location.x -
+	submenuFrame.size.width -
+	frame.size.width;
+
+      if (!_submenusToLeft)
+	{
+	  _submenusToLeft = YES;
+	}
+    }
+
+  return location;
 }
 
 - (NSMenu *) supermenu
@@ -1875,27 +1897,58 @@
     }
   else
     {
-      NSRect	frame = [_aWindow frame];
+      NSRect    frame = [_aWindow frame];
+      NSRect    screen = [[NSScreen mainScreen] visibleFrame];
       NSInterfaceStyle style;
 
       location = [_aWindow mouseLocationOutsideOfEventStream];
       location = [_aWindow convertBaseToScreen: location];
-      location.y -= frame.size.height;
 
+      if (location.x > screen.size.width/2)
+	{
+	  _submenusToLeft = YES;
+	}
+
       /* When using the standard NextStep/OpenStep interface style, the
 	 center of the menu's title view is placed below the mouse cursor.
 	 However, in Macintosh and Windows95 styles, menus have no visible
 	 title. To prevent the user from accidentally selecting the first
-	 item, the top left edge is placed below the mouse cursor for them. */
+	 item, the top left edge is placed below the mouse cursor for them.
+	 If this is not possible (in any interface style), because the mouse
+	 cursor is near of bottom, one of the bottom corners of the menu
+	 is placed below the mouse cursor. */
       style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil);
       if (style != NSWindows95InterfaceStyle &&
 	  style != NSMacintoshInterfaceStyle)
 	{
-	  location.x -= frame.size.width/2;
-	  if (location.x < 0)
-	    location.x = 0;
-	  location.y += 10;
+	  if (location.y > frame.size.height)
+	    {
+	      location.y -= frame.size.height;
+	      location.x -= frame.size.width/2;
+	      if (location.x < 0)
+		location.x = 0;
+	      location.y += 10;
+	    }
+	  else
+	    {
+	      if (frame.size.width > (screen.size.width - location.x))
+		{
+		  location.x -= frame.size.width;
+		}
+	    }
 	}
+      else
+	{
+	  if (location.y > frame.size.height)
+	    {
+	      location.y -= frame.size.height;
+	    }
+	  
+	  if (frame.size.width > (screen.size.width - location.x))
+	    {
+	      location.x -= frame.size.width;
+	    }
+	}
     }
 
   [_bWindow setFrameOrigin: location];
@@ -2160,6 +2213,11 @@
     }
 }
 
+- (BOOL)_displayToLeft
+{
+  return _submenusToLeft;
+}
+
 - (BOOL)_ownedByPopUp
 {
   return _popUpButtonCell != nil;
Index: Source/NSMenuView.m
===================================================================
--- Source/NSMenuView.m	(revision 31909)
+++ Source/NSMenuView.m	(working copy)
@@ -1658,7 +1658,7 @@
 		in a window*/
 	      if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self) ==
 		  NSWindows95InterfaceStyle &&
-		  anAttachedMenu != nil)
+		  ![[self menu] isTransient])
 		{
 		  if ([self hitTest: location] == nil)
 		    {
Index: Headers/AppKit/NSMenu.h
===================================================================
--- Headers/AppKit/NSMenu.h	(revision 31909)
+++ Headers/AppKit/NSMenu.h	(working copy)
@@ -357,6 +357,7 @@
   NSMenu *_oldAttachedMenu;
   int     _oldHiglightedIndex;
   NSString *_name;
+  BOOL _submenusToLeft;
 }
 
 /** Returns the memory allocation zone used to create instances of this class.
@@ -750,6 +751,9 @@
  */
 - (NSWindow*) window;
 
+/* Direction to display submenus */
+- (BOOL) _displayToLeft;
+
 /* Popup behaviour */
 - (BOOL) _ownedByPopUp;
 - (NSPopUpButtonCell *)_owningPopUp;
_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to