Re: changing entry shortcut hooks




Tim Janik <timj@gimp.org> writes:

> > I would also like to intercept things like Ctrl-K in an entry widget
> > (which is the same as Helge's question) and not have the entry widget
> > use it's default handling.
> 
> 
> though i wrote this out of my head, i'm pretty surte it'll work ;)
> 
> gint
> my_handler (GtkEntry *entry,
>             GdkEventKey *event,
>             gpointer user_data)
> {
>   switch (event->keyval)
>   {
>     gint pos;
>     
>   case  GDK_F10:
>     pos = GTK_EDITABLE(entry)->current_pos;
>     gtk_editable_insert_text (GTK_EDITABLE (entry), "my macro", 8, &pos);
>     return TRUE;
>   
>   default:
>     return FALSE;
>   }
> }

Come on, Tim, you can do better than that. ;-) (Well, for F10, it
doesn't matter, but for the arrow keys/C-k it does)


The return values are, as Tim momentarily forgot, only used
to decide whether to do propagate the event beyond the current
widget. (For most events, that means to the parent widget, but for key
press events, the further processing is the focus handling for
the top level)

To prevent further handlers for _this_ widget from being executed,
you'll have to do

>   case  GDK_F10:
>     pos = GTK_EDITABLE(entry)->current_pos;
>     gtk_editable_insert_text (GTK_EDITABLE (entry), "my macro", 8, &pos);
      gtk_signal_emit_stop_by_name (GTK_OBJECT (entry), "key_press_event");
>     return TRUE;

Regards,
                                        Owen



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