After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 703618 - listbox: Add function to get the index of a GtkListBoxRow
listbox: Add function to get the index of a GtkListBoxRow
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
3.9.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2013-07-04 15:18 UTC by Kalev Lember
Modified: 2013-07-04 15:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkListBox: Add a function for getting the index of a row (1.61 KB, patch)
2013-07-04 15:19 UTC, Kalev Lember
committed Details | Review
testsuite: Add tests for gtk_list_box_row_get_index (1.14 KB, patch)
2013-07-04 15:20 UTC, Kalev Lember
committed Details | Review

Description Kalev Lember 2013-07-04 15:18:50 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
Comment 1 Kalev Lember 2013-07-04 15:19:58 UTC
Created attachment 248396 [details] [review]
GtkListBox: Add a function for getting the index of a row
Comment 2 Kalev Lember 2013-07-04 15:20:02 UTC
Created attachment 248397 [details] [review]
testsuite: Add tests for gtk_list_box_row_get_index
Comment 3 Kalev Lember 2013-07-04 15:22:46 UTC
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.
Comment 4 Alexander Larsson 2013-07-04 15:38:52 UTC
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.
Comment 5 Alexander Larsson 2013-07-04 15:39:39 UTC
Review of attachment 248397 [details] [review]:

ack
Comment 6 Kalev Lember 2013-07-04 15:43:37 UTC
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