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