2 * \file RadioButtonGroup.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "RadioButtonGroup.h"
16 #include "xforms_helpers.h"
20 #include "support/lyxfunctional.h"
22 #include "lyx_forms.h"
24 #include <boost/assert.hpp>
31 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
33 // Object must be a ROUND3DBUTTON (let all radio buttons look the same)
34 // and of type RADIO_BUTTON (otherwise it ain't work).
35 BOOST_ASSERT(ob && ob->objclass == FL_ROUND3DBUTTON
36 && ob->type == FL_RADIO_BUTTON);
38 map.push_back(ButtonValuePair(ob, value));
42 void RadioButtonGroup::set(size_type value) const
44 ButtonValueMap::const_iterator it =
45 find_if(map.begin(), map.end(),
46 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
48 if (it != map.end()) {
49 fl_set_button(it->first, 1);
51 // We found nothing: report it and do nothing.
52 lyxerr << "BUG: Requested value in RadioButtonGroup "
53 "doesn't exist" << endl;
58 void RadioButtonGroup::set(FL_OBJECT * ob) const
60 // Object must be member of the radiobutton group.
61 bool isMember = false;
62 ButtonValueMap::const_iterator it = map.begin();
63 for (; it != map.end() && !isMember; ++it) {
64 isMember = it->first == ob;
70 // Object is not a member; report it and do nothing.
71 lyxerr << "BUG: Requested object is not a member of "
72 << "the RadioButtonGroup." << endl;
78 struct is_set_button : public std::unary_function<T, bool> {
79 bool operator() (T const & item) const
81 return fl_get_button((item).first);
86 void RadioButtonGroup::unset() const
88 // Find the active button.
89 ButtonValueMap::const_iterator it =
90 find_if(map.begin(), map.end(),
91 is_set_button<ButtonValuePair> ());
94 // Nothing to do. No button is set.
97 fl_set_button(it->first, 0);
101 size_type RadioButtonGroup::get() const
103 // Find the active button.
104 ButtonValueMap::const_iterator it =
105 find_if(map.begin(), map.end(),
106 is_set_button<ButtonValuePair> ());
111 // We found nothing: report it and return 0
112 lyxerr << "BUG: No active radio button found." << endl;
117 void RadioButtonGroup::setEnabled(bool enable)
119 ButtonValueMap::iterator it = map.begin();
120 ButtonValueMap::iterator end = map.end();
121 for (; it != end; ++it) {
122 lyx::frontend::setEnabled(it->first, enable);
126 } // namespace frontend