From 7816388a7ab06deb31f269c0f716eea5a62c9666 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Fri, 8 Sep 2000 16:51:21 +0000 Subject: Added base ETableModel functions. 2000-09-08 Christopher James Lahey * e-tree-example-1.c: Added base ETableModel functions. * e-tree-example-2.c: Added base ETableModel functions. Made it never return NULL as a string, instead return "". * e-tree-simple.c, e-tree-simple.h: Require base ETableModel functions. svn path=/trunk/; revision=5266 --- widgets/table/e-tree-simple.c | 121 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 105 insertions(+), 16 deletions(-) (limited to 'widgets/table/e-tree-simple.c') diff --git a/widgets/table/e-tree-simple.c b/widgets/table/e-tree-simple.c index e5883e6ae0..2df7586526 100644 --- a/widgets/table/e-tree-simple.c +++ b/widgets/table/e-tree-simple.c @@ -15,6 +15,71 @@ #define PARENT_TYPE E_TREE_MODEL_TYPE +static int +simple_column_count (ETableModel *etm) +{ + ETableSimple *simple = E_TABLE_SIMPLE(etm); + + if (simple->col_count) + return simple->col_count (etm, simple->data); + else + return 0; +} + +/* The default for simple_duplicate_value is to return the raw value. */ +static void * +simple_duplicate_value (ETableModel *etm, int col, const void *value) +{ + ETableSimple *simple = E_TABLE_SIMPLE(etm); + + if (simple->duplicate_value) + return simple->duplicate_value (etm, col, value, simple->data); + else + return (void *)value; +} + +static void +simple_free_value (ETableModel *etm, int col, void *value) +{ + ETableSimple *simple = E_TABLE_SIMPLE(etm); + + if (simple->free_value) + simple->free_value (etm, col, value, simple->data); +} + +static void * +simple_initialize_value (ETableModel *etm, int col) +{ + ETableSimple *simple = E_TABLE_SIMPLE(etm); + + if (simple->initialize_value) + return simple->initialize_value (etm, col, simple->data); + else + return NULL; +} + +static gboolean +simple_value_is_empty (ETableModel *etm, int col, const void *value) +{ + ETableSimple *simple = E_TABLE_SIMPLE(etm); + + if (simple->value_is_empty) + return simple->value_is_empty (etm, col, value, simple->data); + else + return FALSE; +} + +static char * +simple_value_to_string (ETableModel *etm, int col, const void *value) +{ + ETableSimple *simple = E_TABLE_SIMPLE(etm); + + if (simple->value_to_string) + return simple->value_to_string (etm, col, value, simple->data); + else + return g_strdup (""); +} + static void * simple_value_at (ETreeModel *etm, ETreePath *node, int col) { @@ -50,22 +115,38 @@ simple_is_editable (ETreeModel *etm, ETreePath *node, int col) static void e_tree_simple_class_init (GtkObjectClass *object_class) { - ETreeModelClass *model_class = (ETreeModelClass *) object_class; - - model_class->icon_at = simple_icon_at; - model_class->value_at = simple_value_at; - model_class->set_value_at = simple_set_value_at; - model_class->is_editable = simple_is_editable; + ETreeModelClass *model_class = (ETreeModelClass *) object_class; + ETableModelClass *table_model_class = (ETableModelClass *) object_class; + + table_model_class->column_count = simple_column_count; + table_model_class->duplicate_value = simple_duplicate_value; + table_model_class->free_value = simple_free_value; + table_model_class->initialize_value = simple_initialize_value; + table_model_class->value_is_empty = simple_value_is_empty; + table_model_class->value_to_string = simple_value_to_string; + + model_class ->icon_at = simple_icon_at; + model_class ->value_at = simple_value_at; + model_class ->set_value_at = simple_set_value_at; + model_class ->is_editable = simple_is_editable; } E_MAKE_TYPE(e_tree_simple, "ETreeSimple", ETreeSimple, e_tree_simple_class_init, NULL, PARENT_TYPE) ETreeModel * -e_tree_simple_new (ETreeSimpleIconAtFn icon_at, - ETreeSimpleValueAtFn value_at, - ETreeSimpleSetValueAtFn set_value_at, - ETreeSimpleIsEditableFn is_editable, - gpointer model_data) +e_tree_simple_new (ETableSimpleColumnCountFn col_count, + ETableSimpleDuplicateValueFn duplicate_value, + ETableSimpleFreeValueFn free_value, + ETableSimpleInitializeValueFn initialize_value, + ETableSimpleValueIsEmptyFn value_is_empty, + ETableSimpleValueToStringFn value_to_string, + + ETreeSimpleIconAtFn icon_at, + ETreeSimpleValueAtFn value_at, + ETreeSimpleSetValueAtFn set_value_at, + ETreeSimpleIsEditableFn is_editable, + + gpointer model_data) { ETreeSimple *etg; @@ -73,11 +154,19 @@ e_tree_simple_new (ETreeSimpleIconAtFn icon_at, e_tree_model_construct (E_TREE_MODEL (etg)); - etg->icon_at = icon_at; - etg->value_at = value_at; - etg->set_value_at = set_value_at; - etg->is_editable = is_editable; - etg->model_data = model_data; + etg->col_count = col_count; + etg->duplicate_value = duplicate_value; + etg->free_value = free_value; + etg->initialize_value = initialize_value; + etg->value_is_empty = value_is_empty; + etg->value_to_string = value_to_string; + + etg->icon_at = icon_at; + etg->value_at = value_at; + etg->set_value_at = set_value_at; + etg->is_editable = is_editable; + + etg->model_data = model_data; return (ETreeModel*)etg; } -- cgit