GNOME Bugzilla – Bug 703618
listbox: Add function to get the index of a GtkListBoxRow
Last modified: 2013-07-04 15:43:44 UTC
There's currently no easy way to get the index of a row in a GtkListBox, except for iterating over all the children. Since the row internally keeps track of its GSequence iterator, we can do much better with a custom get_index function. 14:43 < kalev> I can do a patch, if you tell me what the function name should be :) 14:46 <@alex> gtk_list_box_row_get_index() ? 14:47 < kalev> alright
Created attachment 248396 [details] [review] GtkListBox: Add a function for getting the index of a row
Created attachment 248397 [details] [review] testsuite: Add tests for gtk_list_box_row_get_index
Review of attachment 248396 [details] [review]: ::: gtk/gtklistbox.c @@ +2687,3 @@ +gtk_list_box_row_get_index (GtkListBoxRow *row) +{ + GtkListBoxRowPrivate *priv = gtk_list_box_row_get_instance_private (row); I'll note that this crashes when doing a gtk_list_box_row_get_index(NULL), but none of the existing gtk_list_box_row public functions check for the NULL pointer, so I just went with the existing style and did the same here.
Review of attachment 248396 [details] [review]: Looks good ::: gtk/gtklistbox.c @@ +2687,3 @@ +gtk_list_box_row_get_index (GtkListBoxRow *row) +{ + GtkListBoxRowPrivate *priv = gtk_list_box_row_get_instance_private (row); It doesn't crash here precisely. gtk_list_box_row_get_instance_private() will eventually expand to "row + offset", and will not dereference the pointer. So it is safe to do before e.g. type checks or NULL checks on the object. Of course, it *will* crash below when we deref the priv.
Review of attachment 248397 [details] [review]: ack
Thanks! Attachment 248396 [details] pushed as b46d583 - GtkListBox: Add a function for getting the index of a row Attachment 248397 [details] pushed as 1f9fd5a - testsuite: Add tests for gtk_list_box_row_get_index