]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/RadioButtonGroup.C
remove defaults stuff, let Qt handle no toolbar
[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) const
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                 fl_set_button(it->first, 1);
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) const
59 {
60         // Object must be member of the radiobutton group.
61         bool isMember = false;
62         ButtonValueMap::const_iterator it = map.begin();
63         for (; it != map.end() && !isMember; ++it) {
64                 isMember = it->first == ob;
65         }
66
67         if (isMember) {
68                 fl_set_button(ob, 1);
69         } else {
70                 // Object is not a member; report it and do nothing.
71                 lyxerr << "BUG: Requested object is not a member of "
72                         << "the RadioButtonGroup." << endl;
73         }
74 }
75
76
77 template < typename T >
78 struct is_set_button {
79         bool operator() (T const & item) const
80         {
81                 return fl_get_button((item).first);
82         }
83 };
84
85
86 RadioButtonGroup::size_type RadioButtonGroup::get() const
87 {
88         // Find the active button.
89         ButtonValueMap::const_iterator it =
90                 find_if(map.begin(), map.end(),
91                         is_set_button<ButtonValuePair> ());
92
93         if (it != map.end())
94                 return it->second;
95
96         // We found nothing: report it and return 0
97         lyxerr << "BUG: No active radio button found." << endl;
98         return 0;
99 }