GtkSocket Constructor

GtkSocket Constructor

GtkSocket (void);

Creates a new socket instance. Note that you have to realize the socket after you have added the widget to a parent container.

The other part of the example can be found at the constructor of the GtkPlug widget.

Example 38. How to use a GtkSocket

<?php
if( !extension_loaded('gtk')) {	
	dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); 
}

function checkSocketState( $objButton, $objSocket, $lblStatus)
{
	if( $objSocket->window == null) {
		$lblStatus->set_text( 'The plug has disconnected');
	} else if( count( $objSocket->window->children) > 0) {
		$lblStatus->set_text( 'The plug has plugged in');
	} else {
		$lblStatus->set_text( 'Nobody plugged in');
	}
}

$objSocket		= &new GtkSocket();

$window	= &new GtkWindow();
$window->set_title( 'socket window');
$window->set_default_size( 300, 300);
$window->connect_object('destroy', array('gtk', 'main_quit'));

$vbox = &new GtkVBox();
$vbox->pack_start_defaults( $objSocket);

$lblStatus = &new GtkLabel( 'status messages go here');
$vbox->pack_start_defaults( $lblStatus);

$btnCheck = &new GtkButton( 'check socket state');
$btnCheck->connect( 'clicked', 'checkSocketState', $objSocket, $lblStatus);
$vbox->pack_start_defaults( $btnCheck);

$window->add( $vbox);
$window->show_all();

function unrealized( $objSocket, $btnCheck, $lblStatus) {
	echo 'The plug has disconnected' . "\r\n";
	checkSocketState( $btnCheck, $objSocket, $lblStatus);
}
$objSocket->connect( 'unrealize', 'unrealized', $btnCheck, $lblStatus);

//realize *after* adding it to a box or window
$objSocket->realize();

$socketid = $objSocket->window->xid;
echo 'socket id to use: ' . $socketid . "\r\n";

if( $GLOBALS['argc'] == 2) {
	//steal the given window
	$objSocket->steal( $GLOBALS['argv'][1]);
}

checkSocketState( null, $objSocket, $lblStatus);

gtk::main();
?>
© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.