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 prop_pickerView (puObject *);
61 do_properties_dialog (const SGPropertyNode * arg)
67 extern void AddWayPoint (puObject *);
69 do_ap_add_waypoint_dialog (const SGPropertyNode * arg)
75 extern void PopWayPoint (puObject *);
77 do_ap_pop_waypoint_dialog (const SGPropertyNode * arg)
83 extern void ClearRoute (puObject *);
85 do_ap_clear_route_dialog (const SGPropertyNode * arg)
92 extern void fgAPAdjust (puObject *);
94 do_ap_adjust_dialog (const SGPropertyNode * arg)
101 extern void fgLatLonFormatToggle (puObject *);
103 do_lat_lon_format_dialog (const SGPropertyNode * arg)
105 fgLatLonFormatToggle(0);
109 extern void helpCb (puObject *);
111 do_help_dialog (const SGPropertyNode * arg)
119 SGCommandMgr::command_t command;
120 } deprecated_dialogs [] = {
121 { "old-reinit-dialog", do_reinit_dialog },
122 #if defined(TR_HIRES_SNAP)
123 { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
125 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
126 { "old-print-dialog", do_print_dialog },
128 { "old-properties-dialog", do_properties_dialog },
129 { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
130 { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
131 { "old-ap-clear-route-dialog", do_ap_clear_route_dialog },
132 { "old-lat-lon-format-dialog", do_lat_lon_format_dialog },
133 { "old-help-dialog", do_help_dialog },
138 add_deprecated_dialogs ()
140 SG_LOG(SG_GENERAL, SG_INFO, "Initializing old dialog commands:");
141 for (int i = 0; deprecated_dialogs[i].name != 0; i++) {
142 SG_LOG(SG_GENERAL, SG_INFO, " " << deprecated_dialogs[i].name);
143 globals->get_commands()->addCommand(deprecated_dialogs[i].name,
144 deprecated_dialogs[i].command);
150 ////////////////////////////////////////////////////////////////////////
152 ////////////////////////////////////////////////////////////////////////
156 menu_callback (puObject * object)
158 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
159 gui->getMenuBar()->fireItem(object);
164 ////////////////////////////////////////////////////////////////////////
165 // Implementation of FGMenuBar.
166 ////////////////////////////////////////////////////////////////////////
169 FGMenuBar::FGMenuBar ()
175 FGMenuBar::~FGMenuBar ()
183 delete _menuBar; // FIXME: check if PUI owns the pointer
185 // FIXME: temporary commands to get at
186 // old, hard-coded dialogs.
187 add_deprecated_dialogs();
207 FGMenuBar::isVisible () const
213 FGMenuBar::fireItem (puObject * item)
215 const char * name = item->getLegend();
216 vector<FGBinding *> &bindings = _bindings[name];
217 int nBindings = bindings.size();
219 for (int i = 0; i < nBindings; i++)
224 FGMenuBar::make_menu (SGPropertyNode * node)
226 const char * name = strdup(node->getStringValue("label"));
227 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
229 int array_size = item_nodes.size();
231 char ** items = make_char_array(array_size);
232 puCallback * callbacks = make_callback_array(array_size);
234 for (unsigned int i = 0, j = item_nodes.size() - 1;
235 i < item_nodes.size();
238 // Set up the PUI entries for this item
239 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
240 callbacks[j] = menu_callback;
242 // Load all the bindings for this item
243 vector<SGPropertyNode_ptr> bindings = item_nodes[i]->getChildren("binding");
244 SGPropertyNode * dest = fgGetNode("/sim/bindings/menu", true);
246 for (unsigned int k = 0; k < bindings.size(); k++) {
248 SGPropertyNode *binding;
249 while (dest->getChild("binding", m))
252 binding = dest->getChild("binding", m, true);
253 copyProperties(bindings[k], binding);
254 _bindings[items[j]].push_back(new FGBinding(binding));
258 _menuBar->add_submenu(name, items, callbacks);
262 FGMenuBar::make_menubar ()
264 SGPropertyNode *targetpath;
266 targetpath = fgGetNode("/sim/menubar/default",true);
267 // fgLoadProps("gui/menubar.xml", targetpath);
269 /* NOTE: there is no check to see whether there's any usable data at all
271 * This would also have the advantage of being able to create some kind of
272 * 'fallback' menu - just in case that either menubar.xml is empty OR that
273 * its XML data is not valid, that way we would avoid displaying an
274 * unusable menubar without any functionality - if we decided to add another
275 * char * element to the commands structure in
276 * $FG_SRC/src/Main/fgcommands.cxx
277 * we could additionally save each function's (short) description and use
278 * this as label for the fallback PUI menubar item labels - as a workaround
279 * one might simply use the internal fgcommands and put them into the
280 * fallback menu, so that the user is at least able to re-init the menu
281 * loading - just in case there was some malformed XML in it
282 * (it happend to me ...)
285 make_menubar(targetpath);
288 /* WARNING: We aren't yet doing any validation of what's found - but since
289 * this isn't done with menubar.xml either, it should not really matter
290 * right now. Although one should later on consider to validate the
291 * contents, whether they are representing a 'legal' menubar structure.
294 FGMenuBar::make_menubar(const SGPropertyNode * props)
298 _menuBar = new puMenuBar;
300 vector<SGPropertyNode_ptr> menu_nodes = props->getChildren("menu");
301 for (unsigned int i = 0; i < menu_nodes.size(); i++)
302 make_menu(menu_nodes[i]);
312 FGMenuBar::destroy_menubar ()
318 puDeleteObject(_menuBar);
322 // Delete all the character arrays
323 // we were forced to keep around for
325 SG_LOG(SG_GENERAL, SG_INFO, "Deleting char arrays");
326 for (i = 0; i < _char_arrays.size(); i++) {
327 for (int j = 0; _char_arrays[i][j] != 0; j++)
328 free(_char_arrays[i][j]); // added with strdup
329 delete[] _char_arrays[i];
332 // Delete all the callback arrays
333 // we were forced to keep around for
335 SG_LOG(SG_GENERAL, SG_INFO, "Deleting callback arrays");
336 for (i = 0; i < _callback_arrays.size(); i++)
337 delete[] _callback_arrays[i];
339 // Delete all those bindings
340 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings");
341 map<string,vector<FGBinding *> >::iterator it;
342 it = _bindings.begin();
343 for (it = _bindings.begin(); it != _bindings.end(); it++) {
344 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings for " << it->first);
345 for ( i = 0; i < it->second.size(); i++ )
346 delete it->second[i];
349 SG_LOG(SG_GENERAL, SG_INFO, "Done.");
354 FGMenuBar::make_char_array (int size)
356 char ** list = new char*[size+1];
357 for (int i = 0; i <= size; i++)
359 _char_arrays.push_back(list);
364 FGMenuBar::make_callback_array (int size)
366 puCallback * list = new puCallback[size+1];
367 for (int i = 0; i <= size; i++)
369 _callback_arrays.push_back(list);
373 // end of menubar.cxx