Add the tgrid::swap_child() function.

This commit is contained in:
Mark de Wever 2008-09-13 08:23:54 +00:00
parent 882aa8550a
commit 2bf9f805c4
2 changed files with 55 additions and 0 deletions

View file

@ -110,6 +110,44 @@ void tgrid::set_child(twidget* widget, const unsigned row,
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)
{
assert(row < rows_ && col < cols_);

View file

@ -113,6 +113,23 @@ public:
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.
*