Re: DrawingArea and Toolbar focus issues



On Sat, Sep 08, 2007 at 11:02:07AM -0400, Brian Ahr wrote:
> I've set up a GtkDrawingArea to catch keypress and keyrelease events. 
> However, if a toolbar created via gtk_ui_manager_get_widget() is 
> visible, the toolbar's first button seems to steal those events - 
> despite my attempts to change the focus, disable key press/release 
> events to the toolbar, etc. If the toolbar isn't visible, everything 
> works as expected. Does anyone have any suggestions on this one?

GtkDrawingArea area does not accept keyboard focus.  If it's
the only widget in the window it gets the keyboard events
anyway, but if there are widgets that accept keyboard focus
(at least one), then the widget with keyboard focus gets
these events -- and this is never your GtkDrawingArea.

You have to make it accept focus:

   GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS);

In additon you probably want to grab focus when the user
clicks on it with mouse, i.e. call

   if (!GTK_WIDGET_HAS_FOCUS(widget))
     gtk_widget_grab_focus(widget);

in the "button-press-event" handler.

Yeti


P.S.: If you are writing something nontrivial, it might make
more sense to subclass GtkWiget directly -- if basing
widgets on GtkDrawingArea would be such a great idea, Gtk+
itself would be full of such widgets, isn't it?


--
http://gwyddion.net/



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