3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Angus Leeming, a.leeming@ic.ac.uk
8 * Tooltips for xforms. xforms 0.89 supports them directly, but 0.88 needs
9 * a bit of jiggery pokery. This class wraps it all up in a neat interface.
10 * Based on code originally in Toolbar_pimpl.C that appears to have been
11 * written by Matthias Ettrich and Jean-Marc Lasgouttes.
17 #pragma implementation
21 #include "support/LAssert.h"
23 //#if FL_REVISION >= 89
24 // Usually, this is all that is needed for xforms 0.89
25 // However, I can't see an easy way to change Tooltips on the fly
26 // with this method, so for now use the jiggery pokery below. ;-)
30 void Tooltips::activateTooltip(FL_OBJECT * ob)
34 string const help(getTooltip(ob));
36 fl_set_object_helper(ob, help.c_str());
40 //#else // if FL_REVISION < 89
44 int TooltipHandler(FL_OBJECT *ob, int event);
46 void TooltipTimerCB(FL_OBJECT * timer, long data);
52 static int C_TooltipHandler(FL_OBJECT * ob, int event,
53 FL_Coord, FL_Coord, int, void *)
55 return TooltipHandler(ob, event);
59 static void C_TooltipTimerCB(FL_OBJECT * ob, long data)
61 TooltipTimerCB(ob, data);
67 void Tooltips::activateTooltip(FL_OBJECT * ob)
71 if (!tooltip_timer_) {
72 lyx::Assert(ob->form);
73 fl_addto_form(ob->form);
74 tooltip_timer_ = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "");
78 fl_set_object_posthandler(ob, C_TooltipHandler);
79 ob->u_cdata = reinterpret_cast<char *>(tooltip_timer_);
80 tooltip_timer_->u_vdata = this;
86 void TooltipTimerCB(FL_OBJECT * timer, long data)
88 FL_OBJECT * ob = reinterpret_cast<FL_OBJECT*>(data);
89 lyx::Assert(ob && ob->form && timer && timer->u_vdata);
90 FL_FORM * form = ob->form;
91 Tooltips * tooltip = static_cast<Tooltips *>(timer->u_vdata);
93 string const help = tooltip->getTooltip(ob);
97 fl_show_oneliner(help.c_str(),
98 form->x + ob->x, form->y + ob->y + ob->h);
102 // post_handler for bubble-help (Matthias)
103 int TooltipHandler(FL_OBJECT *ob, int event)
106 FL_OBJECT * timer = reinterpret_cast<FL_OBJECT *>(ob->u_cdata);
109 // We do not test for empty help here, since this can never happen
110 if (event == FL_ENTER){
111 fl_set_object_callback(timer,
113 reinterpret_cast<long>(ob));
114 fl_set_timer(timer, 1);
116 else if (event != FL_MOTION){
117 fl_set_timer(timer, 0);
125 //#endif // FL_REVISION < 89