creates an empty popup container widget that will exclusively hold GtkMenuItems. It may be instantiated alone as an event-driven popup menu (see the example below) or it can be associated with a higher-level GtkMenuItem as a submenu, or a GtkOptionMenu as a menu. When it is associated with an object in this way, the menu will pop up in response to the object's activation.
Ejemplo 23. Creating a right-click popup menu
<?php if( !extension_loaded('gtk')) { dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); } function show_popup($event, $menu) { if($event->button == 3) { $menu->popup(null, null, null, $event->button, $event->time); } } $window = &new GtkWindow(); $window->set_default_size(350, 450); $window->connect_object('destroy', array('gtk', 'main_quit')); $menu = &new GtkMenu(); $accel = $menu->ensure_uline_accel_group(); $open = &new GtkMenuItem("Open"); $open->lock_accelerators(); $menu->append($open); $save = &new GtkMenuItem("Save as ..."); $save->lock_accelerators(); $menu->append($save); $separator = &new GtkMenuItem(); $separator->set_sensitive(false); $menu->append($separator); $exit = &new GtkMenuItem(""); $accel_label = $exit->child; $accel_key = $accel_label->parse_uline("E_xit"); $exit->add_accelerator('activate', $accel, $accel_key, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); $exit->lock_accelerators(); $exit->connect_object('activate', array('gtk', 'main_quit')); $menu->append($exit); $menu->show_all(); $label = &new GtkLabel( 'Right-click here to see the menu'); $window->add( $label); $window->add_events(GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); $window->connect_object('button-press-event', 'show_popup', $menu); $window->show_all(); gtk::main(); ?> |