]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Tooltips.C
remove defaults stuff, let Qt handle no toolbar
[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
20 #include "Tooltips.h"
21 #include "xforms_helpers.h" // formatted
22 #include "gettext.h"
23 #include "support/lstrings.h"
24 #include "support/LAssert.h"
25 #include FORMS_H_LOCATION
26
27 #include <boost/bind.hpp>
28
29 bool Tooltips::enabled_ = true;
30
31 boost::signal0<void> Tooltips::toggled;
32
33
34 Tooltips::Tooltips()
35 {
36         toggled.connect(boost::bind(&Tooltips::set, this));
37 }
38
39
40 void Tooltips::toggleEnabled()
41 {
42         enabled_ = !enabled_;
43         toggled();
44 }
45
46
47 void Tooltips::set()
48 {
49         if (tooltipsMap.empty())
50                 return;
51
52         TooltipsMap::const_iterator it  = tooltipsMap.begin();
53         TooltipsMap::const_iterator end = tooltipsMap.end();
54         for (; it != end; ++it) {
55                 FL_OBJECT * const ob = it->first;
56                 char const * const c_str = enabled_ ? it->second.c_str() : 0;
57                 fl_set_object_helper(ob, c_str);
58         }
59 }
60
61
62 void Tooltips::init(FL_OBJECT * ob, string const & tip)
63 {
64         lyx::Assert(ob && ob->form);
65
66         // Store the tooltip string
67         string const str = formatted(trim(tip), 400);
68         tooltipsMap[ob] = str;
69
70         // Set the tooltip
71         char const * const c_str = enabled_ ? str.c_str() : 0;
72         fl_set_object_helper(ob, c_str);
73 }