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>
29 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
31 // Object must be a ROUND3DBUTTON (let all radio buttons look the same)
32 // and of type RADIO_BUTTON (otherwise it ain't work).
33 BOOST_ASSERT(ob && ob->objclass == FL_ROUND3DBUTTON
34 && ob->type == FL_RADIO_BUTTON);
36 map.push_back(ButtonValuePair(ob, value));
40 void RadioButtonGroup::set(size_type value) const
42 ButtonValueMap::const_iterator it =
43 find_if(map.begin(), map.end(),
44 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
46 if (it != map.end()) {
47 fl_set_button(it->first, 1);
49 // We found nothing: report it and do nothing.
50 lyxerr << "BUG: Requested value in RadioButtonGroup "
51 "doesn't exist" << endl;
56 void RadioButtonGroup::set(FL_OBJECT * ob) const
58 // Object must be member of the radiobutton group.
59 bool isMember = false;
60 ButtonValueMap::const_iterator it = map.begin();
61 for (; it != map.end() && !isMember; ++it) {
62 isMember = it->first == ob;
68 // Object is not a member; report it and do nothing.
69 lyxerr << "BUG: Requested object is not a member of "
70 << "the RadioButtonGroup." << endl;
75 template < typename T >
76 struct is_set_button {
77 bool operator() (T const & item) const
79 return fl_get_button((item).first);
84 void RadioButtonGroup::unset() const
86 // Find the active button.
87 ButtonValueMap::const_iterator it =
88 find_if(map.begin(), map.end(),
89 is_set_button<ButtonValuePair> ());
92 // Nothing to do. No button is set.
95 fl_set_button(it->first, 0);
99 RadioButtonGroup::size_type RadioButtonGroup::get() const
101 // Find the active button.
102 ButtonValueMap::const_iterator it =
103 find_if(map.begin(), map.end(),
104 is_set_button<ButtonValuePair> ());
109 // We found nothing: report it and return 0
110 lyxerr << "BUG: No active radio button found." << endl;
115 void RadioButtonGroup::setEnabled(bool enable)
117 ButtonValueMap::iterator it = map.begin();
118 ButtonValueMap::iterator end = map.end();
119 for (; it != end; ++it) {
120 ::setEnabled(it->first, enable);