From 5d4a2289f134152f3d660c4af1368bfbb04f8699 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 3 Oct 2013 11:08:14 +0200 Subject: [PATCH] GdaExGrid: added property 'title'. --- src/grid.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/grid.h | 3 +++ tests/grid.c | 1 + 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/src/grid.c b/src/grid.c index da74ea0..d2700ba 100644 --- a/src/grid.c +++ b/src/grid.c @@ -62,7 +62,10 @@ struct _GdaExGridPrivate { GPtrArray *columns; /* GdaExGridColumn */ + gchar *title; + GtkTreeModel *model; + GtkWidget *view; }; G_DEFINE_TYPE (GdaExGrid, gdaex_grid, G_TYPE_OBJECT) @@ -84,6 +87,8 @@ gdaex_grid_init (GdaExGrid *gdaex_grid) GdaExGridPrivate *priv = GDAEX_GRID_GET_PRIVATE (gdaex_grid); priv->columns = g_ptr_array_new (); + priv->title = NULL; + priv->view = NULL; } GdaExGrid @@ -96,6 +101,49 @@ GdaExGrid return gdaex_grid; } +void +gdaex_grid_set_title (GdaExGrid *grid, const gchar *title) +{ + GdaExGridPrivate *priv; + + g_return_if_fail (GDAEX_IS_GRID (grid)); + + priv = GDAEX_GRID_GET_PRIVATE (grid); + + if (priv->title != NULL) + { + g_free (priv->title); + } + + if (title != NULL) + { + priv->title = g_strdup (title); + } + else + { + priv->title = NULL; + } +} + +const gchar +*gdaex_grid_get_title (GdaExGrid *grid) +{ + GdaExGridPrivate *priv; + + g_return_val_if_fail (GDAEX_IS_GRID (grid), NULL); + + priv = GDAEX_GRID_GET_PRIVATE (grid); + + if (priv->title != NULL) + { + return g_strdup (priv->title); + } + else + { + return NULL; + } +} + void gdaex_grid_add_column (GdaExGrid *grid, GdaExGridColumn *column) { @@ -429,9 +477,11 @@ static GtkTreeView } } + priv->view = view; + #ifdef REPTOOL_FOUND g_signal_connect (view, - "key-release-event", G_CALLBACK (gdaex_grid_on_key_release_event), (gpointer)view); + "key-release-event", G_CALLBACK (gdaex_grid_on_key_release_event), (gpointer)grid); #endif return GTK_TREE_VIEW (view); @@ -443,16 +493,30 @@ gdaex_grid_on_key_release_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data) { + GdaExGridPrivate *priv; + RptReport *rptr; RptPrint *rptp; + gchar *_title; + switch (event->keyval) { case GDK_F12: { if (event->state & GDK_CONTROL_MASK) { - rptr = rpt_report_new_from_gtktreeview (GTK_TREE_VIEW (user_data), NULL); + priv = GDAEX_GRID_GET_PRIVATE (user_data); + + if (priv->title != NULL) + { + _title = g_strdup_printf ("\"%s\"", priv->title); + } + else + { + _title = NULL; + } + rptr = rpt_report_new_from_gtktreeview (GTK_TREE_VIEW (priv->view), _title); if (rptr != NULL) { @@ -465,10 +529,14 @@ gdaex_grid_on_key_release_event (GtkWidget *widget, if (rptp != NULL) { rpt_print_set_output_type (rptp, RPT_OUTPUT_GTK); - rpt_print_print (rptp, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (user_data)))); + rpt_print_print (rptp, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (priv->view)))); } } + if (_title != NULL) + { + g_free (_title); + } return TRUE; } break; diff --git a/src/grid.h b/src/grid.h index a487eaf..3abc5e2 100644 --- a/src/grid.h +++ b/src/grid.h @@ -59,6 +59,9 @@ GType gdaex_grid_get_type (void) G_GNUC_CONST; GdaExGrid *gdaex_grid_new (void); +void gdaex_grid_set_title (GdaExGrid *grid, const gchar *title); +const gchar *gdaex_grid_get_title (GdaExGrid *grid); + void gdaex_grid_add_column (GdaExGrid *grid, GdaExGridColumn *column); void gdaex_grid_add_columns (GdaExGrid *grid, GSList *columns); diff --git a/tests/grid.c b/tests/grid.c index 7118695..0519b3b 100644 --- a/tests/grid.c +++ b/tests/grid.c @@ -49,6 +49,7 @@ main (int argc, char **argv) gtk_container_add (GTK_CONTAINER (w), scrolledw); grid = gdaex_grid_new (); + gdaex_grid_set_title (grid, "The grid title"); gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, FALSE, FALSE, FALSE, -1); gdaex_grid_add_column (grid, gcol); -- 2.49.0