一个 GTK+ 的展示菜单应用的代码

<? 
/* id itemfactory.php v 0.0.2 */ 

/* original codesample from Barry Mitchelson, re-hashed by steph for demo 
purposes april 9th 2001, show/hide clues contributed by Markus Fischer april 
11th & subsequently also violently re-hashed ;) */ 

/*I haven't commented a great deal here because most of it seems pretty 
self-explanatory. If there's anything you find hard to follow, please feel free 

to email me ([email protected]) */ 

/* april 12th - added counter to get rid of err msg on first pass - sf */ 

if (strtoupper(substr(PHP_OS03)) == 'WIN'
dl('php_gtk.dll'); 
else 
dl('php_gtk.so'); 

function 
shutdown(){ 
print(
"Shutting down...n"); 
Gtk::main_quit(); 


function 
click_me(){ 
print 
"You clicked me!n"


function 
me_too(){ 
print 
"Why you keeping clicking me?n"


function 
test(){ 
global 
$label
$label->set_text("Some egg! Some chicken!"); 


//Option Menu 
function opt_bar(){ 
global 
$window$vpane$accel$label$menubar$option$count
$window->set_title("ItemFactory Sample - GtkOptionMenu"); 
$label->set_text(".... or whatever ....."); 
$vpane->remove($menubar); 
$count++; 

$opt_items = array( 
//array("/File","",NULL,0,"<Item>"), 
array("/File","",NULL,0,"<Branch>"), 
array(
"/File/Click me","",click_me,0,""), 
array(
"/File/Me too","",me_too,0,""), 
array(
"/Next item on list does test","",test,0,"<Item>"), 
array(
"/Back to MenuBar","",m_bar,0,"<Item>"), 
array(
"/Way out","",shutdown,0,"<Item>"
); 

$opt = &new GtkOptionMenu(); 
$item_factory = &new GtkItemFactory($opt->get_type(),"<omenu>",$accel); 
$item_factory->create_items($opt_items); 
$option $item_factory->get_widget("<omenu>"); 
$option->set_usize(0,30); 
$vpane->add1($option); 
$option->show(); 



//Menu Bar 
function m_bar() { 
global 
$window$vpane$accel$label$option$menubar$count
$window->set_title("ItemFactory Sample - GtkMenuBar"); 
$label->set_text("All things counter, original, spare or strange ...."); 

//this gives an error message (warning) on the first pass without the counter 
if ($count 0
$vpane->remove($option); 
$count++; 

$menu_items = array( 
array(
"/File","",NULL,0,"<Branch>"), 
array(
"/File/Click me","",click_me,0,""), 
array(
"/File/Me too","",me_too,0,""), 
array(
"/Next","",NULL,0,"<Branch>"), 
array(
"/Next/OptionMenu","",opt_bar,0,""), 
array(
"/Way out","",shutdown,0,"<Item>"
); 

$bar = &new GtkMenuBar(); 
$item_factory = &new GtkItemFactory($bar->get_type(),"<mbar>",$accel); 
$item_factory->create_items($menu_items); 
$menubar $item_factory->get_widget("<mbar>"); 
$menubar->set_usize(0,30); 
$vpane->add1($menubar); 
$menubar->show(); 



//The window etc to bung it all into 
$window = &new GtkWindow(); 
$window->connect('destroy'shutdown); 
$window->set_position(GTK_WIN_POS_CENTER); 
$window->set_usize(400,450); 
$window->set_policy(FALSE,TRUE,FALSE); 

$box = &new GtkVBox(); 
$window->add($box); 
$box->show(); 

$vpane= &new GtkVPaned(); 
$vpane->set_border_width(0); 
$vpane->set_handle_size(0); 
$box->add($vpane); 
$vpane->show(); 

$accel = &new GtkAccelGroup(); 
$window->add_accel_group($accel); 

$label = &new GtkLabel(""); 
$label->set_line_wrap(TRUE); 

$scrl_win = &new GtkScrolledWindow(); 
$scrl_win->set_policy(GTK_POLICY_AUTOMATICGTK_POLICY_AUTOMATIC); 
$col1 = &new GdkColor(55000,0,0); 
$col2 = &new GdkColor(0,0,55000); 
$style $scrl_win->style
$style->bg[GTK_STATE_NORMAL] = $col1
$style->fg[GTK_STATE_NORMAL] = $col2
$vpane->add2($scrl_win); 
$scrl_win->show(); 
$scrl_win->add_with_viewport($label); 
$label->show(); 

$window->show_all(); 

//Set the opening menu system up 
m_bar(); 

$count=0
$count=(int)$count

Gtk::main(); 

?>