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,
58 * or all if name is 0 (default).
60 * This method copies values from the FlightGear property tree to
63 * @param objectName The name of the GUI object(s) to update.
64 * Use the empty name for all unnamed objects.
66 virtual void updateValues (const char * objectName = 0);
70 * Apply the values of all GUI objects with a specific name,
71 * or all if name is 0 (default)
73 * This method copies values from the GUI object(s) to the
74 * FlightGear property tree.
76 * @param objectName The name of the GUI object(s) to update.
77 * Use the empty name for all unnamed objects.
79 virtual void applyValues (const char * objectName = 0);
83 * Update state. Called on active dialogs before rendering.
85 virtual void update ();
99 // Private copy constructor to avoid unpleasant surprises.
100 FGDialog (const FGDialog &);
103 void display (SGPropertyNode * props);
105 // Build the dialog or a subobject of it.
106 puObject * makeObject (SGPropertyNode * props,
107 int parentWidth, int parentHeight);
109 // Common configuration for all GUI objects.
110 void setupObject (puObject * object, SGPropertyNode * props);
112 // Common configuration for all GUI group objects.
113 void setupGroup (puGroup * group, SGPropertyNode * props,
114 int width, int height, bool makeFrame = false);
116 // Set object colors: the "which" argument defines which color qualities
117 // (PUCOL_LABEL, etc.) should pick up the <color> property.
118 void setColor(puObject * object, SGPropertyNode * props, int which = 0);
120 // return key code number for keystring
121 int getKeyCode(const char *keystring);
123 // The top-level PUI object.
126 // The GUI subsystem.
129 // The dialog font. Defaults to the global gui font, but can get
130 // overridden by a top level font definition.
133 // The source xml tree, so that we can pass data back, such as the
135 SGPropertyNode_ptr _props;
139 SGPropertyNode_ptr _nasal_close;
141 // PUI provides no way for userdata to be deleted automatically
142 // with a GUI object, so we have to keep track of all the special
143 // data we allocated and then free it manually when the dialog
145 vector<void *> _info;
146 struct PropertyObject {
147 PropertyObject (const char * name,
149 SGPropertyNode_ptr node);
152 SGPropertyNode_ptr node;
154 vector<PropertyObject *> _propertyObjects;
155 vector<PropertyObject *> _liveObjects;
157 // PUI doesn't copy arrays, so we have to allocate string arrays
158 // and then keep pointers so that we can delete them when the
159 // dialog closes. value_list() builds such a list from "value"
161 char ** make_char_array (int size);
162 char ** value_list(const SGPropertyNode * prop);
163 void destroy_char_array (char **array);
164 vector<char **> _char_arrays;
168 // Custom subclass of puPopup to implement "draggable" windows in the
169 // interface. Note that this is a subclass of puPopup, not
170 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
171 // boolean property: modality. That means that we can't implement
172 // dragging of both puPopup windows and puDialogBoxes with the same
173 // code. Rather than duplicate code, I've chosen to implement only
174 // "non-modal dragability" here. Modal dialog boxes (like the exit
175 // confirmation) are not draggable.
177 class fgPopup : public puPopup {
179 fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
180 int checkHit(int b, int up, int x, int y);
181 int checkKey(int key, int updown);
182 int getHitObjects(puObject *, int x, int y);
183 puObject *getKeyObject(puObject *, int key);
184 puObject *getActiveInputField(puObject *);
191 #endif // __DIALOG_HXX