Re: Bug in gtk_edtiable_select_region key_press_event signal



Ariel Rios <ariel linuxppc org> writes:

> I think I caught a bug when using
>  gtk_edtiable_select_region () inside a key_press_event signal callback
> 
> Or to explain it better.
> 1)I have a text widget
> 2)I want to wrap parenthesis matching when a ')' is typed.
> 3)I do:
>  gtk_signal_connect (GTK_OBJECT (text), "key_press_event", 
>                       GTK_SIGNAL_FUNC (text_cb), NULL);
> and my cb is:
> text_cb (GtkWidget *text, GdkEventKey *event)
> {
>         if (event->keyval == GDK_parenright)
>                 gtk_editable_select_region (GTK_EDITABLE (text), 0, 1);
> 
> }
>  
> Ok. So in this example if I first type a '(' and then a ')'
> I expect "()" to be selected, right? Ugly things happen instead
> I might be doing something stupid
> I first hacked with guile-gtk and thought it may be a guile-gtk problem.
> So I tryed it with C and the same thing happened.
> 
> So, I maybe found a bug or I am doing exactly the same stupid
> thing on different languages.
> 
> I have wrote a C and guile simplified programs that show the horrible
> behaviour.

Well:

 a) We're basically ignoring GtkText problems at this point. So, a GtkEntry
    or GTK+-2.0 GtkTextView

 b) Your callback function has a void return, but event signals have a
    gboolean return.

 c) The problem, I believe is simply that you are getting the key press,
    you select the text, then when the keystroke is processed, it deletes
    the selected text before inserting. (Try this with manual selection.)

Getting this right is rather tricky, especially with the GTK+-2.0 
TRUE-return-stops-emit behavior.

I thinl the right psuedo-code is,

 - connect to the key press with gtk_signal_connect (not after), 

 - In the signal handler, do:

    - If the key press was a ')'
       - Block yourself
       - Call gtk_widget_event() with the event event passed in
       - Unblock yourself
       - Select the preceeding () pair
       - [ For GTK+-1.2 ] call gtk_signal_emit_stop_by_name()
       - return TRUE
    - Otherwise
       - return FALSE
       
But is selection really right here? Should the next key the user presses
really delete the entire sexp?
                                        Owen




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