GNOME Bugzilla – Bug 593671
Needed func for GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS)
Last modified: 2011-02-04 16:12:18 UTC
Currently in gedit and gtktreeview is used GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); to implement the interactive search. I'd like to have a func or some kind of api to get rid of this to be able to build gedit with the gseal thingie.
*** This bug has been marked as a duplicate of bug 69872 ***
From https://bugzilla.gnome.org/show_bug.cgi?id=69872#c27 > the GtkTreeView needs that for the search entry focusing, but that's evil and > we should find a way to have public API for doing this correctly - also > for applications using the same search entry semantics on TextView widgets > (e.g. > gedit). Reopening
Seems that all the affected external application just copied this gtktreeview hack into their code: [1] http://git.gnome.org/browse/gtk+/tree/gtk/gtktreeview.c#n10264
something like: gtk_widget_send_focus_change (GtkWidget *widget, gboolean is_focus_in); or: gtk_widget_send_focus_change (GtkWidget *widget, GdkEvent *event); similar to gtk_widget_send_expose(). the implementation would be trivial.
Created attachment 158484 [details] [review] widget: Add send_focus_change() Currently the only users of the GTK_HAS_FOCUS flag are setting it before sending a focus change event. This is normally needed by GtkWindow, but there are widgets that require controlling the focus of widgets that are semantically their children even though they are parented to another top-level. Case in point: the quick search entry for GtkTreeView. Over the years people have been hacking the focus change out of gtkwindow.c and gtktreeview.c, thus leaking the direct access of the GTK_HAS_FOCUS flag. The simplest way to avoid that is to add a function that sends the focus change event and controls the setting of the flag, thus removing the need for external widgets to do the same.
Created attachment 158485 [details] [review] window: Use gtk_widget_send_focus_change() Remove the original user of the GTK_HAS_FOCUS flags.
Created attachment 158486 [details] [review] tree-view: Use gtk_widget_send_focus_change() Remove the second (and last) internal user of the GTK_HAS_FOCUS flag.
the patches above fix the issue of HAS_FOCUS in the most trivial way possible: acknowledging the existing code base. another potential, and more time consuming, solution would be to create a GtkSearchEntry widget and expose it as a way to implement the TreeView-style floating search entry on any widget. while this might be a worthy goal for 3.x I don't think it would be a good way to spend time in the last days of the 2.x development cycle - and it's not fully orthogonal to the send_focus_change() function: at the end of the day, we need a way to affect the focus on widgets that are semantically our children, even if they are not really parented to us.
Looks like a very pragmatic way of dealing with this issue. +1 from me. This is probably something that we need to backport to 2.22 under the 'missing accessor' exception ?
Looks pretty elegant to me, even if it's the same behind the scenes. (In reply to comment #9) > This is probably something that we need to backport to 2.22 under the 'missing > accessor' exception ? Yes.
Attachment 158484 [details] pushed as f04a720 - widget: Add send_focus_change() Attachment 158485 [details] pushed as 91930f8 - window: Use gtk_widget_send_focus_change() Attachment 158486 [details] pushed as 621b415 - tree-view: Use gtk_widget_send_focus_change()