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 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
62 extern void printScreen (puObject *);
64 do_print_dialog (const SGPropertyNode * arg)
71 extern void PilotOffsetAdjust (puObject *);
73 do_pilot_offset_dialog (const SGPropertyNode * arg)
79 extern void fgHUDalphaAdjust (puObject *);
81 do_hud_alpha_dialog (const SGPropertyNode * arg)
87 extern void prop_pickerView (puObject *);
89 do_properties_dialog (const SGPropertyNode * arg)
95 extern void fgPresetAirport (puObject *);
97 do_preset_airport_dialog (const SGPropertyNode * arg)
103 extern void fgPresetRunway (puObject *);
105 do_preset_runway_dialog (const SGPropertyNode * arg)
111 extern void fgPresetOffsetDistance (puObject *);
113 do_preset_offset_distance_dialog (const SGPropertyNode * arg)
115 fgPresetOffsetDistance(0);
119 extern void fgPresetAltitude (puObject *);
121 do_preset_altitude_dialog (const SGPropertyNode * arg)
127 extern void fgPresetGlideslope (puObject *);
129 do_preset_glideslope_dialog (const SGPropertyNode * arg)
131 fgPresetGlideslope(0);
135 extern void fgPresetAirspeed (puObject *);
137 do_preset_airspeed_dialog (const SGPropertyNode * arg)
143 extern void fgPresetCommit (puObject *);
145 do_preset_commit_dialog (const SGPropertyNode * arg)
151 extern void AddWayPoint (puObject *);
153 do_ap_add_waypoint_dialog (const SGPropertyNode * arg)
159 extern void PopWayPoint (puObject *);
161 do_ap_pop_waypoint_dialog (const SGPropertyNode * arg)
167 extern void ClearRoute (puObject *);
169 do_ap_clear_route_dialog (const SGPropertyNode * arg)
175 extern void fgAPAdjust (puObject *);
177 do_ap_adjust_dialog (const SGPropertyNode * arg)
183 extern void fgLatLonFormatToggle (puObject *);
185 do_lat_lon_format_dialog (const SGPropertyNode * arg)
187 fgLatLonFormatToggle(0);
191 extern void helpCb (puObject *);
193 do_help_dialog (const SGPropertyNode * arg)
201 SGCommandMgr::command_t command;
202 } deprecated_dialogs [] = {
203 { "old-save-dialog", do_save_dialog },
204 { "old-load-dialog", do_load_dialog },
205 { "old-reinit_dialog", do_reinit_dialog },
206 #if defined(TR_HIRES_SNAP)
207 { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
209 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
210 { "old-print-dialog", do_print_dialog },
212 { "old-pilot-offset-dialog", do_pilot_offset_dialog },
213 { "old-hud-alpha-dialog", do_hud_alpha_dialog },
214 { "old-properties-dialog", do_properties_dialog },
215 { "old-preset-airport-dialog", do_preset_airport_dialog },
216 { "old-preset-runway-dialog", do_preset_runway_dialog },
217 { "old-preset-offset-distance-dialog", do_preset_offset_distance_dialog },
218 { "old-preset-altitude-dialog", do_preset_altitude_dialog },
219 { "old-preset-glideslope-dialog", do_preset_glideslope_dialog },
220 { "old-preset-airspeed-dialog", do_preset_airspeed_dialog },
221 { "old-preset-commit-dialog", do_preset_commit_dialog },
222 { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
223 { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
224 { "old-ap-clear-route-dialog", do_ap_clear_route_dialog },
225 { "old-ap-adjust-dialog", do_ap_adjust_dialog },
226 { "old-lat-lon-format-dialog", do_lat_lon_format_dialog },
227 { "old-help-dialog", do_help_dialog },
232 add_deprecated_dialogs ()
234 SG_LOG(SG_GENERAL, SG_INFO, "Initializing old dialog commands:");
235 for (int i = 0; deprecated_dialogs[i].name != 0; i++) {
236 SG_LOG(SG_GENERAL, SG_INFO, " " << deprecated_dialogs[i].name);
237 globals->get_commands()->addCommand(deprecated_dialogs[i].name,
238 deprecated_dialogs[i].command);
244 ////////////////////////////////////////////////////////////////////////
246 ////////////////////////////////////////////////////////////////////////
250 menu_callback (puObject * object)
252 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
253 gui->getMenuBar()->fireItem(object);
258 ////////////////////////////////////////////////////////////////////////
259 // Implementation of FGMenuBar.
260 ////////////////////////////////////////////////////////////////////////
263 FGMenuBar::FGMenuBar ()
269 FGMenuBar::~FGMenuBar ()
272 puDeleteObject(_menuBar);
276 // Delete all the character arrays
277 // we were forced to keep around for
279 std::cerr << "Deleting char arrays\n";
280 for (i = 0; i < _char_arrays.size(); i++) {
281 for (int j = 0; _char_arrays[i][j] != 0; j++)
282 free(_char_arrays[i][j]); // added with strdup
283 delete _char_arrays[i];
286 // Delete all the callback arrays
287 // we were forced to keep around for
289 std::cerr << "Deleting callback arrays\n";
290 for (i = 0; i < _callback_arrays.size(); i++)
291 delete _callback_arrays[i];
293 // Delete all those bindings
294 std::cerr << "Deleting bindings\n";
295 map<string,vector<FGBinding *> >::iterator it;
296 it = _bindings.begin();
297 for (it = _bindings.begin(); it != _bindings.end(); it++) {
298 std::cerr << "Deleting bindings for " << it->first << std::endl;
299 for (int i = 0; i < it->second.size(); i++)
300 delete it->second[i];
303 std::cerr << "Done.\n";
309 if (_menuBar != 0) // FIXME: check if PUI owns the pointer
313 // FIXME: temporary commands to get at
314 // old, hard-coded dialogs.
315 add_deprecated_dialogs();
335 FGMenuBar::isVisible () const
341 FGMenuBar::fireItem (puObject * item)
343 const char * name = item->getLegend();
344 vector<FGBinding *> &bindings = _bindings[name];
345 int nBindings = bindings.size();
347 for (int i = 0; i < nBindings; i++)
352 FGMenuBar::make_menu (SGPropertyNode * node)
354 const char * name = strdup(node->getStringValue("label"));
355 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
357 int array_size = item_nodes.size();
359 char ** items = make_char_array(array_size);
360 puCallback * callbacks = make_callback_array(array_size);
362 for (int i = 0, j = item_nodes.size() - 1;
363 i < item_nodes.size();
366 // Set up the PUI entries for this item
367 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
368 callbacks[j] = menu_callback;
370 // Load all the bindings for this item
371 vector<SGPropertyNode_ptr> binding_nodes =
372 item_nodes[i]->getChildren("binding");
374 for (int k = 0; k < binding_nodes.size(); k++)
375 _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
378 _menuBar->add_submenu(name, items, callbacks);
382 FGMenuBar::make_menubar ()
384 _menuBar = new puMenuBar;
385 SGPropertyNode props;
387 fgLoadProps("gui/menubar.xml", &props);
388 vector<SGPropertyNode_ptr> menu_nodes = props.getChildren("menu");
389 for (int i = 0; i < menu_nodes.size(); i++)
390 make_menu(menu_nodes[i]);
400 FGMenuBar::make_char_array (int size)
402 char ** list = new char*[size+1];
403 for (int i = 0; i <= size; i++)
405 _char_arrays.push_back(list);
410 FGMenuBar::make_callback_array (int size)
412 puCallback * list = new puCallback[size+1];
413 for (int i = 0; i <= size; i++)
415 _callback_arrays.push_back(list);
419 // end of menubar.cxx