1 // dialog.hxx - XML-configured dialog box.
7 # error This library requires C++
13 #include <simgear/compiler.h> // for SG_USING_STD
14 #include <simgear/props/props.hxx>
15 #include <simgear/misc/sg_path.hxx>
27 * An XML-configured dialog box.
29 * The GUI manager stores only the property tree for the dialog
30 * boxes. This class creates a PUI dialog box on demand from
31 * the properties in that tree. The manager recreates the dialog
32 * every time it needs to show it.
39 * Construct a new GUI widget configured by a property tree.
41 * The configuration properties are not part of the main
42 * FlightGear property tree; the GUI manager reads them
43 * from individual configuration files.
45 * @param props A property tree describing the dialog.
47 FGDialog (SGPropertyNode * props);
57 * Update the values of all GUI objects with a specific name.
59 * This method copies values from the FlightGear property tree to
62 * @param objectName The name of the GUI object(s) to update.
63 * Use the empty name for all unnamed objects.
65 virtual void updateValue (const char * objectName);
69 * Apply the values of all GUI objects with a specific name.
71 * This method copies values from the GUI object(s) to the
72 * FlightGear property tree.
74 * @param objectName The name of the GUI object(s) to update.
75 * Use the empty name for all unnamed objects.
77 virtual void applyValue (const char * objectName);
81 * Update the values of all GUI objects.
83 * This method copies values from the FlightGear property tree to
86 virtual void updateValues ();
90 * Apply the values of all GUI objects.
92 * This method copies from the GUI objects to the FlightGear
93 * property tree properties.
95 virtual void applyValues ();
99 * Update state. Called on active dialogs before rendering.
101 virtual void update ();
115 // Private copy constructor to avoid unpleasant surprises.
116 FGDialog (const FGDialog &);
119 void display (SGPropertyNode * props);
121 // Build the dialog or a subobject of it.
122 puObject * makeObject (SGPropertyNode * props,
123 int parentWidth, int parentHeight);
125 // Common configuration for all GUI objects.
126 void setupObject (puObject * object, SGPropertyNode * props);
128 // Common configuration for all GUI group objects.
129 void setupGroup (puGroup * group, SGPropertyNode * props,
130 int width, int height, bool makeFrame = false);
132 // Set object colors: the "which" argument defines which color qualities
133 // (PUCOL_LABEL, etc.) should pick up the <color> property.
134 void setColor(puObject * object, SGPropertyNode * props, int which = 0);
136 // return key code number for keystring
137 int getKeyCode(const char *keystring);
139 // The top-level PUI object.
142 // The GUI subsystem.
145 // PUI provides no way for userdata to be deleted automatically
146 // with a GUI object, so we have to keep track of all the special
147 // data we allocated and then free it manually when the dialog
149 vector<void *> _info;
150 struct PropertyObject {
151 PropertyObject (const char * name,
153 SGPropertyNode_ptr node);
156 SGPropertyNode_ptr node;
158 vector<PropertyObject *> _propertyObjects;
159 vector<PropertyObject *> _liveObjects;
161 // PUI doesn't copy arrays, so we have to allocate string arrays
162 // and then keep pointers so that we can delete them when the
164 char ** make_char_array (int size);
165 vector<char **> _char_arrays;
169 // Custom subclass of puPopup to implement "draggable" windows in the
170 // interface. Note that this is a subclass of puPopup, not
171 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
172 // boolean property: modality. That means that we can't implement
173 // dragging of both puPopup windows and puDialogBoxes with the same
174 // code. Rather than duplicate code, I've chosen to implement only
175 // "non-modal dragability" here. Modal dialog boxes (like the exit
176 // confirmation) are not draggable.
178 class fgPopup : public puPopup {
180 fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
181 int checkHit(int b, int up, int x, int y);
182 int checkKey(int key, int updown);
183 int getHitObjects(puObject *, int x, int y);
184 puObject *getKeyObject(puObject *, int key);
185 puObject *getActiveInputField(puObject *);
192 #endif // __DIALOG_HXX