]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Tooltips.C
Change glob() API to accept a dir parameter.
[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 std::string;
30
31
32 namespace lyx {
33
34 using support::trim;
35
36 namespace frontend {
37
38
39 bool Tooltips::enabled_ = true;
40
41 boost::signal<void()> Tooltips::toggled;
42
43
44 Tooltips::Tooltips()
45 {
46         toggled.connect(boost::bind(&Tooltips::set, this));
47 }
48
49
50 void Tooltips::toggleEnabled()
51 {
52         enabled_ = !enabled_;
53         toggled();
54 }
55
56
57 void Tooltips::set()
58 {
59         if (tooltipsMap.empty())
60                 return;
61
62         TooltipsMap::const_iterator it  = tooltipsMap.begin();
63         TooltipsMap::const_iterator end = tooltipsMap.end();
64         for (; it != end; ++it) {
65                 FL_OBJECT * const ob = it->first;
66                 char const * const c_str = enabled_ ? it->second.c_str() : 0;
67                 fl_set_object_helper(ob, c_str);
68         }
69 }
70
71
72 void Tooltips::init(FL_OBJECT * ob, string const & tip)
73 {
74         BOOST_ASSERT(ob && ob->form);
75
76         // Store the tooltip string
77         string const str = formatted(trim(tip), 400);
78         tooltipsMap[ob] = str;
79
80         // Set the tooltip
81         char const * const c_str = enabled_ ? str.c_str() : 0;
82         fl_set_object_helper(ob, c_str);
83 }
84
85 } // namespace frontend
86 } // namespace lyx