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

Re: Emitting a keypress event



Havoc Pennington wrote:

> Kent Schumacher <kent@structural-wood.com> writes:
> >
> > Basically I want to have a toolbar button act exactly as if the user
> > had pressed F3 or F4.
> >
>
> If F3 and F4 are accelerators, they are eventually just going to emit
> "clicked" on the toolbar button, so you can call gtk_button_clicked()
> on it.
>
> To synthesize a key event, you probably want to copy something like
> gtk_drawing_area_send_configure in gtk+/gtk/gtkdrawingarea.c, and you
> want to send the key event to the toplevel window the toolbar is
> inside. However I'm not sure how public gtk_widget_event() is
> considered to be.
>
> Do not do something like gtk_signal_emit(widget, "key_press_event")
> that will not work (or even if it works it's conceptually broken). You
> have to use gtk_widget_event() to emit the event signals.
>
> Havoc
>

First off, thank you for the response.  I appreciate it a great deal although
I'm pretty sure accelerators are not the answer to the problem, and I am also
unwilling to go to great lengths to synthesize keypresses.  I was hoping it
would be an easy answer to a difficult problem.

That said, I would like to state the problem in more abstract terms in the hope
of rapidly exploring the range of solutions (this group is good at brownian motion
thinking:^)

I frequently have widgets that have special functions that can be invoked via
menu-item, toolbar-button, and keypress.

Keypress is easy to implement because it tells you the widget that is in focus
at the time the key is pressed, and you can determine the function to invoke
based on the key pressed.

Menu-item and toolbar-button are hard.  It is easy enough to determine the
item that currently has focus by descending the container-child tree looking
for a widget that has the property GTK_WIDGET_HAS_FOCUS set.  Once
the widget is found you need to determine what kind of a widget it is so that
you can invoke the correct function based on the button or item pressed.

This does not scale well.  An application with thousands of focusable widgets
would require massive tables to be maintained.  Obviously not desirable.

A solution that occurs to me would be to add a new signal to GtkWidget -
something like "user-action".  This would need to be a programatically
emittable signal.  I would think that the handler would need a prototype
something like.

  void user_action_handler( GtkWidget *w ,  gpointer act_data , gpointer con_data)

act_data for the emitter, con_data from the gtk_signal_connect.

If I understand things correctly, adding an additional signal to GtkWidget will break
binary compatabity.  I'm presuming this is not good.

Anyone have any thoughts about this or other options?

Thanks
Kent






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