From 5509f861f7d548fe88da0e836023d1a5dceea6e8 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 29 Jun 2009 18:30:50 +0200 Subject: [PATCH] Added GtkGis::destroy, GtkGis::size_request and GtkGis::size:allocate. Now the widget is visible. --- src/gtkgis.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 4 deletions(-) diff --git a/src/gtkgis.c b/src/gtkgis.c index 0740a39..526cde8 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -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); + } +} + -- 2.49.0