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 FORMS_H_LOCATION
20 #include "support/LAssert.h"
21 #include "debug.h" // for lyxerr
22 #include "support/lyxfunctional.h"
31 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
33 // Object must be a ROUND3DBUTTON (let all radio buttons look the same)
34 // and of type RADIO_BUTTON (otherwise it ain't work).
35 lyx::Assert(ob && ob->objclass == FL_ROUND3DBUTTON
36 && ob->type == FL_RADIO_BUTTON);
38 map.push_back(ButtonValuePair(ob, value));
42 void RadioButtonGroup::set(size_type value)
44 ButtonValueMap::const_iterator it =
45 find_if(map.begin(), map.end(),
46 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
48 if (it != map.end()) {
51 // We found nothing: report it and do nothing.
52 lyxerr << "BUG: Requested value in RadioButtonGroup "
53 "doesn't exist" << endl;
58 void RadioButtonGroup::set(FL_OBJECT * ob)
64 template < typename T >
65 struct is_set_button {
66 bool operator() (T const & item) const
68 return fl_get_button((item).first);
73 RadioButtonGroup::size_type RadioButtonGroup::get() const
75 // Find the active button.
76 ButtonValueMap::const_iterator it =
77 find_if(map.begin(), map.end(),
78 is_set_button<ButtonValuePair> ());
83 // We found nothing: report it and return 0
84 lyxerr << "BUG: No active radio button found." << endl;