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 "lyx_forms.h"
22 #include <boost/assert.hpp>
23 #include <boost/bind.hpp>
33 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
35 // Object must be a ROUND3DBUTTON (let all radio buttons look the same)
36 // and of type RADIO_BUTTON (otherwise it ain't work).
37 BOOST_ASSERT(ob && ob->objclass == FL_ROUND3DBUTTON
38 && ob->type == FL_RADIO_BUTTON);
40 map.push_back(ButtonValuePair(ob, value));
44 void RadioButtonGroup::set(size_type value) const
46 ButtonValueMap::const_iterator it =
47 find_if(map.begin(), map.end(),
48 bind(equal_to<size_type>(),
49 bind(&ButtonValuePair::second, _1),
52 if (it != map.end()) {
53 fl_set_button(it->first, 1);
55 // We found nothing: report it and do nothing.
56 lyxerr << "BUG: Requested value in RadioButtonGroup "
57 "doesn't exist" << endl;
62 void RadioButtonGroup::set(FL_OBJECT * ob) const
64 // Object must be member of the radiobutton group.
65 bool isMember = false;
66 ButtonValueMap::const_iterator it = map.begin();
67 for (; it != map.end() && !isMember; ++it) {
68 isMember = it->first == ob;
74 // Object is not a member; report it and do nothing.
75 lyxerr << "BUG: Requested object is not a member of "
76 << "the RadioButtonGroup." << endl;
82 struct is_set_button : public std::unary_function<T, bool> {
83 bool operator() (T const & item) const
85 return fl_get_button((item).first);
90 void RadioButtonGroup::unset() const
92 // Find the active button.
93 ButtonValueMap::const_iterator it =
94 find_if(map.begin(), map.end(),
95 is_set_button<ButtonValuePair> ());
98 // Nothing to do. No button is set.
101 fl_set_button(it->first, 0);
105 size_type RadioButtonGroup::get() const
107 // Find the active button.
108 ButtonValueMap::const_iterator it =
109 find_if(map.begin(), map.end(),
110 is_set_button<ButtonValuePair> ());
115 // We found nothing: report it and return 0
116 lyxerr << "BUG: No active radio button found." << endl;
121 void RadioButtonGroup::setEnabled(bool enable)
123 ButtonValueMap::iterator it = map.begin();
124 ButtonValueMap::iterator end = map.end();
125 for (; it != end; ++it) {
126 lyx::frontend::setEnabled(it->first, enable);
130 } // namespace frontend