Seleção de Texto em um Entry
Esse é um exemplo de como pegar seleção de dentro de um GtkEntry.
Bastate utilizado se você estiver fazendo um editor de texto em PHP-GTK
Observando as APIs do PHP-GTK, veremos que o GtkEditable é uma interface implemantada pelo GtkEntry.
Nessa interface temos os métodos:
->get_selection_bounds(); retorna um ARRAY com posição inicial e posição final da seleção
->get_chars($ini, $fim); pega os caracteres selecionados.
PS: repare que se os valores colocados em ->get_char($ini, $fim) forem 0 e -1 ele retorna todo o texto do GtkEntry
<?
$win = new GtkWindow();
$hbox = new GtkHBox();
$entryNome = new GtkEntry();
$btn = new GtkButton("_ok");
$btn->connect('clicked', 'salvar', $entryNome);
$hbox->pack_start($entryNome);
$hbox->pack_start($btn);
$win->add($hbox);
function salvar($btn,$entryNome){
$array = $entryNome->get_selection_bounds();
$texto = $entryNome->get_chars($array[0],$array[1]);
echo $texto;
}
$win->show_all();
GTK::main();
?>





