aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/e-table-subset-variable.c
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/table/e-table-subset-variable.c')
-rw-r--r--widgets/table/e-table-subset-variable.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/widgets/table/e-table-subset-variable.c b/widgets/table/e-table-subset-variable.c
new file mode 100644
index 0000000000..76da03c44f
--- /dev/null
+++ b/widgets/table/e-table-subset-variable.c
@@ -0,0 +1,112 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * E-table-subset.c: Implements a table that contains a subset of another table.
+ *
+ * Author:
+ * Miguel de Icaza (miguel@gnu.org)
+ *
+ * (C) 1999 Helix Code, Inc.
+ */
+#include <config.h>
+#include <stdlib.h>
+#include <gtk/gtksignal.h>
+#include <string.h>
+#include "e-util/e-util.h"
+#include "e-table-subset-variable.h"
+
+#define PARENT_TYPE E_TABLE_SUBSET_TYPE
+
+#define INCREMENT_AMOUNT 10
+
+static ETableModelClass *etssv_parent_class;
+
+static void
+etssv_class_init (GtkObjectClass *klass)
+{
+ etssv_parent_class = gtk_type_class (PARENT_TYPE);
+}
+
+E_MAKE_TYPE(e_table_subset_variable, "ETableSubsetVariable", ETableSubsetVariable, etssv_class_init, NULL, PARENT_TYPE);
+
+ETableModel *
+e_table_subset_variable_construct (ETableSubsetVariable *etssv,
+ ETableModel *source)
+{
+ if ( e_table_subset_construct(E_TABLE_SUBSET(etssv), source, 1) == NULL )
+ return NULL;
+ E_TABLE_SUBSET(etssv)->n_map = 0;
+
+ return E_TABLE_MODEL (etssv);
+}
+
+ETableModel *
+e_table_subset_variable_new (ETableModel *source)
+{
+ ETableSubsetVariable *etssv = gtk_type_new (E_TABLE_SUBSET_VARIABLE_TYPE);
+
+ if (e_table_subset_variable_construct (etssv, source) == NULL){
+ gtk_object_destroy (GTK_OBJECT (etssv));
+ return NULL;
+ }
+
+ return (ETableModel *) etssv;
+}
+
+void
+e_table_subset_variable_add (ETableSubsetVariable *etssv,
+ gint row)
+{
+ ETableModel *etm = E_TABLE_MODEL(etssv);
+ ETableSubset *etss = E_TABLE_SUBSET(etssv);
+
+ if ( etss->n_map + 1 > etssv->n_vals_allocated )
+ etss->map_table = g_realloc(etss->map_table, (etssv->n_vals_allocated + INCREMENT_AMOUNT) * sizeof(int));
+ etss->map_table[etss->n_map++] = row;
+ if ( !etm->frozen )
+ e_table_model_changed(etm);
+}
+
+gboolean
+e_table_subset_variable_remove (ETableSubsetVariable *etssv,
+ gint row)
+{
+ ETableModel *etm = E_TABLE_MODEL(etssv);
+ ETableSubset *etss = E_TABLE_SUBSET(etssv);
+ int i;
+
+ for ( i = 0; i < etss->n_map; i++ ) {
+ if (etss->map_table[i] == row) {
+ memmove(etss->map_table + i, etss->map_table + i + 1, (etss->n_map - i - 1) * sizeof(int));
+ etss->n_map --;
+ if ( !etm->frozen )
+ e_table_model_changed(etm);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void
+e_table_subset_variable_increment (ETableSubsetVariable *etssv,
+ gint position,
+ gint amount)
+{
+ int i;
+ ETableSubset *etss = E_TABLE_SUBSET(etssv);
+ for ( i = 0; i < etss->n_map; i++ ) {
+ if ( etss->map_table[i] > position )
+ etss->map_table[i] += amount;
+ }
+}
+
+void
+e_table_subset_variable_set_allocation (ETableSubsetVariable *etssv,
+ gint total)
+{
+ ETableSubset *etss = E_TABLE_SUBSET(etssv);
+ if ( total <= 0 )
+ total = 1;
+ if ( total > etss->n_map ) {
+ etss->map_table = g_realloc(etss->map_table, total * sizeof(int));
+ }
+}