// Callbacks.
////////////////////////////////////////////////////////////////////////
-
/**
- * Callback to update all property values.
+ * Action callback.
*/
static void
-update_callback (puObject * object)
+action_callback (puObject * object)
{
- ((GUIWidget *)object->getUserData())->updateProperties();
+ GUIData * action = (GUIData *)object->getUserData();
+ action->widget->action(action->command);
}
-/**
- * Callback to close the dialog.
- */
-static void
-close_callback (puObject * object)
-{
- delete ((GUIWidget *)object->getUserData());
-}
-
-
-/**
- * Callback to apply the property value for every field.
- */
-static void
-apply_callback (puObject * object)
-{
- ((GUIWidget *)object->getUserData())->applyProperties();
- update_callback(object);
-}
-
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of GUIData.
+////////////////////////////////////////////////////////////////////////
-/**
- * Callback to apply the property values and close the dialog.
- */
-static void
-close_apply_callback (puObject * object)
+GUIData::GUIData (GUIWidget * w, const char * c)
+ : widget(w),
+ command(c)
{
- apply_callback(object);
- close_callback(object);
}
}
}
+void
+GUIWidget::action (const string &command)
+{
+ if (command == "close") {
+ delete this;
+ } else if (command == "apply") {
+ applyProperties();
+ updateProperties();
+ } else if (command == "update") {
+ updateProperties();
+ } else if (command == "close-apply") {
+ applyProperties();
+ delete this;
+ }
+}
void
GUIWidget::applyProperties ()
void
GUIWidget::setupObject (puObject * object, SGPropertyNode * props)
{
- object->setUserData(this);
-
if (props->hasValue("legend"))
object->setLegend(props->getStringValue("legend"));
}
if (props->hasValue("action")) {
- string action = props->getStringValue("action");
- if (action == "update")
- object->setCallback(update_callback);
- else if (action == "close")
- object->setCallback(close_callback);
- else if (action == "apply")
- object->setCallback(apply_callback);
- else if (action == "close-apply")
- object->setCallback(close_apply_callback);
- else
- SG_LOG(SG_GENERAL, SG_ALERT, "Unknown GUI action " + action);
+ _actions.push_back(GUIData(this, props->getStringValue("action")));
+ object->setUserData(&_actions[_actions.size()-1]);
+ object->setCallback(action_callback);
}
object->makeReturnDefault(props->getBoolValue("default"));
+// new_gui.hxx - XML-configurable GUI subsystem.
+
#ifndef __NEW_GUI_HXX
#define __NEW_GUI_HXX 1
#include <Main/fgfs.hxx>
+class GUIWidget;
+
+
+/**
+ * User data attached to a GUI object.
+ */
+struct GUIData
+{
+ GUIData (GUIWidget * w, const char * a);
+ GUIWidget * widget;
+ string command;
+};
+
+
+/**
+ * Top-level GUI widget.
+ */
class GUIWidget
{
public:
GUIWidget (SGPropertyNode_ptr props);
virtual ~GUIWidget ();
- virtual void updateProperties ();
- virtual void applyProperties ();
+ virtual void action (const string &command);
private:
-
- void display (SGPropertyNode_ptr props);
-
GUIWidget (const GUIWidget &); // just for safety
-
+ void display (SGPropertyNode_ptr props);
+ virtual void updateProperties ();
+ virtual void applyProperties ();
puObject * makeObject (SGPropertyNode * props,
int parentWidth, int parentHeight);
-
void setupObject (puObject * object, SGPropertyNode * props);
-
void setupGroup (puGroup * group, SGPropertyNode * props,
int width, int height, bool makeFrame = false);
puObject * _object;
-
+ vector<GUIData> _actions;
struct PropertyObject {
PropertyObject (puObject * object, SGPropertyNode_ptr node);
puObject * object;
SGPropertyNode_ptr node;
};
-
vector<PropertyObject> _propertyObjects;
-
};
};
#endif // __NEW_GUI_HXX
+
+// end of new_gui.hxx