]> git.mxchange.org Git - flightgear.git/blob - src/GUI/dialog.hxx
the last patch fixed the AirportList ... and broke all other PUCLASS_LIST.;
[flightgear.git] / src / GUI / dialog.hxx
1 // dialog.hxx - XML-configured dialog box.
2
3 #ifndef __DIALOG_HXX
4 #define __DIALOG_HXX 1
5
6 #ifndef __cplusplus
7 # error This library requires C++
8 #endif
9
10 #include <plib/puAux.h>
11 #include <plib/sg.h>
12
13 #include <simgear/compiler.h>   // for SG_USING_STD
14 #include <simgear/props/props.hxx>
15 #include <simgear/misc/sg_path.hxx>
16
17 #undef PUCLASS_LIST
18 #include "puList.hxx"
19
20 #include <vector>
21 SG_USING_STD(vector);
22
23 #include "AirportList.hxx"
24
25
26 class FGDialog;
27 class FGBinding;
28 class NewGUI;
29 class FGColor;
30
31
32 /**
33  * An XML-configured dialog box.
34  *
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.
39  */
40 class FGDialog
41 {
42 public:
43
44     /**
45      * Construct a new GUI widget configured by a property tree.
46      *
47      * The configuration properties are not part of the main
48      * FlightGear property tree; the GUI manager reads them
49      * from individual configuration files.
50      *
51      * @param props A property tree describing the dialog.
52      */
53     FGDialog (SGPropertyNode * props);
54
55
56     /**
57      * Destructor.
58      */
59     virtual ~FGDialog ();
60
61
62     /**
63      * Update the values of all GUI objects with a specific name,
64      * or all if name is 0 (default).
65      *
66      * This method copies values from the FlightGear property tree to
67      * the GUI object(s).
68      *
69      * @param objectName The name of the GUI object(s) to update.
70      *        Use the empty name for all unnamed objects.
71      */
72     virtual void updateValues (const char * objectName = 0);
73
74
75     /**
76      * Apply the values of all GUI objects with a specific name,
77      * or all if name is 0 (default)
78      *
79      * This method copies values from the GUI object(s) to the
80      * FlightGear property tree.
81      *
82      * @param objectName The name of the GUI object(s) to update.
83      *        Use the empty name for all unnamed objects.
84      */
85     virtual void applyValues (const char * objectName = 0);
86
87
88     /**
89      * Update state.  Called on active dialogs before rendering.
90      */
91     virtual void update ();
92
93 private:
94
95     enum {
96         BACKGROUND = 0x01,
97         FOREGROUND = 0x02,
98         HIGHLIGHT = 0x04,
99         LABEL = 0x08,
100         LEGEND = 0x10,
101         MISC = 0x20,
102         EDITFIELD = 0x40
103     };
104
105     // Private copy constructor to avoid unpleasant surprises.
106     FGDialog (const FGDialog &);
107
108     // Show the dialog.
109     void display (SGPropertyNode * props);
110
111     // Build the dialog or a subobject of it.
112     puObject * makeObject (SGPropertyNode * props,
113                            int parentWidth, int parentHeight);
114
115     // Common configuration for all GUI objects.
116     void setupObject (puObject * object, SGPropertyNode * props);
117
118     // Common configuration for all GUI group objects.
119     void setupGroup (puGroup * group, SGPropertyNode * props,
120                      int width, int height, bool makeFrame = false);
121
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);
125
126     // return key code number for keystring
127     int getKeyCode(const char *keystring);
128
129     // The top-level PUI object.
130     puObject * _object;
131
132     // The GUI subsystem.
133     NewGUI * _gui;
134
135     // The dialog font. Defaults to the global gui font, but can get
136     // overridden by a top level font definition.
137     puFont * _font;
138
139     // The source xml tree, so that we can pass data back, such as the
140     // last position.
141     SGPropertyNode_ptr _props;
142
143     // Nasal module.
144     string _module;
145     SGPropertyNode_ptr _nasal_close;
146
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
150     // closes.
151     vector<void *> _info;
152     struct PropertyObject {
153         PropertyObject (const char * name,
154                         puObject * object,
155                         SGPropertyNode_ptr node);
156         string name;
157         puObject * object;
158         SGPropertyNode_ptr node;
159     };
160     vector<PropertyObject *> _propertyObjects;
161     vector<PropertyObject *> _liveObjects;
162 };
163
164 //
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.
173 //
174 class fgPopup : public puPopup {
175 public:
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 *);
182 private:
183     bool _draggable;
184     bool _dragging;
185     int _dX, _dY;
186 };
187
188
189 class fgValueList {
190 public:
191     fgValueList(SGPropertyNode *p);
192     virtual ~fgValueList();
193     virtual void update();
194
195 protected:
196     char **_list;
197
198 private:
199     void make_list();
200     void destroy_list();
201     SGPropertyNode_ptr _props;
202 };
203
204
205 class fgList : public fgValueList, public puList, public GUI_ID {
206 public:
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) {}
209     void update();
210 };
211
212 class fgComboBox : public fgValueList, public puaComboBox {
213 public:
214     fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode *p, bool editable) :
215         fgValueList(p), puaComboBox(x1, y1, x2, y2, _list, editable) {}
216 };
217
218 class fgSelectBox : public fgValueList, public puaSelectBox {
219 public:
220     fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode *p) :
221         fgValueList(p), puaSelectBox(x1, y1, x2, y2, _list) {}
222 };
223
224 #endif // __DIALOG_HXX