Author: mordante
Date: Sat Sep 13 10:23:54 2008
New Revision: 29433

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29433&view=rev
Log:
Add the tgrid::swap_child() function.

Modified:
    trunk/src/gui/widgets/grid.cpp
    trunk/src/gui/widgets/grid.hpp

Modified: trunk/src/gui/widgets/grid.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.cpp?rev=29433&r1=29432&r2=29433&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.cpp (original)
+++ trunk/src/gui/widgets/grid.cpp Sat Sep 13 10:23:54 2008
@@ -108,6 +108,44 @@
        }
 
        clear_cache();
+}
+
+twidget* tgrid::swap_child(
+               const std::string& id, twidget* widget, const bool recurse)
+{
+       assert(widget);
+
+       foreach(tchild& child, children_) {
+               if(child.id() != id) {
+
+                       if(recurse) {
+                               // decent in the nested grids.
+                               tgrid* grid = 
dynamic_cast<tgrid*>(child.widget());
+                               if(grid) {
+
+                                       twidget* old = grid->swap_child(id, 
widget, true);
+                                       if(old) {
+                                               return old;
+                                       }
+                               }
+                       }
+
+                       continue;
+               }
+
+               // When find the widget there should be a widget.
+               twidget* old = child.widget();
+               assert(old);
+               old->set_parent(NULL);
+
+               widget->set_parent(this);
+               child.set_widget(widget);
+               child.set_id(widget->id());
+
+               return old;
+       }
+
+       return NULL;
 }
 
 void tgrid::remove_child(const unsigned row, const unsigned col)

Modified: trunk/src/gui/widgets/grid.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.hpp?rev=29433&r1=29432&r2=29433&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.hpp (original)
+++ trunk/src/gui/widgets/grid.hpp Sat Sep 13 10:23:54 2008
@@ -112,6 +112,23 @@
         */
        void set_child(twidget* widget, const unsigned row, 
                const unsigned col, const unsigned flags, const unsigned 
border_size);
+
+       /**
+        * Exchangs a child in the grid.
+        *
+        * It replaced the child with a certain id with the new widget but 
doesn't
+        * touch the other settings of the child.
+        *
+        * @param id                  The id of the widget to free.
+        * @param widget              The widget to put in the grid.
+        * @parem recurse             Do we want to decent into the child grids.
+        *
+        * returns                    The widget which got removed (the parent 
of
+        *                            the widget is cleared). If no widget found
+        *                            and thus not replace NULL will returned.
+        */
+       twidget* swap_child(
+               const std::string& id, twidget* widget, const bool recurse);
 
        /**
         * Removes and frees a widget in a cell.


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to