]> saetta.ns0.it Git - libgtkgis/commitdiff
Added GtkGis::destroy, GtkGis::size_request and GtkGis::size:allocate.
authorAndrea Zagli <azagli@libero.it>
Mon, 29 Jun 2009 16:30:50 +0000 (18:30 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 29 Jun 2009 16:30:50 +0000 (18:30 +0200)
Now the widget is visible.

src/gtkgis.c

index 0740a3917264ec3518246c88151c1c140b4d9b7a..526cde861f627020ab107762780a8c778c67eabc 100644 (file)
@@ -34,6 +34,8 @@
 static void gtk_gis_class_init (GtkGisClass *klass);
 static void gtk_gis_init (GtkGis *gtk_gis);
 
+static void gtk_gis_destroy (GtkObject *object);
+
 static void gtk_gis_add (GtkContainer *container,
                          GtkWidget *widget);
 
@@ -46,6 +48,11 @@ static void gtk_gis_get_property (GObject *object,
                                      GValue *value,
                                      GParamSpec *pspec);
 
+static void gtk_gis_size_request (GtkWidget *widget,
+                                  GtkRequisition *requisition);
+static void gtk_gis_size_allocate (GtkWidget *widget,
+                                   GtkAllocation *allocation);
+
 
 #define GTK_GIS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS, GtkGisPrivate))
 
@@ -57,7 +64,7 @@ struct _GtkGisPrivate
                GtkWidget *canvas;
                GooCanvasItem *canvas_root;
 
-               GList *layer_groups;
+               GList *layers_groups;
                GList *layers;
 
                GtkGisLayerExtent extent;
@@ -68,14 +75,20 @@ G_DEFINE_TYPE (GtkGis, gtk_gis, GTK_TYPE_BIN)
 static void
 gtk_gis_class_init (GtkGisClass *klass)
 {
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+       GtkObjectClass *object_class = (GtkObjectClass*) klass;
        GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
        GtkContainerClass *container_class = (GtkContainerClass*) klass;
 
        g_type_class_add_private (object_class, sizeof (GtkGisPrivate));
 
-       object_class->set_property = gtk_gis_set_property;
-       object_class->get_property = gtk_gis_get_property;
+       gobject_class->set_property = gtk_gis_set_property;
+       gobject_class->get_property = gtk_gis_get_property;
+
+       object_class->destroy = gtk_gis_destroy;
+
+       widget_class->size_request = gtk_gis_size_request;
+       widget_class->size_allocate = gtk_gis_size_allocate;
 
        container_class->add = gtk_gis_add;
 }
@@ -315,6 +328,23 @@ gtk_gis_remove_layer (GtkGis *gtkgis, GtkGisLayer *layer)
        priv->layers = g_list_remove (priv->layers, layer);
 }
 
+static void
+gtk_gis_destroy (GtkObject *object)
+{
+       GtkGis *gtkgis = GTK_GIS (object);
+       GtkGisPrivate *priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
+       /* TO DO */
+       /* free each layers_groups before */
+       g_list_free (priv->layers_groups);
+
+       /* TO DO */
+       /* free each layers before */
+       g_list_free (priv->layers);
+
+       GTK_OBJECT_CLASS (gtk_gis_parent_class)->destroy (object);
+}
+
 static void
 gtk_gis_add (GtkContainer *container,
                         GtkWidget *child)
@@ -360,3 +390,68 @@ gtk_gis_get_property (GObject *object, guint property_id, GValue *value, GParamS
                                break;
                }
 }
+
+static void
+gtk_gis_size_request (GtkWidget *widget,
+                      GtkRequisition *requisition)
+{
+       GtkGis *gtkgis;
+       GtkBin *bin;
+       GtkRequisition child_requisition;
+
+       g_return_if_fail (IS_GTK_GIS (widget));
+       g_return_if_fail (requisition != NULL);
+
+       gtkgis = GTK_GIS (widget);
+       bin = GTK_BIN (gtkgis);
+
+       requisition->width = 0;
+       requisition->height = 0;
+
+       if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+               {
+                       gtk_widget_size_request (bin->child, &child_requisition);
+                       requisition->width += child_requisition.width;
+                       requisition->height += child_requisition.height;
+               }
+
+       requisition->width += GTK_CONTAINER (widget)->border_width * 2;
+       requisition->height += GTK_CONTAINER (widget)->border_width * 2;
+}
+
+static void
+gtk_gis_size_allocate (GtkWidget *widget,
+                       GtkAllocation *allocation)
+{
+       GtkGis *gtkgis;
+       GtkGisPrivate *priv;
+       GtkBin *bin;
+       GtkAllocation relative_allocation;
+       GtkAllocation child_allocation;
+
+       g_return_if_fail (IS_GTK_GIS (widget));
+       g_return_if_fail (allocation != NULL);
+
+       gtkgis = GTK_GIS (widget);
+       bin = GTK_BIN (gtkgis);
+
+       priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
+       widget->allocation = *allocation;
+
+       relative_allocation.x = GTK_CONTAINER (widget)->border_width;
+       relative_allocation.y = GTK_CONTAINER (widget)->border_width;
+       relative_allocation.width = MAX (1, (gint)widget->allocation.width - relative_allocation.x * 2);
+       relative_allocation.height = MAX (1, (gint)widget->allocation.height - relative_allocation.y * 2);
+
+       if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+               {
+                       child_allocation.x = relative_allocation.x + allocation->x;
+                       child_allocation.y = relative_allocation.y + allocation->y;
+                       child_allocation.width = relative_allocation.width;
+                       child_allocation.height = relative_allocation.height;
+
+                       gtk_widget_size_allocate (bin->child, &child_allocation);
+               }
+}
+