]> git.mxchange.org Git - flightgear.git/blob - src/GUI/dialog.hxx
Moved random ground cover object management code (userdata.[ch]xx) over
[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/pu.h>
11
12 #include <simgear/compiler.h>   // for SG_USING_STD
13 #include <simgear/props/props.hxx>
14
15 #include <vector>
16 SG_USING_STD(vector);
17
18 class FGDialog;
19 class FGBinding;
20
21
22 /**
23  * An XML-configured dialog box.
24  *
25  * The GUI manager stores only the property tree for the dialog
26  * boxes.  This class creates a PUI dialog box on demand from
27  * the properties in that tree.  The manager recreates the dialog
28  * every time it needs to show it.
29  */
30 class FGDialog
31 {
32 public:
33
34     /**
35      * Construct a new GUI widget configured by a property tree.
36      *
37      * The configuration properties are not part of the main
38      * FlightGear property tree; the GUI manager reads them
39      * from individual configuration files.
40      *
41      * @param props A property tree describing the dialog.
42      */
43     FGDialog (SGPropertyNode * props);
44
45
46     /**
47      * Destructor.
48      */
49     virtual ~FGDialog ();
50
51
52     /**
53      * Update the values of all GUI objects with a specific name.
54      *
55      * This method copies values from the FlightGear property tree to
56      * the GUI object(s).
57      *
58      * @param objectName The name of the GUI object(s) to update.
59      *        Use the empty name for all unnamed objects.
60      */
61     virtual void updateValue (const char * objectName);
62
63
64     /**
65      * Apply the values of all GUI objects with a specific name.
66      *
67      * This method copies values from the GUI object(s) to the
68      * FlightGear property tree.
69      *
70      * @param objectName The name of the GUI object(s) to update.
71      *        Use the empty name for all unnamed objects.
72      */
73     virtual void applyValue (const char * objectName);
74
75
76     /**
77      * Update the values of all GUI objects.
78      *
79      * This method copies values from the FlightGear property tree to
80      * the GUI objects.
81      */
82     virtual void updateValues ();
83
84
85     /**
86      * Apply the values of all GUI objects.
87      *
88      * This method copies from the GUI objects to the FlightGear
89      * property tree properties.
90      */
91     virtual void applyValues ();
92
93
94 private:
95
96     // Private copy constructor to avoid unpleasant surprises.
97     FGDialog (const FGDialog &);
98
99     // Show the dialog.
100     void display (SGPropertyNode * props);
101
102     // Build the dialog or a subobject of it.
103     puObject * makeObject (SGPropertyNode * props,
104                            int parentWidth, int parentHeight);
105
106     // Common configuration for all GUI objects.
107     void setupObject (puObject * object, SGPropertyNode * props);
108
109     // Common configuration for all GUI group objects.
110     void setupGroup (puGroup * group, SGPropertyNode * props,
111                      int width, int height, bool makeFrame = false);
112
113     // The top-level PUI object.
114     puObject * _object;
115
116     // PUI provides no way for userdata to be deleted automatically
117     // with a GUI object, so we have to keep track of all the special
118     // data we allocated and then free it manually when the dialog
119     // closes.
120     vector<void *> _info;
121     struct PropertyObject {
122         PropertyObject (const char * name,
123                         puObject * object,
124                         SGPropertyNode_ptr node);
125         string name;
126         puObject * object;
127         SGPropertyNode_ptr node;
128     };
129     vector<PropertyObject *> _propertyObjects;
130
131     // PUI doesn't copy arrays, so we have to allocate string arrays
132     // and then keep pointers so that we can delete them when the
133     // dialog closes.
134     char ** make_char_array (int size);
135     vector<char **> _char_arrays;
136 };
137
138 #endif // __DIALOG_HXX