aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/e-table-header.c
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/table/e-table-header.c')
-rw-r--r--widgets/table/e-table-header.c299
1 files changed, 299 insertions, 0 deletions
diff --git a/widgets/table/e-table-header.c b/widgets/table/e-table-header.c
new file mode 100644
index 0000000000..fb493c32a0
--- /dev/null
+++ b/widgets/table/e-table-header.c
@@ -0,0 +1,299 @@
+/*
+ * E-table-col-head.c: TableColHead implementation
+ *
+ * Author:
+ * Miguel de Icaza (miguel@gnu.org)
+ *
+ * (C) 1999 International GNOME Support
+ */
+#include <config.h>
+#include <gtk/gtkobject.h>
+#include <gtk/gtksignal.h>
+#include "e-table-header.h"
+
+enum {
+ STRUCTURE_CHANGE,
+ DIMENSION_CHANGE,
+ LAST_SIGNAL
+};
+
+static guint eth_signals [LAST_SIGNAL] = { 0, };
+
+static GtkObjectClass *e_table_header_parent_class;
+
+static void
+e_table_header_destroy (GtkObject *object)
+{
+ ETableHeader *eth = E_TABLE_HEADER (object);
+ const int cols = eth->col_count;
+ int i;
+
+ /*
+ * Destroy columns
+ */
+ for (i = 0; i < cols; i++)
+ e_table_header_remove (eth, i);
+
+ if (e_table_header_parent_class->destroy)
+ e_table_header_parent_class->destroy (object);
+}
+
+static void
+e_table_header_class_init (GtkObjectClass *object_class)
+{
+ object_class->destroy = e_table_header_destroy;
+
+ e_table_header_parent_class = (gtk_type_class (gtk_object_get_type ()));
+
+ eth_signals [STRUCTURE_CHANGE] =
+ gtk_signal_new ("structure_change",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (ETableHeaderClass, structure_change),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+ eth_signals [DIMENSION_CHANGE] =
+ gtk_signal_new ("dimension_change",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (ETableHeaderClass, dimension_change),
+ gtk_marshal_NONE__INT,
+ GTK_TYPE_NONE, 1, GTK_TYPE_INT);
+
+ gtk_object_class_add_signals (object_class, eth_signals, LAST_SIGNAL);
+}
+
+GtkType
+e_table_header_get_type (void)
+{
+ static GtkType type = 0;
+
+ if (!type){
+ GtkTypeInfo info = {
+ "ETableHeader",
+ sizeof (ETableHeader),
+ sizeof (ETableHeaderClass),
+ (GtkClassInitFunc) e_table_header_class_init,
+ (GtkObjectInitFunc) NULL,
+ NULL, /* reserved 1 */
+ NULL, /* reserved 2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ type = gtk_type_unique (gtk_object_get_type (), &info);
+ }
+
+ return type;
+}
+
+ETableHeader *
+e_table_header_new (void)
+{
+ ETableHeader *eth;
+
+ eth = gtk_type_new (e_table_header_get_type ());
+
+ return eth;
+}
+
+static void
+eth_do_insert (ETableHeader *eth, int pos, ETableCol *val)
+{
+ memcpy (&eth->columns [pos+1], &eth->columns [pos],
+ sizeof (ETableCol *) * (eth->col_count - pos));
+ eth->columns [pos] = val;
+}
+
+void
+e_table_header_add_column (ETableHeader *eth, ETableCol *tc, int pos)
+{
+ ETableCol **new_ptr;
+
+ g_return_if_fail (eth != NULL);
+ g_return_if_fail (E_IS_TABLE_COLUMN (eth));
+ g_return_if_fail (tc != NULL);
+ g_return_if_fail (pos >= 0 && pos < eth->col_count);
+
+ if (pos == -1)
+ pos = eth->col_count;
+ eth->columns = g_realloc (eth->columns, sizeof (ETableCol *) * (eth->col_count + 1));
+ eth_do_insert (eth, pos, tc);
+ eth->col_count++;
+
+ gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]);
+}
+
+ETableCol *
+e_table_header_get_column (ETableHeader *eth, int column)
+{
+ g_return_val_if_fail (eth != NULL, NULL);
+ g_return_val_if_fail (E_IS_TABLE_COLUMN (eth), NULL);
+
+ if (column < 0)
+ return NULL;
+
+ if (column >= eth->col_count)
+ return NULL;
+
+ return eth->columns [column];
+}
+
+int
+e_table_header_count (ETableHeader *eth)
+{
+ g_return_val_if_fail (eth != NULL, 0);
+ g_return_val_if_fail (E_IS_TABLE_COLUMN (eth), 0);
+
+ return eth->col_count;
+}
+
+int
+e_table_header_index (ETableHeader *eth, const char *identifier)
+{
+ int i;
+
+ g_return_val_if_fail (eth != NULL, 0);
+ g_return_val_if_fail (E_IS_TABLE_COLUMN (eth), 0);
+ g_return_val_if_fail (identifier != NULL, 0);
+
+ for (i = 0; i < eth->col_count; i++){
+ ETableCol *tc = eth->columns [i];
+
+ if (strcmp (tc->id, identifier) == 0)
+ return i;
+ }
+
+ return -1;
+}
+
+int
+e_table_header_get_index_at (ETableHeader *eth, int x_offset)
+{
+ int i, total;
+
+ g_return_val_if_fail (eth != NULL, 0);
+ g_return_val_if_fail (E_IS_TABLE_COLUMN (eth), 0);
+
+ total = 0;
+ for (i = 0; i < eth->col_count; i++){
+ total += eth->columns [i]->width;
+
+ if (x_offset < total)
+ return i;
+ }
+
+ return -1;
+}
+
+ETableCol **
+e_table_header_get_columns (ETableHeader *eth)
+{
+ ETableCol **ret;
+ int i;
+
+ g_return_val_if_fail (eth != NULL, 0);
+ g_return_val_if_fail (E_IS_TABLE_COLUMN (eth), 0);
+
+ ret = g_new (ETableCol *, eth->col_count + 1);
+ memcpy (ret, eth->columns, sizeof (ETableCol *) * eth->col_count);
+ ret [eth->col_count] = NULL;
+
+ return ret;
+}
+
+gboolean
+e_table_header_selection_ok (ETableHeader *eth)
+{
+ g_return_val_if_fail (eth != NULL, FALSE);
+ g_return_val_if_fail (E_IS_TABLE_COLUMN (eth), FALSE);
+
+ return eth->selectable;
+}
+
+int
+ve_table_header_get_selected (ETableHeader *eth)
+{
+ int i;
+ int selected = 0;
+
+ g_return_val_if_fail (eth != NULL, 0);
+ g_return_val_if_fail (E_IS_TABLE_COLUMN (eth), 0);
+
+ for (i = 0; i < eth->col_count; i++){
+ if (eth->columns [i]->selected)
+ selected++;
+ }
+
+ return selected;
+}
+
+int
+e_table_header_total_width (ETableHeader *eth)
+{
+ int total, i;
+
+ g_return_val_if_fail (eth != NULL, 0);
+ g_return_val_if_fail (E_IS_TABLE_COLUMN (eth), 0);
+
+ total = 0;
+ for (i = 0; i < eth->col_count; i++)
+ total += eth->columns [i]->width;
+
+ return total;
+}
+
+static void
+eth_do_remove (ETableHeader *eth, int idx)
+{
+ memcpy (&eth->columns [idx], &eth->columns [idx+1],
+ sizeof (ETableCol *) * eth->col_count - idx);
+ eth->col_count--;
+}
+
+void
+e_table_header_move (ETableHeader *eth, int source_index, int target_index)
+{
+ ETableCol *old;
+
+ g_return_if_fail (eth != NULL);
+ g_return_if_fail (E_IS_TABLE_COLUMN (eth));
+ g_return_if_fail (source_index >= 0);
+ g_return_if_fail (target_index >= 0);
+ g_return_if_fail (source_index < eth->col_count);
+ g_return_if_fail (target_index < eth->col_count);
+
+ old = eth->columns [source_index];
+ eth_do_remove (eth, source_index);
+ eth_do_insert (eth, target_index, old);
+ gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]);
+}
+
+void
+e_table_header_remove (ETableHeader *eth, int idx)
+{
+ g_return_if_fail (eth != NULL);
+ g_return_if_fail (E_IS_TABLE_COLUMN (eth));
+ g_return_if_fail (idx >= 0);
+ g_return_if_fail (idx < eth->col_count);
+
+ eth_do_remove (eth, idx);
+ gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]);
+}
+
+void
+e_table_header_set_selection (ETableHeader *eth, gboolean allow_selection)
+{
+}
+
+void
+e_table_header_set_size (ETableHeader *eth, int idx, int size)
+{
+ g_return_if_fail (eth != NULL);
+ g_return_if_fail (E_IS_TABLE_COLUMN (eth));
+ g_return_if_fail (idx >= 0);
+ g_return_if_fail (idx < eth->col_count);
+ g_return_if_fail (size > 0);
+
+ eth->columns [idx]->width = size;
+ gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE], idx);
+}