[libadwaita/wip/exalm/window-rename: 2/4] Rename AdwWindow:child and AdwApplicationWindow:child to content
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/window-rename: 2/4] Rename AdwWindow:child and AdwApplicationWindow:child to content
- Date: Tue, 31 Aug 2021 11:21:11 +0000 (UTC)
commit 58910d80b8b64424eef65b1448b958355b3fbca7
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Aug 31 14:33:07 2021 +0500
Rename AdwWindow:child and AdwApplicationWindow:child to content
Avoid a name clash with gtk_window_set_child() etc.
Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/255
src/adw-application-window.c | 59 +++++++++++++++++++++++---------------
src/adw-application-window.h | 6 ++--
src/adw-window-mixin-private.h | 6 ++--
src/adw-window-mixin.c | 32 ++++++++++-----------
src/adw-window.c | 64 ++++++++++++++++++++++++++----------------
src/adw-window.h | 6 ++--
6 files changed, 102 insertions(+), 71 deletions(-)
---
diff --git a/src/adw-application-window.c b/src/adw-application-window.c
index 32880099..c6b69780 100644
--- a/src/adw-application-window.c
+++ b/src/adw-application-window.c
@@ -40,10 +40,12 @@ static GtkBuildableIface *parent_buildable_iface;
enum {
PROP_0,
- PROP_CHILD,
- LAST_PROP = PROP_0,
+ PROP_CONTENT,
+ LAST_PROP,
};
+static GParamSpec *props[LAST_PROP];
+
#define ADW_GET_WINDOW_MIXIN(obj) (((AdwApplicationWindowPrivate *)
adw_application_window_get_instance_private (ADW_APPLICATION_WINDOW (obj)))->mixin)
static void
@@ -78,8 +80,8 @@ adw_application_window_get_property (GObject *object,
AdwApplicationWindow *self = ADW_APPLICATION_WINDOW (object);
switch (prop_id) {
- case PROP_CHILD:
- g_value_set_object (value, adw_application_window_get_child (self));
+ case PROP_CONTENT:
+ g_value_set_object (value, adw_application_window_get_content (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -95,8 +97,8 @@ adw_application_window_set_property (GObject *object,
AdwApplicationWindow *self = ADW_APPLICATION_WINDOW (object);
switch (prop_id) {
- case PROP_CHILD:
- adw_application_window_set_child (self, g_value_get_object (value));
+ case PROP_CONTENT:
+ adw_application_window_set_content (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -114,8 +116,21 @@ adw_application_window_class_init (AdwApplicationWindowClass *klass)
object_class->set_property = adw_application_window_set_property;
widget_class->size_allocate = adw_application_window_size_allocate;
- g_object_class_override_property (object_class, PROP_CHILD, "child");
-}
+ /**
+ * AdwApplicationWindow:content: (attributes org.gtk.Property.get=adw_application_window_get_content
org.gtk.Property.set=adw_application_window_set_content)
+ *
+ * The content widget.
+ *
+ * Since: 1.0
+ */
+ props[PROP_CONTENT] =
+ g_param_spec_object ("content",
+ "Content",
+ "The content widget",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (object_class, LAST_PROP, props);}
static void
adw_application_window_init (AdwApplicationWindow *self)
@@ -137,7 +152,7 @@ adw_application_window_buildable_add_child (GtkBuildable *buildable,
if (!g_strcmp0 (type, "titlebar"))
GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
else if (GTK_IS_WIDGET (child))
- adw_application_window_set_child (ADW_APPLICATION_WINDOW (buildable), GTK_WIDGET (child));
+ adw_application_window_set_content (ADW_APPLICATION_WINDOW (buildable), GTK_WIDGET (child));
else
parent_buildable_iface->add_child (buildable, builder, child, type);
}
@@ -169,44 +184,44 @@ adw_application_window_new (GtkApplication *app)
}
/**
- * adw_application_window_set_child:
+ * adw_application_window_set_content: (attributes org.gtk.Method.set_property=content)
* @self: a `AdwApplicationWindow`
- * @child: (nullable): the child widget
+ * @content: (nullable): the content widget
*
- * Sets the child widget of @self.
+ * Sets the content widget of @self.
*
* This method should always be used instead of [method@Gtk.Window.set_child].
*
* Since: 1.0
*/
void
-adw_application_window_set_child (AdwApplicationWindow *self,
- GtkWidget *child)
+adw_application_window_set_content (AdwApplicationWindow *self,
+ GtkWidget *content)
{
g_return_if_fail (ADW_IS_APPLICATION_WINDOW (self));
- g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
+ g_return_if_fail (content == NULL || GTK_IS_WIDGET (content));
- adw_window_mixin_set_child (ADW_GET_WINDOW_MIXIN (self), child);
+ adw_window_mixin_set_content (ADW_GET_WINDOW_MIXIN (self), content);
- g_object_notify (G_OBJECT (self), "child");
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CONTENT]);
}
/**
- * adw_application_window_get_child:
+ * adw_application_window_get_content: (attributes org.gtk.Method.get_property=content)
* @self: a `AdwApplicationWindow`
*
- * Gets the child widget of @self.
+ * Gets the content widget of @self.
*
* This method should always be used instead of [method@Gtk.Window.get_child].
*
- * Returns: (nullable) (transfer none): the child widget of @self
+ * Returns: (nullable) (transfer none): the content widget of @self
*
* Since: 1.0
*/
GtkWidget *
-adw_application_window_get_child (AdwApplicationWindow *self)
+adw_application_window_get_content (AdwApplicationWindow *self)
{
g_return_val_if_fail (ADW_IS_APPLICATION_WINDOW (self), NULL);
- return adw_window_mixin_get_child (ADW_GET_WINDOW_MIXIN (self));
+ return adw_window_mixin_get_content (ADW_GET_WINDOW_MIXIN (self));
}
diff --git a/src/adw-application-window.h b/src/adw-application-window.h
index 0bf95859..5c330e85 100644
--- a/src/adw-application-window.h
+++ b/src/adw-application-window.h
@@ -33,9 +33,9 @@ ADW_AVAILABLE_IN_ALL
GtkWidget *adw_application_window_new (GtkApplication *app) G_GNUC_WARN_UNUSED_RESULT;
ADW_AVAILABLE_IN_ALL
-void adw_application_window_set_child (AdwApplicationWindow *self,
- GtkWidget *child);
+void adw_application_window_set_content (AdwApplicationWindow *self,
+ GtkWidget *content);
ADW_AVAILABLE_IN_ALL
-GtkWidget *adw_application_window_get_child (AdwApplicationWindow *self);
+GtkWidget *adw_application_window_get_content (AdwApplicationWindow *self);
G_END_DECLS
diff --git a/src/adw-window-mixin-private.h b/src/adw-window-mixin-private.h
index 7557348f..e64b1957 100644
--- a/src/adw-window-mixin-private.h
+++ b/src/adw-window-mixin-private.h
@@ -26,8 +26,8 @@ void adw_window_mixin_size_allocate (AdwWindowMixin *self,
int height,
int baseline);
-GtkWidget *adw_window_mixin_get_child (AdwWindowMixin *self);
-void adw_window_mixin_set_child (AdwWindowMixin *self,
- GtkWidget *child);
+GtkWidget *adw_window_mixin_get_content (AdwWindowMixin *self);
+void adw_window_mixin_set_content (AdwWindowMixin *self,
+ GtkWidget *content);
G_END_DECLS
diff --git a/src/adw-window-mixin.c b/src/adw-window-mixin.c
index 6d6f98f0..9c2349cd 100644
--- a/src/adw-window-mixin.c
+++ b/src/adw-window-mixin.c
@@ -18,9 +18,9 @@ struct _AdwWindowMixin
GtkWindowClass *klass;
GtkWidget *titlebar;
- GtkWidget *contents;
-
GtkWidget *child;
+
+ GtkWidget *content;
};
G_DEFINE_TYPE (AdwWindowMixin, adw_window_mixin, G_TYPE_OBJECT)
@@ -35,7 +35,7 @@ adw_window_mixin_size_allocate (AdwWindowMixin *self,
if (gtk_window_get_titlebar (self->window) != self->titlebar)
g_error ("gtk_window_set_titlebar() is not supported for AdwWindow");
- if (gtk_window_get_child (self->window) != self->contents)
+ if (gtk_window_get_child (self->window) != self->child)
g_error ("gtk_window_set_child() is not supported for AdwWindow");
GTK_WIDGET_CLASS (self->klass)->size_allocate (GTK_WIDGET (self->window),
@@ -73,29 +73,29 @@ adw_window_mixin_new (GtkWindow *window,
gtk_widget_hide (self->titlebar);
gtk_window_set_titlebar (self->window, self->titlebar);
- self->contents = adw_gizmo_new ("contents", NULL, NULL, NULL, NULL,
- (AdwGizmoFocusFunc) adw_widget_focus_child,
- (AdwGizmoGrabFocusFunc) adw_widget_grab_focus_child);
- gtk_widget_set_layout_manager (self->contents, gtk_bin_layout_new ());
- gtk_window_set_child (window, self->contents);
+ self->child = adw_gizmo_new ("contents", NULL, NULL, NULL, NULL,
+ (AdwGizmoFocusFunc) adw_widget_focus_child,
+ (AdwGizmoGrabFocusFunc) adw_widget_grab_focus_child);
+ gtk_widget_set_layout_manager (self->child, gtk_bin_layout_new ());
+ gtk_window_set_child (window, self->child);
return self;
}
void
-adw_window_mixin_set_child (AdwWindowMixin *self,
- GtkWidget *child)
+adw_window_mixin_set_content (AdwWindowMixin *self,
+ GtkWidget *content)
{
- g_clear_pointer (&self->child, gtk_widget_unparent);
+ g_clear_pointer (&self->content, gtk_widget_unparent);
- if (child) {
- self->child = child;
- gtk_widget_set_parent (child, self->contents);
+ if (content) {
+ self->content = content;
+ gtk_widget_set_parent (content, self->child);
}
}
GtkWidget *
-adw_window_mixin_get_child (AdwWindowMixin *self)
+adw_window_mixin_get_content (AdwWindowMixin *self)
{
- return self->child;
+ return self->content;
}
diff --git a/src/adw-window.c b/src/adw-window.c
index 3cfbaca7..0fcee918 100644
--- a/src/adw-window.c
+++ b/src/adw-window.c
@@ -18,8 +18,8 @@
* titlebar area. It means [class@Gtk.HeaderBar] can be used as follows:
*
* ```xml
- * <object class="AdwWindow"/>
- * <child>
+ * <object class="AdwWindow">
+ * <property name="content">
* <object class="GtkBox">
* <property name="orientation">vertical</property>
* <child>
@@ -29,7 +29,7 @@
* ...
* </child>
* </object>
- * </child>
+ * </property>
* </object>
* ```
*
@@ -54,10 +54,12 @@ static GtkBuildableIface *parent_buildable_iface;
enum {
PROP_0,
- PROP_CHILD,
- LAST_PROP = PROP_0,
+ PROP_CONTENT,
+ LAST_PROP,
};
+static GParamSpec *props[LAST_PROP];
+
#define ADW_GET_WINDOW_MIXIN(obj) (((AdwWindowPrivate *) adw_window_get_instance_private (ADW_WINDOW
(obj)))->mixin)
static void
@@ -92,8 +94,8 @@ adw_window_get_property (GObject *object,
AdwWindow *self = ADW_WINDOW (object);
switch (prop_id) {
- case PROP_CHILD:
- g_value_set_object (value, adw_window_get_child (self));
+ case PROP_CONTENT:
+ g_value_set_object (value, adw_window_get_content (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -109,8 +111,8 @@ adw_window_set_property (GObject *object,
AdwWindow *self = ADW_WINDOW (object);
switch (prop_id) {
- case PROP_CHILD:
- adw_window_set_child (self, g_value_get_object (value));
+ case PROP_CONTENT:
+ adw_window_set_content (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -128,7 +130,21 @@ adw_window_class_init (AdwWindowClass *klass)
object_class->set_property = adw_window_set_property;
widget_class->size_allocate = adw_window_size_allocate;
- g_object_class_override_property (object_class, PROP_CHILD, "child");
+ /**
+ * AdwWindow:content: (attributes org.gtk.Property.get=adw_window_get_content
org.gtk.Property.set=adw_window_set_content)
+ *
+ * The content widget.
+ *
+ * Since: 1.0
+ */
+ props[PROP_CONTENT] =
+ g_param_spec_object ("content",
+ "Content",
+ "The content widget",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (object_class, LAST_PROP, props);
}
static void
@@ -149,7 +165,7 @@ adw_window_buildable_add_child (GtkBuildable *buildable,
if (!g_strcmp0 (type, "titlebar"))
GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
else if (GTK_IS_WIDGET (child))
- adw_window_set_child (ADW_WINDOW (buildable), GTK_WIDGET (child));
+ adw_window_set_content (ADW_WINDOW (buildable), GTK_WIDGET (child));
else
parent_buildable_iface->add_child (buildable, builder, child, type);
}
@@ -178,44 +194,44 @@ adw_window_new (void)
}
/**
- * adw_window_set_child:
+ * adw_window_set_content: (attributes org.gtk.Method.set_property=content)
* @self: a `AdwWindow`
- * @child: (nullable): the child widget
+ * @content: (nullable): the content widget
*
- * Sets the child widget of @self.
+ * Sets the content widget of @self.
*
* This method should always be used instead of [method@Gtk.Window.set_child].
*
* Since: 1.0
*/
void
-adw_window_set_child (AdwWindow *self,
- GtkWidget *child)
+adw_window_set_content (AdwWindow *self,
+ GtkWidget *content)
{
g_return_if_fail (ADW_IS_WINDOW (self));
- g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
+ g_return_if_fail (content == NULL || GTK_IS_WIDGET (content));
- adw_window_mixin_set_child (ADW_GET_WINDOW_MIXIN (self), child);
+ adw_window_mixin_set_content (ADW_GET_WINDOW_MIXIN (self), content);
- g_object_notify (G_OBJECT (self), "child");
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CONTENT]);
}
/**
- * adw_window_get_child:
+ * adw_window_get_content: (attributes org.gtk.Method.get_property=content)
* @self: a `AdwWindow`
*
- * Gets the child widget of @self.
+ * Gets the content widget of @self.
*
* This method should always be used instead of [method@Gtk.Window.get_child].
*
- * Returns: (nullable) (transfer none): the child widget of @self
+ * Returns: (nullable) (transfer none): the content widget of @self
*
* Since: 1.0
*/
GtkWidget *
-adw_window_get_child (AdwWindow *self)
+adw_window_get_content (AdwWindow *self)
{
g_return_val_if_fail (ADW_IS_WINDOW (self), NULL);
- return adw_window_mixin_get_child (ADW_GET_WINDOW_MIXIN (self));
+ return adw_window_mixin_get_content (ADW_GET_WINDOW_MIXIN (self));
}
diff --git a/src/adw-window.h b/src/adw-window.h
index f4221ca2..dc6be3c5 100644
--- a/src/adw-window.h
+++ b/src/adw-window.h
@@ -33,9 +33,9 @@ ADW_AVAILABLE_IN_ALL
GtkWidget *adw_window_new (void) G_GNUC_WARN_UNUSED_RESULT;
ADW_AVAILABLE_IN_ALL
-GtkWidget *adw_window_get_child (AdwWindow *self);
+GtkWidget *adw_window_get_content (AdwWindow *self);
ADW_AVAILABLE_IN_ALL
-void adw_window_set_child (AdwWindow *self,
- GtkWidget *child);
+void adw_window_set_content (AdwWindow *self,
+ GtkWidget *content);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]