]> git.mxchange.org Git - flightgear.git/commitdiff
Moved command information into user data.
authordavid <david>
Fri, 8 Nov 2002 16:33:00 +0000 (16:33 +0000)
committerdavid <david>
Fri, 8 Nov 2002 16:33:00 +0000 (16:33 +0000)
src/GUI/new_gui.cxx
src/GUI/new_gui.hxx

index f04672d2e0ee064677fae11eb9f0070c54cce981..53c1900cd10f4627805e11490124feb9f9aaccda 100644 (file)
@@ -17,46 +17,26 @@ SG_USING_STD(vector);
 // 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);
 }
 
 
@@ -95,6 +75,21 @@ GUIWidget::display (SGPropertyNode_ptr props)
     }
 }
 
+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 ()
@@ -170,8 +165,6 @@ GUIWidget::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight
 void
 GUIWidget::setupObject (puObject * object, SGPropertyNode * props)
 {
-    object->setUserData(this);
-
     if (props->hasValue("legend"))
         object->setLegend(props->getStringValue("legend"));
 
@@ -186,17 +179,9 @@ GUIWidget::setupObject (puObject * object, SGPropertyNode * props)
     }
 
     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"));
index 51c22f76cd706e4bbd2ca3aab8c1851cc28880ce..6baf15b8222861f2a484bd9a6d791e82720c4728 100644 (file)
@@ -1,3 +1,5 @@
+// new_gui.hxx - XML-configurable GUI subsystem.
+
 #ifndef __NEW_GUI_HXX
 #define __NEW_GUI_HXX 1
 
@@ -19,39 +21,50 @@ SG_USING_STD(map);
 #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;
-
 };
 
 
@@ -74,3 +87,5 @@ private:
 };
 
 #endif // __NEW_GUI_HXX
+
+// end of new_gui.hxx