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>
30 * An XML-configured dialog box.
32 * The GUI manager stores only the property tree for the dialog
33 * boxes. This class creates a PUI dialog box on demand from
34 * the properties in that tree. The manager recreates the dialog
35 * every time it needs to show it.
42 * Construct a new GUI widget configured by a property tree.
44 * The configuration properties are not part of the main
45 * FlightGear property tree; the GUI manager reads them
46 * from individual configuration files.
48 * @param props A property tree describing the dialog.
50 FGDialog (SGPropertyNode * props);
60 * Update the values of all GUI objects with a specific name,
61 * or all if name is 0 (default).
63 * This method copies values from the FlightGear property tree to
66 * @param objectName The name of the GUI object(s) to update.
67 * Use the empty name for all unnamed objects.
69 virtual void updateValues (const char * objectName = 0);
73 * Apply the values of all GUI objects with a specific name,
74 * or all if name is 0 (default)
76 * This method copies values from the GUI object(s) to the
77 * FlightGear property tree.
79 * @param objectName The name of the GUI object(s) to update.
80 * Use the empty name for all unnamed objects.
82 virtual void applyValues (const char * objectName = 0);
86 * Update state. Called on active dialogs before rendering.
88 virtual void update ();
102 // Private copy constructor to avoid unpleasant surprises.
103 FGDialog (const FGDialog &);
106 void display (SGPropertyNode * props);
108 // Build the dialog or a subobject of it.
109 puObject * makeObject (SGPropertyNode * props,
110 int parentWidth, int parentHeight);
112 // Common configuration for all GUI objects.
113 void setupObject (puObject * object, SGPropertyNode * props);
115 // Common configuration for all GUI group objects.
116 void setupGroup (puGroup * group, SGPropertyNode * props,
117 int width, int height, bool makeFrame = false);
119 // Set object colors: the "which" argument defines which color qualities
120 // (PUCOL_LABEL, etc.) should pick up the <color> property.
121 void setColor(puObject * object, SGPropertyNode * props, int which = 0);
123 // return key code number for keystring
124 int getKeyCode(const char *keystring);
126 // The top-level PUI object.
129 // The GUI subsystem.
132 // The dialog font. Defaults to the global gui font, but can get
133 // overridden by a top level font definition.
136 // The source xml tree, so that we can pass data back, such as the
138 SGPropertyNode_ptr _props;
142 SGPropertyNode_ptr _nasal_close;
144 // PUI provides no way for userdata to be deleted automatically
145 // with a GUI object, so we have to keep track of all the special
146 // data we allocated and then free it manually when the dialog
148 vector<void *> _info;
149 struct PropertyObject {
150 PropertyObject (const char * name,
152 SGPropertyNode_ptr node);
155 SGPropertyNode_ptr node;
157 vector<PropertyObject *> _propertyObjects;
158 vector<PropertyObject *> _liveObjects;
162 // Custom subclass of puPopup to implement "draggable" windows in the
163 // interface. Note that this is a subclass of puPopup, not
164 // puDialogBox. Sadly, PUI (mis)uses subclassing to implement a
165 // boolean property: modality. That means that we can't implement
166 // dragging of both puPopup windows and puDialogBoxes with the same
167 // code. Rather than duplicate code, I've chosen to implement only
168 // "non-modal dragability" here. Modal dialog boxes (like the exit
169 // confirmation) are not draggable.
171 class fgPopup : public puPopup {
173 fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
174 int checkHit(int b, int up, int x, int y);
175 int checkKey(int key, int updown);
176 int getHitObjects(puObject *, int x, int y);
177 puObject *getKeyObject(puObject *, int key);
178 puObject *getActiveInputField(puObject *);
188 fgValueList(SGPropertyNode *p);
189 virtual ~fgValueList();
190 virtual void update();
198 SGPropertyNode_ptr _props;
202 class fgList : public fgValueList, public puList {
204 fgList(int x1, int y1, int x2, int y2, SGPropertyNode *p, int sw) :
205 fgValueList(p), puList(x1, y1, x2, y2, _list, sw) {}
206 virtual void update();
207 virtual const char *getTypeString() { return "fgList"; }
210 class fgComboBox : public fgValueList, public puaComboBox {
212 fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode *p, bool editable) :
213 fgValueList(p), puaComboBox(x1, y1, x2, y2, _list, editable) {}
216 class fgSelectBox : public fgValueList, public puaSelectBox {
218 fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode *p) :
219 fgValueList(p), puaSelectBox(x1, y1, x2, y2, _list) {}
222 #endif // __DIALOG_HXX