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"
27 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
29 // Object must be a ROUND3DBUTTON (let all radio buttons look the same)
30 // and of type RADIO_BUTTON (otherwise it ain't work).
31 BOOST_ASSERT(ob && ob->objclass == FL_ROUND3DBUTTON
32 && ob->type == FL_RADIO_BUTTON);
34 map.push_back(ButtonValuePair(ob, value));
38 void RadioButtonGroup::set(size_type value) const
40 ButtonValueMap::const_iterator it =
41 find_if(map.begin(), map.end(),
42 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
44 if (it != map.end()) {
45 fl_set_button(it->first, 1);
47 // We found nothing: report it and do nothing.
48 lyxerr << "BUG: Requested value in RadioButtonGroup "
49 "doesn't exist" << endl;
54 void RadioButtonGroup::set(FL_OBJECT * ob) const
56 // Object must be member of the radiobutton group.
57 bool isMember = false;
58 ButtonValueMap::const_iterator it = map.begin();
59 for (; it != map.end() && !isMember; ++it) {
60 isMember = it->first == ob;
66 // Object is not a member; report it and do nothing.
67 lyxerr << "BUG: Requested object is not a member of "
68 << "the RadioButtonGroup." << endl;
73 template < typename T >
74 struct is_set_button {
75 bool operator() (T const & item) const
77 return fl_get_button((item).first);
82 void RadioButtonGroup::unset() const
84 // Find the active button.
85 ButtonValueMap::const_iterator it =
86 find_if(map.begin(), map.end(),
87 is_set_button<ButtonValuePair> ());
90 // Nothing to do. No button is set.
93 fl_set_button(it->first, 0);
97 RadioButtonGroup::size_type RadioButtonGroup::get() const
99 // Find the active button.
100 ButtonValueMap::const_iterator it =
101 find_if(map.begin(), map.end(),
102 is_set_button<ButtonValuePair> ());
107 // We found nothing: report it and return 0
108 lyxerr << "BUG: No active radio button found." << endl;
113 void RadioButtonGroup::setEnabled(bool enable)
115 ButtonValueMap::iterator it = map.begin();
116 ButtonValueMap::iterator end = map.end();
117 for (; it != end; ++it) {
118 ::setEnabled(it->first, enable);