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 // The dialog font. Defaults to the global gui font, but can get
146 // overridden by a top level font definition.
149 // The source xml tree, so that we can pass data back, such as the
151 SGPropertyNode_ptr _props;
155 SGPropertyNode_ptr _nasal_close;
157 // PUI provides no way for userdata to be deleted automatically
158 // with a GUI object, so we have to keep track of all the special
159 // data we allocated and then free it manually when the dialog
161 vector<void *> _info;
162 struct PropertyObject {
163 PropertyObject (const char * name,
165 SGPropertyNode_ptr node);
168 SGPropertyNode_ptr node;
170 vector<PropertyObject *> _propertyObjects;
171 vector<PropertyObject *> _liveObjects;
173 // PUI doesn't copy arrays, so we have to allocate string arrays
174 // and then keep pointers so that we can delete them when the
176 char ** make_char_array (int size);
177 vector<char **> _char_arrays;
181 // Custom subclass of puPopup to implement "draggable" windows in the
182 // interface. Note that this is a subclass of puPopup, not
183 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
184 // boolean property: modality. That means that we can't implement
185 // dragging of both puPopup windows and puDialogBoxes with the same
186 // code. Rather than duplicate code, I've chosen to implement only
187 // "non-modal dragability" here. Modal dialog boxes (like the exit
188 // confirmation) are not draggable.
190 class fgPopup : public puPopup {
192 fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
193 int checkHit(int b, int up, int x, int y);
194 int checkKey(int key, int updown);
195 int getHitObjects(puObject *, int x, int y);
196 puObject *getKeyObject(puObject *, int key);
197 puObject *getActiveInputField(puObject *);
204 #endif // __DIALOG_HXX