gpointer user_data);
#endif
+static gboolean gdaex_grid_on_button_press_event (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data);
+static gboolean gdaex_grid_on_popup_menu (GtkWidget *widget,
+ gpointer user_data);
+static void gdaex_grid_on_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
+ gpointer user_data);
+
static GtkTreeModel *gdaex_grid_get_model (GdaExGrid *grid);
static GtkTreeView *gdaex_grid_get_view (GdaExGrid *grid);
GtkTreeModel *model;
GtkWidget *view;
+ GtkWidget *menu;
};
G_DEFINE_TYPE (GdaExGrid, gdaex_grid, G_TYPE_OBJECT)
priv->columns = g_ptr_array_new ();
priv->title = NULL;
priv->view = NULL;
+ priv->menu = NULL;
}
GdaExGrid
guint col;
+ GtkWidget *mitem;
+
g_return_val_if_fail (GDAEX_IS_GRID (grid), NULL);
priv = GDAEX_GRID_GET_PRIVATE (grid);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
+ if (priv->menu != NULL)
+ {
+ g_free (priv->menu);
+ }
+ if (priv->columns->len > 0)
+ {
+ priv->menu = gtk_menu_new ();
+ }
+ else
+ {
+ priv->menu = NULL;
+ }
+
for (col = 0; col < priv->columns->len; col++)
{
gcolumn = (GdaExGridColumn *)g_ptr_array_index (priv->columns, col);
- if (gdaex_grid_column_get_visible (gcolumn))
+ vcolumn = gdaex_grid_column_get_column (gcolumn);
+ if (vcolumn)
{
- vcolumn = gdaex_grid_column_get_column (gcolumn);
- if (vcolumn)
+ cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (vcolumn));
+ cells = g_list_first (cells);
+
+ if (gdaex_grid_column_get_gtype (gcolumn) == G_TYPE_BOOLEAN)
{
- cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (vcolumn));
- cells = g_list_first (cells);
+ gtk_tree_view_column_add_attribute (vcolumn, (GtkCellRenderer *)cells->data, "active", col);
+ }
+ else
+ {
+ gtk_tree_view_column_add_attribute (vcolumn, (GtkCellRenderer *)cells->data, "text", col);
+ }
- if (gdaex_grid_column_get_gtype (gcolumn) == G_TYPE_BOOLEAN)
- {
- gtk_tree_view_column_add_attribute (vcolumn, (GtkCellRenderer *)cells->data, "active", col);
- }
- else
- {
- gtk_tree_view_column_add_attribute (vcolumn, (GtkCellRenderer *)cells->data, "text", col);
- }
+ if (gdaex_grid_column_get_reorderable (gcolumn))
+ {
+ gtk_tree_view_column_set_sort_column_id (vcolumn, col);
+ }
- if (gdaex_grid_column_get_reorderable (gcolumn))
- {
- gtk_tree_view_column_set_sort_column_id (vcolumn, col);
- }
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view), vcolumn);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), vcolumn);
- }
+ /* popup menu */
+ mitem = gtk_check_menu_item_new_with_label (gdaex_grid_column_get_title (gcolumn));
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mitem), gdaex_grid_column_get_visible (gcolumn));
+
+ g_object_set_data (G_OBJECT (mitem), "GdaExGridColumn", gcolumn);
+
+ g_signal_connect (G_OBJECT (mitem), "toggled",
+ G_CALLBACK (gdaex_grid_on_menu_item_toggled), (gpointer)grid);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), mitem);
+ gtk_widget_show (mitem);
}
}
priv->view = view;
+ if (priv->menu != NULL)
+ {
+ gtk_menu_attach_to_widget (GTK_MENU (priv->menu), priv->view, NULL);
+
+ g_signal_connect (G_OBJECT (priv->view), "button-press-event",
+ G_CALLBACK (gdaex_grid_on_button_press_event), (gpointer)grid);
+ g_signal_connect (G_OBJECT (priv->view), "popup-menu",
+ G_CALLBACK (gdaex_grid_on_popup_menu), (gpointer)grid);
+ }
#ifdef REPTOOL_FOUND
g_signal_connect (view,
"key-release-event", G_CALLBACK (gdaex_grid_on_key_release_event), (gpointer)grid);
#endif
- return GTK_TREE_VIEW (view);
+ return GTK_TREE_VIEW (priv->view);
}
#ifdef REPTOOL_FOUND
return FALSE;
}
#endif
+
+static gboolean
+gdaex_grid_on_button_press_event (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data)
+{
+ GdaExGridPrivate *priv;
+
+ if (event->type == GDK_BUTTON_PRESS && event->button == 3)
+ {
+ priv = GDAEX_GRID_GET_PRIVATE (user_data);
+
+ gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL, NULL, NULL,
+ event->button, event->time);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+gdaex_grid_on_popup_menu (GtkWidget *widget,
+ gpointer user_data)
+{
+ GdaExGridPrivate *priv;
+
+ priv = GDAEX_GRID_GET_PRIVATE (user_data);
+ gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL, NULL, NULL,
+ 0, gtk_get_current_event_time ());
+
+ return TRUE;
+}
+
+static void
+gdaex_grid_on_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
+ gpointer user_data)
+{
+ GdaExGridPrivate *priv;
+
+ priv = GDAEX_GRID_GET_PRIVATE (user_data);
+
+ GdaExGridColumn *gcolumn = g_object_get_data (G_OBJECT (checkmenuitem), "GdaExGridColumn");
+
+ gdaex_grid_column_set_visible (gcolumn,
+ gtk_check_menu_item_get_active (checkmenuitem));
+}
*
* Copyright (C) 2010-2013 Andrea Zagli <azagli@libero.it>
*
- * This file is part of libgdaex_grid_column.
+ * This file is part of libgdaex.
*
* libgdaex_grid_column is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
priv->sortable = FALSE;
priv->reorderable = FALSE;
priv->decimals = -1;
+ priv->vcolumn = NULL;
}
GdaExGridColumn
g_free (priv->title);
priv->title = g_strdup (title);
+
+ if (priv->vcolumn != NULL)
+ {
+ gtk_tree_view_column_set_title (priv->vcolumn, priv->title);
+ }
}
const gchar
GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
priv->visible = visible;
+
+ if (priv->vcolumn != NULL)
+ {
+ gtk_tree_view_column_set_visible (priv->vcolumn, priv->visible);
+ }
}
gboolean
GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
priv->resizable = resizable;
+
+ if (priv->vcolumn != NULL)
+ {
+ gtk_tree_view_column_set_resizable (priv->vcolumn, priv->resizable);
+ }
}
gboolean
GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
priv->sortable = sortable;
+
+ if (priv->vcolumn != NULL)
+ {
+ gtk_tree_view_column_set_clickable (priv->vcolumn, priv->sortable);
+ }
}
gboolean
GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
priv->reorderable = reorderable;
+
+ if (priv->vcolumn != NULL)
+ {
+ gtk_tree_view_column_set_reorderable (priv->vcolumn, priv->reorderable);
+ }
}
gboolean
gtk_tree_view_column_set_clickable (priv->vcolumn, priv->sortable);
gtk_tree_view_column_set_reorderable (priv->vcolumn, priv->reorderable);
+ gtk_tree_view_column_set_visible (priv->vcolumn, priv->visible);
+
return priv->vcolumn;
}
#include <libgdaex.h>
+GdaExGridColumn *gcol_birthday;
+
+static void
+on_btn_birthday_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ gdaex_grid_column_set_visible (gcol_birthday, !gdaex_grid_column_get_visible (gcol_birthday));
+}
+
int
main (int argc, char **argv)
{
GdaEx *gdaex;
GtkWidget *w;
+ GtkWidget *vbox;
GtkWidget *scrolledw;
+ GtkWidget *hbtnbox;
+ GtkWidget *btn;
GdaExGrid *grid;
GdaExGridColumn *gcol;
g_signal_connect (w, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (w), vbox);
+
scrolledw = gtk_scrolled_window_new (NULL, NULL);
- gtk_container_add (GTK_CONTAINER (w), scrolledw);
+ gtk_box_pack_start (GTK_BOX (vbox), scrolledw, TRUE, TRUE, 0);
grid = gdaex_grid_new ();
gdaex_grid_set_title (grid, "The grid title");
gcol = gdaex_grid_column_new_defaults ("Age", "age", G_TYPE_INT);
gdaex_grid_add_column (grid, gcol);
- gcol = gdaex_grid_column_new ("Birthday", "birthday", G_TYPE_DATE, TRUE, TRUE, TRUE, TRUE, -1);
- gdaex_grid_add_column (grid, gcol);
+ gcol_birthday = gdaex_grid_column_new ("Birthday", "birthday", G_TYPE_DATE, FALSE, TRUE, TRUE, TRUE, -1);
+ gdaex_grid_add_column (grid, gcol_birthday);
gcol = gdaex_grid_column_new_defaults ("Incoming", "incoming", G_TYPE_DOUBLE);
gdaex_grid_add_column (grid, gcol);
gdaex_grid_fill_from_sql (grid, gdaex, "SELECT * FROM clients", NULL);
+ hbtnbox = gtk_hbutton_box_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), hbtnbox, TRUE, TRUE, 0);
+
+ btn = gtk_button_new_with_label ("Hide/Show Birthday");
+ gtk_box_pack_start (GTK_BOX (hbtnbox), btn, TRUE, TRUE, 0);
+
+ g_signal_connect (G_OBJECT (btn), "clicked",
+ G_CALLBACK (on_btn_birthday_clicked), NULL);
+
gtk_widget_show_all (w);
gtk_main ();