]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Tooltips.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / Tooltips.C
1 /**
2  * \file Tooltips.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 /* Tooltips for xforms. xforms 0.89 supports them directly, but 0.88 needs
12  * a bit of jiggery pokery. This class wraps it all up in a neat interface.
13  * Based on code originally in Toolbar_pimpl.C that appears to have been
14  * written by Matthias Ettrich and Jean-Marc Lasgouttes.
15  */
16
17 #include <config.h>
18
19 #include "Tooltips.h"
20
21 #include "xforms_helpers.h" // formatted
22
23 #include "support/lstrings.h"
24
25 #include "lyx_forms.h"
26
27 #include <boost/bind.hpp>
28
29 using lyx::support::trim;
30
31 using std::string;
32
33
34 bool Tooltips::enabled_ = true;
35
36 boost::signal0<void> Tooltips::toggled;
37
38
39 Tooltips::Tooltips()
40 {
41         toggled.connect(boost::bind(&Tooltips::set, this));
42 }
43
44
45 void Tooltips::toggleEnabled()
46 {
47         enabled_ = !enabled_;
48         toggled();
49 }
50
51
52 void Tooltips::set()
53 {
54         if (tooltipsMap.empty())
55                 return;
56
57         TooltipsMap::const_iterator it  = tooltipsMap.begin();
58         TooltipsMap::const_iterator end = tooltipsMap.end();
59         for (; it != end; ++it) {
60                 FL_OBJECT * const ob = it->first;
61                 char const * const c_str = enabled_ ? it->second.c_str() : 0;
62                 fl_set_object_helper(ob, c_str);
63         }
64 }
65
66
67 void Tooltips::init(FL_OBJECT * ob, string const & tip)
68 {
69         BOOST_ASSERT(ob && ob->form);
70
71         // Store the tooltip string
72         string const str = formatted(trim(tip), 400);
73         tooltipsMap[ob] = str;
74
75         // Set the tooltip
76         char const * const c_str = enabled_ ? str.c_str() : 0;
77         fl_set_object_helper(ob, c_str);
78 }