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.
11 * Full author contact details are available in file CREDITS
17 #pragma implementation
20 #include "RadioButtonGroup.h"
21 #include FORMS_H_LOCATION
23 #include "support/LAssert.h"
24 #include "debug.h" // for lyxerr
25 #include "support/lyxfunctional.h"
34 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
36 // Object must be a ROUND3DBUTTON (let all radio buttons look the same)
37 // and of type RADIO_BUTTON (otherwise it ain't work).
38 lyx::Assert(ob && ob->objclass == FL_ROUND3DBUTTON
39 && ob->type == FL_RADIO_BUTTON);
41 map.push_back(ButtonValuePair(ob, value));
45 void RadioButtonGroup::set(size_type value)
47 ButtonValueMap::const_iterator it =
48 find_if(map.begin(), map.end(),
49 lyx::equal_2nd_in_pair<ButtonValuePair>(value));
51 if (it != map.end()) {
54 // We found nothing: report it and do nothing.
55 lyxerr << "BUG: Requested value in RadioButtonGroup "
56 "doesn't exist" << endl;
61 void RadioButtonGroup::set(FL_OBJECT * ob)
67 template < typename T >
68 struct is_set_button {
69 bool operator() (T const & item) const
71 return fl_get_button((item).first);
76 RadioButtonGroup::size_type RadioButtonGroup::get() const
78 // Find the active button.
79 ButtonValueMap::const_iterator it =
80 find_if(map.begin(), map.end(),
81 is_set_button<ButtonValuePair> ());
86 // We found nothing: report it and return 0
87 lyxerr << "BUG: No active radio button found." << endl;