From 49a8c070f3b4b5edfe9443cdf5b8fb9ca9b6bf77 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 8 Nov 2002 16:33:00 +0000 Subject: [PATCH] Moved command information into user data. --- src/GUI/new_gui.cxx | 75 ++++++++++++++++++--------------------------- src/GUI/new_gui.hxx | 37 +++++++++++++++------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx index f04672d2e..53c1900cd 100644 --- a/src/GUI/new_gui.cxx +++ b/src/GUI/new_gui.cxx @@ -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) + +//////////////////////////////////////////////////////////////////////// +// Implementation of GUIData. +//////////////////////////////////////////////////////////////////////// + +GUIData::GUIData (GUIWidget * w, const char * c) + : widget(w), + command(c) { - 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); -} - - -/** - * Callback to apply the property values and close the dialog. - */ -static void -close_apply_callback (puObject * object) -{ - 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")); diff --git a/src/GUI/new_gui.hxx b/src/GUI/new_gui.hxx index 51c22f76c..6baf15b82 100644 --- a/src/GUI/new_gui.hxx +++ b/src/GUI/new_gui.hxx @@ -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
+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 _actions; struct PropertyObject { PropertyObject (puObject * object, SGPropertyNode_ptr node); puObject * object; SGPropertyNode_ptr node; }; - vector _propertyObjects; - }; @@ -74,3 +87,5 @@ private: }; #endif // __NEW_GUI_HXX + +// end of new_gui.hxx