]> saetta.ns0.it Git - libgdaex/commitdiff
GdaExGrid: added property 'title'.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 3 Oct 2013 09:08:14 +0000 (11:08 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 3 Oct 2013 09:09:00 +0000 (11:09 +0200)
src/grid.c
src/grid.h
tests/grid.c

index da74ea0d7cbae3c49694d6ac2d4c903450c9dacc..d2700ba97099e82f0ba2897cc14f117d4075ed24 100644 (file)
@@ -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;
index a487eaffdfd08928f05cc8465d0e94bc0a73323e..3abc5e26b0d76ecdcae62e66c3e7e1386581f0ed 100644 (file)
@@ -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);
 
index 71186951ae009b51e1ec61d3f1a1b1f6fce3f267..0519b3bca0c3dae8fa868bbea57ac1fa33efe9bf 100644 (file)
@@ -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);