]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/RadioButtonGroup.C
change some __GNUG_ to __GNUG__
[lyx.git] / src / frontends / xforms / RadioButtonGroup.C
1 /**
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.
7  *
8  * \author Baruch Even, baruch.even@writeme.com
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "RadioButtonGroup.h"
18
19 #include "debug.h" // for lyxerr
20 #include "support/lyxfunctional.h"
21
22 //#include <functional>
23 #include <algorithm>
24 #include <iterator>
25
26 using std::find_if;
27 //using std::bind2nd;
28 using std::endl;
29
30
31 void RadioButtonGroup::init(FL_OBJECT *button, size_type value)
32 {
33         map.push_back(ButtonValuePair(button, value));
34 }
35
36
37 void RadioButtonGroup::reset()
38 {
39         map.clear();
40 }
41
42
43 void RadioButtonGroup::set(size_type value)
44 {
45         ButtonValueMap::const_iterator it =
46                 find_if(map.begin(), map.end(),
47                         lyx::equal_2nd_in_pair<ButtonValuePair>(value));
48
49         // If we found nothing, report it and return
50         if (it == map.end()) {
51                 lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists"
52                        << endl;
53         }
54         else {
55                 fl_set_button(it->first, 1);
56         }
57
58 }
59
60
61 template < typename T >
62 struct is_set_button {
63         bool operator() (T const & item) const
64         {
65                 return fl_get_button((item).first);
66         }
67 };
68
69
70 RadioButtonGroup::size_type RadioButtonGroup::get() const
71 {
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> ());
76
77         // If such a button was found, return its value.
78         if (it != map.end()) {
79                 return it->second;
80         }
81
82         lyxerr << "BUG: No radio button found to be active." << endl;
83
84         // Else return 0.
85         return 0;
86 }