一段用于展示 GTK+ 的帮助说明 (tip) 的代码

<?
/*
GtkTipsQuery test

Markus Fischer <[email protected]>
*/

dl'php_gtk.' . (strstrPHP_OS'WIN') ? 'dll' 'so'));

/* this function gets called when we are in help query mode and actually select a widget */
function tips_query_widget_selected$tipswidget$activated_widget$tipstext$longtiptext$event) {
// only show the longtiptext if a) there is text for it and b) if the button pressed ( type == 4)
if( $event->type == && $longtiptext) {
echo 
$longtiptext "n"flush();
// end help query mode by returning true
return true;
}
}

/* call this function to show the tipsquery widget when we start it */
function tips_query_start$widget) {
$widget->show();
}

/* as soon as the user ends the help query mode, this function is called */
function tips_query_stop$widget) {
// we just hide the tipsquery widget 
$widget->hide();
}

/* Create our main window */
$w = &new GtkWindow;
$w->set_title'GtkTipsQuery Test');
$w->set_default_size450300);
$w->connect'delete_event'create_function'''Gtk::main_quit();'));

// just a normal text entry
$gtext = &new GtkText;
$text = <<<EOT

Select the '?' button and move
the mouse over the other buttons. 

In help query mode, click the
'quit' button.

EOT;
$gtext->insert_text$textstrlen$text), 0);

// our tips label
$tips = &new GtkTipsQuery;
// set alternative labels when there is no widget or, when the widget has no tooltip
$tips->set_labels'No Widget''Widget has no tooltip');
$tips->connect'widget_selected''tips_query_widget_selected');
$tips->connect'start_query''tips_query_start');
$tips->connect'stop_query''tips_query_stop');

// the simple version of tipsquery just displays the widget's tooltip,so we've to create a tooltip group
$tooltips = &new GtkToolTips;

// the button which willl start the tips query mode by calling the tips method 'start_query'
$button_help = &new GtkButton' ? ');
$button_help->connect_object'clicked', array( &$tips'start_query'));
$tips->set_caller$tips);

$tooltips->set_tip$button_help'Actives Help Query''');

// just quit the application
$button_quit = &new GtkButton'Quit');
$button_quit->connect_object'clicked', array( 'Gtk''main_quit'));

$tooltips->set_tip$button_quit'Quit the Application''Here is much information if the user really gets stuck and dont know what to do.');

// arrange the buttons and the tips label
$vbuttonbox = &new GtkVBox;

for( 
$i 0$i 4$i++) {
$button[$i] = &new GtkButton' Button #' . ($i+1) . ' ');
$button[$i]->set_border_width10);
$tooltips->set_tip$button[$i], 'This is button #' . ($i+1), '');
$vbuttonbox->pack_start$button$i], falsefalse);
}
$vbuttonbox->pack_start$tipsfalsefalse);

// arrange all the buttons and the text box
$hbox = &new GtkHBox;
$hbox->pack_start$gtexttruetrue);
$hbox->pack_start$vbuttonboxtruetrue);

// arrange the rest
$vbox = &new GtkVBox;
$vbox->pack_start$button_helpfalsefalse);
$vbox->pack_start$hboxtruetrue);
$vbox->pack_start$button_quitfalsefalse);

// show everything
$w->add$vbox);
$w->show_all();

Gtk::main();

?>