7 #include <Main/fg_os.hxx> // To set toolkit for pu.h
9 #include <simgear/debug/logstream.hxx>
11 #include <Autopilot/auto_gui.hxx>
12 #include <Input/input.hxx>
13 #include <Main/globals.hxx>
14 #include <Main/fg_props.hxx>
16 #include "new_gui.hxx"
17 #include "menubar.hxx"
21 ////////////////////////////////////////////////////////////////////////
24 // Deprecated wrappers for old menu commands.
26 // DO NOT ADD TO THESE. THEY WILL BE DELETED SOON!
28 // These are defined in gui_funcs.cxx. They should be replaced with
29 // user-configured dialogs and new commands where necessary.
30 ////////////////////////////////////////////////////////////////////////
32 extern void saveFlight (puObject *);
34 do_save_dialog (const SGPropertyNode * arg)
40 extern void loadFlight (puObject *);
42 do_load_dialog (const SGPropertyNode * arg)
48 extern void reInit (puObject *);
50 do_reinit_dialog (const SGPropertyNode * arg)
56 #if defined(TR_HIRES_SNAP)
57 extern void dumpHiResSnapShot (puObject *);
59 do_hires_snapshot_dialog (const SGPropertyNode * arg)
64 #endif // TR_HIRES_SNAP
66 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
67 extern void printScreen (puObject *);
69 do_print_dialog (const SGPropertyNode * arg)
76 extern void PilotOffsetAdjust (puObject *);
78 do_pilot_offset_dialog (const SGPropertyNode * arg)
84 extern void fgHUDalphaAdjust (puObject *);
86 do_hud_alpha_dialog (const SGPropertyNode * arg)
92 extern void prop_pickerView (puObject *);
94 do_properties_dialog (const SGPropertyNode * arg)
100 extern void AddWayPoint (puObject *);
102 do_ap_add_waypoint_dialog (const SGPropertyNode * arg)
108 extern void PopWayPoint (puObject *);
110 do_ap_pop_waypoint_dialog (const SGPropertyNode * arg)
116 extern void ClearRoute (puObject *);
118 do_ap_clear_route_dialog (const SGPropertyNode * arg)
125 extern void fgAPAdjust (puObject *);
127 do_ap_adjust_dialog (const SGPropertyNode * arg)
134 extern void fgLatLonFormatToggle (puObject *);
136 do_lat_lon_format_dialog (const SGPropertyNode * arg)
138 fgLatLonFormatToggle(0);
142 extern void helpCb (puObject *);
144 do_help_dialog (const SGPropertyNode * arg)
152 SGCommandMgr::command_t command;
153 } deprecated_dialogs [] = {
154 { "old-save-dialog", do_save_dialog },
155 { "old-load-dialog", do_load_dialog },
156 { "old-reinit-dialog", do_reinit_dialog },
157 #if defined(TR_HIRES_SNAP)
158 { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
160 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
161 { "old-print-dialog", do_print_dialog },
163 { "old-pilot-offset-dialog", do_pilot_offset_dialog },
164 { "old-hud-alpha-dialog", do_hud_alpha_dialog },
165 { "old-properties-dialog", do_properties_dialog },
166 { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
167 { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
168 { "old-ap-clear-route-dialog", do_ap_clear_route_dialog },
169 { "old-lat-lon-format-dialog", do_lat_lon_format_dialog },
170 { "old-help-dialog", do_help_dialog },
175 add_deprecated_dialogs ()
177 SG_LOG(SG_GENERAL, SG_INFO, "Initializing old dialog commands:");
178 for (int i = 0; deprecated_dialogs[i].name != 0; i++) {
179 SG_LOG(SG_GENERAL, SG_INFO, " " << deprecated_dialogs[i].name);
180 globals->get_commands()->addCommand(deprecated_dialogs[i].name,
181 deprecated_dialogs[i].command);
187 ////////////////////////////////////////////////////////////////////////
189 ////////////////////////////////////////////////////////////////////////
193 menu_callback (puObject * object)
195 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
196 gui->getMenuBar()->fireItem(object);
201 ////////////////////////////////////////////////////////////////////////
202 // Implementation of FGMenuBar.
203 ////////////////////////////////////////////////////////////////////////
206 FGMenuBar::FGMenuBar ()
212 FGMenuBar::~FGMenuBar ()
215 puDeleteObject(_menuBar);
219 // Delete all the character arrays
220 // we were forced to keep around for
222 SG_LOG(SG_GENERAL, SG_INFO, "Deleting char arrays");
223 for (i = 0; i < _char_arrays.size(); i++) {
224 for (int j = 0; _char_arrays[i][j] != 0; j++)
225 free(_char_arrays[i][j]); // added with strdup
226 delete[] _char_arrays[i];
229 // Delete all the callback arrays
230 // we were forced to keep around for
232 SG_LOG(SG_GENERAL, SG_INFO, "Deleting callback arrays");
233 for (i = 0; i < _callback_arrays.size(); i++)
234 delete[] _callback_arrays[i];
236 // Delete all those bindings
237 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings");
238 map<string,vector<FGBinding *> >::iterator it;
239 it = _bindings.begin();
240 for (it = _bindings.begin(); it != _bindings.end(); it++) {
241 SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings for " << it->first);
242 for ( i = 0; i < it->second.size(); i++ )
243 delete it->second[i];
246 SG_LOG(SG_GENERAL, SG_INFO, "Done.");
252 if (_menuBar != 0) // FIXME: check if PUI owns the pointer
256 // FIXME: temporary commands to get at
257 // old, hard-coded dialogs.
258 add_deprecated_dialogs();
278 FGMenuBar::isVisible () const
284 FGMenuBar::fireItem (puObject * item)
286 const char * name = item->getLegend();
287 vector<FGBinding *> &bindings = _bindings[name];
288 int nBindings = bindings.size();
290 for (int i = 0; i < nBindings; i++)
295 FGMenuBar::make_menu (SGPropertyNode * node)
297 const char * name = strdup(node->getStringValue("label"));
298 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
300 int array_size = item_nodes.size();
302 char ** items = make_char_array(array_size);
303 puCallback * callbacks = make_callback_array(array_size);
305 for (unsigned int i = 0, j = item_nodes.size() - 1;
306 i < item_nodes.size();
309 // Set up the PUI entries for this item
310 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
311 callbacks[j] = menu_callback;
313 // Load all the bindings for this item
314 vector<SGPropertyNode_ptr> binding_nodes =
315 item_nodes[i]->getChildren("binding");
317 for (unsigned int k = 0; k < binding_nodes.size(); k++)
318 _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
321 _menuBar->add_submenu(name, items, callbacks);
325 FGMenuBar::make_menubar ()
327 _menuBar = new puMenuBar;
328 SGPropertyNode props;
330 fgLoadProps("gui/menubar.xml", &props);
331 vector<SGPropertyNode_ptr> menu_nodes = props.getChildren("menu");
332 for (unsigned int i = 0; i < menu_nodes.size(); i++)
333 make_menu(menu_nodes[i]);
343 FGMenuBar::make_char_array (int size)
345 char ** list = new char*[size+1];
346 for (int i = 0; i <= size; i++)
348 _char_arrays.push_back(list);
353 FGMenuBar::make_callback_array (int size)
355 puCallback * list = new puCallback[size+1];
356 for (int i = 0; i <= size; i++)
358 _callback_arrays.push_back(list);
362 // end of menubar.cxx