8 #include <simgear/debug/logstream.hxx>
10 #include <Autopilot/auto_gui.hxx>
11 #include <Input/input.hxx>
12 #include <Main/globals.hxx>
13 #include <Main/fg_props.hxx>
15 #include "new_gui.hxx"
16 #include "menubar.hxx"
20 ////////////////////////////////////////////////////////////////////////
23 // Deprecated wrappers for old menu commands.
25 // DO NOT ADD TO THESE. THEY WILL BE DELETED SOON!
27 // These are defined in gui_funcs.cxx. They should be replaced with
28 // user-configured dialogs and new commands where necessary.
29 ////////////////////////////////////////////////////////////////////////
31 extern void saveFlight (puObject *);
33 do_save_dialog (const SGPropertyNode * arg)
39 extern void loadFlight (puObject *);
41 do_load_dialog (const SGPropertyNode * arg)
47 extern void reInit (puObject *);
49 do_reinit_dialog (const SGPropertyNode * arg)
55 #if defined(TR_HIRES_SNAP)
56 extern void dumpHiResSnapShot (puObject *);
58 do_hires_snapshot_dialog (const SGPropertyNode * arg)
63 #endif // TR_HIRES_SNAP
65 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
66 extern void printScreen (puObject *);
68 do_print_dialog (const SGPropertyNode * arg)
75 extern void PilotOffsetAdjust (puObject *);
77 do_pilot_offset_dialog (const SGPropertyNode * arg)
83 extern void fgHUDalphaAdjust (puObject *);
85 do_hud_alpha_dialog (const SGPropertyNode * arg)
91 extern void prop_pickerView (puObject *);
93 do_properties_dialog (const SGPropertyNode * arg)
99 extern void AddWayPoint (puObject *);
101 do_ap_add_waypoint_dialog (const SGPropertyNode * arg)
107 extern void PopWayPoint (puObject *);
109 do_ap_pop_waypoint_dialog (const SGPropertyNode * arg)
115 extern void ClearRoute (puObject *);
117 do_ap_clear_route_dialog (const SGPropertyNode * arg)
124 extern void fgAPAdjust (puObject *);
126 do_ap_adjust_dialog (const SGPropertyNode * arg)
133 extern void fgLatLonFormatToggle (puObject *);
135 do_lat_lon_format_dialog (const SGPropertyNode * arg)
137 fgLatLonFormatToggle(0);
141 extern void helpCb (puObject *);
143 do_help_dialog (const SGPropertyNode * arg)
151 SGCommandMgr::command_t command;
152 } deprecated_dialogs [] = {
153 { "old-save-dialog", do_save_dialog },
154 { "old-load-dialog", do_load_dialog },
155 { "old-reinit-dialog", do_reinit_dialog },
156 #if defined(TR_HIRES_SNAP)
157 { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
159 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
160 { "old-print-dialog", do_print_dialog },
162 { "old-pilot-offset-dialog", do_pilot_offset_dialog },
163 { "old-hud-alpha-dialog", do_hud_alpha_dialog },
164 { "old-properties-dialog", do_properties_dialog },
165 { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
166 { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
167 { "old-ap-clear-route-dialog", do_ap_clear_route_dialog },
168 { "old-lat-lon-format-dialog", do_lat_lon_format_dialog },
169 { "old-help-dialog", do_help_dialog },
174 add_deprecated_dialogs ()
176 SG_LOG(SG_GENERAL, SG_INFO, "Initializing old dialog commands:");
177 for (int i = 0; deprecated_dialogs[i].name != 0; i++) {
178 SG_LOG(SG_GENERAL, SG_INFO, " " << deprecated_dialogs[i].name);
179 globals->get_commands()->addCommand(deprecated_dialogs[i].name,
180 deprecated_dialogs[i].command);
186 ////////////////////////////////////////////////////////////////////////
188 ////////////////////////////////////////////////////////////////////////
192 menu_callback (puObject * object)
194 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
195 gui->getMenuBar()->fireItem(object);
200 ////////////////////////////////////////////////////////////////////////
201 // Implementation of FGMenuBar.
202 ////////////////////////////////////////////////////////////////////////
205 FGMenuBar::FGMenuBar ()
211 FGMenuBar::~FGMenuBar ()
214 puDeleteObject(_menuBar);
218 // Delete all the character arrays
219 // we were forced to keep around for
221 SG_LOG(SG_GENERAL, SG_INFO, "Deleting char arrays");
222 for (i = 0; i < _char_arrays.size(); i++) {
223 for (int j = 0; _char_arrays[i][j] != 0; j++)
224 free(_char_arrays[i][j]); // added with strdup
225 delete[] _char_arrays[i];
228 // Delete all the callback arrays
229 // we were forced to keep around for
231 SG_LOG(SG_GENERAL, SG_INFO, "Deleting callback arrays");
232 for (i = 0; i < _callback_arrays.size(); i++)
233 delete[] _callback_arrays[i];
235 // Delete all those bindings
236 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings");
237 map<string,vector<FGBinding *> >::iterator it;
238 it = _bindings.begin();
239 for (it = _bindings.begin(); it != _bindings.end(); it++) {
240 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings for " << it->first);
241 for ( i = 0; i < it->second.size(); i++ )
242 delete it->second[i];
245 SG_LOG(SG_GENERAL, SG_INFO, "Done.");
251 if (_menuBar != 0) // FIXME: check if PUI owns the pointer
255 // FIXME: temporary commands to get at
256 // old, hard-coded dialogs.
257 add_deprecated_dialogs();
277 FGMenuBar::isVisible () const
283 FGMenuBar::fireItem (puObject * item)
285 const char * name = item->getLegend();
286 vector<FGBinding *> &bindings = _bindings[name];
287 int nBindings = bindings.size();
289 for (int i = 0; i < nBindings; i++)
294 FGMenuBar::make_menu (SGPropertyNode * node)
296 const char * name = strdup(node->getStringValue("label"));
297 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
299 int array_size = item_nodes.size();
301 char ** items = make_char_array(array_size);
302 puCallback * callbacks = make_callback_array(array_size);
304 for (unsigned int i = 0, j = item_nodes.size() - 1;
305 i < item_nodes.size();
308 // Set up the PUI entries for this item
309 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
310 callbacks[j] = menu_callback;
312 // Load all the bindings for this item
313 vector<SGPropertyNode_ptr> binding_nodes =
314 item_nodes[i]->getChildren("binding");
316 for (unsigned int k = 0; k < binding_nodes.size(); k++)
317 _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
320 _menuBar->add_submenu(name, items, callbacks);
324 FGMenuBar::make_menubar ()
326 _menuBar = new puMenuBar;
327 SGPropertyNode props;
329 fgLoadProps("gui/menubar.xml", &props);
330 vector<SGPropertyNode_ptr> menu_nodes = props.getChildren("menu");
331 for (unsigned int i = 0; i < menu_nodes.size(); i++)
332 make_menu(menu_nodes[i]);
342 FGMenuBar::make_char_array (int size)
344 char ** list = new char*[size+1];
345 for (int i = 0; i <= size; i++)
347 _char_arrays.push_back(list);
352 FGMenuBar::make_callback_array (int size)
354 puCallback * list = new puCallback[size+1];
355 for (int i = 0; i <= size; i++)
357 _callback_arrays.push_back(list);
361 // end of menubar.cxx