I have some problems with GtkEntry and selections



Hi,
What I want to do is to send some hint during text immission.

This fragment of code works but doesn't do what I want...
I neet do select from position previous+1.
If I write "previsious=*posizione+1" instead "previsious=*posizione"
this don't works
Someone can tell me  why??? (I use gtk 1.2.7)
More generally what i MUST do if a want to select a region of a text
after user modification??

--------------------------------------------------------------------------
void handle_insert_text(GtkEditable *entry, gchar *nuovo, gint
lunghezzNuovo, gint *posizione, gpointer dato){
  static char buffer[100];
  static int previous;

  gtk_signal_handler_block_by_func (GTK_OBJECT(entry),GTK_SIGNAL_FUNC
(handle_insert_text),dato);
  gtk_editable_delete_selection(GTK_EDITABLE(entry));
  previous=*posizione;
  //inserting the text.. a simplified one
  buffer[0]=nuovo[0];
  buffer[1]=0;

gtk_editable_insert_text(GTK_EDITABLE(entry),buffer,strlen(buffer),posizione);
  //if the sursor is at the end of the line
  if(strlen(gtk_entry_get_text(GTK_ENTRY(entry)))==*posizione){
    *posizione=previous;

gtk_editable_select_region(GTK_EDITABLE(entry),*posizione,*posizione+4);
  }
  gtk_signal_handler_unblock_by_func (GTK_OBJECT(entry),GTK_SIGNAL_FUNC
(handle_insert_text),dato);
  gtk_signal_emit_stop_by_name (GTK_OBJECT (entry), "insert-text");
  g_print("\n");
}

int main(int argc,char *argv[] ){
  ...

gtk_signal_connect(GTK_OBJECT(entry),"insert-text",GTK_SIGNAL_FUNC(handle_insert_text),0);
  ...
}

--------------------------------------------------------------------------

Many thanks
Edoardo Panfili




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]