]> git.draconx.ca Git - aspectbin.git/commitdiff
Add constrain as a GObject property.
authorNick Bowler <nbowler@draconx.ca>
Sun, 15 Mar 2009 04:15:56 +0000 (00:15 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sun, 15 Mar 2009 04:15:56 +0000 (00:15 -0400)
aspectbin.c

index 82aba4025bd47482e052a69d9c5e090647916ae1..2ce72bdf82a4f5bda7ec4c021e246601d08ce6fa 100644 (file)
@@ -1,6 +1,11 @@
 #include <stdio.h>
 #include "aspectbin.h"
 
+enum {
+       PROP_0,
+       PROP_CONSTRAIN,
+};
+
 static void aspect_bin_size_request(GtkWidget *, GtkRequisition *);
 static void aspect_bin_size_allocate(GtkWidget *, GtkAllocation *);
 static void aspect_bin_add(GtkContainer *, GtkWidget *);
@@ -8,6 +13,10 @@ static void aspect_bin_remove(GtkContainer *, GtkWidget *);
 static void aspect_bin_forall(GtkContainer *, gboolean, GtkCallback, gpointer);
 static GType aspect_bin_child_type(GtkContainer *);
 
+static void aspect_bin_get_property(GObject *, guint, GValue *, GParamSpec *);
+static void aspect_bin_set_property(GObject *, guint, const GValue *,
+                                                          GParamSpec *);
+
 G_DEFINE_TYPE(AspectBin, aspect_bin, GTK_TYPE_CONTAINER)
 
 static void aspect_bin_init(AspectBin *abin)
@@ -23,6 +32,7 @@ static void aspect_bin_init(AspectBin *abin)
 
 static void aspect_bin_class_init(AspectBinClass *class)
 {
+       GObjectClass      *object_class    = G_OBJECT_CLASS(class);
        GtkWidgetClass    *widget_class    = GTK_WIDGET_CLASS(class);
        GtkContainerClass *container_class = GTK_CONTAINER_CLASS(class);
 
@@ -33,6 +43,17 @@ static void aspect_bin_class_init(AspectBinClass *class)
        container_class->remove     = aspect_bin_remove;
        container_class->forall     = aspect_bin_forall;
        container_class->child_type = aspect_bin_child_type;
+
+       object_class->set_property = aspect_bin_set_property;
+       object_class->get_property = aspect_bin_get_property;
+
+       g_object_class_install_property(object_class, PROP_CONSTRAIN,
+               g_param_spec_boolean("constrain",
+                       "Constrain",
+                       "TRUE if side child should expand only as much as the"
+                                                                      " body",
+                       FALSE,
+                       G_PARAM_READWRITE));
 }
 
 GtkWidget *aspect_bin_new(void)
@@ -40,6 +61,39 @@ GtkWidget *aspect_bin_new(void)
        return GTK_WIDGET(g_object_new(ASPECT_BIN_TYPE, NULL));
 }
 
+static void aspect_bin_set_property(GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+       AspectBin *abin = ASPECT_BIN(object);
+
+       switch (prop_id) {
+       case PROP_CONSTRAIN:
+               abin->constrain = g_value_get_boolean(value);
+               gtk_widget_queue_resize(GTK_WIDGET(abin));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+       }
+}
+
+static void aspect_bin_get_property(GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+       AspectBin *abin = ASPECT_BIN(object);
+
+       switch (prop_id) {
+       case PROP_CONSTRAIN:
+               g_value_set_boolean(value, abin->constrain);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+       }
+}
+
 static void aspect_bin_add(GtkContainer *container, GtkWidget *widget)
 {
        AspectBin *abin;