1 /* This file is part of
2 * =================================================
4 * LyX, The Document Processor
5 * Copyright 1995 Matthias Ettrich.
6 * Copyright 1995-2001 The LyX Team.
8 * This file Copyright 2000 Baruch Even
9 * ================================================= */
18 #pragma implementation
21 #include "RadioButtonGroup.h"
23 #include "debug.h" // for lyxerr
29 void RadioButtonGroup::registerRadioButton(FL_OBJECT *button, int value)
31 map.push_back( ButtonValuePair(button, value) );
35 void RadioButtonGroup::reset()
40 // Functor to help us in our work, we should try to find how to achieve
41 // this with only STL predicates, but its easier to write this than to
42 // dig. If you can find the equivalent STL predicate combination, let me
45 // The idea is to take a pair and a value and return true when the second
46 // element in the pair equals the value.
47 template < typename T >
48 struct equal_to_second_in_pair
50 typedef bool result_type;
51 typedef T first_argument_type;
52 typedef typename T::second_type second_argument_type;
55 pair < typename T::first_type, typename T::second_type > const & left,
56 typename T::second_type const & right) const
58 return left.second == right;
62 void RadioButtonGroup::setButton(int value)
64 ButtonValueMap::const_iterator it =
65 find_if(map.begin(), map.end(),
66 bind2nd(equal_to_second_in_pair < ButtonValuePair > (),
69 // If we found nothing, report it and return
70 if (it == map.end()) {
71 lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists"
75 fl_set_button(it->first, 1);
80 template < typename T >
81 struct is_set_button {
82 bool operator() (T const & item) const
84 return fl_get_button( (item).first );
88 int RadioButtonGroup::getButton()
90 // Find the first button that is active
91 ButtonValueMap::iterator it =
92 find_if(map.begin(), map.end(),
93 is_set_button < ButtonValuePair > () );
95 // If such a button was found, return its value.
96 if (it != map.end()) {
100 lyxerr << "BUG: No radio button found to be active." << endl;