]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/RadioButtonGroup.h
fa013b7c261cd313c6eac9bf16370fa76566e980
[lyx.git] / src / frontends / xforms / RadioButtonGroup.h
1 // -*- C++ -*-
2 /**
3  * \file RadioButtonGroup.h
4  * Copyright 2000 Baruch Even
5  * Read the file COPYING
6  *
7  * \author Baruch Even
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12
13 #ifndef RADIOBUTTONGROUP_H
14 #define RADIOBUTTONGROUP_H
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "support/types.h"
21 #include <vector>
22 #include <utility>
23 #include "forms_fwd.h"
24
25 /** This class simplifies the work with a group of radio buttons,
26  * the idea is that you register a bunch of radio buttons with the accompanying
27  * value for each radio button and then you get to query or set the active
28  * button in a single function call.
29  */
30 class RadioButtonGroup {
31 public:
32         ///
33         typedef lyx::size_type size_type;
34
35         /// Constructor. Allocate space for 'n' items in the group.
36         RadioButtonGroup(unsigned n = 5) : map(n) {};
37
38         /// Register a radio button with it's corresponding value.
39         void init(FL_OBJECT * button, size_type value);
40         /// Reset registrations.
41         void reset();
42
43         // Set the active button.
44         void set(size_type value);
45
46         // Get the active button.
47         size_type get() const;
48
49 private:
50         ///
51         typedef std::pair<FL_OBJECT *, size_type> ButtonValuePair;
52         ///
53         typedef std::vector<ButtonValuePair> ButtonValueMap;
54         ///
55         ButtonValueMap map;
56 };
57
58 #endif