GtkOptionMenu Constructor

GtkOptionMenu Constructor

Constructing a GtkOptionMenu is less complicated that creating most other forms of menu.

Example 31. Creating a simple GtkOptionMenu.

<?php

dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));

function echo_activated($item, $label, $rank, $x) {
    echo "\$items[$x] ('$label') is the $rank 
".$item->get_name().".\n";
    flush();
}

$window = &new GtkWindow();
$window->set_position(GTK_WIN_POS_CENTER);
$window->connect_object('destroy', array('gtk', 'main_quit'));

$menu = &new GtkMenu();
$labels = array('File', 'Edit', 'Save', 'Exit');
$pos = array('first', 'second', 'third', 'fourth');
for($i = 0; $i < 4; $i++) {
$items[$i] = &new GtkMenuItem($labels[$i]);
$items[$i]->connect('activate', 'echo_activated', $labels[$i], $pos[$i], 
$i);
$menu->append($items[$i]);
}
$menu->show_all();

$optionmenu = &new GtkOptionMenu();
$optionmenu->set_menu($menu);
$window->add($optionmenu);

$window->show_all();
gtk::main();

?>

© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.