4 #include <simgear/debug/logstream.hxx>
6 #include <Main/globals.hxx>
7 #include <Main/fg_props.hxx>
9 #include <Input/input.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)
119 extern void fgAPAdjust (puObject *);
121 do_ap_adjust_dialog (const SGPropertyNode * arg)
127 extern void fgLatLonFormatToggle (puObject *);
129 do_lat_lon_format_dialog (const SGPropertyNode * arg)
131 fgLatLonFormatToggle(0);
135 extern void helpCb (puObject *);
137 do_help_dialog (const SGPropertyNode * arg)
145 SGCommandMgr::command_t command;
146 } deprecated_dialogs [] = {
147 { "old-save-dialog", do_save_dialog },
148 { "old-load-dialog", do_load_dialog },
149 { "old-reinit_dialog", do_reinit_dialog },
150 #if defined(TR_HIRES_SNAP)
151 { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
153 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
154 { "old-print-dialog", do_print_dialog },
156 { "old-pilot-offset-dialog", do_pilot_offset_dialog },
157 { "old-hud-alpha-dialog", do_hud_alpha_dialog },
158 { "old-properties-dialog", do_properties_dialog },
159 { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
160 { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
161 { "old-ap-clear-route-dialog", do_ap_clear_route_dialog },
162 { "old-ap-adjust-dialog", do_ap_adjust_dialog },
163 { "old-lat-lon-format-dialog", do_lat_lon_format_dialog },
164 { "old-help-dialog", do_help_dialog },
169 add_deprecated_dialogs ()
171 SG_LOG(SG_GENERAL, SG_INFO, "Initializing old dialog commands:");
172 for (int i = 0; deprecated_dialogs[i].name != 0; i++) {
173 SG_LOG(SG_GENERAL, SG_INFO, " " << deprecated_dialogs[i].name);
174 globals->get_commands()->addCommand(deprecated_dialogs[i].name,
175 deprecated_dialogs[i].command);
181 ////////////////////////////////////////////////////////////////////////
183 ////////////////////////////////////////////////////////////////////////
187 menu_callback (puObject * object)
189 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
190 gui->getMenuBar()->fireItem(object);
195 ////////////////////////////////////////////////////////////////////////
196 // Implementation of FGMenuBar.
197 ////////////////////////////////////////////////////////////////////////
200 FGMenuBar::FGMenuBar ()
206 FGMenuBar::~FGMenuBar ()
209 puDeleteObject(_menuBar);
213 // Delete all the character arrays
214 // we were forced to keep around for
216 std::cerr << "Deleting char arrays\n";
217 for (i = 0; i < _char_arrays.size(); i++) {
218 for (int j = 0; _char_arrays[i][j] != 0; j++)
219 free(_char_arrays[i][j]); // added with strdup
220 delete _char_arrays[i];
223 // Delete all the callback arrays
224 // we were forced to keep around for
226 std::cerr << "Deleting callback arrays\n";
227 for (i = 0; i < _callback_arrays.size(); i++)
228 delete _callback_arrays[i];
230 // Delete all those bindings
231 std::cerr << "Deleting bindings\n";
232 map<string,vector<FGBinding *> >::iterator it;
233 it = _bindings.begin();
234 for (it = _bindings.begin(); it != _bindings.end(); it++) {
235 std::cerr << "Deleting bindings for " << it->first << std::endl;
236 for (int i = 0; i < it->second.size(); i++)
237 delete it->second[i];
240 std::cerr << "Done.\n";
246 if (_menuBar != 0) // FIXME: check if PUI owns the pointer
250 // FIXME: temporary commands to get at
251 // old, hard-coded dialogs.
252 add_deprecated_dialogs();
272 FGMenuBar::isVisible () const
278 FGMenuBar::fireItem (puObject * item)
280 const char * name = item->getLegend();
281 vector<FGBinding *> &bindings = _bindings[name];
282 int nBindings = bindings.size();
284 for (int i = 0; i < nBindings; i++)
289 FGMenuBar::make_menu (SGPropertyNode * node)
291 const char * name = strdup(node->getStringValue("label"));
292 vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
294 int array_size = item_nodes.size();
296 char ** items = make_char_array(array_size);
297 puCallback * callbacks = make_callback_array(array_size);
299 for (int i = 0, j = item_nodes.size() - 1;
300 i < item_nodes.size();
303 // Set up the PUI entries for this item
304 items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
305 callbacks[j] = menu_callback;
307 // Load all the bindings for this item
308 vector<SGPropertyNode_ptr> binding_nodes =
309 item_nodes[i]->getChildren("binding");
311 for (int k = 0; k < binding_nodes.size(); k++)
312 _bindings[items[j]].push_back(new FGBinding(binding_nodes[k]));
315 _menuBar->add_submenu(name, items, callbacks);
319 FGMenuBar::make_menubar ()
321 _menuBar = new puMenuBar;
322 SGPropertyNode props;
324 fgLoadProps("gui/menubar.xml", &props);
325 vector<SGPropertyNode_ptr> menu_nodes = props.getChildren("menu");
326 for (int i = 0; i < menu_nodes.size(); i++)
327 make_menu(menu_nodes[i]);
337 FGMenuBar::make_char_array (int size)
339 char ** list = new char*[size+1];
340 for (int i = 0; i <= size; i++)
342 _char_arrays.push_back(list);
347 FGMenuBar::make_callback_array (int size)
349 puCallback * list = new puCallback[size+1];
350 for (int i = 0; i <= size; i++)
352 _callback_arrays.push_back(list);
356 // end of menubar.cxx