Writing a class extension
| From: | Michael Dransfield | Date: | Sun, 26 May 2002 10:31:54 +0000 |
| Subject: | Writing a class extension | ||
| Groups: | php.gtk.dev | ||
| Request: | Send a blank email to php-gtk-dev+get-410@lists.php.net to get a copy of this message | ||
I am trying to extend the GtkMenuBar object so that I can add an array of values to a menu.
For example.
====== CLASS CODE ======
<?php
class GtkMenuBarExt extends GtkMenuBar{
function fill_from_array($items){
if (!is_array($items)){
return false;
}
foreach ($items as $menu_name => $menu_array){
$menu =& new GtkMenu();
foreach ($menu_array as $item_name => $item_label){
$item =& new GtkMenuItem($item_label);
$item->show();
$menu->append($item);
}
$menu->show();
parent::add($menu);
}
}
}
?>
====== MAIN SCRIPT ========
$menubar =& new GtkMenuBarExt();
$menu_items = Array("file" => Array("new" => "New", "save" => "Save"), "help" => Array("help_contents" => "Help", "about" => "About..."));
$menubar->fill_from_array($menu_items);
$menubar->show();
//// pack this into the window etc
==========================
I have tried everything, but the menu doesn't seem to have the array items added. Am I losing a reference somewhere, or is this something php-gtk can't do?
Mike