4 #include <simgear/debug/logstream.hxx>
6 #include <Main/globals.hxx>
7 #include <Main/fg_props.hxx>
9 #include <Input/input.hxx>
11 #include "new_gui.hxx"
12 #include "menubar.hxx"
16 ////////////////////////////////////////////////////////////////////////
19 // Deprecated wrappers for old menu commands.
21 // DO NOT ADD TO THESE. THEY WILL BE DELETED SOON!
23 // These are defined in gui_funcs.cxx. They should be replaced with
24 // user-configured dialogs and new commands where necessary.
25 ////////////////////////////////////////////////////////////////////////
27 extern void saveFlight (puObject *);
29 do_save_dialog (const SGPropertyNode * arg)
35 extern void loadFlight (puObject *);
37 do_load_dialog (const SGPropertyNode * arg)
43 extern void reInit (puObject *);
45 do_reinit_dialog (const SGPropertyNode * arg)
51 #if defined(TR_HIRES_SNAP)
52 extern void dumpHiResSnapShot (puObject *);
54 do_hires_snapshot_dialog (const SGPropertyNode * arg)
59 #endif // TR_HIRES_SNAP
61 extern void dumpSnapShot (puObject *);
63 do_snapshot_dialog (const SGPropertyNode * arg)
70 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
71 extern void printScreen (puObject *);
73 do_print_dialog (const SGPropertyNode * arg)
80 extern void PilotOffsetAdjust (puObject *);
82 do_pilot_offset_dialog (const SGPropertyNode * arg)
88 extern void fgHUDalphaAdjust (puObject *);
90 do_hud_alpha_dialog (const SGPropertyNode * arg)
96 extern void prop_pickerView (puObject *);
98 do_properties_dialog (const SGPropertyNode * arg)
104 extern void fgPresetAirport (puObject *);
106 do_preset_airport_dialog (const SGPropertyNode * arg)
112 extern void fgPresetRunway (puObject *);
114 do_preset_runway_dialog (const SGPropertyNode * arg)
120 extern void fgPresetOffsetDistance (puObject *);
122 do_preset_offset_distance_dialog (const SGPropertyNode * arg)
124 fgPresetOffsetDistance(0);
128 extern void fgPresetAltitude (puObject *);
130 do_preset_altitude_dialog (const SGPropertyNode * arg)
136 extern void fgPresetGlideslope (puObject *);
138 do_preset_glideslope_dialog (const SGPropertyNode * arg)
140 fgPresetGlideslope(0);
144 extern void fgPresetAirspeed (puObject *);
146 do_preset_airspeed_dialog (const SGPropertyNode * arg)
152 extern void fgPresetCommit (puObject *);
154 do_preset_commit_dialog (const SGPropertyNode * arg)
160 extern void NewAltitude (puObject *);
162 do_ap_altitude_dialog (const SGPropertyNode * arg)
168 extern void NewHeading (puObject *);
170 do_ap_heading_dialog (const SGPropertyNode * arg)
176 extern void AddWayPoint (puObject *);
178 do_ap_add_waypoint_dialog (const SGPropertyNode * arg)
184 extern void PopWayPoint (puObject *);
186 do_ap_pop_waypoint_dialog (const SGPropertyNode * arg)
192 extern void ClearRoute (puObject *);
194 do_ap_clear_route_dialog (const SGPropertyNode * arg)
200 extern void fgAPAdjust (puObject *);
202 do_ap_adjust_dialog (const SGPropertyNode * arg)
208 extern void fgLatLonFormatToggle (puObject *);
210 do_lat_lon_format_dialog (const SGPropertyNode * arg)
212 fgLatLonFormatToggle(0);
216 extern void helpCb (puObject *);
218 do_help_dialog (const SGPropertyNode * arg)
226 SGCommandMgr::command_t command;
227 } deprecated_dialogs [] = {
228 { "old-save-dialog", do_save_dialog },
229 { "old-load-dialog", do_load_dialog },
230 { "old-reinit_dialog", do_reinit_dialog },
231 #if defined(TR_HIRES_SNAP)
232 { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
234 { "old-snapshot-dialog", do_snapshot_dialog },
235 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
236 { "old-print-dialog", do_print_dialog },
238 { "old-pilot-offset-dialog", do_pilot_offset_dialog },
239 { "old-hud-alpha-dialog", do_hud_alpha_dialog },
240 { "old-properties-dialog", do_properties_dialog },
241 { "old-preset-airport-dialog", do_preset_airport_dialog },
242 { "old-preset-runway-dialog", do_preset_runway_dialog },
243 { "old-preset-offset-distance-dialog", do_preset_offset_distance_dialog },
244 { "old-preset-altitude-dialog", do_preset_altitude_dialog },
245 { "old-preset-glideslope-dialog", do_preset_glideslope_dialog },
246 { "old-preset-airspeed-dialog", do_preset_airspeed_dialog },
247 { "old-preset-commit-dialog", do_preset_commit_dialog },
248 { "old-ap-altitude-dialog", do_ap_altitude_dialog },
249 { "old-ap-heading-dialog", do_ap_heading_dialog },
250 { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
251 { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
252 { "old-ap-clear-route-dialog", do_ap_clear_route_dialog },
253 { "old-ap-adjust-dialog", do_ap_adjust_dialog },
254 { "old-lat-lon-format-dialog", do_lat_lon_format_dialog },
255 { "old-help-dialog", do_help_dialog },
260 add_deprecated_dialogs ()
262 SG_LOG(SG_GENERAL, SG_INFO, "Initializing old dialog commands:");
263 for (int i = 0; deprecated_dialogs[i].name != 0; i++) {
264 SG_LOG(SG_GENERAL, SG_INFO, " " << deprecated_dialogs[i].name);
265 globals->get_commands()->addCommand(deprecated_dialogs[i].name,
266 deprecated_dialogs[i].command);
272 ////////////////////////////////////////////////////////////////////////
274 ////////////////////////////////////////////////////////////////////////
278 menu_callback (puObject * object)
280 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
281 gui->getMenuBar()->fireItem(object);
286 ////////////////////////////////////////////////////////////////////////
287 // Implementation of FGMenuBar.
288 ////////////////////////////////////////////////////////////////////////
291 FGMenuBar::FGMenuBar ()
297 FGMenuBar::~FGMenuBar ()
300 delete _menuBar; // FIXME: check if PUI owns the pointer
302 // Delete all those bindings
303 map<string,vector<FGBinding *> >::iterator it;
304 it = _bindings.begin();
305 while (it != _bindings.end()) {
306 for (int i = 0; i < it->second.size(); i++)
307 delete it->second[i];
314 if (_menuBar != 0) // FIXME: check if PUI owns the pointer
318 // FIXME: temporary commands to get at
319 // old, hard-coded dialogs.
320 add_deprecated_dialogs();
340 FGMenuBar::isVisible () const
346 FGMenuBar::fireItem (puObject * item)
348 const char * name = item->getLegend();
349 vector<FGBinding *> &bindings = _bindings[name];
351 for (int i = 0; i < bindings.size(); i++)
356 FGMenuBar::make_menu (SGPropertyNode_ptr node)
358 const char * name = strdup(node->getStringValue("label"));
359 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
361 int array_size = item_nodes.size() + 1;
363 char ** items = new char*[array_size];
364 puCallback * callbacks = new puCallback[array_size];
366 for (int i = 0, j = item_nodes.size() - 1;
367 i < item_nodes.size();
370 // Set up the PUI entries for this item
371 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
372 callbacks[j] = menu_callback;
374 // Load all the bindings for this item
375 vector<SGPropertyNode_ptr> binding_nodes =
376 item_nodes[i]->getChildren("binding");
377 for (int k = 0; k < binding_nodes.size(); k++)
378 _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
381 items[item_nodes.size()] = 0;
382 callbacks[item_nodes.size()] = 0;
384 _menuBar->add_submenu(name, items, callbacks);
388 FGMenuBar::make_menubar ()
390 _menuBar = new puMenuBar;
391 SGPropertyNode props;
393 fgLoadProps("gui/menubar.xml", &props);
394 vector<SGPropertyNode_ptr> menu_nodes = props.getChildren("menu");
395 for (int i = 0; i < menu_nodes.size(); i++)
396 make_menu(menu_nodes[i]);
405 // end of menubar.cxx