1 // dialog.hxx - XML-configured dialog box.
7 # error This library requires C++
10 #include <plib/puAux.h>
12 #include <simgear/compiler.h> // for SG_USING_STD
13 #include <simgear/props/props.hxx>
14 #include <simgear/misc/sg_path.hxx>
15 #include <simgear/props/condition.hxx>
21 // ugly temporary workaround for plib's lack of user defined class ids FIXME
22 #define FGCLASS_LIST 0x00000001
23 #define FGCLASS_AIRPORTLIST 0x00000002
24 #define FGCLASS_PROPERTYLIST 0x00000004
25 class GUI_ID { public: GUI_ID(int id) : id(id) {} virtual ~GUI_ID() {} int id; };
35 * An XML-configured dialog box.
37 * The GUI manager stores only the property tree for the dialog
38 * boxes. This class creates a PUI dialog box on demand from
39 * the properties in that tree. The manager recreates the dialog
40 * every time it needs to show it.
47 * Construct a new GUI widget configured by a property tree.
49 * The configuration properties are not part of the main
50 * FlightGear property tree; the GUI manager reads them
51 * from individual configuration files.
53 * @param props A property tree describing the dialog.
55 FGDialog (SGPropertyNode * props);
65 * Update the values of all GUI objects with a specific name,
66 * or all if name is 0 (default).
68 * This method copies values from the FlightGear property tree to
71 * @param objectName The name of the GUI object(s) to update.
72 * Use the empty name for all unnamed objects.
74 virtual void updateValues (const char * objectName = 0);
78 * Apply the values of all GUI objects with a specific name,
79 * or all if name is 0 (default)
81 * This method copies values from the GUI object(s) to the
82 * FlightGear property tree.
84 * @param objectName The name of the GUI object(s) to update.
85 * Use the empty name for all unnamed objects.
87 virtual void applyValues (const char * objectName = 0);
91 * Update state. Called on active dialogs before rendering.
93 virtual void update ();
96 * Recompute the dialog's layout
101 void setNeedsLayout() {
102 _needsRelayout = true;
116 // Private copy constructor to avoid unpleasant surprises.
117 FGDialog (const FGDialog &);
120 void display (SGPropertyNode * props);
122 // Build the dialog or a subobject of it.
123 puObject * makeObject (SGPropertyNode * props,
124 int parentWidth, int parentHeight);
126 // Common configuration for all GUI objects.
127 void setupObject (puObject * object, SGPropertyNode * props);
129 // Common configuration for all GUI group objects.
130 void setupGroup (puGroup * group, SGPropertyNode * props,
131 int width, int height, bool makeFrame = false);
133 // Set object colors: the "which" argument defines which color qualities
134 // (PUCOL_LABEL, etc.) should pick up the <color> property.
135 void setColor(puObject * object, SGPropertyNode * props, int which = 0);
137 // return key code number for keystring
138 int getKeyCode(const char *keystring);
141 * Apply layout sizes to a tree of puObjects
143 void applySize(puObject *object);
145 // The top-level PUI object.
148 // The GUI subsystem.
151 // The dialog font. Defaults to the global gui font, but can get
152 // overridden by a top level font definition.
155 // The source xml tree, so that we can pass data back, such as the
157 SGPropertyNode_ptr _props;
163 SGPropertyNode_ptr _nasal_close;
165 // PUI provides no way for userdata to be deleted automatically
166 // with a GUI object, so we have to keep track of all the special
167 // data we allocated and then free it manually when the dialog
169 vector<void *> _info;
170 struct PropertyObject {
171 PropertyObject (const char * name,
173 SGPropertyNode_ptr node);
176 SGPropertyNode_ptr node;
178 vector<PropertyObject *> _propertyObjects;
179 vector<PropertyObject *> _liveObjects;
181 class ConditionalObject : public SGConditional
184 ConditionalObject(const std::string& aName, puObject* aPu) :
189 void update(FGDialog* aDlg);
192 const std::string _name;
196 typedef SGSharedPtr<ConditionalObject> ConditionalObjectRef;
197 vector<ConditionalObjectRef> _conditionalObjects;
201 // Custom subclass of puPopup to implement "draggable" windows in the
202 // interface. Note that this is a subclass of puPopup, not
203 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
204 // boolean property: modality. That means that we can't implement
205 // dragging of both puPopup windows and puDialogBoxes with the same
206 // code. Rather than duplicate code, I've chosen to implement only
207 // "non-modal dragability" here. Modal dialog boxes (like the exit
208 // confirmation) are not draggable.
210 class fgPopup : public puPopup {
212 fgPopup(int x, int y, bool r = true, bool d = true) :
213 puPopup(x, y), _draggable(d), _resizable(r), _dragging(false)
215 int checkHit(int b, int up, int x, int y);
216 int checkKey(int key, int updown);
217 int getHitObjects(puObject *, int x, int y);
218 puObject *getKeyObject(puObject *, int key);
219 puObject *getActiveInputField(puObject *);
220 void applySize(puObject *);
222 enum { LEFT = 1, RIGHT = 2, TOP = 4, BOTTOM = 8 };
229 int _dlgX, _dlgY, _dlgW, _dlgH;
230 int _startX, _startY;
236 fgValueList(SGPropertyNode *p);
237 virtual ~fgValueList();
238 virtual void update();
246 SGPropertyNode_ptr _props;
250 class fgList : public fgValueList, public puaList, public GUI_ID {
252 fgList(int x1, int y1, int x2, int y2, SGPropertyNode *p, int sw) :
253 fgValueList(p), puaList(x1, y1, x2, y2, _list, sw), GUI_ID(FGCLASS_LIST) {}
257 class fgComboBox : public fgValueList, public puaComboBox {
259 fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode *p, bool editable) :
260 fgValueList(p), puaComboBox(x1, y1, x2, y2, _list, editable) {}
263 class fgSelectBox : public fgValueList, public puaSelectBox {
265 fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode *p) :
266 fgValueList(p), puaSelectBox(x1, y1, x2, y2, _list) {}
269 #endif // __DIALOG_HXX