Use the constructor to generate a new menu item with an icon. You may pass a string as the label, or a stock id, if you want to use the existing stock icons.
You may even precede a character of the label with an _ to indicate the mnemonic for the menu item.
Example 76. Creating image menu items
<?php
//Example: using GtkSeparatorMenuItems to
// separate menu items
//Create a menu bar
$mbar = new GtkMenuBar();
//Add a menu item
$file = new GtkMenuItem('_File');
//with a submenu
$fmenu = new GtkMenu();
$file->set_submenu($fmenu);
$mbar->add($file);
//Now, we create a "normal" file menu:
// New, Open, Save, Save As, Quit
//To make it visually appealing, we separate
// the items with GtkSeparatorMenuItems
$fmenu->add(new GtkImageMenuItem(Gtk::STOCK_NEW));
$fmenu->add(new GtkImageMenuItem(Gtk::STOCK_OPEN));
$fmenu->add(new GtkSeparatorMenuItem());
$fmenu->add(new GtkImageMenuItem(Gtk::STOCK_SAVE));
$fmenu->add(new GtkImageMenuItem(Gtk::STOCK_SAVE_AS));
$fmenu->add(new GtkSeparatorMenuItem());
$fmenu->add(new GtkImageMenuItem(Gtk::STOCK_QUIT));
//standard stuff
$wnd = new GtkWindow();
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));
$wnd->add($mbar);
$wnd->show_all();
Gtk::main();
?> |