Activate menu bar with ALT key

This enables a user to activate the menu without using the mouse or combining keys, just by pressing ALT. This can be important for accessibility.

<?php

if (!extension_loaded('gtk')) {
 
dl( 'php_gtk.' . PHP_SHLIB_SUFFIX);
  }
 
/**
* test functions
*/
function func1() {
 
$label = &new GtkLabel( 'Go selected');
 
$label->show();
 
$GLOBALS['vbox']->add($label);
  }

function
func2(){
 
$label = &new GtkLabel( 'Clear selected');
 
$label->show();
 
$GLOBALS['vbox']->add($label);
  }

/**
* Body of code
*/

//simple menu items
$menu_info = array(
 
'_Test'=>array(
   
'_Go'=>'func1',
   
'_Clear'=>'func2',
   
'seperator'=>'',
   
'E_xit'=>array('gtk','main_quit'),
  )
);

$window = &new GtkWindow();
$window->set_default_size(350, 450);
$window->connect_object('destroy', array('gtk', 'main_quit'));

//create accegroup for main window
$accelgroup = &new GtkAccelGroup();
$window->add_accel_group($accelgroup);

//add vbox
$vbox = &new GtkVBox(FALSE, 0);
$vbox->show();
$vbox->set_spacing(1);
$window->add($vbox);

$menubar = &new GtkMenuBar();
$menubar->set_shadow_type(GTK_SHADOW_ETCHED_IN);

//make menu

foreach ($menu_info as $title=>$items) {
 
$menu = &new GtkMenuItem($title);
 
$mlabel = $menu->child;
 
$mlabel_key = $mlabel->parse_uline($title);
  if(
$mlabel_key) {
   
//add accel with Alt key
   
$menu->add_accelerator('activate_item', $accelgroup,
     
$mlabel_key, GDK_MOD1_MASK, 0);
   
$menu->lock_accelerators();
  }
 
$menubar->append($menu);
 
$menu->show();
 
$submenu = &new GtkMenu();
 
 
//create a new accelgroup for submenus
 
$accel = $submenu->ensure_uline_accel_group();
  foreach (
$items as $sub_title=>$function) {
    if(
$sub_title == 'seperator') {
     
$item =& new GtkMenuItem();
     
$item->set_sensitive(false);
    } else {
     
$item =& new GtkMenuItem($sub_title);
     
$label = $item->child;
     
$label_key = $label->parse_uline($sub_title);
      if (!empty(
$function)) {
       
$item->connect_object('activate',$function);
        if(
$label_key){
         
$item->add_accelerator('activate_item', $accel, $label_key, 0, 0);
         
$item->lock_accelerators();
        }
      }
    }
   
$submenu->append($item);
   
$item->show();
  }
 
$menu->set_submenu($submenu);

}

$menubar->show();
$vbox->pack_start($menubar,FALSE,FALSE,0);
$window->show_all(); gtk::main();
?>