| If you want your application to use tool tips, the first step is to create a
(single) instance of an FXTooltip object:
new FXToolTip(getApp());
Through the magic of FOX's GUI update process, this tool tip object
(which in itself is just a little window) will notice when the mouse
pointer hovers over a widget for a short period of time. The tool tip
will then "ask" that widget for its tool tip text, and show itself with
that text. When you move the mouse again (or when the tool tip times
out) it will hide itself again.
For most widgets, you set the tool tip text once, either at widget
construction time, e.g.
new FXButton(p, "Button Text\tToolTip text", ...);
or by using that widget's setTipText() member function, e.g.
button->setTipText("the tooltip text");
Tooltip Modes
The normal tooltip mode is to popup for a certain amount time and
then disappear. The amount of time it stays up can be set with:
getApp()->setTooltipTime(num_milliseconds);
There is normally also a slight delay before showing the tooltip (in
case the mouse is moved to another widget). This delay can be set with:
getApp()->setTooltipPause(num_milliseconds);
Besides the normal tooltip mode, there are two additional modes available:
- TOOLTIP_PERMANENT - leaves the tooltip visible until the mouse is moved again.
- TOOLTIP_VARIABLE - shows the tooltip for a certain amount of
time based on the length of the tip text. The longer the text, the
longer it stays up.
These can be set as additional parameter in the tooltip constructor (by default the TOOLTIP_NORMAL mode is set):
new FXToolTip(getApp(),TOOLTIP_PERMANENT);
Adding Tooltips to WidgetsTo add tooltip support to your
own customized widget is very simple. The only thing you have to do is
to respond to the SEL_QUERYTIP message send to your widget, by sending
a message back with the tip text:
FXDEFMAP(FXWidget) FXWidgetMap[]={ FXMAPFUNC(SEL_QUERY_TIP,0,FXWidget::onQueryTip), };
// We were asked about tip text long FXWidget::onQueryTip(FXObject* sender,FXSelector sel,void* ptr){ FXString tip="Hello World"; if(FXWidgetBase::onQueryTip(sender,sel,ptr)) return 1; if((flags&FLAG_TIP) && !tip.empty()){ sender->handle(this,FXSEL(SEL_COMMAND,ID_SETSTRINGVALUE),(void*)&tip); return 1; } return 0; }
|