GtkItemFactory Constructor

GtkItemFactory Constructor

GtkItemFactory (GtkType container_type, String path, GtkAccelGroup accel_group);

Creates a new instance of the GtkItemFactory class. One factory can be used for one menu, and not more. This means that if you want to have a standard GtkMenuBar at the top of a window and an additional right-click popup menu, you have to use 2 item factories.

The container_type determines, which type the root menu will have: GtkMenu, GtkMenuBar or GtkOptionMenu. To get the GtkType you want, just use the the get_type() function of this class:
$type = GtkMenuBar::get_type();     

The path is a unique name for this menu, enclosed in < and >, e.g. <mainmenu>. This path has to be unique in the whole application.

The accel_group is the accelerator group belonging to this window and is responsible for the menu shortcuts. It can be NULL, but then the menu shortcuts won't work.

Example 18. Using a GtkItemFactory

<?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 quit( $number, $item) {
	gtk::main_quit();
}
$arItems	= array(
array( "/_File/_Open", null, null, 0, null ),
array( "/_File/_Save", null, null, 0, null ),
array( "/_File/_Quit", "<CTRL>Q", 'quit', 0, null )
);

$fac->create_items( $arItems);

$window->add( $fac->get_widget( "<mainmenu>"));
$window->show_all();
gtk::main();
?>

A more sophisticated example can be found at the create_items() function.

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