Creating a GtkList widget is straightforward, populating it slightly less so. Each item added to the list container must itself be contained in a GtkListItem. In its simplest and most common form, all that means is that the GtkListItem is created with a label, the text content of which will be displayed in the list.
Ejemplo 22. Constructing a GtkList
<?php if( !extension_loaded('gtk')) { dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); } function echo_it($list, $listitem) { /* collect the text from the selected list item's label */ $listlabel = $listitem->child; /* filter list items according to child object type */ if($listlabel->get_name() == 'GtkLabel') { $name = $listlabel->get(); $label = &new GtkLabel("You chose $name just now"); /* create a popup window and display a message relevant to selected item */ $popup = &new GtkWindow(GTK_WINDOW_POPUP); $popup->set_uposition((gdk::screen_width()/2)+50, (gdk::screen_height()/3)); $popup->add($label); $popup->show_all(); /* connect the list item's own deselect signal (not the list's) */ $listitem->connect_object('deselect', create_function('$popup', '$popup->destroy();'), $popup); } else gtk::main_quit(); } $window = &new GtkWindow(GTK_WINDOW_DIALOG); $window->set_position(GTK_WIN_POS_CENTER); $window->connect_object('destroy', array('gtk', 'main_quit')); $list = &new GtkList(); /* the contents of this array will populate the list */ $fill = array('Angela', 'Belinda', 'Carolyn', 'Danike', 'Etha', 'Fiona', 'Gertraud', 'Heidi', 'Jessica', 'Kirstin', 'Lorinda', 'Marianne'); foreach(range(0, count($fill)-1) as $i) $listitem[] = &new GtkListItem($fill[$i]); $list->append_items($listitem); $enditem = &new GtkListItem(); /* a list item is also a container */ $button = &new GtkButton('Close'); $enditem->add($button); /* there is no way to append() a single item - but GtkList is a container widget, so it's okay to use add() */ $list->add($enditem); $list->connect('select-child', 'echo_it'); $list->show_all(); $window->add($list); $window->show_all(); gtk::main(); ?> |