2 * \file RadioButtonGroup.C
3 * Copyright 1995 Matthias Ettrich.
4 * Copyright 1995-2001 The LyX Team.
5 * Copyright 2000 Baruch Even
6 * See the file COPYING.
8 * \author Baruch Even, baruch.even@writeme.com
14 #pragma implementation
17 #include "RadioButtonGroup.h"
18 #include FORMS_H_LOCATION
20 #include "debug.h" // for lyxerr
21 #include "support/lyxfunctional.h"
23 //#include <functional>
32 void RadioButtonGroup::init(FL_OBJECT *button, size_type value)
34 map.push_back(ButtonValuePair(button, value));
38 void RadioButtonGroup::reset()
44 void RadioButtonGroup::set(size_type value)
46 ButtonValueMap::const_iterator it =
47 find_if(map.begin(), map.end(),
48 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
50 // If we found nothing, report it and return
51 if (it == map.end()) {
52 lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists"
56 fl_set_button(it->first, 1);
62 template < typename T >
63 struct is_set_button {
64 bool operator() (T const & item) const
66 return fl_get_button((item).first);
71 RadioButtonGroup::size_type RadioButtonGroup::get() const
73 // Find the first button that is active
74 ButtonValueMap::const_iterator it =
75 find_if(map.begin(), map.end(),
76 is_set_button<ButtonValuePair> ());
78 // If such a button was found, return its value.
79 if (it != map.end()) {
83 lyxerr << "BUG: No radio button found to be active." << endl;