[gtk/wip/otte/boxes: 42/52] widget: Remove toplevel flag



commit aeda099f47b0868e84bb26217539904e490d7ea8
Author: Benjamin Otte <otte redhat com>
Date:   Fri Apr 6 20:30:34 2018 +0200

    widget: Remove toplevel flag
    
    Instead, rely on GTK_IS_ROOT().
    
    Also implement GtkRoot on GtkWindow and GtkInvisible, the two widgets
    that used to set the toplevel flag before.

 gtk/gtkinvisible.c            | 19 ++++++++++++++-----
 gtk/gtkprintoperation-win32.c |  2 --
 gtk/gtkwidget.c               | 19 ++++---------------
 gtk/gtkwidgetprivate.h        |  6 ++----
 gtk/gtkwindow.c               | 14 ++++++++++++--
 5 files changed, 32 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkinvisible.c b/gtk/gtkinvisible.c
index 37821039a6..910b406376 100644
--- a/gtk/gtkinvisible.c
+++ b/gtk/gtkinvisible.c
@@ -23,11 +23,13 @@
  */
 
 #include "config.h"
-#include <gdk/gdk.h>
+
 #include "gtkinvisibleprivate.h"
-#include "gtkwidgetprivate.h"
-#include "gtkprivate.h"
+
 #include "gtkintl.h"
+#include "gtkprivate.h"
+#include "gtkroot.h"
+#include "gtkwidgetprivate.h"
 
 
 /**
@@ -69,7 +71,15 @@ static void gtk_invisible_get_property  (GObject           *object,
                                         GParamSpec        *pspec);
 static void gtk_invisible_constructed   (GObject           *object);
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET)
+static void
+gtk_invisible_root_interface_init (GtkRootInterface *iface)
+{
+}
+
+G_DEFINE_TYPE_WITH_CODE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET,
+                         G_ADD_PRIVATE (GtkInvisible)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ROOT,
+                                               gtk_invisible_root_interface_init))
 
 static void
 gtk_invisible_class_init (GtkInvisibleClass *class)
@@ -107,7 +117,6 @@ gtk_invisible_init (GtkInvisible *invisible)
   priv = invisible->priv;
 
   gtk_widget_set_has_surface (GTK_WIDGET (invisible), TRUE);
-  _gtk_widget_set_is_toplevel (GTK_WIDGET (invisible), TRUE);
 
   g_object_ref_sink (invisible);
 
diff --git a/gtk/gtkprintoperation-win32.c b/gtk/gtkprintoperation-win32.c
index ac18261c71..4f21c1f17f 100644
--- a/gtk/gtkprintoperation-win32.c
+++ b/gtk/gtkprintoperation-win32.c
@@ -1382,8 +1382,6 @@ pageDlgProc (HWND wnd, UINT message, WPARAM wparam, LPARAM lparam)
 
       SetWindowLongPtrW (wnd, GWLP_USERDATA, (LONG_PTR)op);
 
-      _gtk_widget_set_is_toplevel (plug, TRUE);
-
       gtk_window_set_modal (GTK_WINDOW (plug), TRUE);
       op_win32->embed_widget = plug;
       gtk_container_add (GTK_CONTAINER (plug), op->priv->custom_widget);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 98505bbb59..4002e2ba12 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -6314,20 +6314,9 @@ gtk_widget_get_has_surface (GtkWidget *widget)
 gboolean
 gtk_widget_is_toplevel (GtkWidget *widget)
 {
-  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
-
   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
 
-  return priv->toplevel;
-}
-
-void
-_gtk_widget_set_is_toplevel (GtkWidget *widget,
-                             gboolean   is_toplevel)
-{
-  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
-
-  priv->toplevel = is_toplevel;
+  return GTK_IS_ROOT (widget);
 }
 
 /**
@@ -6898,7 +6887,7 @@ gtk_widget_verify_invariants (GtkWidget *widget)
         g_warning ("%s %p is mapped but not visible",
                    G_OBJECT_TYPE_NAME (widget), widget);
 
-      if (!priv->toplevel)
+      if (!GTK_IS_ROOT (widget))
         {
           if (!priv->child_visible)
             g_warning ("%s %p is mapped but not child_visible",
@@ -6946,7 +6935,7 @@ gtk_widget_verify_invariants (GtkWidget *widget)
                        G_OBJECT_TYPE_NAME (widget), widget);
 #endif
         }
-      else if (!priv->toplevel)
+      else if (!GTK_IS_ROOT (widget))
         {
           /* No parent or parent not realized on non-toplevel implies... */
 
@@ -6968,7 +6957,7 @@ gtk_widget_verify_invariants (GtkWidget *widget)
                        G_OBJECT_TYPE_NAME (parent), parent,
                        G_OBJECT_TYPE_NAME (widget), widget);
         }
-      else if (!widget->priv->toplevel)
+      else if (!GTK_IS_ROOT (widget))
         {
           /* No parent or parent not mapped on non-toplevel implies... */
 
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 6aa41f2430..cdfe98b9be 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -32,6 +32,7 @@
 #include "gtkcsstypesprivate.h"
 #include "gtkeventcontroller.h"
 #include "gtklistlistmodelprivate.h"
+#include "gtkroot.h"
 #include "gtksizerequestcacheprivate.h"
 #include "gtkwindowprivate.h"
 #include "gtkinvisibleprivate.h"
@@ -55,7 +56,6 @@ struct _GtkWidgetPrivate
 #endif
 
   guint in_destruction        : 1;
-  guint toplevel              : 1;
   guint anchored              : 1;
   guint no_surface            : 1;
   guint no_surface_set        : 1;
@@ -226,8 +226,6 @@ void              _gtk_widget_set_has_default              (GtkWidget *widget,
                                                             gboolean   has_default);
 void              _gtk_widget_set_has_grab                 (GtkWidget *widget,
                                                             gboolean   has_grab);
-void              _gtk_widget_set_is_toplevel              (GtkWidget *widget,
-                                                            gboolean   is_toplevel);
 
 void              _gtk_widget_grab_notify                  (GtkWidget *widget,
                                                             gboolean   was_grabbed);
@@ -390,7 +388,7 @@ _gtk_widget_get_realized (GtkWidget *widget)
 static inline gboolean
 _gtk_widget_is_toplevel (GtkWidget *widget)
 {
-  return widget->priv->toplevel;
+  return GTK_IS_ROOT (widget);
 }
 
 static inline GtkStateFlags
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 03b8c500e9..4eccf40b2d 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -61,6 +61,7 @@
 #include "gtkpointerfocusprivate.h"
 #include "gtkpopoverprivate.h"
 #include "gtkprivate.h"
+#include "gtkroot.h"
 #include "gtkseparatormenuitem.h"
 #include "gtksettings.h"
 #include "gtksnapshot.h"
@@ -561,6 +562,9 @@ static void gtk_window_buildable_custom_finished (GtkBuildable  *buildable,
                                                      const gchar   *tagname,
                                                      gpointer       user_data);
 
+/* GtkRoot */
+static void             gtk_window_root_interface_init                  (GtkRootInterface       *iface);
+
 static void ensure_state_flag_backdrop (GtkWidget *widget);
 static void unset_titlebar (GtkWindow *window);
 static void on_titlebar_title_notify (GtkHeaderBar *titlebar,
@@ -575,7 +579,9 @@ static void gtk_window_update_debugging (void);
 G_DEFINE_TYPE_WITH_CODE (GtkWindow, gtk_window, GTK_TYPE_BIN,
                          G_ADD_PRIVATE (GtkWindow)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
-                                               gtk_window_buildable_interface_init))
+                                               gtk_window_buildable_interface_init)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ROOT,
+                                               gtk_window_root_interface_init))
 
 static void
 add_tab_bindings (GtkBindingSet    *binding_set,
@@ -1860,7 +1866,6 @@ gtk_window_init (GtkWindow *window)
   widget = GTK_WIDGET (window);
 
   gtk_widget_set_has_surface (widget, TRUE);
-  _gtk_widget_set_is_toplevel (widget, TRUE);
   _gtk_widget_set_anchored (widget, TRUE);
 
   priv->title = NULL;
@@ -2493,6 +2498,11 @@ gtk_window_buildable_custom_finished (GtkBuildable  *buildable,
     }
 }
 
+static void
+gtk_window_root_interface_init (GtkRootInterface *iface)
+{
+}
+
 /**
  * gtk_window_new:
  * @type: type of window


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