2
votes

I want to find out which widget is in a given direction in GTK+, i.e. doing what the "move-focus" signal does, but without actually changing the focus. What I have in mind is a function that takes a GtkWidget * and a GtkDirectionType and returns the GtkWidget in the given direction (if any).

What I want this for is to ultimately enumerate the widgets inside a specific GtkFrame in my UI definition, in order from left to right. I.e. basically create a list of widgets from leftmost to rightmost, inside my GtkFrame (or in the general case, inside any container).

I've tried to search the GTK documentation but haven't found anything that doesn't also change focus.

2

2 Answers

1
votes

Failing any other approach, the way I'm going forward with is to copy a selected set of static functions from the library implementation of GtkContainer and put them in a file in my own application, modifying them to suit my needs.

More specifically, the function gtk_container_focus_sort_left_right() and any local functions that it depends on. This includes the GCompareFunc left_right_compare() and get_allocation_coords().

0
votes

Assuming the directions you care about are "Forward" and "Backward", it sounds like you want to use gtk_container_get_focus_chain() on the frame: it does pretty much what it says on the tin: you get a list of widgets in order of focus when tabbing.