]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/RadioButtonGroup.C
Removed all redundant using directives from the source.
[lyx.git] / src / frontends / xforms / RadioButtonGroup.C
1 /**
2  * \file RadioButtonGroup.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Baruch Even
7  * \author Rob Lahaye
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "RadioButtonGroup.h"
15
16 #include "xforms_helpers.h"
17
18 #include "debug.h"
19
20 #include "support/LAssert.h"
21 #include "support/lyxfunctional.h"
22
23 #include "lyx_forms.h"
24
25 using namespace lyx::support;
26
27 using std::endl;
28
29
30 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
31 {
32         // Object must be a ROUND3DBUTTON (let all radio buttons look the same)
33         // and of type RADIO_BUTTON (otherwise it ain't work).
34         Assert(ob && ob->objclass == FL_ROUND3DBUTTON
35                         && ob->type == FL_RADIO_BUTTON);
36
37         map.push_back(ButtonValuePair(ob, value));
38 }
39
40
41 void RadioButtonGroup::set(size_type value) const
42 {
43         ButtonValueMap::const_iterator it =
44                 find_if(map.begin(), map.end(),
45                         lyx::equal_2nd_in_pair<ButtonValuePair>(value));
46
47         if (it != map.end()) {
48                 fl_set_button(it->first, 1);
49         } else {
50                 // We found nothing: report it and do nothing.
51                 lyxerr << "BUG: Requested value in RadioButtonGroup "
52                         "doesn't exist" << endl;
53         }
54 }
55
56
57 void RadioButtonGroup::set(FL_OBJECT * ob) const
58 {
59         // Object must be member of the radiobutton group.
60         bool isMember = false;
61         ButtonValueMap::const_iterator it = map.begin();
62         for (; it != map.end() && !isMember; ++it) {
63                 isMember = it->first == ob;
64         }
65
66         if (isMember) {
67                 fl_set_button(ob, 1);
68         } else {
69                 // Object is not a member; report it and do nothing.
70                 lyxerr << "BUG: Requested object is not a member of "
71                         << "the RadioButtonGroup." << endl;
72         }
73 }
74
75
76 template < typename T >
77 struct is_set_button {
78         bool operator() (T const & item) const
79         {
80                 return fl_get_button((item).first);
81         }
82 };
83
84
85 void RadioButtonGroup::unset() const
86 {
87         // Find the active button.
88         ButtonValueMap::const_iterator it =
89                 find_if(map.begin(), map.end(),
90                         is_set_button<ButtonValuePair> ());
91
92         if (it == map.end())
93                 // Nothing to do. No button is set.
94                 return;
95
96         fl_set_button(it->first, 0);
97 }
98
99
100 RadioButtonGroup::size_type RadioButtonGroup::get() const
101 {
102         // Find the active button.
103         ButtonValueMap::const_iterator it =
104                 find_if(map.begin(), map.end(),
105                         is_set_button<ButtonValuePair> ());
106
107         if (it != map.end())
108                 return it->second;
109
110         // We found nothing: report it and return 0
111         lyxerr << "BUG: No active radio button found." << endl;
112         return 0;
113 }
114
115
116 void RadioButtonGroup::setEnabled(bool enable)
117 {
118         ButtonValueMap::iterator it  = map.begin();
119         ButtonValueMap::iterator end = map.end();
120         for (; it != end; ++it) {
121                 ::setEnabled(it->first, enable);
122         }
123 }