diff options
-rw-r--r-- | src/gtk-valuegraph.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/gtk-valuegraph.c b/src/gtk-valuegraph.c index e0bc112..f508d29 100644 --- a/src/gtk-valuegraph.c +++ b/src/gtk-valuegraph.c @@ -18,7 +18,6 @@ static GtkObjectClass *parent_class = NULL; static void gtk_value_graph_destroy(GtkObject *gtk_value_graph) { - free(GTK_VALUE_GRAPH(gtk_value_graph)->data); parent_class->destroy(gtk_value_graph); } @@ -53,17 +52,27 @@ static void gtk_value_graph_class_init(GtkValueGraphClass *class) { GtkObjectClass *object_class; GObjectClass *g_object_class; - + object_class = (GtkObjectClass *) class; g_object_class = G_OBJECT_CLASS(class); object_class->destroy = gtk_value_graph_destroy; g_object_class->constructor = gtk_value_graph_constructor; - + parent_class = gtk_type_class(gtk_drawing_area_get_type()); } +static gint gtk_value_graph_destroyed(GtkWidget *graph, gpointer data) { + + if ( GTK_VALUE_GRAPH(graph)->data ) { + free(GTK_VALUE_GRAPH(graph)->data); + } + + return 0; + +} + static gint gtk_value_graph_draw(GtkWidget *graph, GdkEventExpose *event, gpointer data) { GtkValueGraph *vg; @@ -143,7 +152,7 @@ static gint gtk_value_graph_draw(GtkWidget *graph, GdkEventExpose *event, gpoint cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); cairo_set_line_width(cr, 1.0); cairo_stroke(cr); - + /* Label axes */ cairo_new_path(cr); cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); @@ -188,12 +197,13 @@ static gint gtk_value_graph_draw(GtkWidget *graph, GdkEventExpose *event, gpoint static void gtk_value_graph_init(GtkValueGraph *gtk_value_graph) { gtk_widget_set_size_request(GTK_WIDGET(gtk_value_graph), 100, 200); g_signal_connect(G_OBJECT(gtk_value_graph), "expose_event", G_CALLBACK(gtk_value_graph_draw), NULL); + g_signal_connect(G_OBJECT(gtk_value_graph), "destroy", G_CALLBACK(gtk_value_graph_destroyed), NULL); } guint gtk_value_graph_get_type(void) { static guint gtk_value_graph_type = 0; - + if ( !gtk_value_graph_type ) { GtkTypeInfo gtk_value_graph_info = { @@ -209,7 +219,7 @@ guint gtk_value_graph_get_type(void) { gtk_value_graph_type = gtk_type_unique(gtk_drawing_area_get_type(), >k_value_graph_info); } - + return gtk_value_graph_type; } @@ -225,7 +235,7 @@ static double gtk_value_graph_peak(double *data, unsigned int n) { for ( i=0; i<n; i++ ) { if ( data[i] > max ) max = data[i]; } - + return max; } @@ -241,7 +251,7 @@ static double gtk_value_graph_min(double *data, unsigned int n) { for ( i=0; i<n; i++ ) { if ( data[i] < min ) min = data[i]; } - + return min; } @@ -250,7 +260,7 @@ void gtk_value_graph_set_data(GtkValueGraph *vg, double *data, unsigned int n) { vg->data = data; vg->n = n; - + /* Recalculate axes */ vg->xmax = n; vg->ymax = gtk_value_graph_peak(data, n); |