puDeleteObject(_object);
unsigned int i;
-
// Delete all the arrays we made
// and were forced to keep around
// because PUI won't do its own
// memory management.
- for (i = 0; i < _char_arrays.size(); i++) {
- for (int j = 0; _char_arrays[i][j] != 0; j++)
- free(_char_arrays[i][j]); // added with strdup
- delete[] _char_arrays[i];
- }
+ for (i = 0; i < _char_arrays.size(); i++)
+ destroy_char_array(_char_arrays[i]);
// Delete all the info objects we
// were forced to keep around because
delete (GUIInfo *)_info[i];
_info[i] = 0;
}
-
// Finally, delete the property links.
for (i = 0; i < _propertyObjects.size(); i++) {
delete _propertyObjects[i];
}
void
-FGDialog::updateValue (const char * objectName)
+FGDialog::updateValues (const char * objectName)
{
for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
const string &name = _propertyObjects[i]->name;
- if (name == objectName)
- copy_to_pui(_propertyObjects[i]->node,
- _propertyObjects[i]->object);
- }
-}
+ if (name.size() && name != objectName)
+ continue;
-void
-FGDialog::applyValue (const char * objectName)
-{
- for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
- if (_propertyObjects[i]->name == objectName)
- copy_from_pui(_propertyObjects[i]->object,
- _propertyObjects[i]->node);
+ puObject *obj = _propertyObjects[i]->object;
+ copy_to_pui(_propertyObjects[i]->node, obj);
}
}
void
-FGDialog::updateValues ()
+FGDialog::applyValues (const char * objectName)
{
- for (unsigned int i = 0; i < _propertyObjects.size(); i++)
- copy_to_pui(_propertyObjects[i]->node, _propertyObjects[i]->object);
-}
+ for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
+ const string &name = _propertyObjects[i]->name;
+ if (name.size() && name != objectName)
+ continue;
-void
-FGDialog::applyValues ()
-{
- for (unsigned int i = 0; i < _propertyObjects.size(); i++)
copy_from_pui(_propertyObjects[i]->object,
_propertyObjects[i]->node);
+ }
}
void
return obj;
} else if (type == "list") {
- vector<SGPropertyNode_ptr> value_nodes = props->getChildren("value");
- char ** entries = make_char_array(value_nodes.size());
- for (unsigned int i = 0; i < value_nodes.size(); i++)
- entries[i] = strdup((char *)value_nodes[i]->getStringValue());
-
+ char ** entries = value_list(props);
int slider_width = props->getIntValue("slider", 20);
puList * obj = new puList(x, y, x + width, y + height, entries, slider_width);
if (presetSize)
return obj;
} else if (type == "combo") {
- vector<SGPropertyNode_ptr> value_nodes = props->getChildren("value");
- char ** entries = make_char_array(value_nodes.size());
- for (unsigned int i = 0; i < value_nodes.size(); i++)
- entries[i] = strdup((char *)value_nodes[i]->getStringValue());
-
+ char ** entries = value_list(props);
puComboBox * obj = new puComboBox(x, y, x + width, y + height, entries,
props->getBoolValue("editable", false));
setupObject(obj, props);
return key;
}
+char **
+FGDialog::value_list (const SGPropertyNode *props)
+{
+ vector<SGPropertyNode_ptr> value_nodes = props->getChildren("value");
+ char ** entries = make_char_array(value_nodes.size());
+ for (unsigned int i = 0; i < value_nodes.size(); i++)
+ entries[i] = strdup((char *)value_nodes[i]->getStringValue());
+ return entries;
+}
+
char **
FGDialog::make_char_array (int size)
{
return list;
}
+void
+FGDialog::destroy_char_array (char ** array)
+{
+ for (int i = 0; array[i] != 0; i++)
+ if (array[i])
+ free(array[i]);// added with strdup
+ delete[] array;
+}
\f
////////////////////////////////////////////////////////////////////////
/**
- * Update the values of all GUI objects with a specific name.
+ * Update the values of all GUI objects with a specific name,
+ * or all if name is 0 (default).
*
* This method copies values from the FlightGear property tree to
* the GUI object(s).
* @param objectName The name of the GUI object(s) to update.
* Use the empty name for all unnamed objects.
*/
- virtual void updateValue (const char * objectName);
+ virtual void updateValues (const char * objectName = 0);
/**
- * Apply the values of all GUI objects with a specific name.
+ * Apply the values of all GUI objects with a specific name,
+ * or all if name is 0 (default)
*
* This method copies values from the GUI object(s) to the
* FlightGear property tree.
* @param objectName The name of the GUI object(s) to update.
* Use the empty name for all unnamed objects.
*/
- virtual void applyValue (const char * objectName);
-
-
- /**
- * Update the values of all GUI objects.
- *
- * This method copies values from the FlightGear property tree to
- * the GUI objects.
- */
- virtual void updateValues ();
-
-
- /**
- * Apply the values of all GUI objects.
- *
- * This method copies from the GUI objects to the FlightGear
- * property tree properties.
- */
- virtual void applyValues ();
+ virtual void applyValues (const char * objectName = 0);
/**
// PUI doesn't copy arrays, so we have to allocate string arrays
// and then keep pointers so that we can delete them when the
- // dialog closes.
+ // dialog closes. value_list() builds such a list from "value"
+ // children.
char ** make_char_array (int size);
+ char ** value_list(const SGPropertyNode * prop);
+ void destroy_char_array (char **array);
vector<char **> _char_arrays;
};