]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/RadioButtonGroup.h
b05cc063e8fb159f95cce27a68b27458998e3b9c
[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         // Get the active button's value.
45         size_type get() const;
46
47 private:
48         ///
49         typedef std::pair<FL_OBJECT *, size_type> ButtonValuePair;
50         ///
51         typedef std::vector<ButtonValuePair> ButtonValueMap;
52         ///
53         ButtonValueMap map;
54 };
55
56 #endif // RADIOBUTTONGROUP_H