[libshumate] marker: Add GTK4-style child API
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libshumate] marker: Add GTK4-style child API
- Date: Wed, 3 Mar 2021 12:41:56 +0000 (UTC)
commit 5a984e2caca451ca5cc1114a2b8e05101a83692b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Mar 2 14:29:47 2021 -0300
marker: Add GTK4-style child API
Add shumate_marker_set_child() and shumate_marker_get_child(), which
matches the GTK4-style of child APIs, where each container exposes
the appropriate functions to manage their children.
Fixes https://gitlab.gnome.org/GNOME/libshumate/-/issues/13
docs/reference/libshumate-sections.txt | 2 +
shumate/shumate-marker.c | 76 ++++++++++++++++++++++++++++++++--
shumate/shumate-marker.h | 4 ++
3 files changed, 79 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/libshumate-sections.txt b/docs/reference/libshumate-sections.txt
index bd2d3f4..ae76033 100644
--- a/docs/reference/libshumate-sections.txt
+++ b/docs/reference/libshumate-sections.txt
@@ -45,6 +45,8 @@ shumate_marker_set_draggable
shumate_marker_get_draggable
shumate_marker_set_selected
shumate_marker_get_selected
+shumate_marker_set_child
+shumate_marker_get_child
shumate_marker_animate_in
shumate_marker_animate_in_with_delay
shumate_marker_animate_out
diff --git a/shumate/shumate-marker.c b/shumate/shumate-marker.c
index 356ed91..d86ff8a 100644
--- a/shumate/shumate-marker.c
+++ b/shumate/shumate-marker.c
@@ -57,6 +57,7 @@ enum
{
PROP_SELECTABLE = 1,
PROP_DRAGGABLE,
+ PROP_CHILD,
N_PROPERTIES,
PROP_LONGITUDE,
@@ -78,6 +79,8 @@ typedef struct
float click_x;
float click_y;
gboolean moved;
+
+ GtkWidget *child;
} ShumateMarkerPrivate;
static void location_interface_init (ShumateLocationInterface *iface);
@@ -218,6 +221,10 @@ shumate_marker_get_property (GObject *object,
g_value_set_boolean (value, priv->draggable);
break;
+ case PROP_CHILD:
+ g_value_set_object (value, priv->child);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -263,6 +270,13 @@ shumate_marker_set_property (GObject *object,
break;
}
+ case PROP_CHILD:
+ {
+ GtkWidget *child = g_value_get_object (value);
+ shumate_marker_set_child (marker, child);
+ break;
+ }
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -271,10 +285,9 @@ shumate_marker_set_property (GObject *object,
static void
shumate_marker_dispose (GObject *object)
{
- GtkWidget *child;
+ ShumateMarker *marker = SHUMATE_MARKER (object);
- while ((child = gtk_widget_get_first_child (GTK_WIDGET (object))))
- gtk_widget_unparent (child);
+ shumate_marker_set_child (marker, NULL);
G_OBJECT_CLASS (shumate_marker_parent_class)->dispose (object);
}
@@ -289,6 +302,18 @@ shumate_marker_class_init (ShumateMarkerClass *klass)
object_class->set_property = shumate_marker_set_property;
object_class->dispose = shumate_marker_dispose;
+ /**
+ * ShumateMarker:child:
+ *
+ * The child widget of the marker
+ */
+ obj_properties[PROP_CHILD] =
+ g_param_spec_object ("child",
+ "Child",
+ "The child widget of the marker",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
/**
* ShumateMarker:selectable:
*
@@ -491,3 +516,48 @@ shumate_marker_get_draggable (ShumateMarker *marker)
return priv->draggable;
}
+/**
+ * shumate_marker_get_child:
+ * @marker: a #ShumateMarker
+ *
+ * Retrieves the current child of @marker.
+ *
+ * Returns: (transfer none) (nullable): a #GtkWidget.
+ */
+GtkWidget *
+shumate_marker_get_child (ShumateMarker *marker)
+{
+ ShumateMarkerPrivate *priv = shumate_marker_get_instance_private (marker);
+
+ g_return_val_if_fail (SHUMATE_IS_MARKER (marker), NULL);
+
+ return priv->child;
+}
+
+/**
+ * shumate_marker_set_child:
+ * @marker: a #ShumateMarker
+ * @child: (nullable): a #GtkWidget
+ *
+ * Sets the child widget of @marker.
+ */
+void
+shumate_marker_set_child (ShumateMarker *marker,
+ GtkWidget *child)
+{
+ ShumateMarkerPrivate *priv = shumate_marker_get_instance_private (marker);
+
+ g_return_if_fail (SHUMATE_IS_MARKER (marker));
+
+ if (priv->child == child)
+ return;
+
+ g_clear_pointer (&priv->child, gtk_widget_unparent);
+
+ priv->child = child;
+
+ if (priv->child)
+ gtk_widget_set_parent (priv->child, GTK_WIDGET (marker));
+
+ g_object_notify_by_pspec (G_OBJECT (marker), obj_properties[PROP_CHILD]);
+}
diff --git a/shumate/shumate-marker.h b/shumate/shumate-marker.h
index a781a78..7cd45f1 100644
--- a/shumate/shumate-marker.h
+++ b/shumate/shumate-marker.h
@@ -73,6 +73,10 @@ const GdkRGBA *shumate_marker_get_selection_color (void);
void shumate_marker_set_selection_text_color (GdkRGBA *color);
const GdkRGBA *shumate_marker_get_selection_text_color (void);
+GtkWidget *shumate_marker_get_child (ShumateMarker *marker);
+void shumate_marker_set_child (ShumateMarker *marker,
+ GtkWidget *child);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]