2 * \file RadioButtonGroup.C
3 * Copyright 1995 Matthias Ettrich.
4 * Copyright 2000 Baruch Even
5 * This file is part of LyX, the document processor.
6 * Licence details can be found in the file COPYING.
11 * Full author contact details are available in file CREDITS
17 #include "RadioButtonGroup.h"
18 #include "lyx_forms.h"
20 #include "support/LAssert.h"
21 #include "debug.h" // for lyxerr
22 #include "support/lyxfunctional.h"
27 using namespace lyx::support;
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 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 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
50 if (it != map.end()) {
51 fl_set_button(it->first, 1);
53 // We found nothing: report it and do nothing.
54 lyxerr << "BUG: Requested value in RadioButtonGroup "
55 "doesn't exist" << endl;
60 void RadioButtonGroup::set(FL_OBJECT * ob) const
62 // Object must be member of the radiobutton group.
63 bool isMember = false;
64 ButtonValueMap::const_iterator it = map.begin();
65 for (; it != map.end() && !isMember; ++it) {
66 isMember = it->first == ob;
72 // Object is not a member; report it and do nothing.
73 lyxerr << "BUG: Requested object is not a member of "
74 << "the RadioButtonGroup." << endl;
79 template < typename T >
80 struct is_set_button {
81 bool operator() (T const & item) const
83 return fl_get_button((item).first);
88 RadioButtonGroup::size_type RadioButtonGroup::get() const
90 // Find the active button.
91 ButtonValueMap::const_iterator it =
92 find_if(map.begin(), map.end(),
93 is_set_button<ButtonValuePair> ());
98 // We found nothing: report it and return 0
99 lyxerr << "BUG: No active radio button found." << endl;