17 feb. 2010 : PHP-GTK Application descriptions can now be submitted in Brazilian Portuguese too. Thanks Bruno Bandeira !.

German and Italian still missing: who will contribute the translated categories for these languages ? Contact the team to offer your translations !

How to empty a GtkHBox or GtkVBox

These examples show how to empty instances of classes derived from GtkContainer.

A simple function to empty Box widgets

<?php
function empty_widget($widget) {
  if (
count($widget->children()) != 0) {
    while ((
$child=$widget->children[0]->widget) != NULL) {
     
$widget->remove($child);
      }
    }
  }
?>

A more flexible but more complex solution

The next function allow you to use it as a callback function and allow you to preserve the childs widget by passing FALSE as the last parameter.

<?php
/**
* remove and optionnally destroy all child from a widget
* @param GtkWidget &$call_widget is the calling widget
*     or if is the only Gtkcontainer is the one to empty
* @param GtkContainer [&$target_widget] is the gtkcontainer
*   to empty if only one Gtkwidget is passed and is a
*   Gtkcontainer it would be this one by default
* @param bool $destroy_childs default is TRUE
*   so the childs widget will be destroy by default,
*   pass FALSE as last argument to preserve childs widgets
* @licence LGPL
**/
function empty_widget(&$call_widget) {
 
# If we receive only one arguments it must be the target widget
 
$n = func_num_args();
  if(
$n>1) {
    if (!
is_bool($destroy_childs = func_get_arg($n-1)))
      unset(
$destroy_childs);
    }
  switch(
$n) {
    case
1:
      if (!
is_a($call_widget,"GtkContainer"))
        return
FALSE;
     
$widget = &$call_widget;
     
$destroy_childs = TRUE;
      break;
    case
2:
      if (
is_bool($destroy_childs = func_get_arg(1))) {
        if (!
is_a($widget = func_get_arg(0),"GtkContainer"))
          return
FALSE;
      } elseif (
is_a($destroy_childs,"GtkContainer")) {
       
$widget = &$destroy_childs;
       
$destroy_childs = TRUE;
      } else {
        return
FALSE;
      }
      break;
    case
3:
      if (
is_bool($destroy_childs = func_get_arg(2)))
        if (!
is_a($widget = func_get_arg(1),"GtkContainer"))
          return
FALSE;
        else
          return
FALSE;
        break;
    default:
      return
FALSE;
  }

  if (
count($widget->children())!=0) {
    while (
is_a(($child=$widget->children[0]->widget),
     
"GtkWidget")) {
     
$widget->remove($child);
      if(
$destroy_childs)
       
$child->destroy();
      }
    return
TRUE;
  } else {
    return
FALSE;
  }
}
?>