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::registerRadioButton(FL_OBJECT *button, int value)
33 map.push_back(ButtonValuePair(button, value));
37 void RadioButtonGroup::reset()
44 // Functor to help us in our work, we should try to find how to achieve
45 // this with only STL predicates, but its easier to write this than to
46 // dig. If you can find the equivalent STL predicate combination, let me
49 // The idea is to take a pair and a value and return true when the second
50 // element in the pair equals the value.
51 template < typename T >
52 struct equal_to_second_in_pair
54 typedef bool result_type;
55 typedef T first_argument_type;
56 typedef typename T::second_type second_argument_type;
59 pair < typename T::first_type, typename T::second_type > const & left,
60 typename T::second_type const & right) const
62 return left.second == right;
68 void RadioButtonGroup::setButton(int value)
71 ButtonValueMap::const_iterator it =
72 find_if(map.begin(), map.end(),
73 bind2nd(equal_to_second_in_pair<ButtonValuePair>(),
76 ButtonValueMap::const_iterator it =
77 find_if(map.begin(), map.end(),
78 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
81 // If we found nothing, report it and return
82 if (it == map.end()) {
83 lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists"
87 fl_set_button(it->first, 1);
93 template < typename T >
94 struct is_set_button {
95 bool operator() (T const & item) const
97 return fl_get_button((item).first);
102 int RadioButtonGroup::getButton()
104 // Find the first button that is active
105 ButtonValueMap::iterator it =
106 find_if(map.begin(), map.end(),
107 is_set_button<ButtonValuePair> ());
109 // If such a button was found, return its value.
110 if (it != map.end()) {
114 lyxerr << "BUG: No radio button found to be active." << endl;