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"
19 #include "debug.h" // for lyxerr
20 #include "support/lyxfunctional.h"
22 //#include <functional>
31 void RadioButtonGroup::init(FL_OBJECT *button, size_type value)
33 map.push_back(ButtonValuePair(button, value));
37 void RadioButtonGroup::reset()
43 void RadioButtonGroup::set(size_type value)
45 ButtonValueMap::const_iterator it =
46 find_if(map.begin(), map.end(),
47 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
49 // If we found nothing, report it and return
50 if (it == map.end()) {
51 lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists"
55 fl_set_button(it->first, 1);
61 template < typename T >
62 struct is_set_button {
63 bool operator() (T const & item) const
65 return fl_get_button((item).first);
70 RadioButtonGroup::size_type RadioButtonGroup::get() const
72 // Find the first button that is active
73 ButtonValueMap::const_iterator it =
74 find_if(map.begin(), map.end(),
75 is_set_button<ButtonValuePair> ());
77 // If such a button was found, return its value.
78 if (it != map.end()) {
82 lyxerr << "BUG: No radio button found to be active." << endl;