1 // new_gui.cxx: implementation of XML-configurable GUI support.
8 #include <simgear/compiler.h>
9 #include <simgear/structure/exception.hxx>
11 #include <Main/fg_props.hxx>
13 #include "menubar.hxx"
19 ////////////////////////////////////////////////////////////////////////
20 // Implementation of NewGUI.
21 ////////////////////////////////////////////////////////////////////////
25 : _menubar(new FGMenuBar),
40 ulMakePath(path1, globals->get_fg_root().c_str(), "gui");
41 ulMakePath(path2, path1, "dialogs");
51 _menubar = new FGMenuBar;
59 fgTie("/sim/menubar/visibility", this,
60 &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible);
66 fgUntie("/sim/menubar/visibility");
70 NewGUI::update (double delta_time_sec)
72 map<string,FGDialog *>::iterator iter = _active_dialogs.begin();
73 for(/**/; iter != _active_dialogs.end(); iter++)
74 iter->second->update();
78 NewGUI::showDialog (const string &name)
80 if (_dialog_props.find(name) == _dialog_props.end()) {
81 SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
84 if(!_active_dialogs[name])
85 _active_dialogs[name] = new FGDialog(_dialog_props[name]);
91 NewGUI::closeActiveDialog ()
93 if (_active_dialog == 0)
96 // Kill any entries in _active_dialogs... Is there an STL
97 // algorithm to do (delete map entries by value, not key)? I hate
99 map<string,FGDialog *>::iterator iter = _active_dialogs.begin();
100 for(/**/; iter != _active_dialogs.end(); iter++) {
101 if(iter->second == _active_dialog) {
102 _active_dialogs.erase(iter);
103 // iter is no longer valid
108 delete _active_dialog;
114 NewGUI::closeDialog (const string& name)
116 if(_active_dialogs.find(name) != _active_dialogs.end()) {
117 if(_active_dialog == _active_dialogs[name])
119 delete _active_dialogs[name];
120 _active_dialogs.erase(name);
123 return false; // dialog wasn't open...
127 NewGUI::setActiveDialog (FGDialog * dialog)
129 _active_dialog = dialog;
133 NewGUI::getActiveDialog ()
135 return _active_dialog;
139 NewGUI::getMenuBar ()
145 NewGUI::getMenuBarVisible () const
147 return _menubar->isVisible();
151 NewGUI::setMenuBarVisible (bool visible)
164 _dialog_props.clear();
168 test_extension (const char * path, const char * ext)
170 int pathlen = strlen(path);
171 int extlen = strlen(ext);
173 for (int i = 1; i <= pathlen && i <= extlen; i++) {
174 if (path[pathlen-i] != ext[extlen-i])
181 NewGUI::newDialog (SGPropertyNode* props)
183 const char* cname = props->getStringValue("name");
185 SG_LOG(SG_GENERAL, SG_ALERT, "New dialog has no <name> property");
188 string name = props->getStringValue("name");
189 _dialog_props[name] = props;
193 NewGUI::readDir (const char * path)
195 ulDir * dir = ulOpenDir(path);
198 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
203 for (ulDirEnt * dirEnt = ulReadDir(dir);
205 dirEnt = ulReadDir(dir)) {
209 ulMakePath(subpath, path, dirEnt->d_name);
211 if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) {
212 SGPropertyNode * props = new SGPropertyNode;
214 readProperties(subpath, props);
215 } catch (const sg_exception &) {
216 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
221 if (!props->hasValue("name")) {
222 SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
223 << " has no name; skipping.");
233 // end of new_gui.cxx