1 // menubar.hxx - XML-configured menu bar.
3 #ifndef FG_PUI_MENUBAR_HXX
4 #define FG_PUI_MENUBAR_HXX 1
7 # error This library requires C++
10 #include <GUI/menubar.hxx>
15 // forward decls, avoid pulling in PLIB headers here
21 typedef void (*puCallback)(class puObject *) ;
24 * XML-configured PUI menu bar.
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).
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.
34 class FGPUIMenuBar : public FGMenuBar
47 virtual ~FGPUIMenuBar ();
51 * Initialize the menu bar from $FG_ROOT/gui/menubar.xml
56 * Make the menu bar visible.
62 * Make the menu bar invisible.
68 * Test whether the menu bar is visible.
70 virtual bool isVisible () const;
74 * IGNORE THIS METHOD!!!
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.
81 virtual void fireItem (puObject * item);
85 * create a menubar based on a PropertyList within the PropertyTree
87 void make_menubar (SGPropertyNode * props);
91 * destroy a menubar based on a PropertyList within the PropertyTree
93 void destroy_menubar ();
97 * Disable/enable menu titles and entries
99 bool enable_item (const SGPropertyNode * item, bool state);
104 // Make a single menu.
105 void make_menu (SGPropertyNode * node);
107 // Make the top-level menubar.
108 void make_menubar ();
110 // Create a property-path -> puObject map for menu node
111 void make_object_map(SGPropertyNode * node);
113 // Add <enabled> listener that enables/disables menu entries.
114 void add_enabled_listener(SGPropertyNode * node);
116 // Is the menu visible?
119 // The top-level menubar itself.
120 puMenuBar * _menuBar;
122 // A map of bindings for the menubar.
123 std::map<std::string,std::vector<SGBinding *> > _bindings;
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
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;
134 // A map for {menu node path}->puObject translation.
135 std::map<std::string, puObject *> _objects;
138 #endif // __MENUBAR_HXX