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