1 // dialog.hxx - XML-configured dialog box.
7 # error This library requires C++
10 #include <plib/puAux.h>
13 #include <simgear/compiler.h> // for SG_USING_STD
14 #include <simgear/props/props.hxx>
15 #include <simgear/misc/sg_path.hxx>
23 #include "AirportList.hxx"
33 * An XML-configured dialog box.
35 * The GUI manager stores only the property tree for the dialog
36 * boxes. This class creates a PUI dialog box on demand from
37 * the properties in that tree. The manager recreates the dialog
38 * every time it needs to show it.
45 * Construct a new GUI widget configured by a property tree.
47 * The configuration properties are not part of the main
48 * FlightGear property tree; the GUI manager reads them
49 * from individual configuration files.
51 * @param props A property tree describing the dialog.
53 FGDialog (SGPropertyNode * props);
63 * Update the values of all GUI objects with a specific name,
64 * or all if name is 0 (default).
66 * This method copies values from the FlightGear property tree to
69 * @param objectName The name of the GUI object(s) to update.
70 * Use the empty name for all unnamed objects.
72 virtual void updateValues (const char * objectName = 0);
76 * Apply the values of all GUI objects with a specific name,
77 * or all if name is 0 (default)
79 * This method copies values from the GUI object(s) to the
80 * FlightGear property tree.
82 * @param objectName The name of the GUI object(s) to update.
83 * Use the empty name for all unnamed objects.
85 virtual void applyValues (const char * objectName = 0);
89 * Update state. Called on active dialogs before rendering.
91 virtual void update ();
105 // Private copy constructor to avoid unpleasant surprises.
106 FGDialog (const FGDialog &);
109 void display (SGPropertyNode * props);
111 // Build the dialog or a subobject of it.
112 puObject * makeObject (SGPropertyNode * props,
113 int parentWidth, int parentHeight);
115 // Common configuration for all GUI objects.
116 void setupObject (puObject * object, SGPropertyNode * props);
118 // Common configuration for all GUI group objects.
119 void setupGroup (puGroup * group, SGPropertyNode * props,
120 int width, int height, bool makeFrame = false);
122 // Set object colors: the "which" argument defines which color qualities
123 // (PUCOL_LABEL, etc.) should pick up the <color> property.
124 void setColor(puObject * object, SGPropertyNode * props, int which = 0);
126 // return key code number for keystring
127 int getKeyCode(const char *keystring);
129 // The top-level PUI object.
132 // The GUI subsystem.
135 // The dialog font. Defaults to the global gui font, but can get
136 // overridden by a top level font definition.
139 // The source xml tree, so that we can pass data back, such as the
141 SGPropertyNode_ptr _props;
145 SGPropertyNode_ptr _nasal_close;
147 // PUI provides no way for userdata to be deleted automatically
148 // with a GUI object, so we have to keep track of all the special
149 // data we allocated and then free it manually when the dialog
151 vector<void *> _info;
152 struct PropertyObject {
153 PropertyObject (const char * name,
155 SGPropertyNode_ptr node);
158 SGPropertyNode_ptr node;
160 vector<PropertyObject *> _propertyObjects;
161 vector<PropertyObject *> _liveObjects;
165 // Custom subclass of puPopup to implement "draggable" windows in the
166 // interface. Note that this is a subclass of puPopup, not
167 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
168 // boolean property: modality. That means that we can't implement
169 // dragging of both puPopup windows and puDialogBoxes with the same
170 // code. Rather than duplicate code, I've chosen to implement only
171 // "non-modal dragability" here. Modal dialog boxes (like the exit
172 // confirmation) are not draggable.
174 class fgPopup : public puPopup {
176 fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
177 int checkHit(int b, int up, int x, int y);
178 int checkKey(int key, int updown);
179 int getHitObjects(puObject *, int x, int y);
180 puObject *getKeyObject(puObject *, int key);
181 puObject *getActiveInputField(puObject *);
191 fgValueList(SGPropertyNode *p);
192 virtual ~fgValueList();
193 virtual void update();
201 SGPropertyNode_ptr _props;
205 class fgList : public fgValueList, public puList, public GUI_ID {
207 fgList(int x1, int y1, int x2, int y2, SGPropertyNode *p, int sw) :
208 fgValueList(p), puList(x1, y1, x2, y2, _list, sw), GUI_ID(FGCLASS_LIST) {}
212 class fgComboBox : public fgValueList, public puaComboBox {
214 fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode *p, bool editable) :
215 fgValueList(p), puaComboBox(x1, y1, x2, y2, _list, editable) {}
218 class fgSelectBox : public fgValueList, public puaSelectBox {
220 fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode *p) :
221 fgValueList(p), puaSelectBox(x1, y1, x2, y2, _list) {}
224 #endif // __DIALOG_HXX