mail[Wesnoth-commits] r33203 - /trunk/src/gui/widgets/window_builder.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by koraq on March 01, 2009 - 09:23:
Author: mordante
Date: Sun Mar  1 09:23:32 2009
New Revision: 33203

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33203&view=rev
Log:
Retval fixes and cleanups.

The toggle_[panel|button] didn't look at the id and the new
return_value_id, which has been fixed. Added a new helper function to do
this. Also only use return_value_id if it has a valid value.

Modified:
    trunk/src/gui/widgets/window_builder.cpp

Modified: trunk/src/gui/widgets/window_builder.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_builder.cpp?rev=33203&r1=33202&r2=33203&view=diff
==============================================================================
--- trunk/src/gui/widgets/window_builder.cpp (original)
+++ trunk/src/gui/widgets/window_builder.cpp Sun Mar  1 09:23:32 2009
@@ -210,6 +210,33 @@
        }
 }
 
+/**
+ * Returns the return value for a widget.
+ *
+ * If there's a valid retval_id that will be returned.
+ * Else if there's a retval that's returned.
+ * Else it falls back to the id.
+ */
+int get_retval(const std::string& retval_id,
+               const int retval, const std::string& id)
+{
+       if(!retval_id.empty()) {
+               int result = twindow::get_retval_by_id(retval_id);
+               if(result) {
+                       return result;
+               } else {
+                       ERR_G_E << "Window builder: retval_id '"
+                                       << retval_id << "' is unknown.\n";
+               }
+       }
+
+       if(retval) {
+               return retval;
+       } else {
+               return twindow::get_retval_by_id(id);
+       }
+}
+
 } // namespace
 
 twindow* build(CVideo& video, const std::string& type)
@@ -634,13 +661,7 @@
 
        init_control(button);
 
-       if(!retval_id_.empty()) {
-               button->set_retval(twindow::get_retval_by_id(retval_id_));
-       } else if(retval_) {
-               button->set_retval(retval_);
-       } else {
-               button->set_retval(twindow::get_retval_by_id(id));
-       }
+       button->set_retval(get_retval(retval_id_, retval_, id));
 
        DBG_GUI << "Window builder: placed button '" << id << "' with 
defintion '"
                << definition << "'.\n";
@@ -1081,10 +1102,10 @@
        init_control(toggle_button);
 
        toggle_button->set_icon_name(icon_name_);
-       toggle_button->set_retval(retval_);
-
-       DBG_GUI << "Window builder: placed toggle button '" << id << "' with 
defintion '"
-               << definition << "'.\n";
+       toggle_button->set_retval(get_retval(retval_id_, retval_, id));
+
+       DBG_GUI << "Window builder: placed toggle button '" 
+                       << id << "' with defintion '" << definition << "'.\n";
 
        return toggle_button;
 }
@@ -1128,11 +1149,10 @@
 
        init_control(toggle_panel);
 
-       toggle_panel->set_retval(retval_);
-
-       DBG_GUI << "Window builder: placed toggle panel '" << id << "' with 
defintion '"
-               << definition << "'.\n";
-
+       toggle_panel->set_retval(get_retval(retval_id_, retval_, id));
+
+       DBG_GUI << "Window builder: placed toggle panel '"
+                       << id << "' with defintion '" << definition << "'.\n";
 
        log_scope2(gui, "Window builder: building grid for toggle panel.");
 




Related Messages


Powered by MHonArc, Updated Sun Mar 01 09:40:06 2009