]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/RadioButtonGroup.C
dont use pragma impementation and interface anymore
[lyx.git] / src / frontends / xforms / RadioButtonGroup.C
1 /**
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.
7  *
8  * \author Baruch Even
9  * \author Rob Lahaye
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 #include <config.h>
15
16
17 #include "RadioButtonGroup.h"
18 #include FORMS_H_LOCATION
19
20 #include "support/LAssert.h"
21 #include "debug.h" // for lyxerr
22 #include "support/lyxfunctional.h"
23
24 #include <algorithm>
25 #include <iterator>
26
27 using std::find_if;
28 using std::endl;
29
30
31 void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
32 {
33         // Object must be a ROUND3DBUTTON (let all radio buttons look the same)
34         // and of type RADIO_BUTTON (otherwise it ain't work).
35         lyx::Assert(ob && ob->objclass == FL_ROUND3DBUTTON
36                         && ob->type == FL_RADIO_BUTTON);
37
38         map.push_back(ButtonValuePair(ob, value));
39 }
40
41
42 void RadioButtonGroup::set(size_type value)
43 {
44         ButtonValueMap::const_iterator it =
45                 find_if(map.begin(), map.end(),
46                         lyx::equal_2nd_in_pair<ButtonValuePair>(value));
47
48         if (it != map.end()) {
49                 set(it->first);
50         } else {
51                 // We found nothing: report it and do nothing.
52                 lyxerr << "BUG: Requested value in RadioButtonGroup "
53                         "doesn't exist" << endl;
54         }
55 }
56
57
58 void RadioButtonGroup::set(FL_OBJECT * ob)
59 {
60         fl_set_button(ob, 1);
61 }
62
63
64 template < typename T >
65 struct is_set_button {
66         bool operator() (T const & item) const
67         {
68                 return fl_get_button((item).first);
69         }
70 };
71
72
73 RadioButtonGroup::size_type RadioButtonGroup::get() const
74 {
75         // Find the active button.
76         ButtonValueMap::const_iterator it =
77                 find_if(map.begin(), map.end(),
78                         is_set_button<ButtonValuePair> ());
79
80         if (it != map.end())
81                 return it->second;
82
83         // We found nothing: report it and return 0
84         lyxerr << "BUG: No active radio button found." << endl;
85         return 0;
86 }