From: jmt Date: Mon, 2 Nov 2009 23:35:10 +0000 (+0000) Subject: Dynamic combo-boxes; read values from the property tree. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=71c03b1ce408e85c18782220612bc9d5a8974e44;p=flightgear.git Dynamic combo-boxes; read values from the property tree. --- diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index 59a2fa2f3..95fe5f04c 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -553,18 +553,24 @@ FGDialog::updateValues (const char *objectName) if (objectName && !objectName[0]) objectName = 0; - for (unsigned int i = 0; i < _propertyObjects.size(); i++) { - const string &name = _propertyObjects[i]->name; - if (objectName && name != objectName) - continue; - - puObject *obj = _propertyObjects[i]->object; - if ((obj->getType() & PUCLASS_LIST) && (dynamic_cast(obj)->id & FGCLASS_LIST)) { - fgList *pl = static_cast(obj); - pl->update(); - } else - copy_to_pui(_propertyObjects[i]->node, obj); + for (unsigned int i = 0; i < _propertyObjects.size(); i++) { + const string &name = _propertyObjects[i]->name; + if (objectName && name != objectName) { + continue; } + + puObject *widget = _propertyObjects[i]->object; + int widgetType = widget->getType(); + if ((widgetType & PUCLASS_LIST) && (dynamic_cast(widget)->id & FGCLASS_LIST)) { + fgList *pl = static_cast(widget); + pl->update(); + } else if (widgetType & PUCLASS_COMBOBOX) { + fgComboBox* combo = static_cast(widget); + combo->update(); + } else { + copy_to_pui(_propertyObjects[i]->node, widget); + } + } // of property objects iteration } void @@ -1259,12 +1265,26 @@ fgValueList::~fgValueList() void fgValueList::make_list() { - vector value_nodes = _props->getChildren("value"); - _list = new char *[value_nodes.size() + 1]; - unsigned int i; - for (i = 0; i < value_nodes.size(); i++) - _list[i] = strdup((char *)value_nodes[i]->getStringValue()); - _list[i] = 0; + SGPropertyNode_ptr values = _props; + const char* vname = "value"; + + if (_props->hasChild("properties")) { + // dynamic values, read from a property's children + const char* path = _props->getStringValue("properties"); + values = fgGetNode(path, true); + } + + if (_props->hasChild("property-name")) { + vname = _props->getStringValue("property-name"); + } + + vector value_nodes = values->getChildren(vname); + _list = new char *[value_nodes.size() + 1]; + unsigned int i; + for (i = 0; i < value_nodes.size(); i++) { + _list[i] = strdup((char *)value_nodes[i]->getStringValue()); + } + _list[i] = 0; } void @@ -1287,4 +1307,10 @@ fgList::update() setTopItem(top); } +void fgComboBox::update() +{ + fgValueList::update(); + newList(_list); +} + // end of dialog.cxx diff --git a/src/GUI/dialog.hxx b/src/GUI/dialog.hxx index 9981006ca..63aef704b 100644 --- a/src/GUI/dialog.hxx +++ b/src/GUI/dialog.hxx @@ -258,6 +258,8 @@ class fgComboBox : public fgValueList, public puaComboBox { public: fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode *p, bool editable) : fgValueList(p), puaComboBox(x1, y1, x2, y2, _list, editable) {} + + void update(); }; class fgSelectBox : public fgValueList, public puaSelectBox {