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