]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Tooltips.C
to much stuff for my liking...
[lyx.git] / src / frontends / xforms / Tooltips.C
1 /*
2  * \file Tooltips.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Angus Leeming, a.leeming@ic.ac.uk
7  *
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.
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "Tooltips.h"
21 #include "support/LAssert.h"
22
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. ;-)
27 // Angus 6 Feb 2002
28
29 /*
30 void Tooltips::activateTooltip(FL_OBJECT * ob)
31 {
32         lyx::Assert(ob);
33
34         string const help(getTooltip(ob));
35         if (!help.empty())
36                 fl_set_object_helper(ob, help.c_str()); 
37 }
38 */
39
40 //#else // if FL_REVISION < 89
41
42 namespace {
43
44 int TooltipHandler(FL_OBJECT *ob, int event);
45
46 void TooltipTimerCB(FL_OBJECT * timer, long data);
47  
48 }
49
50 extern "C" {
51
52 static int C_TooltipHandler(FL_OBJECT * ob, int event,
53                                     FL_Coord, FL_Coord, int, void *)
54 {
55         return TooltipHandler(ob, event);
56 }
57
58
59 static void C_TooltipTimerCB(FL_OBJECT * ob, long data)
60 {
61         TooltipTimerCB(ob, data);
62 }
63
64 }
65  
66
67 void Tooltips::activateTooltip(FL_OBJECT * ob)
68 {
69         lyx::Assert(ob);
70
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, "");
75                 fl_end_form();
76         }
77
78         fl_set_object_posthandler(ob, C_TooltipHandler);
79         ob->u_cdata = reinterpret_cast<char *>(tooltip_timer_);
80         tooltip_timer_->u_vdata = this;
81 }
82
83
84 namespace {
85
86 void TooltipTimerCB(FL_OBJECT * timer, long data)
87 {
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);
92         
93         string const help = tooltip->getTooltip(ob);
94         if (help.empty())
95                 return;
96
97         fl_show_oneliner(help.c_str(),
98                          form->x + ob->x, form->y + ob->y + ob->h);
99 }
100
101
102 // post_handler for bubble-help (Matthias)
103 int TooltipHandler(FL_OBJECT *ob, int event)
104 {
105         lyx::Assert(ob);
106         FL_OBJECT * timer = reinterpret_cast<FL_OBJECT *>(ob->u_cdata);
107         lyx::Assert(timer);
108
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,
112                                        C_TooltipTimerCB,
113                                        reinterpret_cast<long>(ob));
114                 fl_set_timer(timer, 1);
115         }
116         else if (event != FL_MOTION) {
117                 fl_set_timer(timer, 0);
118                 fl_hide_oneliner();
119         }
120         return 0;
121 }
122
123 } // namespace anon
124
125 //#endif // FL_REVISION < 89