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 ();
95 * Update state. Called on active dialogs before rendering.
97 virtual void update ();
101 // Private copy constructor to avoid unpleasant surprises.
102 FGDialog (const FGDialog &);
105 void display (SGPropertyNode * props);
107 // Build the dialog or a subobject of it.
108 puObject * makeObject (SGPropertyNode * props,
109 int parentWidth, int parentHeight);
111 // Common configuration for all GUI objects.
112 void setupObject (puObject * object, SGPropertyNode * props);
114 // Common configuration for all GUI group objects.
115 void setupGroup (puGroup * group, SGPropertyNode * props,
116 int width, int height, bool makeFrame = false);
118 // The top-level PUI object.
121 // PUI provides no way for userdata to be deleted automatically
122 // with a GUI object, so we have to keep track of all the special
123 // data we allocated and then free it manually when the dialog
125 vector<void *> _info;
126 struct PropertyObject {
127 PropertyObject (const char * name,
129 SGPropertyNode_ptr node);
132 SGPropertyNode_ptr node;
134 vector<PropertyObject *> _propertyObjects;
135 vector<PropertyObject *> _liveObjects;
137 // PUI doesn't copy arrays, so we have to allocate string arrays
138 // and then keep pointers so that we can delete them when the
140 char ** make_char_array (int size);
141 vector<char **> _char_arrays;
145 // Custom subclass of puPopup to implement "draggable" windows in the
146 // interface. Note that this is a subclass of puPopup, not
147 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
148 // boolean property: modality. That means that we can't implement
149 // dragging of both puPopup windows and puDialogBoxes with the same
150 // code. Rather than duplicate code, I've chosen to implement only
151 // "non-modal dragability" here. Modal dialog boxes (like the exit
152 // confirmation) are not draggable.
154 class fgPopup : public puPopup {
156 fgPopup(int x, int y) : puPopup(x, y) { _dragging = false; }
157 int checkHit(int b, int up, int x, int y);
163 #endif // __DIALOG_HXX