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.
10 * Full author contact details are available in file CREDITS
16 #pragma implementation
19 #include "RadioButtonGroup.h"
20 #include FORMS_H_LOCATION
22 #include "debug.h" // for lyxerr
23 #include "support/lyxfunctional.h"
25 //#include <functional>
34 void RadioButtonGroup::init(FL_OBJECT *button, size_type value)
36 map.push_back(ButtonValuePair(button, value));
40 void RadioButtonGroup::reset()
46 void RadioButtonGroup::set(size_type value)
48 ButtonValueMap::const_iterator it =
49 find_if(map.begin(), map.end(),
50 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
52 // If we found nothing, report it and return
53 if (it == map.end()) {
54 lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists"
58 fl_set_button(it->first, 1);
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 first button that is active
76 ButtonValueMap::const_iterator it =
77 find_if(map.begin(), map.end(),
78 is_set_button<ButtonValuePair> ());
80 // If such a button was found, return its value.
81 if (it != map.end()) {
85 lyxerr << "BUG: No radio button found to be active." << endl;