[gtk/kill-containers: 15/45] stack: Derive from GtkWidget



commit 2d67a04d7a6d38da549b964a71447127ea2e89f9
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu May 7 16:04:42 2020 -0400

    stack: Derive from GtkWidget

 gtk/a11y/gtkstackaccessible.c |   9 +---
 gtk/a11y/gtkstackaccessible.h |   6 +--
 gtk/gtkstack.c                | 112 +++++++++++++++++++++---------------------
 gtk/gtkstack.h                |   2 +-
 4 files changed, 60 insertions(+), 69 deletions(-)
---
diff --git a/gtk/a11y/gtkstackaccessible.c b/gtk/a11y/gtkstackaccessible.c
index 240daad264..23b4e13762 100644
--- a/gtk/a11y/gtkstackaccessible.c
+++ b/gtk/a11y/gtkstackaccessible.c
@@ -23,7 +23,7 @@
 #include "gtkwidgetprivate.h"
 
 
-G_DEFINE_TYPE (GtkStackAccessible, gtk_stack_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE)
+G_DEFINE_TYPE (GtkStackAccessible, gtk_stack_accessible, GTK_TYPE_WIDGET_ACCESSIBLE)
 
 static AtkObject*
 gtk_stack_accessible_ref_child (AtkObject *obj,
@@ -64,16 +64,9 @@ static void
 gtk_stack_accessible_class_init (GtkStackAccessibleClass *klass)
 {
   AtkObjectClass *class                        = ATK_OBJECT_CLASS (klass);
-  GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
 
   class->get_n_children = gtk_stack_accessible_get_n_children;
   class->ref_child      = gtk_stack_accessible_ref_child;
-  /*
-   * As we report the stack as having only the visible child,
-   * we are not interested in add and remove signals
-   */
-  container_class->add_gtk    = NULL;
-  container_class->remove_gtk = NULL;
 }
 
 static void
diff --git a/gtk/a11y/gtkstackaccessible.h b/gtk/a11y/gtkstackaccessible.h
index 11862bbc85..6254c33802 100644
--- a/gtk/a11y/gtkstackaccessible.h
+++ b/gtk/a11y/gtkstackaccessible.h
@@ -22,7 +22,7 @@
 #error "Only <gtk/gtk-a11y.h> can be included directly."
 #endif
 
-#include <gtk/a11y/gtkcontaineraccessible.h>
+#include <gtk/a11y/gtkwidgetaccessible.h>
 
 G_BEGIN_DECLS
 
@@ -38,12 +38,12 @@ typedef struct _GtkStackAccessibleClass   GtkStackAccessibleClass;
 
 struct _GtkStackAccessible
 {
-  GtkContainerAccessible parent;
+  GtkWidgetAccessible parent;
 };
 
 struct _GtkStackAccessibleClass
 {
-  GtkContainerAccessibleClass parent_class;
+  GtkWidgetAccessibleClass parent_class;
 };
 
 GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index 9feb4f8d0d..255a35a3e0 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -118,12 +118,12 @@
  */
 
 struct _GtkStack {
-  GtkContainer parent_instance;
+  GtkWidget parent_instance;
 };
 
 typedef struct _GtkStackClass GtkStackClass;
 struct _GtkStackClass {
-  GtkContainerClass parent_class;
+  GtkWidgetClass parent_class;
 };
 
 typedef struct {
@@ -157,7 +157,7 @@ typedef struct {
 
 static void gtk_stack_buildable_interface_init (GtkBuildableIface *iface);
 
-G_DEFINE_TYPE_WITH_CODE (GtkStack, gtk_stack, GTK_TYPE_CONTAINER,
+G_DEFINE_TYPE_WITH_CODE (GtkStack, gtk_stack, GTK_TYPE_WIDGET,
                          G_ADD_PRIVATE (GtkStack)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
                                                 gtk_stack_buildable_interface_init))
@@ -552,11 +552,12 @@ gtk_stack_pages_new (GtkStack *stack)
   return pages;
 }
 
-static void     gtk_stack_add                            (GtkContainer  *widget,
-                                                          GtkWidget     *child);
-static void     gtk_stack_forall                         (GtkContainer  *container,
-                                                          GtkCallback    callback,
-                                                          gpointer       callback_data);
+static GtkStackPage *gtk_stack_add_internal (GtkStack *stack,
+                                             GtkWidget  *child,
+                                             const char *name,
+                                             const char *title);
+
+static GtkSizeRequestMode gtk_stack_get_request_mode (GtkWidget *widget);
 static void     gtk_stack_compute_expand                 (GtkWidget     *widget,
                                                           gboolean      *hexpand,
                                                           gboolean      *vexpand);
@@ -589,6 +590,8 @@ static void     gtk_stack_unschedule_ticks               (GtkStack      *stack);
 static void     gtk_stack_add_page                       (GtkStack     *stack,
                                                           GtkStackPage *page);
 
+static GtkBuildableIface *parent_buildable_iface;
+
 static void
 gtk_stack_buildable_add_child (GtkBuildable *buildable,
                                GtkBuilder   *builder,
@@ -598,14 +601,16 @@ gtk_stack_buildable_add_child (GtkBuildable *buildable,
   if (GTK_IS_STACK_PAGE (child))
     gtk_stack_add_page (GTK_STACK (buildable), GTK_STACK_PAGE (child));
   else if (GTK_IS_WIDGET (child))
-    gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
+    gtk_stack_add_internal (GTK_STACK (buildable), GTK_WIDGET (child), NULL, NULL);
   else
-    g_warning ("Can't add a child of type '%s' to '%s'", G_OBJECT_TYPE_NAME (child), G_OBJECT_TYPE_NAME 
(buildable));
+    parent_buildable_iface->add_child (buildable, builder, child, type);
 }
 
 static void
 gtk_stack_buildable_interface_init (GtkBuildableIface *iface)
 {
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+
   iface->add_child = gtk_stack_buildable_add_child;
 }
 
@@ -613,22 +618,18 @@ static void stack_remove (GtkStack  *stack,
                           GtkWidget *child,
                           gboolean   in_dispose);
 
-static void
-remove_child (GtkWidget *child, gpointer user_data)
-{
-  stack_remove (GTK_STACK (user_data), child, TRUE);
-}
-
 static void
 gtk_stack_dispose (GObject *obj)
 {
   GtkStack *stack = GTK_STACK (obj);
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
+  GtkWidget *child;
 
   if (priv->pages)
     g_list_model_items_changed (G_LIST_MODEL (priv->pages), 0, g_list_length (priv->children), 0);
 
-  gtk_container_foreach (GTK_CONTAINER (obj), remove_child, obj);
+  while ((child = gtk_widget_get_first_child (GTK_WIDGET (stack))))
+    stack_remove (stack, child, TRUE);
 
   G_OBJECT_CLASS (gtk_stack_parent_class)->dispose (obj);
 }
@@ -734,7 +735,6 @@ gtk_stack_class_init (GtkStackClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
   object_class->get_property = gtk_stack_get_property;
   object_class->set_property = gtk_stack_set_property;
@@ -745,10 +745,9 @@ gtk_stack_class_init (GtkStackClass *klass)
   widget_class->snapshot = gtk_stack_snapshot;
   widget_class->measure = gtk_stack_measure;
   widget_class->compute_expand = gtk_stack_compute_expand;
-
-  container_class->add = gtk_stack_add;
-  container_class->remove = gtk_stack_remove;
-  container_class->forall = gtk_stack_forall;
+  widget_class->get_request_mode = gtk_stack_get_request_mode;
+  widget_class->focus = gtk_widget_focus_child;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
 
   /**
    * GtkStack:hhomogeneous:
@@ -1323,12 +1322,6 @@ stack_child_visibility_notify_cb (GObject    *obj,
     }
 }
 
-static GtkStackPage *
-gtk_stack_add_internal (GtkStack *stack,
-                        GtkWidget  *child,
-                        const char *name,
-                        const char *title);
-
 /**
  * gtk_stack_add_titled:
  * @stack: a #GtkStack
@@ -1377,15 +1370,6 @@ gtk_stack_add_named (GtkStack   *stack,
   return gtk_stack_add_internal (stack, child, name, NULL);
 }
 
-static void
-gtk_stack_add (GtkContainer *container,
-               GtkWidget    *child)
-{
-  GtkStack *stack = GTK_STACK (container);
-
-  gtk_stack_add_internal (stack, child, NULL, NULL);
-}
-
 static GtkStackPage *
 gtk_stack_add_internal (GtkStack   *stack,
                         GtkWidget  *child,
@@ -2002,26 +1986,6 @@ gtk_stack_set_visible_child_full (GtkStack               *stack,
     set_visible_child (stack, child_info, transition, priv->transition_duration);
 }
 
-static void
-gtk_stack_forall (GtkContainer *container,
-                  GtkCallback   callback,
-                  gpointer      callback_data)
-{
-  GtkStack *stack = GTK_STACK (container);
-  GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
-  GtkStackPage *child_info;
-  GList *l;
-
-  l = priv->children;
-  while (l)
-    {
-      child_info = l->data;
-      l = l->next;
-
-      (* callback) (child_info->widget, callback_data);
-    }
-}
-
 static void
 gtk_stack_compute_expand (GtkWidget *widget,
                           gboolean  *hexpand_p,
@@ -2057,6 +2021,40 @@ gtk_stack_compute_expand (GtkWidget *widget,
   *vexpand_p = vexpand;
 }
 
+static GtkSizeRequestMode
+gtk_stack_get_request_mode (GtkWidget *widget)
+{
+  GtkWidget *w;
+  int wfh = 0, hfw = 0;
+
+  for (w = gtk_widget_get_first_child (widget);
+       w != NULL;
+       w = gtk_widget_get_next_sibling (w))
+    {
+      GtkSizeRequestMode mode = gtk_widget_get_request_mode (w);
+
+      switch (mode)
+        {
+        case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH:
+          hfw ++;
+          break;
+        case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
+          wfh ++;
+          break;
+        case GTK_SIZE_REQUEST_CONSTANT_SIZE:
+        default:
+          break;
+        }
+    }
+
+  if (hfw == 0 && wfh == 0)
+    return GTK_SIZE_REQUEST_CONSTANT_SIZE;
+  else
+    return wfh > hfw ?
+        GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
+        GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+}
+
 static void
 gtk_stack_snapshot_crossfade (GtkWidget   *widget,
                               GtkSnapshot *snapshot)
diff --git a/gtk/gtkstack.h b/gtk/gtkstack.h
index 23f22a6fb8..6e52039de6 100644
--- a/gtk/gtkstack.h
+++ b/gtk/gtkstack.h
@@ -26,7 +26,7 @@
 #error "Only <gtk/gtk.h> can be included directly."
 #endif
 
-#include <gtk/gtkcontainer.h>
+#include <gtk/gtkwidget.h>
 #include <gtk/gtkselectionmodel.h>
 
 G_BEGIN_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]