[gtk/bin-removal: 8/15] window: Add a child property



commit caeff850775004fd8f561aa63b49b49e02ad6196
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 2 11:33:10 2020 -0400

    window: Add a child property

 docs/reference/gtk/gtk4-sections.txt |  2 ++
 gtk/gtkwindow.c                      | 49 ++++++++++++++++++++++++++++++++++++
 gtk/gtkwindow.h                      |  6 +++++
 3 files changed, 57 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index ec513092d7..4b4c5f875e 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4203,6 +4203,8 @@ gtk_requisition_get_type
 GtkWindow
 GtkWindowClass
 gtk_window_new
+gtk_window_get_child
+gtk_window_set_child
 gtk_window_set_title
 gtk_window_set_resizable
 gtk_window_get_resizable
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 9319cce2ea..0dc421be1a 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -293,6 +293,7 @@ enum {
   PROP_APPLICATION,
   PROP_DEFAULT_WIDGET,
   PROP_FOCUS_WIDGET,
+  PROP_CHILD,
 
   /* Readonly properties */
   PROP_IS_ACTIVE,
@@ -961,6 +962,14 @@ gtk_window_class_init (GtkWindowClass *klass)
                            GTK_TYPE_WIDGET,
                            GTK_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
 
+  window_props[PROP_CHILD] =
+      g_param_spec_object ("child",
+                           P_("Child"),
+                           P_("The child widget"),
+                           GTK_TYPE_WIDGET,
+                           GTK_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
+
+
   g_object_class_install_properties (gobject_class, LAST_ARG, window_props);
 
   /**
@@ -1937,6 +1946,9 @@ gtk_window_set_property (GObject      *object,
     case PROP_FOCUS_WIDGET:
       gtk_window_set_focus (window, g_value_get_object (value));
       break;
+    case PROP_CHILD:
+      gtk_window_set_child (window, g_value_get_object (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2020,6 +2032,9 @@ gtk_window_get_property (GObject      *object,
     case PROP_FOCUS_WIDGET:
       g_value_set_object (value, gtk_window_get_focus (window));
       break;
+    case PROP_CHILD:
+      g_value_set_object (value, gtk_window_get_child (window));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -8105,3 +8120,37 @@ gtk_window_maybe_update_cursor (GtkWindow *window,
         break;
     }
 }
+
+/**
+ * gtk_window_set_child:
+ * @window: a #GtkWindow
+ * @child: (allow-none): the child widget
+ *
+ * Sets the child widget of @window.
+ */
+void
+gtk_window_set_child (GtkWindow *window,
+                      GtkWidget *child)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+  g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
+
+  gtk_window_add (GTK_CONTAINER (window), child);
+  g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_CHILD]);
+}
+
+/**
+ * gtk_window_get_child:
+ * @window: a #GtkWindow
+ *
+ * Gets the child widget of @window.
+ *
+ * Returns: (nullable) (transfer none): the child widget of @window
+ */
+GtkWidget *
+gtk_window_get_child (GtkWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
+
+  return gtk_bin_get_child (GTK_BIN (window));
+}
diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h
index 2563ac5cac..8333ac9160 100644
--- a/gtk/gtkwindow.h
+++ b/gtk/gtkwindow.h
@@ -239,6 +239,12 @@ GDK_AVAILABLE_IN_ALL
 void            gtk_window_set_application      (GtkWindow          *window,
                                                  GtkApplication     *application);
 
+GDK_AVAILABLE_IN_ALL
+void     gtk_window_set_child              (GtkWindow    *window,
+                                            GtkWidget    *child);
+GDK_AVAILABLE_IN_ALL
+GtkWidget *gtk_window_get_child            (GtkWindow    *window);
+
 GDK_AVAILABLE_IN_ALL
 void     gtk_window_set_titlebar           (GtkWindow    *window,
                                             GtkWidget    *titlebar);


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