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.
15 #include "RadioButtonGroup.h"
16 #include "lyx_forms.h"
17 #include "xforms_helpers.h"
19 #include "support/LAssert.h"
20 #include "debug.h" // for lyxerr
21 #include "support/lyxfunctional.h"
26 using namespace lyx::support;
32 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
34 // Object must be a ROUND3DBUTTON (let all radio buttons look the same)
35 // and of type RADIO_BUTTON (otherwise it ain't work).
36 Assert(ob && ob->objclass == FL_ROUND3DBUTTON
37 && ob->type == FL_RADIO_BUTTON);
39 map.push_back(ButtonValuePair(ob, value));
43 void RadioButtonGroup::set(size_type value) const
45 ButtonValueMap::const_iterator it =
46 find_if(map.begin(), map.end(),
47 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
49 if (it != map.end()) {
50 fl_set_button(it->first, 1);
52 // We found nothing: report it and do nothing.
53 lyxerr << "BUG: Requested value in RadioButtonGroup "
54 "doesn't exist" << endl;
59 void RadioButtonGroup::set(FL_OBJECT * ob) const
61 // Object must be member of the radiobutton group.
62 bool isMember = false;
63 ButtonValueMap::const_iterator it = map.begin();
64 for (; it != map.end() && !isMember; ++it) {
65 isMember = it->first == ob;
71 // Object is not a member; report it and do nothing.
72 lyxerr << "BUG: Requested object is not a member of "
73 << "the RadioButtonGroup." << endl;
78 template < typename T >
79 struct is_set_button {
80 bool operator() (T const & item) const
82 return fl_get_button((item).first);
87 void RadioButtonGroup::unset() const
89 // Find the active button.
90 ButtonValueMap::const_iterator it =
91 find_if(map.begin(), map.end(),
92 is_set_button<ButtonValuePair> ());
95 // Nothing to do. No button is set.
98 fl_set_button(it->first, 0);
102 RadioButtonGroup::size_type RadioButtonGroup::get() const
104 // Find the active button.
105 ButtonValueMap::const_iterator it =
106 find_if(map.begin(), map.end(),
107 is_set_button<ButtonValuePair> ());
112 // We found nothing: report it and return 0
113 lyxerr << "BUG: No active radio button found." << endl;
118 void RadioButtonGroup::setEnabled(bool enable)
120 ButtonValueMap::iterator it = map.begin();
121 ButtonValueMap::iterator end = map.end();
122 for (; it != end; ++it) {
123 ::setEnabled(it->first, enable);