From fbf9c54b02af08ba8fe08d4f73e8c5f6c9b22c31 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 18 Oct 2016 21:53:40 +0200 Subject: Extended the graph widget as much as needed and centered its content. --- ChangeLog | 8 ++++ src/gtkext/gtkgraphview.c | 107 +++++++++++++++++++++++++++++++++++++++++++--- src/gtkext/gtkviewpanel.c | 3 +- 3 files changed, 109 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3c3025..1f6cfbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ 16-10-18 Cyrille Bagard * src/gtkext/gtkgraphview.c: + Extend the graph widget as much as needed and center its content. + + * src/gtkext/gtkviewpanel.c: + Typo. + +16-10-18 Cyrille Bagard + + * src/gtkext/gtkgraphview.c: Fix a huge memory leak when computing shadows. 16-10-17 Cyrille Bagard diff --git a/src/gtkext/gtkgraphview.c b/src/gtkext/gtkgraphview.c index 1666488..1fa654d 100644 --- a/src/gtkext/gtkgraphview.c +++ b/src/gtkext/gtkgraphview.c @@ -41,6 +41,7 @@ struct _GtkGraphView { GtkViewPanel parent; /* A laisser en premier */ GtkWidget *support; /* Support des vues en bloc */ + GtkWidget *extender; /* Force la taille du support */ GBinRoutine *routine; /* Routine en cours d'affichage*/ @@ -87,6 +88,12 @@ static void gtk_graph_view_dispose(GtkGraphView *); /* Procède à la libération totale de la mémoire. */ static void gtk_graph_view_finalize(GtkGraphView *); +/* S'adapte à la surface concédée par le composant parent. */ +static void gtk_graph_view_size_allocate(GtkWidget *, GtkAllocation *); + +/* Centre si possible le contenu du panneau d'affichage. */ +static void gtk_graph_view_update_support_margins(GtkGraphView *, const GtkAllocation *); + /* Indique les dimensions de travail du composant d'affichage. */ static void gtk_graph_view_compute_requested_size(GtkGraphView *, gint *, gint *); @@ -156,6 +163,7 @@ G_DEFINE_TYPE(GtkGraphView, gtk_graph_view, GTK_TYPE_VIEW_PANEL) static void gtk_graph_view_class_init(GtkGraphViewClass *class) { GObjectClass *object; /* Autre version de la classe */ + GtkWidgetClass *widget_class; /* Classe de haut niveau */ GtkViewPanelClass *panel_class; /* Classe parente */ object = G_OBJECT_CLASS(class); @@ -163,6 +171,10 @@ static void gtk_graph_view_class_init(GtkGraphViewClass *class) object->dispose = (GObjectFinalizeFunc/* ! */)gtk_graph_view_dispose; object->finalize = (GObjectFinalizeFunc)gtk_graph_view_finalize; + widget_class = GTK_WIDGET_CLASS(class); + + widget_class->size_allocate = gtk_graph_view_size_allocate; + panel_class = GTK_VIEW_PANEL_CLASS(class); panel_class->compute_size = (compute_requested_size_fc)gtk_graph_view_compute_requested_size; @@ -230,6 +242,13 @@ static void gtk_graph_view_init(GtkGraphView *view) //view->cond = g_cond_new(); + view->extender = gtk_fixed_new(); + + gtk_widget_set_margin_end(view->extender, 1); + gtk_widget_set_margin_top(view->extender, 1); + + gtk_widget_show(view->extender); + view->cluster = NULL; @@ -251,6 +270,8 @@ static void gtk_graph_view_init(GtkGraphView *view) static void gtk_graph_view_dispose(GtkGraphView *view) { + g_object_unref(G_OBJECT(view->extender)); + if (view->cluster != NULL) { g_object_unref(G_OBJECT(view->cluster)); @@ -281,12 +302,67 @@ static void gtk_graph_view_finalize(GtkGraphView *view) } +/****************************************************************************** +* * +* Paramètres : widget = composant GTK à mettre à jour. * +* allocation = étendue accordée à la vue. * +* * +* Description : S'adapte à la surface concédée par le composant parent. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_graph_view_size_allocate(GtkWidget *widget, GtkAllocation *allocation) +{ + GtkGraphView *view; /* Autre version du composant */ + + GTK_WIDGET_CLASS(gtk_graph_view_parent_class)->size_allocate(widget, allocation); + + view = GTK_GRAPH_VIEW(widget); + + gtk_graph_view_update_support_margins(view, allocation); + +} + +/****************************************************************************** +* * +* Paramètres : view = panneau dont le contenu est à déplacer. * +* allocation = étendue accordée à la vue. * +* * +* Description : Centre si possible le contenu du panneau d'affichage. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +static void gtk_graph_view_update_support_margins(GtkGraphView *view, const GtkAllocation *allocation) +{ + gint width; /* Largeur totale du support */ + gint height; /* Hauteur totale du support */ + gint start; /* Bordure horizontale */ + gint top; /* Bordure verticale */ + gtk_graph_view_compute_requested_size(view, &width, &height); + if (width > allocation->width) + start = 0; + else + start = (allocation->width - width) / 2; + if (height > allocation->height) + top = 0; + else + top = (allocation->height - height) / 2; + gtk_widget_set_margin_start(view->support, start); + gtk_widget_set_margin_top(view->support, top); +} /****************************************************************************** @@ -609,8 +685,9 @@ static void gtk_graph_view_define_main_address(GtkGraphView *view, const vmpa2t GBinRoutine **routines; /* Liste des routines trouvées */ size_t routines_count; /* Nombre de ces routines */ size_t i; /* Boucle de parcours */ - gint width; /* Largeur idéale du composant */ - gint height; /* Hauteur idéale du composant */ + gint right; /* Abscisse du coin droit */ + gint bottom; /* Ordonnée du coin inférieur */ + GtkAllocation allocation; /* Espace alloué au panneau */ if (view->routine == NULL) need_update = true; @@ -671,6 +748,26 @@ static void gtk_graph_view_define_main_address(GtkGraphView *view, const vmpa2t g_graph_cluster_place(view->cluster, view); + /** + * Comme la taille du support ne peut pas être forcée et + * étendue pour comprendre les ombres, on place un composant + * minuscule à l'extrémité de ce support. + */ + + gtk_graph_view_compute_requested_size(view, &right, &bottom); + + g_object_ref(G_OBJECT(view->extender)); + gtk_fixed_put(GTK_FIXED(view->support), view->extender, right, bottom); + + /** + * Si possible, on centre le contenu obtenu. + */ + + gtk_widget_get_allocation(GTK_WIDGET(view), &allocation); + + gtk_graph_view_update_support_margins(view, &allocation); + + } while (0); @@ -683,13 +780,9 @@ static void gtk_graph_view_define_main_address(GtkGraphView *view, const vmpa2t } - gtk_graph_view_compute_requested_size(view, &width, &height); - - gtk_widget_size_allocate(GTK_WIDGET(view), (GtkAllocation []){ { 0, 0, width, height } }); - gtk_widget_size_allocate(view->support, (GtkAllocation []){ { 0, 0, width, height } }); - change_editor_items_current_view_content(GTK_VIEW_PANEL(view)); + } } diff --git a/src/gtkext/gtkviewpanel.c b/src/gtkext/gtkviewpanel.c index 8672bb9..a39ea24 100644 --- a/src/gtkext/gtkviewpanel.c +++ b/src/gtkext/gtkviewpanel.c @@ -328,10 +328,9 @@ static void gtk_view_panel_realize(GtkWidget *widget) } - /****************************************************************************** * * -* Paramètres : view = composant GTK à mettre à jour. * +* Paramètres : widget = composant GTK à mettre à jour. * * allocation = étendue accordée à la vue. * * * * Description : S'adapte à la surface concédée par le composant parent. * -- cgit v0.11.2-87-g4458