]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/RadioButtonGroup.C
Fix broken tooltips.
[lyx.git] / src / frontends / xforms / RadioButtonGroup.C
1 /**
2  * \file RadioButtonGroup.C
3  * Copyright 1995 Matthias Ettrich.
4  * Copyright 2000 Baruch Even
5  * This file is part of LyX, the document processor.
6  * Licence details can be found in the file COPYING.
7  *
8  * \author Baruch Even
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 #include <config.h>
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "RadioButtonGroup.h"
20 #include FORMS_H_LOCATION
21
22 #include "debug.h" // for lyxerr
23 #include "support/lyxfunctional.h"
24
25 //#include <functional>
26 #include <algorithm>
27 #include <iterator>
28
29 using std::find_if;
30 //using std::bind2nd;
31 using std::endl;
32
33
34 void RadioButtonGroup::init(FL_OBJECT *button, size_type value)
35 {
36         map.push_back(ButtonValuePair(button, value));
37 }
38
39
40 void RadioButtonGroup::reset()
41 {
42         map.clear();
43 }
44
45
46 void RadioButtonGroup::set(size_type value)
47 {
48         ButtonValueMap::const_iterator it =
49                 find_if(map.begin(), map.end(),
50                         lyx::equal_2nd_in_pair<ButtonValuePair>(value));
51
52         // If we found nothing, report it and return
53         if (it == map.end()) {
54                 lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists"
55                        << endl;
56         }
57         else {
58                 fl_set_button(it->first, 1);
59         }
60
61 }
62
63
64 template < typename T >
65 struct is_set_button {
66         bool operator() (T const & item) const
67         {
68                 return fl_get_button((item).first);
69         }
70 };
71
72
73 RadioButtonGroup::size_type RadioButtonGroup::get() const
74 {
75         // Find the first button that is active
76         ButtonValueMap::const_iterator it =
77                 find_if(map.begin(), map.end(),
78                         is_set_button<ButtonValuePair> ());
79
80         // If such a button was found, return its value.
81         if (it != map.end()) {
82                 return it->second;
83         }
84
85         lyxerr << "BUG: No radio button found to be active." << endl;
86
87         // Else return 0.
88         return 0;
89 }