]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/RadioButtonGroup.h
Add a couple of new functions.
[lyx.git] / src / frontends / xforms / RadioButtonGroup.h
1 // -*- C++ -*-
2 /**
3  * \file RadioButtonGroup.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Baruch Even
8  * \author Rob Lahaye
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13
14 #ifndef RADIOBUTTONGROUP_H
15 #define RADIOBUTTONGROUP_H
16
17
18 #include "support/types.h"
19 #include <vector>
20 #include <utility>
21 #include "forms_fwd.h"
22
23 /** This class simplifies interaction with a group of radio buttons:
24  *  one, and only one, can be selected.
25  *  The idea is that you register a bunch of radio buttons with
26  *  an accompanying value. Then you can get or set the active button with a
27  *  single function call.
28  *  It is necessary to also group a family of radio buttons in the
29  *  corresponding .fd file in order to unset the previously chosen button
30  *  when a new one is selected.
31  */
32 class RadioButtonGroup {
33 public:
34         ///
35         typedef lyx::size_type size_type;
36
37         /// Register a radio button with its corresponding value.
38         void init(FL_OBJECT * ob, size_type value);
39
40         // Set a single active button.
41         void set(size_type value) const;
42         void set(FL_OBJECT * ob) const;
43
44         // None of the radiobuttons are set.
45         void unset() const;
46
47         // Get the active button's value.
48         size_type get() const;
49
50         void setEnabled(bool enabled);
51
52 private:
53         ///
54         typedef std::pair<FL_OBJECT *, size_type> ButtonValuePair;
55         ///
56         typedef std::vector<ButtonValuePair> ButtonValueMap;
57         ///
58         ButtonValueMap map;
59 };
60
61 #endif // RADIOBUTTONGROUP_H