Author: noelgrandin
Date: Thu Oct 27 08:32:09 2011
New Revision: 1189671
URL: http://svn.apache.org/viewvc?rev=1189671&view=rev
Log:
PIVOT-809 Wrong position for nested menu
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java?rev=1189671&r1=1189670&r2=1189671&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java Thu Oct 27
08:32:09 2011
@@ -21,6 +21,7 @@ import org.apache.pivot.wtk.Button;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Container;
import org.apache.pivot.wtk.ContainerMouseListener;
+import org.apache.pivot.wtk.Dimensions;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.Menu;
import org.apache.pivot.wtk.MenuPopup;
@@ -159,12 +160,24 @@ public abstract class MenuItemSkin exten
if (menu != null
&& !menuPopup.isOpen()) {
+ // Size and position the popup
Display display = menuItem.getDisplay();
+ Dimensions displaySize = display.getSize();
+
Point location = menuItem.mapPointToAncestor(display, getWidth(),
0);
+ menuPopup.setLocation(location.x, location.y);
+
+ int width = getWidth();
+
+ // If the popup extends over the right edge of the display,
+ // move it so that the right edge of the popup lines up with the
+ // left edge of the menu item
+ int popupWidth = menuPopup.getPreferredWidth();
+ if (location.x + popupWidth > displaySize.width) {
+ menuPopup.setX(location.x - width - popupWidth);
+ }
- // TODO Ensure that the popup remains within the bounds of the
display
- menuPopup.setLocation(location.x, location.y);
menuPopup.open(menuItem.getWindow());
menuPopup.requestFocus();
}