]> git.mxchange.org Git - flightgear.git/blob - src/GUI/menubar.hxx
final cosmetics (s/_entries/_objects/ and comments)
[flightgear.git] / src / GUI / menubar.hxx
1 // menubar.hxx - XML-configured menu bar.
2
3 #ifndef __MENUBAR_HXX
4 #define __MENUBAR_HXX 1
5
6 #ifndef __cplusplus
7 # error This library requires C++
8 #endif
9
10 #include <simgear/compiler.h>   // for SG_USING_STD
11
12 #include <plib/pu.h>
13
14 #include <map>
15 SG_USING_STD(map);
16
17 #include <vector>
18 SG_USING_STD(vector);
19
20
21 class puMenuBar;
22 class puObject;
23 class FGBinding;
24
25
26 /**
27  * XML-configured PUI menu bar.
28  *
29  * This class creates a menu bar from a tree of XML properties.  These
30  * properties are not part of the main FlightGear property tree, but
31  * are read from a separate file ($FG_ROOT/gui/menubar.xml).
32  *
33  * WARNING: because PUI provides no easy way to attach user data to a
34  * menu item, all menu item strings must be unique; otherwise, this
35  * class will always use the first binding with any given name.
36  */
37 class FGMenuBar
38 {
39 public:
40
41     /**
42      * Constructor.
43      */
44     FGMenuBar ();
45
46
47     /**
48      * Destructor.
49      */
50     virtual ~FGMenuBar ();
51
52
53     /**
54      * Initialize the menu bar from $FG_ROOT/gui/menubar.xml
55      */
56     virtual void init ();
57     
58     /**
59      * Make the menu bar visible.
60      */
61     virtual void show ();
62
63
64     /**
65      * Make the menu bar invisible.
66      */
67     virtual void hide ();
68
69
70     /**
71      * Test whether the menu bar is visible.
72      */
73     virtual bool isVisible () const;
74
75
76     /**
77      * IGNORE THIS METHOD!!!
78      *
79      * This is necessary only because plib does not provide any easy
80      * way to attach user data to a menu item.  FlightGear should not
81      * have to know about PUI internals, but this method allows the
82      * callback to pass the menu item one-shot on to the current menu.
83      */
84     virtual void fireItem (puObject * item);
85
86
87     /**
88      * create a menubar based on a PropertyList within the PropertyTree
89      */
90     void make_menubar (SGPropertyNode * props);
91
92
93     /**
94      * destroy a menubar based on a PropertyList within the PropertyTree
95      */
96     void destroy_menubar ();
97
98
99     /**
100      * Disable/enable menu titles and entries
101      */
102     bool enable_item (const SGPropertyNode * item, bool state);
103
104
105 private:
106
107     // Make a single menu.
108     void make_menu (SGPropertyNode * node);
109
110     // Make the top-level menubar.
111     void make_menubar ();
112
113     // Create a property-path -> puObject map for menu node
114     void make_map(SGPropertyNode * node);
115
116     // Add <enabled> listener that enables/disables menu entries.
117     void add_enabled_listener(SGPropertyNode * node);
118
119     // Is the menu visible?
120     bool _visible;
121
122     // The top-level menubar itself.
123     puMenuBar * _menuBar;
124
125     // A map of bindings for the menubar.
126     map<string,vector<FGBinding *> > _bindings;
127
128     // These are hoops that we have to jump through because PUI doesn't
129     // do memory management for lists.  We have to allocate the arrays,
130     // hang onto pointers, and then delete them when the menubar is
131     // freed.
132     char ** make_char_array (int size);
133     puCallback * make_callback_array (int size);
134     vector<char **> _char_arrays;
135     vector<puCallback *> _callback_arrays;
136
137     // A map for {menu node path}->puObject translation.
138     map<string, puObject *> _objects;
139 };
140
141 #endif // __MENUBAR_HXX