radibutton: Use focusing facilities from GtkWidget
authorTimm Bäder <mail@baedert.org>
Sat, 17 Mar 2018 09:30:10 +0000 (10:30 +0100)
committerTimm Bäder <mail@baedert.org>
Sat, 17 Mar 2018 11:09:30 +0000 (12:09 +0100)
Instead of the ones from GtkContainer which will hopefully soon go away.

gtk/gtkradiobutton.c

index 514f274ea144a6cba59ddd5dd310a12aaf945c43..64c2ca63313d60e3720e1a73e54b5b17de54b5ad 100644 (file)
@@ -26,8 +26,7 @@
 
 #include "gtkradiobutton.h"
 
-#include "gtkcontainerprivate.h"
-#include "gtkbuttonprivate.h"
+#include "gtkwidgetprivate.h"
 #include "gtktogglebuttonprivate.h"
 #include "gtkcheckbuttonprivate.h"
 #include "gtklabel.h"
@@ -632,68 +631,55 @@ gtk_radio_button_focus (GtkWidget         *widget,
 
   if (gtk_widget_is_focus (widget))
     {
-      GList *children, *focus_list, *tmp_list;
-      GtkWidget *toplevel;
+      GPtrArray *child_array;
       GtkWidget *new_focus = NULL;
       GSList *l;
+      guint index;
+      gboolean found;
+      guint i;
 
       if (direction == GTK_DIR_TAB_FORWARD ||
           direction == GTK_DIR_TAB_BACKWARD)
         return FALSE;
 
-      toplevel = gtk_widget_get_toplevel (widget);
-      children = NULL;
+      child_array = g_ptr_array_sized_new (g_slist_length (priv->group));
       for (l = priv->group; l; l = l->next)
-        children = g_list_prepend (children, l->data);
+        g_ptr_array_add (child_array, l->data);
 
-      focus_list = _gtk_container_focus_sort (GTK_CONTAINER (toplevel), children, direction, widget);
-      tmp_list = g_list_find (focus_list, widget);
+      gtk_widget_focus_sort (widget, direction, child_array);
+      found = g_ptr_array_find (child_array, widget, &index);
 
-      if (tmp_list)
-       {
-         tmp_list = tmp_list->next;
-
-         while (tmp_list)
-           {
-             GtkWidget *child = tmp_list->data;
-
-             if (gtk_widget_get_mapped (child) && gtk_widget_is_sensitive (child))
-               {
-                 new_focus = child;
-                 break;
-               }
-
-             tmp_list = tmp_list->next;
-           }
-       }
-
-      if (!new_focus)
-       {
-         tmp_list = focus_list;
-
-         while (tmp_list)
-           {
-             GtkWidget *child = tmp_list->data;
+      if (found)
+        {
+          /* Start at the *next* widget in the list */
+          if (index < child_array->len - 1)
+            index ++;
+        }
+      else
+        {
+          /* Search from the start of the list */
+          index = 0;
+        }
 
-             if (gtk_widget_get_mapped (child) && gtk_widget_is_sensitive (child))
-               {
-                 new_focus = child;
-                 break;
-               }
+      for (i = index; i < child_array->len; i ++)
+        {
+          GtkWidget *child = g_ptr_array_index (child_array, i);
 
-             tmp_list = tmp_list->next;
-           }
-       }
+          if (gtk_widget_get_mapped (child) && gtk_widget_is_sensitive (child))
+            {
+              new_focus = child;
+              break;
+            }
+        }
 
-      g_list_free (focus_list);
-      g_list_free (children);
 
       if (new_focus)
-       {
-         gtk_widget_grab_focus (new_focus);
-
+        {
+          gtk_widget_grab_focus (new_focus);
           gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (new_focus), TRUE);
-       }
+        }
+
+      g_ptr_array_free (child_array, TRUE);
 
       return TRUE;
     }