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/LAssert.h"
21 #include "support/lyxfunctional.h"
23 #include "lyx_forms.h"
25 using namespace lyx::support;
30 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
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);
37 map.push_back(ButtonValuePair(ob, value));
41 void RadioButtonGroup::set(size_type value) const
43 ButtonValueMap::const_iterator it =
44 find_if(map.begin(), map.end(),
45 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
47 if (it != map.end()) {
48 fl_set_button(it->first, 1);
50 // We found nothing: report it and do nothing.
51 lyxerr << "BUG: Requested value in RadioButtonGroup "
52 "doesn't exist" << endl;
57 void RadioButtonGroup::set(FL_OBJECT * ob) const
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;
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;
76 template < typename T >
77 struct is_set_button {
78 bool operator() (T const & item) const
80 return fl_get_button((item).first);
85 void RadioButtonGroup::unset() const
87 // Find the active button.
88 ButtonValueMap::const_iterator it =
89 find_if(map.begin(), map.end(),
90 is_set_button<ButtonValuePair> ());
93 // Nothing to do. No button is set.
96 fl_set_button(it->first, 0);
100 RadioButtonGroup::size_type RadioButtonGroup::get() const
102 // Find the active button.
103 ButtonValueMap::const_iterator it =
104 find_if(map.begin(), map.end(),
105 is_set_button<ButtonValuePair> ());
110 // We found nothing: report it and return 0
111 lyxerr << "BUG: No active radio button found." << endl;
116 void RadioButtonGroup::setEnabled(bool enable)
118 ButtonValueMap::iterator it = map.begin();
119 ButtonValueMap::iterator end = map.end();
120 for (; it != end; ++it) {
121 ::setEnabled(it->first, enable);