<?php
/**
@description (pt_BR) - Classe para ajudar na criação de janelas em PHP-GTK1
@description (en) - Class to help with the window creation in PHP-GTK1
@license GPL
@language PHP(GTK)
@author Christian Weiske <hide@address.com>
@comments (pt_BR) Essa classe foi criada com base no WidgetHTML
@comments (en) Class created with help of WidgetHtml
@date 03/09/2006
*/
class GtkCallback {
var $arCallbacks = array();
var $nCallbackHandlerId = 0;
var $arConnectObjects = array();
function connect( $strSignal, $objCallback,$bConnectObject = false)
{
switch( $strSignal)
{
default:
//register it
$this->arCallbacks[$strSignal][ ++$this->nCallbackHandlerId] = &$objCallback;
$this->arConnectObjects[$this->nCallbackHandlerId] = $bConnectObject;
return $this->nCallbackHandlerId;
break;
/*default:
trigger_error( 'Signal "' . $strSignal . '" does not exist');
return;*/
}
}
function connect_object( $strSignal, $objCallback)
{
return $this->connect( $strSignal, $objCallback, true);
}//function connect_object( $strSignal, $objCallback)
function disconnect( $nHandlerId)
{
foreach( $this->arCallbacks as $strSignal => $arHandler)
{
if( isset( $arHandler[$nHandlerId])) {
//we've found it
unset( $this->arCallbacks[$strSignal][$nHandlerId]);
return true;
}
}
return false;
}
function doCallback( $strSignal, $param1 = null, $param2 = null, $param3 = null)
{
if( !isset( $this->arCallbacks[$strSignal]) || count( $this->arCallbacks[$strSignal]) == 0) {
//nothing to do
return false;
}
foreach( $this->arCallbacks[$strSignal] as $nHandlerId => $objCallback)
{
$objCallback = &$this->arCallbacks[$strSignal][$nHandlerId];
$bConnectObject = $this->arConnectObjects[$nHandlerId];
if( is_array( $objCallback))
{
//array
$objFirst = &$objCallback[0];
$objFunction = &$objCallback[1];
if( is_string( $objCallback[0])) {
//first element is string -> no object -> static function
trigger_error( 'static class methods are not supported for callbacks');
continue;
if( $bConnectObject) {
objFirst::$objFunction( $param1, $param2, $param3);
} else {
objFirst::$objFunction( $this, $param1, $param2, $param3);
}
} else {
//real object
if( $bConnectObject) {
//don't pass the object
$objFirst->$objFunction( $param1, $param2, $param3);
} else {
$objFirst->$objFunction( $this, $param1, $param2, $param3);
}
}
} else {
//should be string
if( $bConnectObject) {
//omit the object
$objCallback( $param1, $param2, $param3);
} else {
$objCallback( $this, $param1, $param2, $param3);
}
}
}//foreach handler
//we had one
return true;
}//function doCallback( $strSignal, $param1
}
/**
@description (pt_BR) - Classe para ajudar na criação de janelas em PHP-GTK1
@description (en) - Class to help with the window creation in PHP-GTK1
@license GPL
@language PHP(GTK)
@author Max Miller <hide@address.com>
@comments (pt_BR) Qualquer duvida mande um e-mail para hide@address.com a classe é facil de usar
@comments (en) Any Doughts, send a email to hide@address.com the class is very easy to use
@date 03/09/2006
*/
class Window extends GtkCallback {
function button($label,$image = null,$window = null,$style = null,$font_size = 100,$font_name = 'helvetica') {
if ( $image != "" && $label != "") {
$image = $this->gtk_image($image,$window);
$label = $this->label($label,$style,$font_size,$font_name);
$vbox = new GtkVbox();
$vbox->pack_start($image);
$vbox->pack_end($label,false);
$button = new GtkButton();
$button->add($vbox);
return $button;
}
elseif ( $image != "" && $label == "") {
$image = $this->gtk_image($image,$window);
$button = new GtkButton();
$button->add($image);
}
else {
$label = $this->label($label,$style,$font_size,$font_name);
$button = new GtkButton();
$button->add($label);
return $button;
}
}
/* I stopped here because i was a little confused?*/
//Pay Attention, this function does not work !!!!
function alert($message) {
$j = $this->new_window('Alerta','300','100',GTK_WIN_POS_NONE);
$j->set_position(GTK_WIN_POS_MOUSE);
$j->set_policy(false,false,false);
$button = $this->button('Ok');
$label = $this->Label($message,'bold','120','helvetica');
$label->set_line_wrap(true);
$image = $this->gtk_image('./images/alerta.xpm',null);
$hbox = new GtkHbox();
$hbox->pack_start($image);
$hbox->pack_end($label,false);
$vbox = new GtkVbox();
$vbox->pack_start($hbox);
$vbox->pack_end($button,false);
$j->add($vbox);
$button->connect_object('clicked',array(&$j,'destroy'));
$j->show_all();
}
function gtk_image($image,$window) {
$pixmap = file2pixmap($window->window,
$image,null,true);
return $pixmap;
}
function new_window($title,$x = 500,$y = 300,$pos = GTK_WIN_POS_CENTER) {
$window = new GtkWindow($pos);
$window->set_title($title);
$window->set_usize($x,$y);
$window->realize();
list($pxWindow, $maskWindow) = file2pixmap($window->window,'./images/ico.xpm',null,false);
$gdkwindow = $window->window;
$gdkwindow->set_icon($gdkwindow,$pxWindow,$maskWindow);
return $window;
}
function status_bar() {
$status = new GtkStatusBar();
return $status;
}
/*update_statusbar
@param text = texto a ser exibido
@param status = classe da status bar
*/
function update_statusbar($text,$status) {
$status->pop($status->get_context_id(''));
$status->push($status->get_context_id(''),$text);
$this->update();
}
function update() {
while(gtk::events_pending() ) {
gtk::main_iteration();
}
}
function ProgressBar_Start($annex_on,$hor_pos,$ver_pos,$progress=0,$num_blocks = NULL) {
$this->adjust = new GtkAdjustment(0,0,100,1,0,0);
$this->progress = new GtkProgressBar($this->adjust);
$this->progress->set_();
}
function pop_fixed($fix) {
$number = count($fix->children);
/*O Loop eh so para poder excluir todos os elementos afinal o fixed se rearranja quando um elemento eh excluido*/
for($i = 1; $i <= $number; $i++ ) {
$fix->remove($fix->children[0]->widget);
}
$this->update();
}
function pop_layout($layout) {
$child = $layout->children();
$child2 = $layout->children();
for ( $i = 1; $i <= count($child); $i++ ) {
$layout->remove($child2[0]);
$child2 = $layout->children();
}
}
function __see($num,$j) {
$this->res = $num;
$j->destroy();
}
function question($question) {
$j = $this->new_window('Pergunta','300','100');
$label = new GtkLabel($question . "\n\n");
$button_ok = new GtkButton('Sim');
$button_ok->set_usize('150','30');
$button_no = new GtkButton('Nao');
$button_no->set_usize('150','30');
$vbox = new GtkVbox();
$hbox = new GtkHbox();
$hbox->pack_start($button_ok);
$hbox->pack_end($button_no,false);
$vbox->pack_start($label);
$vbox->pack_end($hbox,false);
$j->add($vbox);
$button_ok->connect_object('clicked',array(&$this,'__see'),'0',$j);
$button_no->connect_object('clicked',array(&$this,'__see'),'1',$j);
$j->show_all();
$j->connect_object('destroy','return',$this->res);
return($this->res);
}
function normal_toolbar($array_elements,$window = NULL) {
if ( !is_array($array_elements) ) {
error_log('O Primeiro elemento tem que ser uma array');
return false;
}
elseif ( !is_object($window) ) {
error_log('O Segundo elemento tem que ser um objeto GtkWindow');
return false;
}
else {
$hbox = new GtkHbox();
for( $i = 0; $i < count($array_elements); $i++ ) {
$array[$i] = $this->button($array_elements[$i][0],$array_elements[$i][1],$window);
$hbox->pack_start($array[$i]);
}
return $hbox;
}
}
function label($text,$style = "",$font = 140,$font_name = '*',$extra = 'r',$width = '-1',$height='-1',$align = GTK_JUSTIFY_LEFT) {
$label = new GtkLabel($text);
if ( $style == "bold" ) {
$label_style = new GtkStyle();
$label_style->font = gdk::font_load("-*-" . $font_name . "-bold-" . $extra . "-*-*-*-" . $font . "-*-*-*-*-*-*");
$label->set_style($label_style);
}
elseif ( $style == "link" ) {
$label_style = new GtkStyle();
$label_style->font = gdk::font_load("-*-" . $font_name . "-bold-*-*-*-*-" . $font . "-*-*-*-*-*-*");
$label_style->fg[GTK_STATE_NORMAL] = new GdkColor('blue');
$label->set_style($label_style);
}
elseif ( $style = 'italic' ) {
$label_style = new GtkStyle();
$label_style->font = gdk::font_load("-*-*-bold-i-*-*-*-" . $font . "-*-*-*-*-*-*");
$label->set_style($label_style);
}
$label->set_usize($width,$height);
$label->set_justify($align);
return $label;
}
/**
@author Max Miller <hide@address.com>
@return void
*/
function append_vhbox($array_elements,$vhbox,$end = false) {
if ( !$end ) {
for ( $i = 0; $i < count($array_elements); $i++ ) {
$vhbox->pack_start($array_elements[$i],false);
}
}
else {
for ( $i = 0; $i < count($array_elements); $i++ ) {
$vhbox->pack_end($array_elements[$i],false);
}
}
return true;
}
function entry($width = '-1',$height = '-1') {
$entry = new GtkEntry();
$entry->set_editable(true);
$entry->set_usize($width,$height);
return $entry;
}
function combo($array_elements) {
$combo = new GtkCombo();
$combo->set_popdown_strings($array_elements);
return $combo;
}
}
?>