MenuBar to auto-reposition and/or auto-resize submenus - GWT Committer Required

220 views
Skip to first unread message

melody

unread,
Jul 2, 2009, 3:17:34 PM7/2/09
to Google Web Toolkit
I have had problems with MenuBar submenus not repositioning or
resizing when there is more menu items than can fit in the height
available.

So I decided to copy MenuBar.java and made the following changes

add the following member variables and static members
<code>
private int oldOffsetHeight = -1;
private static final int MIN_MENUHEIGHT = 200;
<code>


in private void onHide() method, add the following code segment

<code>
//reset the offset height to what was originally
if (oldOffsetHeight != -1) {
setHeight(Utils.toHTMLPixels(oldOffsetHeight));
}
oldOffsetHeight = -1;
</code>


In method void doItemAction(final MenuItem item, boolean fireCommand),
change the setPosition method of PopupPanel.PositionCallback as
shown

<code>
public void setPosition(int offsetWidth, int offsetHeight) {

// depending on the bidi direction position a menu on the left
or right
// of its base item
if (LocaleInfo.getCurrentLocale().isRTL()) {
if (vertical) {
popup.setPopupPosition(MenuBar.this.getAbsoluteLeft() -
offsetWidth + 1,
item.getAbsoluteTop());
} else {
popup.setPopupPosition(item.getAbsoluteLeft() +
item.getOffsetWidth() - offsetWidth,
MenuBar.this.getAbsoluteTop() +
MenuBar.this.getOffsetHeight() - 1);
}
} else {
if (vertical) {
int left = shownChildMenu.parentMenu.getAbsoluteLeft() +
shownChildMenu.parentMenu.getOffsetWidth();
int top = item.getAbsoluteTop();
if (top + offsetHeight > Window.getClientHeight())
{
int li_offsetHeight = Window.getClientHeight() - top;
if (li_offsetHeight < MIN_MENUHEIGHT) {
li_offsetHeight = MIN_MENUHEIGHT;
top = Window.getClientHeight() - li_offsetHeight;
}
oldOffsetHeight =
shownChildMenu.parentMenu.getOffsetHeight();
shownChildMenu.setHeight(Utils.toHTMLPixels
(li_offsetHeight));
}
popup.setPopupPosition(left, top);
} else {
popup.setPopupPosition(item.getAbsoluteLeft(),
MenuBar.this.getAbsoluteTop() + MenuBar.this.getOffsetHeight() - 1);
}
}
}
</code>


If there is GWT committer out there who is willing to take this code
and put into GWT please feel free. Its working wonders for me and I
believe that is how menubar should work. Or Better

Thanks,

Melody

Alex Rudnick

unread,
Jul 2, 2009, 3:24:47 PM7/2/09
to Google-We...@googlegroups.com
Hey Melody,

If you'd like to put in a change to GWT, please take a look at the
"Making GWT Better" guide over here:
http://code.google.com/webtoolkit/makinggwtbetter.html#submittingpatches

... and mail your patch to the Google-Web-Toolkit-Contributors group.
http://groups.google.com/group/Google-Web-Toolkit-Contributors

It probably wouldn't hurt to make an issue in the issue tracker for
the bug that your patch fixes.

Thanks very much!

--
Alex Rudnick
swe, gwt, atl

Reply all
Reply to author
Forward
0 new messages