mail[Wesnoth-commits] r28556 - in /trunk/src/gui: dialogs/editor_resize_map.cpp widgets/widget.hpp


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

Header


Content

Posted by koraq on August 13, 2008 - 19:32:
Author: mordante
Date: Wed Aug 13 18:10:13 2008
New Revision: 28556

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28556&view=rev
Log:
- Fixed the const version of get_widget to return const values.
- Cleaned up the comment of get_widget.
- Since the return must exist, return a reference instead of pointer per 
coding
  style and fix the callers.

Modified:
    trunk/src/gui/dialogs/editor_resize_map.cpp
    trunk/src/gui/widgets/widget.hpp

Modified: trunk/src/gui/dialogs/editor_resize_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_resize_map.cpp?rev=28556&r1=28555&r2=28556&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_resize_map.cpp (original)
+++ trunk/src/gui/dialogs/editor_resize_map.cpp Wed Aug 13 18:10:13 2008
@@ -100,15 +100,15 @@
 
 void teditor_resize_map::pre_show(CVideo& /*video*/, twindow& window)
 {
-       tlabel* old_width = window.get_widget<tlabel>("old_width", false);
-       tlabel* old_height = window.get_widget<tlabel>("old_height", false);
-       height_ = window.get_widget<tslider>("height", false);
-       width_ = window.get_widget<tslider>("width", false);
+       tlabel& old_width = window.get_widget<tlabel>("old_width", false);
+       tlabel& old_height = window.get_widget<tlabel>("old_height", false);
+       height_ = &window.get_widget<tslider>("height", false);
+       width_ = &window.get_widget<tslider>("width", false);
        
        
height_->set_callback_positioner_move(dialog_callback<teditor_resize_map, 
&teditor_resize_map::update_expand_direction>);
        
width_->set_callback_positioner_move(dialog_callback<teditor_resize_map, 
&teditor_resize_map::update_expand_direction>);
-       old_width->set_label(lexical_cast<std::string>(old_width_));
-       old_height->set_label(lexical_cast<std::string>(old_height_));
+       old_width.set_label(lexical_cast<std::string>(old_width_));
+       old_height.set_label(lexical_cast<std::string>(old_height_));
        
        std::string name_prefix = "expand";
        for (int i = 0; i < 9; ++i) {

Modified: trunk/src/gui/widgets/widget.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/widget.hpp?rev=28556&r1=28555&r2=28556&view=diff
==============================================================================
--- trunk/src/gui/widgets/widget.hpp (original)
+++ trunk/src/gui/widgets/widget.hpp Wed Aug 13 18:10:13 2008
@@ -435,29 +435,33 @@
                { return id_ == id ? this : 0; }
                
        /** 
-        * The template counterpart of find_widget(id) with automatic 
dynamic_cast 
-        * and error checking.
+        * Gets a widget with the wanted id.
+        *
+        * This template function doesn't return a pointer to a generic 
widget but
+        * return the wanted type and tests for its existence.
+        *
+        * @param id                  The id of the widget to find.
+        * @param must_be_active      The widget should be active, not all 
widgets
+        *                            have an active flag, those who don't 
ignore
+        *                            flag.
+        * 
+        * @returns                   The widget with the id.
         */
        template <class T>
-       T* get_widget(const std::string& id,
-                                  const bool must_be_active)
+       T& get_widget(const std::string& id, const bool must_be_active)
        {
                T* result = dynamic_cast<T*>(find_widget(id, must_be_active));
                VALIDATE(result, missing_widget(id));
-               return result;
+               return *result;
        }
 
-       /** 
-        * The template counterpart of find_widget(id) with automatic 
dynamic_cast 
-        * and error checking - const version.
-        */
+       /** The const version of get_widget. */
        template <class T>
-       T* get_widget(const std::string& id,
-                                  const bool must_be_active) const
+       const T& get_widget(const std::string& id, const bool must_be_active) 
const
        {
-               T* result = dynamic_cast<T*>(find_widget(id, must_be_active));
+               const T* result = dynamic_cast<const T*>(find_widget(id, 
must_be_active));
                VALIDATE(result, missing_widget(id));
-               return result;
+               return *result;
        }
        
        /** 




Related Messages


Powered by MHonArc, Updated Wed Aug 13 23:02:05 2008