]> git.mxchange.org Git - flightgear.git/blob - src/GUI/menubar.cxx
Removed a couple of the deprecated dialogs, and removed the old
[flightgear.git] / src / GUI / menubar.cxx
1 #include <string.h>
2 #include <iostream>
3 #include <plib/pu.h>
4 #include <simgear/debug/logstream.hxx>
5
6 #include <Main/globals.hxx>
7 #include <Main/fg_props.hxx>
8
9 #include <Input/input.hxx>
10
11 #include "new_gui.hxx"
12 #include "menubar.hxx"
13
14
15 \f
16 ////////////////////////////////////////////////////////////////////////
17 // FIXME!!
18 //
19 // Deprecated wrappers for old menu commands.
20 //
21 // DO NOT ADD TO THESE.  THEY WILL BE DELETED SOON!
22 //
23 // These are defined in gui_funcs.cxx.  They should be replaced with
24 // user-configured dialogs and new commands where necessary.
25 ////////////////////////////////////////////////////////////////////////
26
27 extern void saveFlight (puObject *);
28 static bool
29 do_save_dialog (const SGPropertyNode * arg)
30 {
31     saveFlight(0);
32     return true;
33 }
34
35 extern void loadFlight (puObject *);
36 static bool
37 do_load_dialog (const SGPropertyNode * arg)
38 {
39     loadFlight(0);
40     return true;
41 }
42
43 extern void reInit (puObject *);
44 static bool
45 do_reinit_dialog (const SGPropertyNode * arg)
46 {
47     reInit(0);
48     return true;
49 }
50
51 #if defined(TR_HIRES_SNAP)
52 extern void dumpHiResSnapShot (puObject *);
53 static bool
54 do_hires_snapshot_dialog (const SGPropertyNode * arg)
55 {
56     dumpHiResSnapShot(0);
57     return true;
58 }
59 #endif // TR_HIRES_SNAP
60
61 extern void dumpSnapShot (puObject *);
62 static bool
63 do_snapshot_dialog (const SGPropertyNode * arg)
64 {
65     dumpSnapShot(0);
66     return true;
67 }
68
69
70 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
71 extern void printScreen (puObject *);
72 static bool
73 do_print_dialog (const SGPropertyNode * arg)
74 {
75     printScreen(0);
76     return true;
77 }
78 #endif
79
80 extern void PilotOffsetAdjust (puObject *);
81 static bool
82 do_pilot_offset_dialog (const SGPropertyNode * arg)
83 {
84     PilotOffsetAdjust(0);
85     return true;
86 }
87
88 extern void fgHUDalphaAdjust (puObject *);
89 static bool
90 do_hud_alpha_dialog (const SGPropertyNode * arg)
91 {
92     fgHUDalphaAdjust(0);
93     return true;
94 }
95
96 extern void prop_pickerView (puObject *);
97 static bool
98 do_properties_dialog (const SGPropertyNode * arg)
99 {
100     prop_pickerView(0);
101     return true;
102 }
103
104 extern void fgPresetAirport (puObject *);
105 static bool
106 do_preset_airport_dialog (const SGPropertyNode * arg)
107 {
108     fgPresetAirport(0);
109     return true;
110 }
111
112 extern void fgPresetRunway (puObject *);
113 static bool
114 do_preset_runway_dialog (const SGPropertyNode * arg)
115 {
116     fgPresetRunway(0);
117     return true;
118 }
119
120 extern void fgPresetOffsetDistance (puObject *);
121 static bool
122 do_preset_offset_distance_dialog (const SGPropertyNode * arg)
123 {
124     fgPresetOffsetDistance(0);
125     return true;
126 }
127
128 extern void fgPresetAltitude (puObject *);
129 static bool
130 do_preset_altitude_dialog (const SGPropertyNode * arg)
131 {
132     fgPresetAltitude(0);
133     return true;
134 }
135
136 extern void fgPresetGlideslope (puObject *);
137 static bool
138 do_preset_glideslope_dialog (const SGPropertyNode * arg)
139 {
140     fgPresetGlideslope(0);
141     return true;
142 }
143
144 extern void fgPresetAirspeed (puObject *);
145 static bool
146 do_preset_airspeed_dialog (const SGPropertyNode * arg)
147 {
148     fgPresetAirspeed(0);
149     return true;
150 }
151
152 extern void fgPresetCommit (puObject *);
153 static bool
154 do_preset_commit_dialog (const SGPropertyNode * arg)
155 {
156     fgPresetCommit(0);
157     return true;
158 }
159
160 extern void AddWayPoint (puObject *);
161 static bool
162 do_ap_add_waypoint_dialog (const SGPropertyNode * arg)
163 {
164     AddWayPoint(0);
165     return true;
166 }
167
168 extern void PopWayPoint (puObject *);
169 static bool
170 do_ap_pop_waypoint_dialog (const SGPropertyNode * arg)
171 {
172     PopWayPoint(0);
173     return true;
174 }
175
176 extern void ClearRoute (puObject *);
177 static bool
178 do_ap_clear_route_dialog (const SGPropertyNode * arg)
179 {
180     ClearRoute(0);
181     return true;
182 }
183
184 extern void fgAPAdjust (puObject *);
185 static bool
186 do_ap_adjust_dialog (const SGPropertyNode * arg)
187 {
188     fgAPAdjust(0);
189     return true;
190 }
191
192 extern void fgLatLonFormatToggle (puObject *);
193 static bool
194 do_lat_lon_format_dialog (const SGPropertyNode * arg)
195 {
196     fgLatLonFormatToggle(0);
197     return true;
198 }
199
200 extern void helpCb (puObject *);
201 static bool
202 do_help_dialog (const SGPropertyNode * arg)
203 {
204     helpCb(0);
205     return true;
206 }
207
208 static struct {
209     const char * name;
210     SGCommandMgr::command_t command;
211 } deprecated_dialogs [] = {
212     { "old-save-dialog", do_save_dialog },
213     { "old-load-dialog", do_load_dialog },
214     { "old-reinit_dialog", do_reinit_dialog },
215 #if defined(TR_HIRES_SNAP)
216     { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
217 #endif
218     { "old-snapshot-dialog", do_snapshot_dialog },
219 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
220     { "old-print-dialog", do_print_dialog },
221 #endif
222     { "old-pilot-offset-dialog", do_pilot_offset_dialog },
223     { "old-hud-alpha-dialog", do_hud_alpha_dialog },
224     { "old-properties-dialog", do_properties_dialog },
225     { "old-preset-airport-dialog", do_preset_airport_dialog },
226     { "old-preset-runway-dialog", do_preset_runway_dialog },
227     { "old-preset-offset-distance-dialog", do_preset_offset_distance_dialog },
228     { "old-preset-altitude-dialog", do_preset_altitude_dialog },
229     { "old-preset-glideslope-dialog", do_preset_glideslope_dialog },
230     { "old-preset-airspeed-dialog", do_preset_airspeed_dialog },
231     { "old-preset-commit-dialog", do_preset_commit_dialog },
232     { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
233     { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
234     { "old-ap-clear-route-dialog", do_ap_clear_route_dialog },
235     { "old-ap-adjust-dialog", do_ap_adjust_dialog },
236     { "old-lat-lon-format-dialog", do_lat_lon_format_dialog },
237     { "old-help-dialog", do_help_dialog },
238     { 0, 0 }
239 };
240
241 static void
242 add_deprecated_dialogs ()
243 {
244   SG_LOG(SG_GENERAL, SG_INFO, "Initializing old dialog commands:");
245   for (int i = 0; deprecated_dialogs[i].name != 0; i++) {
246     SG_LOG(SG_GENERAL, SG_INFO, "  " << deprecated_dialogs[i].name);
247     globals->get_commands()->addCommand(deprecated_dialogs[i].name,
248                                         deprecated_dialogs[i].command);
249   }
250 }
251
252
253 \f
254 ////////////////////////////////////////////////////////////////////////
255 // Static functions.
256 ////////////////////////////////////////////////////////////////////////
257
258
259 static void
260 menu_callback (puObject * object)
261 {
262     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
263     gui->getMenuBar()->fireItem(object);
264 }
265
266
267 \f
268 ////////////////////////////////////////////////////////////////////////
269 // Implementation of FGMenuBar.
270 ////////////////////////////////////////////////////////////////////////
271
272
273 FGMenuBar::FGMenuBar ()
274     : _visible(false),
275       _menuBar(0)
276 {
277 }
278
279 FGMenuBar::~FGMenuBar ()
280 {
281     hide();
282     delete _menuBar;            // FIXME: check if PUI owns the pointer
283
284                                 // Delete all those bindings
285     map<string,vector<FGBinding *> >::iterator it;
286     it = _bindings.begin();
287     while (it != _bindings.end()) {
288         for (int i = 0; i < it->second.size(); i++)
289             delete it->second[i];
290     }
291 }
292
293 void
294 FGMenuBar::init ()
295 {
296     if (_menuBar != 0)          // FIXME: check if PUI owns the pointer
297         delete _menuBar;
298     make_menubar();
299
300                                 // FIXME: temporary commands to get at
301                                 // old, hard-coded dialogs.
302     add_deprecated_dialogs();
303 }
304
305 void
306 FGMenuBar::show ()
307 {
308     if (_menuBar != 0)
309         _menuBar->reveal();
310     _visible = true;
311 }
312
313 void
314 FGMenuBar::hide ()
315 {
316     if (_menuBar != 0)
317         _menuBar->hide();
318     _visible = false;
319 }
320
321 bool
322 FGMenuBar::isVisible () const
323 {
324     return _visible;
325 }
326
327 bool
328 FGMenuBar::fireItem (puObject * item)
329 {
330     const char * name = item->getLegend();
331     vector<FGBinding *> &bindings = _bindings[name];
332
333     for (int i = 0; i < bindings.size(); i++)
334         bindings[i]->fire();
335 }
336
337 void
338 FGMenuBar::make_menu (SGPropertyNode_ptr node)
339 {
340     const char * name = strdup(node->getStringValue("label"));
341     vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
342
343     int array_size = item_nodes.size() + 1;
344
345     char ** items = new char*[array_size];
346     puCallback * callbacks = new puCallback[array_size];
347
348     for (int i = 0, j = item_nodes.size() - 1;
349          i < item_nodes.size();
350          i++, j--) {
351         
352                                 // Set up the PUI entries for this item
353         items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
354         callbacks[j] = menu_callback;
355
356                                 // Load all the bindings for this item
357         vector<SGPropertyNode_ptr> binding_nodes =
358             item_nodes[i]->getChildren("binding");
359         for (int k = 0; k < binding_nodes.size(); k++)
360             _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
361     }
362
363     items[item_nodes.size()] = 0;
364     callbacks[item_nodes.size()] = 0;
365
366     _menuBar->add_submenu(name, items, callbacks);
367 }
368
369 void
370 FGMenuBar::make_menubar ()
371 {
372     _menuBar = new puMenuBar;
373     SGPropertyNode props;
374
375     fgLoadProps("gui/menubar.xml", &props);
376     vector<SGPropertyNode_ptr> menu_nodes = props.getChildren("menu");
377     for (int i = 0; i < menu_nodes.size(); i++)
378         make_menu(menu_nodes[i]);
379
380     _menuBar->close();
381     if (_visible)
382         _menuBar->reveal();
383     else
384         _menuBar->hide();
385 }
386
387 // end of menubar.cxx