From bb8babce1ef6af677cf5e77b8bc61edba5b52ac8 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 7 Aug 2011 18:36:28 +0400 Subject: [PATCH] (dlg_find_by_id): use the GLib way to find widget. Signed-off-by: Andrew Borodin --- lib/widget/dialog.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 027d1993f..8032f3b40 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -558,6 +558,17 @@ frontend_run_dlg (Dlg_head * h) } } +/* --------------------------------------------------------------------------------------------- */ + +static int +dlg_find_widget_by_id (gconstpointer a, gconstpointer b) +{ + Widget *w = (Widget *) a; + unsigned long id = GPOINTER_TO_UINT (b); + + return w->id == id ? 0 : 1; +} + /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -942,16 +953,10 @@ find_widget_type (const Dlg_head * h, callback_fn callback) Widget * dlg_find_by_id (const Dlg_head * h, unsigned int id) { - if (h->widgets != NULL) - { - GList *w; + GList *w; - for (w = h->widgets; w != NULL; w = g_list_next (w)) - if (((Widget *) w->data)->id == id) - return (Widget *) w->data; - } - - return NULL; + w = g_list_find_custom (h->widgets, GUINT_TO_POINTER (id), dlg_find_widget_by_id); + return w != NULL ? (Widget *) w->data : NULL; } /* --------------------------------------------------------------------------------------------- */