1 // dialog.hxx - XML-configured dialog box.
7 # error This library requires C++
12 #include <simgear/compiler.h> // for SG_USING_STD
13 #include <simgear/props/props.hxx>
23 * An XML-configured dialog box.
25 * The GUI manager stores only the property tree for the dialog
26 * boxes. This class creates a PUI dialog box on demand from
27 * the properties in that tree. The manager recreates the dialog
28 * every time it needs to show it.
35 * Construct a new GUI widget configured by a property tree.
37 * The configuration properties are not part of the main
38 * FlightGear property tree; the GUI manager reads them
39 * from individual configuration files.
41 * @param props A property tree describing the dialog.
43 FGDialog (SGPropertyNode * props);
53 * Update the values of all GUI objects with a specific name.
55 * This method copies values from the FlightGear property tree to
58 * @param objectName The name of the GUI object(s) to update.
59 * Use the empty name for all unnamed objects.
61 virtual void updateValue (const char * objectName);
65 * Apply the values of all GUI objects with a specific name.
67 * This method copies values from the GUI object(s) to the
68 * FlightGear property tree.
70 * @param objectName The name of the GUI object(s) to update.
71 * Use the empty name for all unnamed objects.
73 virtual void applyValue (const char * objectName);
77 * Update the values of all GUI objects.
79 * This method copies values from the FlightGear property tree to
82 virtual void updateValues ();
86 * Apply the values of all GUI objects.
88 * This method copies from the GUI objects to the FlightGear
89 * property tree properties.
91 virtual void applyValues ();
96 // Private copy constructor to avoid unpleasant surprises.
97 FGDialog (const FGDialog &);
100 void display (SGPropertyNode * props);
102 // Build the dialog or a subobject of it.
103 puObject * makeObject (SGPropertyNode * props,
104 int parentWidth, int parentHeight);
106 // Common configuration for all GUI objects.
107 void setupObject (puObject * object, SGPropertyNode * props);
109 // Common configuration for all GUI group objects.
110 void setupGroup (puGroup * group, SGPropertyNode * props,
111 int width, int height, bool makeFrame = false);
113 // The top-level PUI object.
116 // PUI provides no way for userdata to be deleted automatically
117 // with a GUI object, so we have to keep track of all the special
118 // data we allocated and then free it manually when the dialog
120 vector<void *> _info;
121 struct PropertyObject {
122 PropertyObject (const char * name,
124 SGPropertyNode_ptr node);
127 SGPropertyNode_ptr node;
129 vector<PropertyObject *> _propertyObjects;
131 // PUI doesn't copy arrays, so we have to allocate string arrays
132 // and then keep pointers so that we can delete them when the
134 char ** make_char_array (int size);
135 vector<char **> _char_arrays;
139 // Custom subclass of puPopup to implement "draggable" windows in the
140 // interface. Note that this is a subclass of puPopup, not
141 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
142 // boolean property: modality. That means that we can't implement
143 // dragging of both puPopup windows and puDialogBoxes with the same
144 // code. Rather than duplicate code, I've chosen to implement only
145 // "non-modal dragability" here. Modal dialog boxes (like the exit
146 // confirmation) are not draggable.
148 class fgPopup : public puPopup {
150 fgPopup(int x, int y) : puPopup(x, y) { _dragging = false; }
151 int checkHit(int b, int up, int x, int y);
157 #endif // __DIALOG_HXX