Use this constructor to create a new GtkEventBox.
Example 61. A Demonstration of usage of the event box.
<?php
//Initialising the event box and adding an image to it
$imageEvent = new GtkEventBox();
$imageWidget = GtkImage::new_from_stock(
Gtk::STOCK_DIALOG_WARNING,
Gtk::ICON_SIZE_DIALOG
);
$imageEvent->add($imageWidget);
//Initialising another event box and adding a label to it
$labelEvent = new GtkEventBox();
$labelWidget = new GtkLabel('Click something!');
$labelEvent->add($labelWidget);
//Connecting the signals to the callback
$imageEvent->connect('button_press_event', 'doSomething');
$labelEvent->connect('button_press_event', 'doSomething');
//The callback function
function doSomething($widget, $event)
{
//Determine which widget triggered the signal
$widget = $widget->get_child()->get_name();
if ($widget == 'GtkImage') {
$type = 'image';
} else {
$type = 'label';
}
//Show a dialog that displays a message
$dialog = new GtkMessageDialog(
null,
0,
Gtk::MESSAGE_INFO,
Gtk::BUTTONS_OK,
'You clicked the ' . $type . '!'
);
$dialog->run();
$dialog->destroy();
}
//Creating a VBox to add the event boxes to
$vbox = new GtkVBox();
$seperator = new GtkHSeparator();
$vbox->pack_start($imageEvent);
$vbox->pack_start($seperator);
$vbox->pack_start($labelEvent);
//Creating a window and adding the VBox to it
$window = new GtkWindow();
$window->add($vbox);
$window->set_position(Gtk::WIN_POS_CENTER);
$window->set_default_size(200,150);
$window->show_all();
$window->set_title("Event Boxes!");
$window->connect_simple(
'destroy',
array('Gtk', 'main_quit')
);
//Starting main loop
Gtk::main();
?>
|