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