2003-01-20 16:02:26 +00:00
|
|
|
// menubar.hxx - XML-configured menu bar.
|
|
|
|
|
2003-01-16 18:06:27 +00:00
|
|
|
#ifndef __MENUBAR_HXX
|
|
|
|
#define __MENUBAR_HXX 1
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
|
|
|
|
2006-04-17 13:40:20 +00:00
|
|
|
#include <Main/fg_props.hxx>
|
2003-01-16 18:06:27 +00:00
|
|
|
|
|
|
|
#include <plib/pu.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class puMenuBar;
|
|
|
|
class puObject;
|
2007-01-04 13:22:27 +00:00
|
|
|
class SGBinding;
|
2003-01-16 18:06:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* XML-configured PUI menu bar.
|
2003-01-20 16:02:26 +00:00
|
|
|
*
|
|
|
|
* This class creates a menu bar from a tree of XML properties. These
|
|
|
|
* properties are not part of the main FlightGear property tree, but
|
|
|
|
* are read from a separate file ($FG_ROOT/gui/menubar.xml).
|
|
|
|
*
|
|
|
|
* WARNING: because PUI provides no easy way to attach user data to a
|
|
|
|
* menu item, all menu item strings must be unique; otherwise, this
|
|
|
|
* class will always use the first binding with any given name.
|
2003-01-16 18:06:27 +00:00
|
|
|
*/
|
|
|
|
class FGMenuBar
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
FGMenuBar ();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
virtual ~FGMenuBar ();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the menu bar from $FG_ROOT/gui/menubar.xml
|
|
|
|
*/
|
|
|
|
virtual void init ();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the menu bar visible.
|
|
|
|
*/
|
|
|
|
virtual void show ();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the menu bar invisible.
|
|
|
|
*/
|
|
|
|
virtual void hide ();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test whether the menu bar is visible.
|
|
|
|
*/
|
|
|
|
virtual bool isVisible () const;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IGNORE THIS METHOD!!!
|
|
|
|
*
|
|
|
|
* This is necessary only because plib does not provide any easy
|
|
|
|
* way to attach user data to a menu item. FlightGear should not
|
|
|
|
* have to know about PUI internals, but this method allows the
|
|
|
|
* callback to pass the menu item one-shot on to the current menu.
|
|
|
|
*/
|
2003-01-19 15:27:29 +00:00
|
|
|
virtual void fireItem (puObject * item);
|
2003-01-16 18:06:27 +00:00
|
|
|
|
|
|
|
|
2004-10-22 09:26:51 +00:00
|
|
|
/**
|
|
|
|
* create a menubar based on a PropertyList within the PropertyTree
|
|
|
|
*/
|
2005-12-06 19:51:31 +00:00
|
|
|
void make_menubar (SGPropertyNode * props);
|
2004-10-22 09:26:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* destroy a menubar based on a PropertyList within the PropertyTree
|
|
|
|
*/
|
|
|
|
void destroy_menubar ();
|
|
|
|
|
2005-12-09 10:43:09 +00:00
|
|
|
|
2005-12-06 17:56:17 +00:00
|
|
|
/**
|
|
|
|
* Disable/enable menu titles and entries
|
|
|
|
*/
|
|
|
|
bool enable_item (const SGPropertyNode * item, bool state);
|
|
|
|
|
2004-10-22 09:26:51 +00:00
|
|
|
|
2003-01-16 18:06:27 +00:00
|
|
|
private:
|
|
|
|
|
2003-01-20 16:02:26 +00:00
|
|
|
// Make a single menu.
|
2003-01-21 15:44:21 +00:00
|
|
|
void make_menu (SGPropertyNode * node);
|
2003-01-20 16:02:26 +00:00
|
|
|
|
|
|
|
// Make the top-level menubar.
|
2003-01-16 18:06:27 +00:00
|
|
|
void make_menubar ();
|
|
|
|
|
2005-12-06 17:56:17 +00:00
|
|
|
// Create a property-path -> puObject map for menu node
|
2005-12-14 07:45:47 +00:00
|
|
|
void make_object_map(SGPropertyNode * node);
|
2005-12-06 17:56:17 +00:00
|
|
|
|
2005-12-06 18:46:39 +00:00
|
|
|
// Add <enabled> listener that enables/disables menu entries.
|
2005-12-06 17:56:17 +00:00
|
|
|
void add_enabled_listener(SGPropertyNode * node);
|
|
|
|
|
2003-01-20 16:02:26 +00:00
|
|
|
// Is the menu visible?
|
2003-01-16 18:06:27 +00:00
|
|
|
bool _visible;
|
2003-01-20 16:02:26 +00:00
|
|
|
|
|
|
|
// The top-level menubar itself.
|
2003-01-16 18:06:27 +00:00
|
|
|
puMenuBar * _menuBar;
|
2003-01-20 16:02:26 +00:00
|
|
|
|
|
|
|
// A map of bindings for the menubar.
|
2011-10-17 16:41:59 +00:00
|
|
|
std::map<std::string,std::vector<SGBinding *> > _bindings;
|
2003-01-20 16:02:26 +00:00
|
|
|
|
|
|
|
// These are hoops that we have to jump through because PUI doesn't
|
|
|
|
// do memory management for lists. We have to allocate the arrays,
|
|
|
|
// hang onto pointers, and then delete them when the menubar is
|
|
|
|
// freed.
|
|
|
|
char ** make_char_array (int size);
|
|
|
|
puCallback * make_callback_array (int size);
|
2011-10-17 16:41:59 +00:00
|
|
|
std::vector<char **> _char_arrays;
|
|
|
|
std::vector<puCallback *> _callback_arrays;
|
2005-12-06 17:56:17 +00:00
|
|
|
|
2005-12-09 10:43:09 +00:00
|
|
|
// A map for {menu node path}->puObject translation.
|
2011-10-17 16:41:59 +00:00
|
|
|
std::map<std::string, puObject *> _objects;
|
2003-01-16 18:06:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __MENUBAR_HXX
|