1 // FGPUIDialog.hxx - XML-configured dialog box.
3 #ifndef FG_PUI_DIALOG_HXX
4 #define FG_PUI_DIALOG_HXX 1
8 #include <plib/puAux.h>
10 #include <simgear/props/props.hxx>
11 #include <simgear/misc/sg_path.hxx>
12 #include <simgear/props/condition.hxx>
17 // ugly temporary workaround for plib's lack of user defined class ids FIXME
18 #define FGCLASS_LIST 0x00000001
19 #define FGCLASS_AIRPORTLIST 0x00000002
20 #define FGCLASS_PROPERTYLIST 0x00000004
21 #define FGCLASS_WAYPOINTLIST 0x00000008
22 #define FGCLASS_LOGLIST 0x00000010
24 class GUI_ID { public: GUI_ID(int id) : id(id) {} virtual ~GUI_ID() {} int id; };
34 * An XML-configured dialog box.
36 * The GUI manager stores only the property tree for the dialog
37 * boxes. This class creates a PUI dialog box on demand from
38 * the properties in that tree. The manager recreates the dialog
39 * every time it needs to show it.
41 class FGPUIDialog : public FGDialog
46 * Construct a new GUI widget configured by a property tree.
48 * The configuration properties are not part of the main
49 * FlightGear property tree; the GUI manager reads them
50 * from individual configuration files.
52 * @param props A property tree describing the dialog.
54 FGPUIDialog (SGPropertyNode * props);
60 virtual ~FGPUIDialog ();
64 * Update the values of all GUI objects with a specific name,
65 * or all if an empty name is given (default).
67 * This method copies values from the FlightGear property tree to
70 * @param objectName The name of the GUI object(s) to update.
71 * Use the empty name for all objects.
73 virtual void updateValues(const std::string& objectName = "");
77 * Apply the values of all GUI objects with a specific name,
78 * or all if an empty name is given (default).
80 * This method copies values from the GUI object(s) to the
81 * FlightGear property tree.
83 * @param objectName The name of the GUI object(s) to update.
84 * Use the empty name for all objects.
86 virtual void applyValues(const std::string& objectName = "");
90 * Update state. Called on active dialogs before rendering.
92 virtual void update ();
95 * Recompute the dialog's layout
100 void setNeedsLayout() {
101 _needsRelayout = true;
107 virtual void update() = 0;
122 void display (SGPropertyNode * props);
124 // Build the dialog or a subobject of it.
125 puObject * makeObject (SGPropertyNode * props,
126 int parentWidth, int parentHeight);
128 // Common configuration for all GUI objects.
129 void setupObject (puObject * object, SGPropertyNode * props);
131 // Common configuration for all GUI group objects.
132 void setupGroup (puGroup * group, SGPropertyNode * props,
133 int width, int height, bool makeFrame = false);
135 // Set object colors: the "which" argument defines which color qualities
136 // (PUCOL_LABEL, etc.) should pick up the <color> property.
137 void setColor(puObject * object, SGPropertyNode * props, int which = 0);
139 // return key code number for keystring
140 int getKeyCode(const char *keystring);
143 * Apply layout sizes to a tree of puObjects
145 void applySize(puObject *object);
147 // The top-level PUI object.
150 // The GUI subsystem.
153 // The dialog font. Defaults to the global gui font, but can get
154 // overridden by a top level font definition.
157 // The source xml tree, so that we can pass data back, such as the
159 SGPropertyNode_ptr _props;
165 SGPropertyNode_ptr _nasal_close;
167 // PUI provides no way for userdata to be deleted automatically
168 // with a GUI object, so we have to keep track of all the special
169 // data we allocated and then free it manually when the dialog
171 std::vector<void *> _info;
172 struct PropertyObject {
173 PropertyObject (const char * name,
175 SGPropertyNode_ptr node);
178 SGPropertyNode_ptr node;
180 std::vector<PropertyObject *> _propertyObjects;
181 std::vector<PropertyObject *> _liveObjects;
183 class ConditionalObject : public SGConditional
186 ConditionalObject(const std::string& aName, puObject* aPu) :
191 void update(FGPUIDialog* aDlg);
194 const std::string _name;
198 typedef SGSharedPtr<ConditionalObject> ConditionalObjectRef;
199 std::vector<ConditionalObjectRef> _conditionalObjects;
201 std::vector<ActiveWidget*> _activeWidgets;
204 #endif // __DIALOG_HXX