From 47ff8d0bf0444e1c533d4bcfa5793395d22c40e6 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 24 Aug 2015 19:12:29 +0100 Subject: [PATCH] Factor out columns_find_child() in the Columns class. This is an obviously reusable loop over cols->children looking for a widget, which I'm about to use a couple more times so it seems worth pulling it out into its own helper function. --- unix/gtkcols.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/unix/gtkcols.c b/unix/gtkcols.c index c3df584a..4d0d23c3 100644 --- a/unix/gtkcols.c +++ b/unix/gtkcols.c @@ -418,26 +418,36 @@ void columns_add(Columns *cols, GtkWidget *child, } } +static ColumnsChild *columns_find_child(Columns *cols, GtkWidget *widget) +{ + GList *children; + ColumnsChild *child; + + for (children = cols->children; + children && (child = children->data); + children = children->next) { + + if (child->widget == widget) + return child; + } + + return NULL; +} + void columns_force_left_align(Columns *cols, GtkWidget *widget) { ColumnsChild *child; - GList *children; g_return_if_fail(cols != NULL); g_return_if_fail(IS_COLUMNS(cols)); g_return_if_fail(widget != NULL); - for (children = cols->children; - children && (child = children->data); - children = children->next) { - if (child->widget != widget) - continue; + child = columns_find_child(cols, widget); + g_return_if_fail(child != NULL); - child->force_left = TRUE; - if (gtk_widget_get_visible(widget)) - gtk_widget_queue_resize(GTK_WIDGET(cols)); - break; - } + child->force_left = TRUE; + if (gtk_widget_get_visible(widget)) + gtk_widget_queue_resize(GTK_WIDGET(cols)); } void columns_taborder_last(Columns *cols, GtkWidget *widget)