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 ()
219 delete _menuBar; // FIXME: check if PUI owns the pointer
221 // FIXME: temporary commands to get at
222 // old, hard-coded dialogs.
223 add_deprecated_dialogs();
243 FGMenuBar::isVisible () const
249 FGMenuBar::fireItem (puObject * item)
251 const char * name = item->getLegend();
252 vector<FGBinding *> &bindings = _bindings[name];
253 int nBindings = bindings.size();
255 for (int i = 0; i < nBindings; i++)
260 FGMenuBar::make_menu (SGPropertyNode * node)
262 const char * name = strdup(node->getStringValue("label"));
263 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
265 int array_size = item_nodes.size();
267 char ** items = make_char_array(array_size);
268 puCallback * callbacks = make_callback_array(array_size);
270 for (unsigned int i = 0, j = item_nodes.size() - 1;
271 i < item_nodes.size();
274 // Set up the PUI entries for this item
275 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
276 callbacks[j] = menu_callback;
278 // Load all the bindings for this item
279 vector<SGPropertyNode_ptr> binding_nodes =
280 item_nodes[i]->getChildren("binding");
282 for (unsigned int k = 0; k < binding_nodes.size(); k++)
283 _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
286 _menuBar->add_submenu(name, items, callbacks);
290 FGMenuBar::make_menubar ()
292 SGPropertyNode *targetpath;
294 targetpath = fgGetNode("/sim/menubar/default",true);
295 // fgLoadProps("gui/menubar.xml", targetpath);
297 /* NOTE: there is no check to see whether there's any usable data at all
299 * This would also have the advantage of being able to create some kind of
300 * 'fallback' menu - just in case that either menubar.xml is empty OR that
301 * its XML data is not valid, that way we would avoid displaying an
302 * unusable menubar without any functionality - if we decided to add another
303 * char * element to the commands structure in
304 * $FG_SRC/src/Main/fgcommands.cxx
305 * we could additionally save each function's (short) description and use
306 * this as label for the fallback PUI menubar item labels - as a workaround
307 * one might simply use the internal fgcommands and put them into the
308 * fallback menu, so that the user is at least able to re-init the menu
309 * loading - just in case there was some malformed XML in it
310 * (it happend to me ...)
313 make_menubar(targetpath);
316 /* WARNING: We aren't yet doing any validation of what's found - but since
317 * this isn't done with menubar.xml either, it should not really matter
318 * right now. Although one should later on consider to validate the
319 * contents, whether they are representing a 'legal' menubar structure.
322 FGMenuBar::make_menubar(const SGPropertyNode * props)
326 _menuBar = new puMenuBar;
328 vector<SGPropertyNode_ptr> menu_nodes = props->getChildren("menu");
329 for (unsigned int i = 0; i < menu_nodes.size(); i++)
330 make_menu(menu_nodes[i]);
340 FGMenuBar::destroy_menubar ()
346 puDeleteObject(_menuBar);
350 // Delete all the character arrays
351 // we were forced to keep around for
353 SG_LOG(SG_GENERAL, SG_INFO, "Deleting char arrays");
354 for (i = 0; i < _char_arrays.size(); i++) {
355 for (int j = 0; _char_arrays[i][j] != 0; j++)
356 free(_char_arrays[i][j]); // added with strdup
357 delete[] _char_arrays[i];
360 // Delete all the callback arrays
361 // we were forced to keep around for
363 SG_LOG(SG_GENERAL, SG_INFO, "Deleting callback arrays");
364 for (i = 0; i < _callback_arrays.size(); i++)
365 delete[] _callback_arrays[i];
367 // Delete all those bindings
368 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings");
369 map<string,vector<FGBinding *> >::iterator it;
370 it = _bindings.begin();
371 for (it = _bindings.begin(); it != _bindings.end(); it++) {
372 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings for " << it->first);
373 for ( i = 0; i < it->second.size(); i++ )
374 delete it->second[i];
377 SG_LOG(SG_GENERAL, SG_INFO, "Done.");
382 FGMenuBar::make_char_array (int size)
384 char ** list = new char*[size+1];
385 for (int i = 0; i <= size; i++)
387 _char_arrays.push_back(list);
392 FGMenuBar::make_callback_array (int size)
394 puCallback * list = new puCallback[size+1];
395 for (int i = 0; i <= size; i++)
397 _callback_arrays.push_back(list);
401 // end of menubar.cxx