]> saetta.ns0.it Git - libgdaexgrid/commitdiff
Added property GdaExGridColumn::viewable (closes #986).
authorAndrea Zagli <azagli@libero.it>
Thu, 6 Jun 2019 08:50:24 +0000 (10:50 +0200)
committerAndrea Zagli <azagli@libero.it>
Thu, 6 Jun 2019 08:50:24 +0000 (10:50 +0200)
src/grid.c
src/gridcolumn.c
src/gridcolumn.h
tests/grid.c

index bbb957da1d2449121c4dc70512cac32ad30384a8..78360445e808c27d9f3436c69da339ff24c58ed3 100644 (file)
@@ -1175,7 +1175,14 @@ static GtkTreeView
                                                                G_CALLBACK (gdaex_grid_on_menu_item_toggled), (gpointer)grid);
 
                                        gtk_menu_shell_append (GTK_MENU_SHELL (submitem), mitem);
-                                       gtk_widget_show (mitem);
+                                       if (gdaex_grid_column_get_viewable (gcolumn))
+                                               {
+                                                       gtk_widget_show (mitem);
+                                               }
+                                       else
+                                               {
+                                                       gtk_widget_set_visible (GTK_WIDGET (mitem), FALSE);
+                                               }
 
                                        g_object_set_data (G_OBJECT (gcolumn), "menuitem", mitem);
                                        g_object_set_data (G_OBJECT (gcolumn), "menuitem_handler_id", GINT_TO_POINTER (hid));
index 3786d07df16a0b417560e65d0ac151d02338a480..bc923f55d5ceb9e343d33a1521a91e47e54e17bb 100644 (file)
@@ -50,6 +50,7 @@ struct _GdaExGridColumnPrivate
                gchar *field_name;
                GType type;
                gboolean visible;
+               gboolean viewable;
                gboolean resizable;
                gboolean sortable;
                gboolean reorderable;
@@ -80,6 +81,7 @@ gdaex_grid_column_init (GdaExGridColumn *gdaex_grid_column)
        priv->field_name = NULL;
        priv->type = G_TYPE_NONE;
        priv->visible = FALSE;
+       priv->viewable = TRUE;
        priv->resizable = FALSE;
        priv->sortable = FALSE;
        priv->reorderable = FALSE;
@@ -265,6 +267,11 @@ gdaex_grid_column_set_visible (GdaExGridColumn *column, gboolean visible)
 
        GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
 
+       if (!priv->viewable)
+               {
+                       return;
+               }
+
        priv->visible = visible;
 
        if (priv->vcolumn != NULL)
@@ -297,6 +304,46 @@ gdaex_grid_column_get_visible (GdaExGridColumn *column)
        return priv->visible;
 }
 
+/**
+ * gdaex_grid_column_set_viewable:
+ * @column:
+ * @viewable:
+ *
+ */
+void
+gdaex_grid_column_set_viewable (GdaExGridColumn *column, gboolean viewable)
+{
+       g_return_if_fail (GDAEX_IS_GRID_COLUMN (column));
+
+       GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
+
+       if (!viewable)
+               {
+                       gdaex_grid_column_set_visible (column, FALSE);
+               }
+
+       priv->viewable = viewable;
+
+       gtk_widget_set_visible (GTK_WIDGET (g_object_get_data (G_OBJECT (column), "menuitem")),
+                               priv->viewable);
+}
+
+/**
+ * gdaex_grid_column_get_viewable:
+ * column:
+ *
+ * Returns: if column is viewable.
+ */
+gboolean
+gdaex_grid_column_get_viewable (GdaExGridColumn *column)
+{
+       g_return_val_if_fail (GDAEX_IS_GRID_COLUMN (column), FALSE);
+
+       GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
+
+       return priv->viewable;
+}
+
 /**
  * gdaex_grid_column_set_resizable:
  * @column:
index df17572c77bb35bc38ee56321a6d9a30beac5ff5..9b413889ea3e99bc3b88d35ee4a95a323e826d44 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  gridcolumn.h
  *
- *  Copyright (C) 2010-2015 Andrea Zagli <azagli@libero.it>
+ *  Copyright (C) 2010-2019 Andrea Zagli <azagli@libero.it>
  *
  *  This file is part of libgdaexgrid.
  *
@@ -81,6 +81,9 @@ GType gdaex_grid_column_get_gtype (GdaExGridColumn *column);
 void gdaex_grid_column_set_visible (GdaExGridColumn *column, gboolean visible);
 gboolean gdaex_grid_column_get_visible (GdaExGridColumn *column);
 
+void gdaex_grid_column_set_viewable (GdaExGridColumn *column, gboolean viewable);
+gboolean gdaex_grid_column_get_viewable (GdaExGridColumn *column);
+
 void gdaex_grid_column_set_resizable (GdaExGridColumn *column, gboolean resizable);
 gboolean gdaex_grid_column_get_resizable (GdaExGridColumn *column);
 
index 38a3ba5786964f6625e3e7cf655ddae90e1fc229..c5241ccc63919fa08f520c3f3e567d285445a497 100644 (file)
@@ -22,6 +22,7 @@
 #include "gridcolumn.h"
 
 GdaExGridColumn *gcol_birthday;
+GdaExGridColumn *gcol_viewable;
 
 static void
 missing_func (GtkTreeStore *tstore, GtkTreeIter *iter, gpointer user_data)
@@ -38,6 +39,13 @@ on_btn_birthday_clicked (GtkButton *button,
        gdaex_grid_column_set_visible (gcol_birthday, !gdaex_grid_column_get_visible (gcol_birthday));
 }
 
+static void
+on_btn_viewable_clicked (GtkButton *button,
+                         gpointer user_data)
+{
+       gdaex_grid_column_set_viewable (gcol_viewable, !gdaex_grid_column_get_viewable (gcol_viewable));
+}
+
 int
 main (int argc, char **argv)
 {
@@ -105,6 +113,9 @@ main (int argc, char **argv)
        gcol = gdaex_grid_column_new ("Married", "married", G_TYPE_BOOLEAN, TRUE, TRUE, TRUE, TRUE, -1);
        gdaex_grid_add_column (grid, gcol);
 
+       gcol_viewable = gdaex_grid_column_new ("Viewable", "viewable", G_TYPE_BOOLEAN, TRUE, TRUE, TRUE, TRUE, -1);
+       gdaex_grid_add_column (grid, gcol_viewable);
+
        wgrid = gdaex_grid_get_widget (grid);
        gtk_container_add (GTK_CONTAINER (scrolledw), wgrid);
 
@@ -119,6 +130,12 @@ main (int argc, char **argv)
        g_signal_connect (G_OBJECT (btn), "clicked",
                          G_CALLBACK (on_btn_birthday_clicked), NULL);
 
+       btn = gtk_button_new_with_label ("Set/Unset Viewable");
+       gtk_box_pack_start (GTK_BOX (hbtnbox), btn, TRUE, TRUE, 0);
+
+       g_signal_connect (G_OBJECT (btn), "clicked",
+                         G_CALLBACK (on_btn_viewable_clicked), NULL);
+
        gtk_widget_show_all (w);
 
        gtk_main ();