[libshumate] marker: Implement Gtk.Buildable.add_child



commit 732f3472f7e5b012dcbca6937a838f33be210cd8
Author: James Westman <james jwestman net>
Date:   Tue Jan 18 17:00:54 2022 -0600

    marker: Implement Gtk.Buildable.add_child
    
    That way, markers can be built from xml correctly.

 shumate/shumate-marker.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/shumate/shumate-marker.c b/shumate/shumate-marker.c
index 9a27287..6d563c0 100644
--- a/shumate/shumate-marker.c
+++ b/shumate/shumate-marker.c
@@ -78,11 +78,14 @@ typedef struct
 } ShumateMarkerPrivate;
 
 static void location_interface_init (ShumateLocationInterface *iface);
+static void buildable_interface_init (GtkBuildableIface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (ShumateMarker, shumate_marker, GTK_TYPE_WIDGET,
     G_ADD_PRIVATE (ShumateMarker)
-    G_IMPLEMENT_INTERFACE (SHUMATE_TYPE_LOCATION, location_interface_init));
+    G_IMPLEMENT_INTERFACE (SHUMATE_TYPE_LOCATION, location_interface_init)
+    G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_interface_init));
 
+static GtkBuildableIface *parent_buildable_iface;
 
 static void
 shumate_marker_set_location (ShumateLocation *location,
@@ -125,6 +128,18 @@ shumate_marker_get_longitude (ShumateLocation *location)
   return priv->lon;
 }
 
+static void
+shumate_marker_add_child (GtkBuildable *buildable,
+                          GtkBuilder   *builder,
+                          GObject      *child,
+                          const char   *type)
+{
+  if (GTK_IS_WIDGET (child))
+    shumate_marker_set_child (SHUMATE_MARKER (buildable), GTK_WIDGET (child));
+  else
+    parent_buildable_iface->add_child (buildable, builder, child, type);
+}
+
 static void
 shumate_marker_get_property (GObject *object,
     guint prop_id,
@@ -303,6 +318,13 @@ location_interface_init (ShumateLocationInterface *iface)
   iface->set_location = shumate_marker_set_location;
 }
 
+static void
+buildable_interface_init (GtkBuildableIface *iface)
+{
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+  iface->add_child = shumate_marker_add_child;
+}
+
 /**
  * shumate_marker_new:
  *


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