Bugfixes.
*.bak
libgdaex*tar*
tests/test_prefix*
+tests/grid
+tests/grid.exe
/*
* grid.c
*
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
*
- * This file is part of libgdaex_grid.
+ * This file is part of libgdaex.
*
* libgdaex_grid is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
GValue *value,
GParamSpec *pspec);
-#define GDAEX_GRID_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDAEX_TYPE_GRID, GdaExGridPrivate))
+static GtkTreeModel *gdaex_grid_get_model (GdaExGrid *grid);
+static GtkTreeView *gdaex_grid_get_view (GdaExGrid *grid);
-typedef struct
- {
- GtkTreeViewColumn *view_col;
- GdaExGridColumn *grid_col;
- } _Column;
+#define GDAEX_GRID_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDAEX_TYPE_GRID, GdaExGridPrivate))
typedef struct _GdaExGridPrivate GdaExGridPrivate;
struct _GdaExGridPrivate
{
- GPtrArray *columns; /* _Column */
+ GPtrArray *columns; /* GdaExGridColumn */
};
G_DEFINE_TYPE (GdaExGrid, gdaex_grid, G_TYPE_OBJECT)
{
GdaExGridPrivate *priv;
- _Column *col;
-
g_return_if_fail (GDAEX_IS_GRID (grid));
g_return_if_fail (GDAEX_IS_GRID_COLUMN (column));
priv = GDAEX_GRID_GET_PRIVATE (grid);
- col = g_new0 (_Column, 1);
- col->view_col = NULL;
- col->grid_col = g_memdup (column, sizeof (GdaExGridColumn));
-
- g_ptr_array_add (priv->columns, col);
+ g_ptr_array_add (priv->columns, g_object_ref (column));
}
void
priv->columns = g_ptr_array_new ();
}
+GtkWidget
+*gdaex_grid_get_widget (GdaExGrid *grid)
+{
+ g_return_val_if_fail (GDAEX_IS_GRID (grid), NULL);
+
+ return GTK_WIDGET (gdaex_grid_get_view (grid));
+}
+
/* PRIVATE */
static void
gdaex_grid_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
GdaExGrid *gdaex_grid = GDAEX_GRID (object);
-
GdaExGridPrivate *priv = GDAEX_GRID_GET_PRIVATE (gdaex_grid);
switch (property_id)
gdaex_grid_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
GdaExGrid *gdaex_grid = GDAEX_GRID (object);
-
GdaExGridPrivate *priv = GDAEX_GRID_GET_PRIVATE (gdaex_grid);
switch (property_id)
break;
}
}
+
+static GtkTreeModel
+*gdaex_grid_get_model (GdaExGrid *grid)
+{
+ /* TODO for now it returns always a GtkListStore */
+
+ GtkListStore *store;
+
+ GdaExGridPrivate *priv;
+
+ guint col;
+ GType *gtype;
+
+ g_return_val_if_fail (GDAEX_IS_GRID (grid), NULL);
+
+ priv = GDAEX_GRID_GET_PRIVATE (grid);
+
+ gtype = g_new0 (GType, priv->columns->len);
+
+ for (col = 0; col < priv->columns->len; col++)
+ {
+ gtype[col] = gdaex_grid_column_get_gtype ((GdaExGridColumn *)g_ptr_array_index (priv->columns, col));
+ }
+
+ store = gtk_list_store_newv (priv->columns->len, gtype);
+
+ return GTK_TREE_MODEL (store);
+}
+
+static GtkTreeView
+*gdaex_grid_get_view (GdaExGrid *grid)
+{
+ GtkWidget *view;
+
+ GdaExGridPrivate *priv;
+
+ GtkTreeModel *model;
+ GdaExGridColumn *gcolumn;
+
+ guint col;
+
+ g_return_val_if_fail (GDAEX_IS_GRID (grid), NULL);
+
+ priv = GDAEX_GRID_GET_PRIVATE (grid);
+
+ model = gdaex_grid_get_model (grid);
+ view = gtk_tree_view_new_with_model (model);
+
+ for (col = 0; col < priv->columns->len; col++)
+ {
+ gcolumn = (GdaExGridColumn *)g_ptr_array_index (priv->columns, col);
+ if (gdaex_grid_column_get_visible (gcolumn))
+ {
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view), gdaex_grid_column_get_column (gcolumn, col));
+ }
+ }
+
+ return GTK_TREE_VIEW (view);
+}
/*
* grid.h
*
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
*
* This file is part of libgdaex.
*
G_BEGIN_DECLS
-#define GDAEX_TYPE_GRID (gdaex_get_type ())
+#define GDAEX_TYPE_GRID (gdaex_grid_get_type ())
#define GDAEX_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDAEX_TYPE_GRID, GdaExGrid))
#define GDAEX_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDAEX_TYPE_GRID, GdaExGridClass))
#define GDAEX_IS_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDAEX_TYPE_GRID))
void gdaex_grid_clear (GdaExGrid *grid);
+GtkWidget *gdaex_grid_get_widget (GdaExGrid *grid);
+
G_END_DECLS
/*
* gridcolumn.c
*
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
*
* This file is part of libgdaex_grid_column.
*
gboolean resizable;
gboolean sortable;
gboolean reorderable;
+ guint decimals;
};
G_DEFINE_TYPE (GdaExGridColumn, gdaex_grid_column, G_TYPE_OBJECT)
priv->resizable = FALSE;
priv->sortable = FALSE;
priv->reorderable = FALSE;
+ priv->decimals = 0;
}
GdaExGridColumn
gboolean visible,
gboolean resizable,
gboolean sortable,
- gboolean reorderable)
+ gboolean reorderable,
+ guint decimals)
{
GdaExGridColumn *gdaex_grid_column = GDAEX_GRID_COLUMN (g_object_new (gdaex_grid_column_get_type (), NULL));
gdaex_grid_column_set_resizable (gdaex_grid_column, resizable);
gdaex_grid_column_set_sortable (gdaex_grid_column, sortable);
gdaex_grid_column_set_reorderable (gdaex_grid_column, reorderable);
+ gdaex_grid_column_set_decimals (gdaex_grid_column, decimals);
return gdaex_grid_column;
}
return priv->reorderable;
}
+void
+gdaex_grid_column_set_decimals (GdaExGridColumn *column, guint decimals)
+{
+ g_return_if_fail (GDAEX_IS_GRID_COLUMN (column));
+
+ GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
+
+ priv->decimals = decimals;
+}
+
+guint
+gdaex_grid_column_get_decimals (GdaExGridColumn *column)
+{
+ g_return_val_if_fail (GDAEX_IS_GRID_COLUMN (column), FALSE);
+
+ GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
+
+ return priv->decimals;
+}
+
+GtkTreeViewColumn
+*gdaex_grid_column_get_column (GdaExGridColumn *column, gint model_column_number)
+{
+ GtkTreeViewColumn *col;
+
+ GdaExGridColumnPrivate *priv;
+
+ GtkCellRenderer *renderer;
+
+ g_return_val_if_fail (GDAEX_IS_GRID_COLUMN (column), NULL);
+
+ priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
+
+ renderer = NULL;
+ switch (priv->type)
+ {
+ case G_TYPE_STRING:
+ renderer = gtk_cell_renderer_text_new ();
+ break;
+
+ case G_TYPE_INT:
+ case G_TYPE_FLOAT:
+ case G_TYPE_DOUBLE:
+ renderer = gtk_cell_renderer_spin_new ();
+ break;
+ }
+ if (renderer == NULL)
+ {
+ g_warning ("Error on creating the renderer.");
+ return NULL;
+ }
+
+ col = gtk_tree_view_column_new ();
+
+ gtk_tree_view_column_pack_start (col, renderer, TRUE);
+
+ gtk_tree_view_column_add_attribute (col, renderer, "text", model_column_number);
+
+ gtk_tree_view_column_set_title (col, priv->title);
+ gtk_tree_view_column_set_resizable (col, priv->resizable);
+ gtk_tree_view_column_set_clickable (col, priv->sortable);
+ gtk_tree_view_column_set_reorderable (col, priv->reorderable);
+
+ return col;
+}
+
/* PRIVATE */
static void
gdaex_grid_column_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
/*
* gridcolumn.h
*
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
*
* This file is part of libgdaex.
*
#include <glib.h>
#include <glib-object.h>
+#include <gtk/gtk.h>
+
G_BEGIN_DECLS
-#define GDAEX_TYPE_GRID_COLUMN (gdaex_get_type ())
+#define GDAEX_TYPE_GRID_COLUMN (gdaex_grid_column_get_type ())
#define GDAEX_GRID_COLUMN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDAEX_TYPE_GRID_COLUMN, GdaExGridColumn))
#define GDAEX_GRID_COLUMN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDAEX_TYPE_GRID_COLUMN, GdaExGridColumnClass))
#define GDAEX_IS_GRID_COLUMN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDAEX_TYPE_GRID_COLUMN))
gboolean visible,
gboolean resizable,
gboolean sortable,
- gboolean reorderable);
+ gboolean reorderable,
+ guint decimals);
void gdaex_grid_column_set_title (GdaExGridColumn *column, const gchar *title);
const gchar *gdaex_grid_column_get_title (GdaExGridColumn *column);
void gdaex_grid_column_set_reorderable (GdaExGridColumn *column, gboolean reorderable);
gboolean gdaex_grid_column_get_reorderable (GdaExGridColumn *column);
+void gdaex_grid_column_set_decimals (GdaExGridColumn *column, guint decimals);
+guint gdaex_grid_column_get_decimals (GdaExGridColumn *column);
+
+GtkTreeViewColumn *gdaex_grid_column_get_column (GdaExGridColumn *column, gint model_column_number);
+
G_END_DECLS
-I$(top_srcdir)/src \
-DTESTSDIR="\"@abs_builddir@\""
-noinst_PROGRAMS = test_prefix
+noinst_PROGRAMS = test_prefix \
+ grid
LDADD = $(top_builddir)/src/libgdaex.la
--- /dev/null
+/*
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <libgdaex.h>
+
+int
+main (int argc, char **argv)
+{
+ GtkWidget *w;
+
+ GdaExGrid *grid;
+ GdaExGridColumn *gcol;
+ GtkWidget *wgrid;
+
+ gtk_init (&argc, &argv);
+
+ w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ grid = gdaex_grid_new ();
+
+ gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, FALSE, FALSE, FALSE, 0);
+ gdaex_grid_add_column (grid, gcol);
+
+ gcol = gdaex_grid_column_new ("Name", "name", G_TYPE_STRING, TRUE, TRUE, TRUE, TRUE, 0);
+ gdaex_grid_add_column (grid, gcol);
+
+ wgrid = gdaex_grid_get_widget (grid);
+ gtk_container_add (GTK_CONTAINER (w), wgrid);
+
+ gtk_widget_show_all (w);
+
+ gtk_main ();
+
+ return 0;
+}