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 AddWayPoint (puObject *);
162 do_ap_add_waypoint_dialog (const SGPropertyNode * arg)
168 extern void PopWayPoint (puObject *);
170 do_ap_pop_waypoint_dialog (const SGPropertyNode * arg)
176 extern void ClearRoute (puObject *);
178 do_ap_clear_route_dialog (const SGPropertyNode * arg)
184 extern void fgAPAdjust (puObject *);
186 do_ap_adjust_dialog (const SGPropertyNode * arg)
192 extern void fgLatLonFormatToggle (puObject *);
194 do_lat_lon_format_dialog (const SGPropertyNode * arg)
196 fgLatLonFormatToggle(0);
200 extern void helpCb (puObject *);
202 do_help_dialog (const SGPropertyNode * arg)
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 },
218 { "old-snapshot-dialog", do_snapshot_dialog },
219 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
220 { "old-print-dialog", do_print_dialog },
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 },
242 add_deprecated_dialogs ()
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);
254 ////////////////////////////////////////////////////////////////////////
256 ////////////////////////////////////////////////////////////////////////
260 menu_callback (puObject * object)
262 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
263 gui->getMenuBar()->fireItem(object);
268 ////////////////////////////////////////////////////////////////////////
269 // Implementation of FGMenuBar.
270 ////////////////////////////////////////////////////////////////////////
273 FGMenuBar::FGMenuBar ()
279 FGMenuBar::~FGMenuBar ()
282 delete _menuBar; // FIXME: check if PUI owns the pointer
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];
296 if (_menuBar != 0) // FIXME: check if PUI owns the pointer
300 // FIXME: temporary commands to get at
301 // old, hard-coded dialogs.
302 add_deprecated_dialogs();
322 FGMenuBar::isVisible () const
328 FGMenuBar::fireItem (puObject * item)
330 const char * name = item->getLegend();
331 vector<FGBinding *> &bindings = _bindings[name];
333 for (int i = 0; i < bindings.size(); i++)
338 FGMenuBar::make_menu (SGPropertyNode_ptr node)
340 const char * name = strdup(node->getStringValue("label"));
341 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
343 int array_size = item_nodes.size() + 1;
345 char ** items = new char*[array_size];
346 puCallback * callbacks = new puCallback[array_size];
348 for (int i = 0, j = item_nodes.size() - 1;
349 i < item_nodes.size();
352 // Set up the PUI entries for this item
353 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
354 callbacks[j] = menu_callback;
356 // Load all the bindings for this item
357 vector<SGPropertyNode_ptr> binding_nodes =
358 item_nodes[i]->getChildren("binding");
360 for (int k = 0; k < binding_nodes.size(); k++)
361 _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
364 items[item_nodes.size()] = 0;
365 callbacks[item_nodes.size()] = 0;
367 _menuBar->add_submenu(name, items, callbacks);
371 FGMenuBar::make_menubar ()
373 _menuBar = new puMenuBar;
374 SGPropertyNode props;
376 fgLoadProps("gui/menubar.xml", &props);
377 vector<SGPropertyNode_ptr> menu_nodes = props.getChildren("menu");
378 for (int i = 0; i < menu_nodes.size(); i++)
379 make_menu(menu_nodes[i]);
388 // end of menubar.cxx