<?php
if( !extension_loaded('gtk')) {
dl( 'php_gtk.' . PHP_SHLIB_SUFFIX);
}
$window = &new GtkWindow();
$window->set_default_size( 300, 20);
$window->connect_object('destroy', array('gtk', 'main_quit'));
$accelgroup = &new GtkAccelGroup();
$window->add_accel_group( $accelgroup);
$fac = &new GtkItemFactory( GtkMenuBar::get_type(), '<mainmenu>', $accelgroup);
function menucall( $number, $item) {
switch( $number) {
case 1: echo 'New file'; break;
case 15: echo 'This is a small GtkItemFactory example'; break;
case 20: gtk::main_quit(); break;
default: echo 'Unknown action ' . $number;
}
echo "\r\n";
}
$arItems = array(
array( '/_File/_New', '<CTRL>N', 'menucall', 1, null ),
array( '/_File/_Open', '<CTRL>O', 'menucall', 2, '' ),
array( '/_File/sep1', null, null, 0, '<Separator>' ),
array( '/_File/_Save', '<CTRL>S', 'menucall', 0, null ),
array( '/_File/Save _as', null, 'menucall', 0, null ),
array( '/_File/sep2', null, null, 0, '<Separator>' ),
array( '/_File/_Quit', '<CTRL>Q', 'menucall', 20, null ),
array( '/_View', null, null, 0, '<Branch>' ),
array( '/_View/tearoff', null, null, 0, '<Tearoff>' ),
array( '/_View/_Toolbar', null, null, 0, '<CheckItem>' ),
array( '/_View/_Preview', null, null, 0, '<CheckItem>' ),
array( '/_Colors/tearoff', null, null, 0, '<Tearoff>' ),
array( '/_Colors/Foreground', null, null, 0, '<Title>' ),
array( '/_Colors/White', null, null, 0, '<RadioItem>' ),
array( '/_Colors/Yellow', null, null, 0, '/Colors/White' ),
array( '/_Colors/Orange', null, null, 0, '/Colors/White' ),
array( '/_Colors/sep1', null, null, 0, '<Separator>' ),
array( '/_Colors/Background', null, null, 0, '<Title>' ),
array( '/_Colors/Black', null, null, 0, '<RadioItem>' ),
array( '/_Colors/Blue', null, null, 0, '/Colors/Black' ),
array( '/_Colors/Red', null, null, 0, '/Colors/Black' ),
array( '/_Help', null, null, 0, '<LastBranch>' ),
array( '/_Help/_About', 'F1', 'menucall', 15, '<Item>' )
);
$fac->create_items( $arItems);
//By default, the first item of a radio group is selected. We change this
$mnuColorRed = $fac->get_widget( '/Colors/Red');
$mnuColorRed->set_active( true);
$arMoreItems = array(
array( '/_View/sep1', null, null, 0, '<Separator>' ),
array( '/_View/more/items/are/appended/here', null, null, 0, null)
);
$fac->create_items( $arMoreItems);
$window->add( $fac->get_widget( "<mainmenu>"));
$window->show_all();
gtk::main();
?>
|