<?php
dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));
/* callback that forces a redraw of simple child widgets */
function exposure($adj, $layout) {
$layout->queue_draw();
}
/* set up a window and size it to be smaller than the intended layout */
$window = &new GtkWindow();
$window->set_position(GTK_WIN_POS_CENTER);
$window->set_title('Layout');
$window->set_usize(200, 200);
$window->connect_object('destroy', array('gtk', 'main_quit'));
/* create and add the scrolled window to the main window */
$scrolledwindow = &new GtkScrolledWindow();
$window->add($scrolledwindow);
/* create and add the layout widget to the scrolled window */
$layout = &new GtkLayout(null, null);
$scrolledwindow->add($layout);
/* set the layout to be bigger than the windows that contain it */
$x = gdk::screen_width();
$y = gdk::screen_height();
$layout->set_size($x, $y);
/* get the adjustment objects and connect them to the callback. This
part should not be necessary under *nix systems */
$hadj = $scrolledwindow->get_hadjustment();
$vadj = $scrolledwindow->get_vadjustment();
$hadj->connect('value-changed', 'exposure', $layout);
$vadj->connect('value-changed', 'exposure', $layout);
/* populate the layout with a mixture of buttons and labels */
for ($i=0 ; $i < round($y/100); $i++) {
for ($j=0 ; $j < round($x/100); $j++) {
$buf =sprintf('Button %d, %d', $i, $j);
if (($i + $j) % 2) $button = &new GtkButton($buf);
else $button = &new GtkLabel($buf);
$layout->put($button, $j*100, $i*100);
}
}
/* display everything and run the main loop */
$layout->show_all();
$window->show_all();
gtk::main();
?>
|