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 puDeleteObject(_menuBar);
286 // Delete all the character arrays
287 // we were forced to keep around for
289 std::cerr << "Deleting char arrays\n";
290 for (i = 0; i < _char_arrays.size(); i++) {
291 for (int j = 0; _char_arrays[i][j] != 0; j++)
292 free(_char_arrays[i][j]); // added with strdup
293 delete _char_arrays[i];
296 // Delete all the callback arrays
297 // we were forced to keep around for
299 std::cerr << "Deleting callback arrays\n";
300 for (i = 0; i < _callback_arrays.size(); i++)
301 delete _callback_arrays[i];
303 // Delete all those bindings
304 std::cerr << "Deleting bindings\n";
305 map<string,vector<FGBinding *> >::iterator it;
306 it = _bindings.begin();
307 for (it = _bindings.begin(); it != _bindings.end(); it++) {
308 std::cerr << "Deleting bindings for " << it->first << std::endl;
309 for (int i = 0; i < it->second.size(); i++)
310 delete it->second[i];
313 std::cerr << "Done.\n";
319 if (_menuBar != 0) // FIXME: check if PUI owns the pointer
323 // FIXME: temporary commands to get at
324 // old, hard-coded dialogs.
325 add_deprecated_dialogs();
345 FGMenuBar::isVisible () const
351 FGMenuBar::fireItem (puObject * item)
353 const char * name = item->getLegend();
354 vector<FGBinding *> &bindings = _bindings[name];
355 int nBindings = bindings.size();
357 for (int i = 0; i < nBindings; i++)
362 FGMenuBar::make_menu (SGPropertyNode_ptr node)
364 const char * name = strdup(node->getStringValue("label"));
365 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
367 int array_size = item_nodes.size();
369 char ** items = make_char_array(array_size);
370 puCallback * callbacks = make_callback_array(array_size);
372 for (int i = 0, j = item_nodes.size() - 1;
373 i < item_nodes.size();
376 // Set up the PUI entries for this item
377 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
378 callbacks[j] = menu_callback;
380 // Load all the bindings for this item
381 vector<SGPropertyNode_ptr> binding_nodes =
382 item_nodes[i]->getChildren("binding");
384 for (int k = 0; k < binding_nodes.size(); k++)
385 _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
388 _menuBar->add_submenu(name, items, callbacks);
392 FGMenuBar::make_menubar ()
394 _menuBar = new puMenuBar;
395 SGPropertyNode props;
397 fgLoadProps("gui/menubar.xml", &props);
398 vector<SGPropertyNode_ptr> menu_nodes = props.getChildren("menu");
399 for (int i = 0; i < menu_nodes.size(); i++)
400 make_menu(menu_nodes[i]);
410 FGMenuBar::make_char_array (int size)
412 char ** list = new char*[size+1];
413 for (int i = 0; i <= size; i++)
415 _char_arrays.push_back(list);
420 FGMenuBar::make_callback_array (int size)
422 puCallback * list = new puCallback[size+1];
423 for (int i = 0; i <= size; i++)
425 _callback_arrays.push_back(list);
429 // end of menubar.cxx