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 reInit (puObject *);
33 do_reinit_dialog (const SGPropertyNode * arg)
39 #if defined(TR_HIRES_SNAP)
40 extern void dumpHiResSnapShot (puObject *);
42 do_hires_snapshot_dialog (const SGPropertyNode * arg)
47 #endif // TR_HIRES_SNAP
49 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
50 extern void printScreen (puObject *);
52 do_print_dialog (const SGPropertyNode * arg)
59 extern void fgHUDalphaAdjust (puObject *);
61 do_hud_alpha_dialog (const SGPropertyNode * arg)
67 extern void prop_pickerView (puObject *);
69 do_properties_dialog (const SGPropertyNode * arg)
75 extern void AddWayPoint (puObject *);
77 do_ap_add_waypoint_dialog (const SGPropertyNode * arg)
83 extern void PopWayPoint (puObject *);
85 do_ap_pop_waypoint_dialog (const SGPropertyNode * arg)
91 extern void ClearRoute (puObject *);
93 do_ap_clear_route_dialog (const SGPropertyNode * arg)
100 extern void fgAPAdjust (puObject *);
102 do_ap_adjust_dialog (const SGPropertyNode * arg)
109 extern void fgLatLonFormatToggle (puObject *);
111 do_lat_lon_format_dialog (const SGPropertyNode * arg)
113 fgLatLonFormatToggle(0);
117 extern void helpCb (puObject *);
119 do_help_dialog (const SGPropertyNode * arg)
127 SGCommandMgr::command_t command;
128 } deprecated_dialogs [] = {
129 { "old-reinit-dialog", do_reinit_dialog },
130 #if defined(TR_HIRES_SNAP)
131 { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
133 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
134 { "old-print-dialog", do_print_dialog },
136 { "old-hud-alpha-dialog", do_hud_alpha_dialog },
137 { "old-properties-dialog", do_properties_dialog },
138 { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
139 { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
140 { "old-ap-clear-route-dialog", do_ap_clear_route_dialog },
141 { "old-lat-lon-format-dialog", do_lat_lon_format_dialog },
142 { "old-help-dialog", do_help_dialog },
147 add_deprecated_dialogs ()
149 SG_LOG(SG_GENERAL, SG_INFO, "Initializing old dialog commands:");
150 for (int i = 0; deprecated_dialogs[i].name != 0; i++) {
151 SG_LOG(SG_GENERAL, SG_INFO, " " << deprecated_dialogs[i].name);
152 globals->get_commands()->addCommand(deprecated_dialogs[i].name,
153 deprecated_dialogs[i].command);
159 ////////////////////////////////////////////////////////////////////////
161 ////////////////////////////////////////////////////////////////////////
165 menu_callback (puObject * object)
167 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
168 gui->getMenuBar()->fireItem(object);
173 ////////////////////////////////////////////////////////////////////////
174 // Implementation of FGMenuBar.
175 ////////////////////////////////////////////////////////////////////////
178 FGMenuBar::FGMenuBar ()
184 FGMenuBar::~FGMenuBar ()
192 delete _menuBar; // FIXME: check if PUI owns the pointer
194 // FIXME: temporary commands to get at
195 // old, hard-coded dialogs.
196 add_deprecated_dialogs();
216 FGMenuBar::isVisible () const
222 FGMenuBar::fireItem (puObject * item)
224 const char * name = item->getLegend();
225 vector<FGBinding *> &bindings = _bindings[name];
226 int nBindings = bindings.size();
228 for (int i = 0; i < nBindings; i++)
233 FGMenuBar::make_menu (SGPropertyNode * node)
235 const char * name = strdup(node->getStringValue("label"));
236 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
238 int array_size = item_nodes.size();
240 char ** items = make_char_array(array_size);
241 puCallback * callbacks = make_callback_array(array_size);
243 for (unsigned int i = 0, j = item_nodes.size() - 1;
244 i < item_nodes.size();
247 // Set up the PUI entries for this item
248 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
249 callbacks[j] = menu_callback;
251 // Load all the bindings for this item
252 vector<SGPropertyNode_ptr> bindings = item_nodes[i]->getChildren("binding");
253 SGPropertyNode * dest = fgGetNode("/sim/bindings/menu", true);
255 for (unsigned int k = 0; k < bindings.size(); k++) {
257 SGPropertyNode *binding;
258 while (dest->getChild("binding", m))
261 binding = dest->getChild("binding", m, true);
262 copyProperties(bindings[k], binding);
263 _bindings[items[j]].push_back(new FGBinding(binding));
267 _menuBar->add_submenu(name, items, callbacks);
271 FGMenuBar::make_menubar ()
273 SGPropertyNode *targetpath;
275 targetpath = fgGetNode("/sim/menubar/default",true);
276 // fgLoadProps("gui/menubar.xml", targetpath);
278 /* NOTE: there is no check to see whether there's any usable data at all
280 * This would also have the advantage of being able to create some kind of
281 * 'fallback' menu - just in case that either menubar.xml is empty OR that
282 * its XML data is not valid, that way we would avoid displaying an
283 * unusable menubar without any functionality - if we decided to add another
284 * char * element to the commands structure in
285 * $FG_SRC/src/Main/fgcommands.cxx
286 * we could additionally save each function's (short) description and use
287 * this as label for the fallback PUI menubar item labels - as a workaround
288 * one might simply use the internal fgcommands and put them into the
289 * fallback menu, so that the user is at least able to re-init the menu
290 * loading - just in case there was some malformed XML in it
291 * (it happend to me ...)
294 make_menubar(targetpath);
297 /* WARNING: We aren't yet doing any validation of what's found - but since
298 * this isn't done with menubar.xml either, it should not really matter
299 * right now. Although one should later on consider to validate the
300 * contents, whether they are representing a 'legal' menubar structure.
303 FGMenuBar::make_menubar(const SGPropertyNode * props)
307 _menuBar = new puMenuBar;
309 vector<SGPropertyNode_ptr> menu_nodes = props->getChildren("menu");
310 for (unsigned int i = 0; i < menu_nodes.size(); i++)
311 make_menu(menu_nodes[i]);
321 FGMenuBar::destroy_menubar ()
327 puDeleteObject(_menuBar);
331 // Delete all the character arrays
332 // we were forced to keep around for
334 SG_LOG(SG_GENERAL, SG_INFO, "Deleting char arrays");
335 for (i = 0; i < _char_arrays.size(); i++) {
336 for (int j = 0; _char_arrays[i][j] != 0; j++)
337 free(_char_arrays[i][j]); // added with strdup
338 delete[] _char_arrays[i];
341 // Delete all the callback arrays
342 // we were forced to keep around for
344 SG_LOG(SG_GENERAL, SG_INFO, "Deleting callback arrays");
345 for (i = 0; i < _callback_arrays.size(); i++)
346 delete[] _callback_arrays[i];
348 // Delete all those bindings
349 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings");
350 map<string,vector<FGBinding *> >::iterator it;
351 it = _bindings.begin();
352 for (it = _bindings.begin(); it != _bindings.end(); it++) {
353 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings for " << it->first);
354 for ( i = 0; i < it->second.size(); i++ )
355 delete it->second[i];
358 SG_LOG(SG_GENERAL, SG_INFO, "Done.");
363 FGMenuBar::make_char_array (int size)
365 char ** list = new char*[size+1];
366 for (int i = 0; i <= size; i++)
368 _char_arrays.push_back(list);
373 FGMenuBar::make_callback_array (int size)
375 puCallback * list = new puCallback[size+1];
376 for (int i = 0; i <= size; i++)
378 _callback_arrays.push_back(list);
382 // end of menubar.cxx