toolTip_.setVisible(false);
return;
}
// screen unable to find menu or selected item
final MenuItem selectedItem = event.getSelectedItem();
if (selectedItem == null)
{
toolTip_.setVisible(false);
return;
}
int index = menuBar_.getItemIndex(selectedItem);
if (index == -1)
{
toolTip_.setVisible(false);
return;
}
// screen no completion text
CppCompletion completion = completions_.get(index);
if (completion.getText() == null)
{
toolTip_.setVisible(false);
return;
}
String text = completion.getText().get(0);
// only do tooltips for functions and variables
if (completion.getType() != CppCompletion.FUNCTION &&
completion.getType() != CppCompletion.VARIABLE)
{
toolTip_.setVisible(false);
return;
}
// set the tooltip text
toolTip_.setText(text);
// position it in the next event loop
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute()
{
// bail if there is no longer a tooltip
if (toolTip_ == null)
return;
// some constants
final int H_PAD = 12;
final int V_PAD = -3;
final int H_BUFFER = 100;
final int MIN_WIDTH = 300;
// candidate left and top
final int left = selectedItem.getAbsoluteLeft()
+ selectedItem.getOffsetWidth() + H_PAD;
final int top = selectedItem.getAbsoluteTop() + V_PAD;
// do we have enough room to the right? if not then
int roomRight = Window.getClientWidth() - left;
int maxWidth = Math.min(roomRight - H_BUFFER, 500);
final boolean showLeft = maxWidth < MIN_WIDTH;
if (showLeft)
maxWidth = selectedItem.getAbsoluteLeft() - H_BUFFER;
if (toolTip_.getAbsoluteLeft() != left ||
toolTip_.getAbsoluteTop() != top)
{
toolTip_.setMaxWidth(maxWidth);
toolTip_.setPopupPositionAndShow(new PositionCallback(){
@Override
public void setPosition(int offsetWidth,
int offsetHeight)
{
// if we are showing left then adjust
int adjustedLeft = left;
if (showLeft)
{
adjustedLeft = selectedItem.getAbsoluteLeft() -
offsetWidth - H_PAD;
}
toolTip_.setPopupPosition(adjustedLeft, top);
}
});