4 #include <simgear/debug/logstream.hxx>
6 #include <Autopilot/auto_gui.hxx>
7 #include <Input/input.hxx>
8 #include <Main/globals.hxx>
9 #include <Main/fg_props.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 AddWayPoint (puObject *);
97 do_ap_add_waypoint_dialog (const SGPropertyNode * arg)
103 extern void PopWayPoint (puObject *);
105 do_ap_pop_waypoint_dialog (const SGPropertyNode * arg)
111 extern void ClearRoute (puObject *);
113 do_ap_clear_route_dialog (const SGPropertyNode * arg)
120 extern void fgAPAdjust (puObject *);
122 do_ap_adjust_dialog (const SGPropertyNode * arg)
129 extern void fgLatLonFormatToggle (puObject *);
131 do_lat_lon_format_dialog (const SGPropertyNode * arg)
133 fgLatLonFormatToggle(0);
137 extern void helpCb (puObject *);
139 do_help_dialog (const SGPropertyNode * arg)
147 SGCommandMgr::command_t command;
148 } deprecated_dialogs [] = {
149 { "old-save-dialog", do_save_dialog },
150 { "old-load-dialog", do_load_dialog },
151 { "old-reinit-dialog", do_reinit_dialog },
152 #if defined(TR_HIRES_SNAP)
153 { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
155 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
156 { "old-print-dialog", do_print_dialog },
158 { "old-pilot-offset-dialog", do_pilot_offset_dialog },
159 { "old-hud-alpha-dialog", do_hud_alpha_dialog },
160 { "old-properties-dialog", do_properties_dialog },
161 { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
162 { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
163 { "old-ap-clear-route-dialog", do_ap_clear_route_dialog },
164 { "old-lat-lon-format-dialog", do_lat_lon_format_dialog },
165 { "old-help-dialog", do_help_dialog },
170 add_deprecated_dialogs ()
172 SG_LOG(SG_GENERAL, SG_INFO, "Initializing old dialog commands:");
173 for (int i = 0; deprecated_dialogs[i].name != 0; i++) {
174 SG_LOG(SG_GENERAL, SG_INFO, " " << deprecated_dialogs[i].name);
175 globals->get_commands()->addCommand(deprecated_dialogs[i].name,
176 deprecated_dialogs[i].command);
182 ////////////////////////////////////////////////////////////////////////
184 ////////////////////////////////////////////////////////////////////////
188 menu_callback (puObject * object)
190 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
191 gui->getMenuBar()->fireItem(object);
196 ////////////////////////////////////////////////////////////////////////
197 // Implementation of FGMenuBar.
198 ////////////////////////////////////////////////////////////////////////
201 FGMenuBar::FGMenuBar ()
207 FGMenuBar::~FGMenuBar ()
210 puDeleteObject(_menuBar);
214 // Delete all the character arrays
215 // we were forced to keep around for
217 SG_LOG(SG_GENERAL, SG_INFO, "Deleting char arrays");
218 for (i = 0; i < _char_arrays.size(); i++) {
219 for (int j = 0; _char_arrays[i][j] != 0; j++)
220 free(_char_arrays[i][j]); // added with strdup
221 delete[] _char_arrays[i];
224 // Delete all the callback arrays
225 // we were forced to keep around for
227 SG_LOG(SG_GENERAL, SG_INFO, "Deleting callback arrays");
228 for (i = 0; i < _callback_arrays.size(); i++)
229 delete[] _callback_arrays[i];
231 // Delete all those bindings
232 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings");
233 map<string,vector<FGBinding *> >::iterator it;
234 it = _bindings.begin();
235 for (it = _bindings.begin(); it != _bindings.end(); it++) {
236 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings for " << it->first);
237 for ( i = 0; i < it->second.size(); i++ )
238 delete it->second[i];
241 SG_LOG(SG_GENERAL, SG_INFO, "Done.");
247 if (_menuBar != 0) // FIXME: check if PUI owns the pointer
251 // FIXME: temporary commands to get at
252 // old, hard-coded dialogs.
253 add_deprecated_dialogs();
273 FGMenuBar::isVisible () const
279 FGMenuBar::fireItem (puObject * item)
281 const char * name = item->getLegend();
282 vector<FGBinding *> &bindings = _bindings[name];
283 int nBindings = bindings.size();
285 for (int i = 0; i < nBindings; i++)
290 FGMenuBar::make_menu (SGPropertyNode * node)
292 const char * name = strdup(node->getStringValue("label"));
293 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
295 int array_size = item_nodes.size();
297 char ** items = make_char_array(array_size);
298 puCallback * callbacks = make_callback_array(array_size);
300 for (unsigned int i = 0, j = item_nodes.size() - 1;
301 i < item_nodes.size();
304 // Set up the PUI entries for this item
305 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
306 callbacks[j] = menu_callback;
308 // Load all the bindings for this item
309 vector<SGPropertyNode_ptr> binding_nodes =
310 item_nodes[i]->getChildren("binding");
312 for (unsigned int k = 0; k < binding_nodes.size(); k++)
313 _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
316 _menuBar->add_submenu(name, items, callbacks);
320 FGMenuBar::make_menubar ()
322 _menuBar = new puMenuBar;
323 SGPropertyNode props;
325 fgLoadProps("gui/menubar.xml", &props);
326 vector<SGPropertyNode_ptr> menu_nodes = props.getChildren("menu");
327 for (unsigned int i = 0; i < menu_nodes.size(); i++)
328 make_menu(menu_nodes[i]);
338 FGMenuBar::make_char_array (int size)
340 char ** list = new char*[size+1];
341 for (int i = 0; i <= size; i++)
343 _char_arrays.push_back(list);
348 FGMenuBar::make_callback_array (int size)
350 puCallback * list = new puCallback[size+1];
351 for (int i = 0; i <= size; i++)
353 _callback_arrays.push_back(list);
357 // end of menubar.cxx