1 // menubar.hxx - XML-configured menu bar.
4 #define __MENUBAR_HXX 1
7 # error This library requires C++
10 #include <Main/fg_props.hxx>
23 * XML-configured PUI menu bar.
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).
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.
46 virtual ~FGMenuBar ();
50 * Initialize the menu bar from $FG_ROOT/gui/menubar.xml
55 * Make the menu bar visible.
61 * Make the menu bar invisible.
67 * Test whether the menu bar is visible.
69 virtual bool isVisible () const;
73 * IGNORE THIS METHOD!!!
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.
80 virtual void fireItem (puObject * item);
84 * create a menubar based on a PropertyList within the PropertyTree
86 void make_menubar (SGPropertyNode * props);
90 * destroy a menubar based on a PropertyList within the PropertyTree
92 void destroy_menubar ();
96 * Disable/enable menu titles and entries
98 bool enable_item (const SGPropertyNode * item, bool state);
103 // Make a single menu.
104 void make_menu (SGPropertyNode * node);
106 // Make the top-level menubar.
107 void make_menubar ();
109 // Create a property-path -> puObject map for menu node
110 void make_object_map(SGPropertyNode * node);
112 // Add <enabled> listener that enables/disables menu entries.
113 void add_enabled_listener(SGPropertyNode * node);
115 // Is the menu visible?
118 // The top-level menubar itself.
119 puMenuBar * _menuBar;
121 // A map of bindings for the menubar.
122 std::map<std::string,std::vector<SGBinding *> > _bindings;
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
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;
133 // A map for {menu node path}->puObject translation.
134 std::map<std::string, puObject *> _objects;
137 #endif // __MENUBAR_HXX