<?
/*
GtkTipsQuery test
Markus Fischer <[email protected]>
*/
dl( 'php_gtk.' . (strstr( PHP_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 == 4 && $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_size( 450, 300);
$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( $text, strlen( $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_width( 10);
$tooltips->set_tip( $button[$i], 'This is button #' . ($i+1), '');
$vbuttonbox->pack_start( $button[ $i], false, false);
}
$vbuttonbox->pack_start( $tips, false, false);
// arrange all the buttons and the text box
$hbox = &new GtkHBox;
$hbox->pack_start( $gtext, true, true);
$hbox->pack_start( $vbuttonbox, true, true);
// arrange the rest
$vbox = &new GtkVBox;
$vbox->pack_start( $button_help, false, false);
$vbox->pack_start( $hbox, true, true);
$vbox->pack_start( $button_quit, false, false);
// show everything
$w->add( $vbox);
$w->show_all();
Gtk::main();
?>
|