diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-05-20 02:47:16 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-05-20 02:47:16 +0800 |
commit | 46f211579d1dfd60147099942b40c9697796e7c8 (patch) | |
tree | 5f8e8027e3e378bd2c8061ecf10061f4609ab02e /widgets | |
parent | ae208c7e8ff0463666c52392553af2572a8ee9b5 (diff) | |
download | gsoc2013-evolution-46f211579d1dfd60147099942b40c9697796e7c8.tar.gz gsoc2013-evolution-46f211579d1dfd60147099942b40c9697796e7c8.tar.zst gsoc2013-evolution-46f211579d1dfd60147099942b40c9697796e7c8.zip |
Added initialize_value and value_is_empty callbacks.
2000-05-19 Christopher James Lahey <clahey@helixcode.com>
* e-table-example-1.c, e-table-example-2.c, e-table-simple.c,
e-table-simple.h, e-table-size-test.c, test-check.c, test-cols.c,
test-table.c: Added initialize_value and value_is_empty callbacks.
* e-table-model.c, e-table-model.h: Added initialize_value and
value_is_callback virtual functions to the ETableModel class.
* e-table-subset.c: Perpetuate the initialize_value and
value_is_empty methods.
svn path=/trunk/; revision=3138
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/e-table/ChangeLog | 10 | ||||
-rw-r--r-- | widgets/e-table/e-table-example-1.c | 18 | ||||
-rw-r--r-- | widgets/e-table/e-table-example-2.c | 98 | ||||
-rw-r--r-- | widgets/e-table/e-table-model.c | 41 | ||||
-rw-r--r-- | widgets/e-table/e-table-model.h | 12 | ||||
-rw-r--r-- | widgets/e-table/e-table-simple.c | 78 | ||||
-rw-r--r-- | widgets/e-table/e-table-simple.h | 28 | ||||
-rw-r--r-- | widgets/e-table/e-table-size-test.c | 18 | ||||
-rw-r--r-- | widgets/e-table/e-table-subset.c | 18 | ||||
-rw-r--r-- | widgets/e-table/test-check.c | 41 | ||||
-rw-r--r-- | widgets/e-table/test-cols.c | 36 | ||||
-rw-r--r-- | widgets/e-table/test-table.c | 19 | ||||
-rw-r--r-- | widgets/table/e-table-example-1.c | 18 | ||||
-rw-r--r-- | widgets/table/e-table-example-2.c | 98 | ||||
-rw-r--r-- | widgets/table/e-table-model.c | 41 | ||||
-rw-r--r-- | widgets/table/e-table-model.h | 12 | ||||
-rw-r--r-- | widgets/table/e-table-simple.c | 78 | ||||
-rw-r--r-- | widgets/table/e-table-simple.h | 28 | ||||
-rw-r--r-- | widgets/table/e-table-size-test.c | 18 | ||||
-rw-r--r-- | widgets/table/e-table-subset.c | 18 | ||||
-rw-r--r-- | widgets/table/test-check.c | 41 | ||||
-rw-r--r-- | widgets/table/test-cols.c | 36 | ||||
-rw-r--r-- | widgets/table/test-table.c | 19 |
23 files changed, 656 insertions, 168 deletions
diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog index 8d26a03b34..c824ddd142 100644 --- a/widgets/e-table/ChangeLog +++ b/widgets/e-table/ChangeLog @@ -1,5 +1,15 @@ 2000-05-19 Christopher James Lahey <clahey@helixcode.com> + * e-table-example-1.c, e-table-example-2.c, e-table-simple.c, + e-table-simple.h, e-table-size-test.c, test-check.c, test-cols.c, + test-table.c: Added initialize_value and value_is_empty callbacks. + + * e-table-model.c, e-table-model.h: Added initialize_value and + value_is_callback virtual functions to the ETableModel class. + + * e-table-subset.c: Perpetuate the initialize_value and + value_is_empty methods. + From a patch by Iain Holmes <ih@csd.abdn.ac.uk> * e-table-config.c, e-table.c: Fixed getting text content from a diff --git a/widgets/e-table/e-table-example-1.c b/widgets/e-table/e-table-example-1.c index 70689c2953..fbaa3389a2 100644 --- a/widgets/e-table/e-table-example-1.c +++ b/widgets/e-table/e-table-example-1.c @@ -157,6 +157,20 @@ my_free_value (ETableModel *etc, int col, void *value, void *data) g_free (value); } +/* This function creates an empty value. */ +static void * +my_initialize_value (ETableModel *etc, int col, void *data) +{ + return g_strdup (""); +} + +/* This function reports if a value is empty. */ +static gboolean +my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + return !(value && *(char *)value); +} + /* This function is for when the model is unfrozen. This can mostly be ignored for simple models. */ static void @@ -184,7 +198,9 @@ create_table (void) e_table_model = e_table_simple_new ( my_col_count, my_row_count, my_value_at, my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, my_thaw, NULL); + my_duplicate_value, my_free_value, + my_initialize_value, my_value_is_empty, + my_thaw, NULL); /* * Next we create a header. The ETableHeader is used in two * different way. The first is the full_header. This is the diff --git a/widgets/e-table/e-table-example-2.c b/widgets/e-table/e-table-example-2.c index 5bc6910437..c318507ea4 100644 --- a/widgets/e-table/e-table-example-2.c +++ b/widgets/e-table/e-table-example-2.c @@ -121,66 +121,90 @@ my_col_count (ETableModel *etc, void *data) static int my_row_count (ETableModel *etc, void *data) { - return ROWS; + return ROWS; } static void * my_value_at (ETableModel *etc, int col, int row, void *data) { - if (col == COLOR_COLUMN){ - if (importance_data[row]){ - return color1; - } else { - return color2; - } - } else if (col == IMPORTANCE_COLUMN){ - return (gpointer) importance_data[row]; - } else { - return (void *) table_data [row][col]; - } + if (col == COLOR_COLUMN){ + if (importance_data[row]){ + return color1; + } else { + return color2; + } + } else if (col == IMPORTANCE_COLUMN){ + return (gpointer) importance_data[row]; + } else { + return (void *) table_data [row][col]; + } } static void my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) { - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - importance_data[row] = (gboolean) val; - } else { - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - } + if (col == COLOR_COLUMN){ + } else if (col == IMPORTANCE_COLUMN){ + importance_data[row] = (gboolean) val; + } else { + g_free (table_data [row][col]); + table_data [row][col] = g_strdup (val); + } } static gboolean my_is_cell_editable (ETableModel *etc, int col, int row, void *data) { - if (col == IMPORTANCE_COLUMN) - return FALSE; - else - return TRUE; + if (col == IMPORTANCE_COLUMN) + return FALSE; + else + return TRUE; } static void * my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) { - if (col == COLOR_COLUMN){ - return (void *) value; - } else if (col == IMPORTANCE_COLUMN){ - return (void *) value; - } else { - return g_strdup (value); - } + if (col == COLOR_COLUMN){ + return (void *) value; + } else if (col == IMPORTANCE_COLUMN){ + return (void *) value; + } else { + return g_strdup (value); + } } static void my_free_value (ETableModel *etc, int col, void *value, void *data) { - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - } else { - g_free (value); - } + if (col == COLOR_COLUMN){ + } else if (col == IMPORTANCE_COLUMN){ + } else { + g_free (value); + } +} + +static void * +my_initialize_value (ETableModel *etc, int col, void *data) +{ + if (col == COLOR_COLUMN){ + return NULL; + } else if (col == IMPORTANCE_COLUMN){ + return NULL; + } else { + return g_strdup (""); + } +} + +static gboolean +my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + if (col == COLOR_COLUMN){ + return value == NULL; + } else if (col == IMPORTANCE_COLUMN){ + return value == NULL; + } else { + return !(value && *(char *)value); + } } static void @@ -213,7 +237,9 @@ create_table () e_table_model = e_table_simple_new ( my_col_count, my_row_count, my_value_at, my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, my_thaw, NULL); + my_duplicate_value, my_free_value, + my_initialize_value, my_value_is_empty, + my_thaw, NULL); /* Next we create a header. The ETableHeader is used in two different way. The first is the full_header. This is the diff --git a/widgets/e-table/e-table-model.c b/widgets/e-table/e-table-model.c index 3ea01c05e1..7ed8a9ba5f 100644 --- a/widgets/e-table/e-table-model.c +++ b/widgets/e-table/e-table-model.c @@ -107,6 +107,30 @@ e_table_model_free_value (ETableModel *e_table_model, int col, void *value) ETM_CLASS (e_table_model)->free_value (e_table_model, col, value); } +void * +e_table_model_initialize_value (ETableModel *e_table_model, int col) +{ + g_return_val_if_fail (e_table_model != NULL, NULL); + g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); + + if (ETM_CLASS (e_table_model)->initialize_value) + return ETM_CLASS (e_table_model)->initialize_value (e_table_model, col); + else + return NULL; +} + +gboolean +e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value) +{ + g_return_val_if_fail (e_table_model != NULL, FALSE); + g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); + + if (ETM_CLASS (e_table_model)->value_is_empty) + return ETM_CLASS (e_table_model)->value_is_empty (e_table_model, col, value); + else + return FALSE; +} + static void e_table_model_destroy (GtkObject *object) { @@ -117,6 +141,7 @@ e_table_model_destroy (GtkObject *object) static void e_table_model_class_init (GtkObjectClass *object_class) { + ETableModelClass *klass = E_TABLE_MODEL_CLASS(object_class); e_table_model_parent_class = gtk_type_class (gtk_object_get_type ()); object_class->destroy = e_table_model_destroy; @@ -162,6 +187,22 @@ e_table_model_class_init (GtkObjectClass *object_class) GTK_TYPE_NONE, 1, GTK_TYPE_INT); gtk_object_class_add_signals (object_class, e_table_model_signals, LAST_SIGNAL); + + klass->column_count = NULL; + klass->row_count = NULL; + klass->value_at = NULL; + klass->set_value_at = NULL; + klass->is_cell_editable = NULL; + klass->duplicate_value = NULL; + klass->free_value = NULL; + klass->initialize_value = NULL; + klass->value_is_empty = NULL; + klass->thaw = NULL; + klass->model_changed = NULL; + klass->model_row_changed = NULL; + klass->model_cell_changed = NULL; + klass->model_row_inserted = NULL; + klass->model_row_deleted = NULL; } diff --git a/widgets/e-table/e-table-model.h b/widgets/e-table/e-table-model.h index e542754f22..0c8d51b882 100644 --- a/widgets/e-table/e-table-model.h +++ b/widgets/e-table/e-table-model.h @@ -28,8 +28,14 @@ typedef struct { void (*set_value_at) (ETableModel *etm, int col, int row, const void *value); gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - void *(*duplicate_value) (ETableModel *etm, int col, const void *value); - void (*free_value) (ETableModel *etm, int col, void *value); + /* Allocate a copy of the given value. */ + void *(*duplicate_value) (ETableModel *etm, int col, const void *value); + /* Free an allocated value. */ + void (*free_value) (ETableModel *etm, int col, void *value); + /* Return an allocated empty value. */ + void *(*initialize_value) (ETableModel *etm, int col); + /* Return TRUE if value is equivalent to an empty cell. */ + gboolean (*value_is_empty) (ETableModel *etm, int col, const void *value); void (*thaw) (ETableModel *etm); /* @@ -62,6 +68,8 @@ gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, void *e_table_model_duplicate_value (ETableModel *e_table_model, int col, const void *value); void e_table_model_free_value (ETableModel *e_table_model, int col, void *value); +void *e_table_model_initialize_value (ETableModel *e_table_model, int col); +gboolean e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value); void e_table_model_freeze (ETableModel *e_table_model); void e_table_model_thaw (ETableModel *e_table_model); diff --git a/widgets/e-table/e-table-simple.c b/widgets/e-table/e-table-simple.c index e8c4d1debb..7e0135b21e 100644 --- a/widgets/e-table/e-table-simple.c +++ b/widgets/e-table/e-table-simple.c @@ -18,63 +18,103 @@ static int simple_column_count (ETableModel *etm) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->col_count (etm, simple->data); + if (simple->col_count) + return simple->col_count (etm, simple->data); + else + return 0; } static int simple_row_count (ETableModel *etm) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->row_count (etm, simple->data); + if (simple->row_count) + return simple->row_count (etm, simple->data); + else + return 0; } static void * simple_value_at (ETableModel *etm, int col, int row) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->value_at (etm, col, row, simple->data); + if (simple->value_at) + return simple->value_at (etm, col, row, simple->data); + else + return NULL; } static void simple_set_value_at (ETableModel *etm, int col, int row, const void *val) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - simple->set_value_at (etm, col, row, val, simple->data); + if (simple->set_value_at) + simple->set_value_at (etm, col, row, val, simple->data); } static gboolean simple_is_cell_editable (ETableModel *etm, int col, int row) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->is_cell_editable (etm, col, row, simple->data); + if (simple->is_cell_editable) + return simple->is_cell_editable (etm, col, row, simple->data); + else + return FALSE; } +/* 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 = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->duplicate_value (etm, col, value, simple->data); + 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 = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - simple->free_value (etm, col, value, simple->data); + 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 void simple_thaw (ETableModel *etm) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); simple->thaw (etm, simple->data); } @@ -91,6 +131,8 @@ e_table_simple_class_init (GtkObjectClass *object_class) model_class->is_cell_editable = simple_is_cell_editable; model_class->duplicate_value = simple_duplicate_value; model_class->free_value = simple_free_value; + model_class->initialize_value = simple_initialize_value; + model_class->value_is_empty = simple_value_is_empty; model_class->thaw = simple_thaw; } @@ -125,6 +167,8 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleIsCellEditableFn is_cell_editable, ETableSimpleDuplicateValueFn duplicate_value, ETableSimpleFreeValueFn free_value, + ETableSimpleInitializeValueFn initialize_value, + ETableSimpleValueIsEmptyFn value_is_empty, ETableSimpleThawFn thaw, void *data) { @@ -137,9 +181,11 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, et->value_at = value_at; et->set_value_at = set_value_at; et->is_cell_editable = is_cell_editable; - et->thaw = thaw; et->duplicate_value = duplicate_value; et->free_value = free_value; + et->initialize_value = initialize_value; + et->value_is_empty = value_is_empty; + et->thaw = thaw; et->data = data; return (ETableModel *) et; diff --git a/widgets/e-table/e-table-simple.h b/widgets/e-table/e-table-simple.h index 51134f45aa..ab97452f10 100644 --- a/widgets/e-table/e-table-simple.h +++ b/widgets/e-table/e-table-simple.h @@ -4,14 +4,22 @@ #include "e-table-model.h" -typedef int (*ETableSimpleColumnCountFn) (ETableModel *etm, void *data); -typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *data); -typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data); -typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); -typedef void *(*ETableSimpleDuplicateValueFn) (ETableModel *etm, int col, const void *val, void *data); -typedef void (*ETableSimpleFreeValueFn) (ETableModel *etm, int col, void *val, void *data); -typedef void (*ETableSimpleThawFn) (ETableModel *etm, void *data); +#define E_TABLE_SIMPLE_TYPE (e_table_simple_get_type ()) +#define E_TABLE_SIMPLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SIMPLE_TYPE, ETableSimple)) +#define E_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SIMPLE_TYPE, ETableSimpleClass)) +#define E_IS_TABLE_SIMPLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SIMPLE_TYPE)) +#define E_IS_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SIMPLE_TYPE)) + +typedef int (*ETableSimpleColumnCountFn) (ETableModel *etm, void *data); +typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *data); +typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); +typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data); +typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); +typedef void *(*ETableSimpleDuplicateValueFn) (ETableModel *etm, int col, const void *val, void *data); +typedef void (*ETableSimpleFreeValueFn) (ETableModel *etm, int col, void *val, void *data); +typedef void *(*ETableSimpleInitializeValueFn) (ETableModel *etm, int col, void *data); +typedef gboolean (*ETableSimpleValueIsEmptyFn) (ETableModel *etm, int col, const void *val, void *data); +typedef void (*ETableSimpleThawFn) (ETableModel *etm, void *data); typedef struct { ETableModel parent; @@ -23,6 +31,8 @@ typedef struct { ETableSimpleIsCellEditableFn is_cell_editable; ETableSimpleDuplicateValueFn duplicate_value; ETableSimpleFreeValueFn free_value; + ETableSimpleInitializeValueFn initialize_value; + ETableSimpleValueIsEmptyFn value_is_empty; ETableSimpleThawFn thaw; void *data; } ETableSimple; @@ -40,6 +50,8 @@ ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleIsCellEditableFn is_cell_editable, ETableSimpleDuplicateValueFn duplicate_value, ETableSimpleFreeValueFn free_value, + ETableSimpleInitializeValueFn initialize_value, + ETableSimpleValueIsEmptyFn value_is_empty, ETableSimpleThawFn thaw, void *data); diff --git a/widgets/e-table/e-table-size-test.c b/widgets/e-table/e-table-size-test.c index d12a57fbbb..058429ca64 100644 --- a/widgets/e-table/e-table-size-test.c +++ b/widgets/e-table/e-table-size-test.c @@ -157,6 +157,20 @@ my_free_value (ETableModel *etc, int col, void *value, void *data) g_free (value); } +/* This function creates an empty value. */ +static void * +my_initialize_value (ETableModel *etc, int col, void *data) +{ + return g_strdup (""); +} + +/* This function reports if a value is empty. */ +static gboolean +my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + return !(value && *(char *)value); +} + /* This function is for when the model is unfrozen. This can mostly be ignored for simple models. */ static void @@ -179,7 +193,9 @@ create_table (void) e_table_model = e_table_simple_new ( my_col_count, my_row_count, my_value_at, my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, my_thaw, NULL); + my_duplicate_value, my_free_value, + my_initialize_value, my_value_is_empty, + my_thaw, NULL); /* * Next we create a header. The ETableHeader is used in two * different way. The first is the full_header. This is the diff --git a/widgets/e-table/e-table-subset.c b/widgets/e-table/e-table-subset.c index b0c5671b65..a0add3b954 100644 --- a/widgets/e-table/e-table-subset.c +++ b/widgets/e-table/e-table-subset.c @@ -98,6 +98,22 @@ etss_free_value (ETableModel *etm, int col, void *value) e_table_model_free_value (etss->source, col, value); } +static void * +etss_initialize_value (ETableModel *etm, int col) +{ + ETableSubset *etss = (ETableSubset *)etm; + + return e_table_model_initialize_value (etss->source, col); +} + +static gboolean +etss_value_is_empty (ETableModel *etm, int col, const void *value) +{ + ETableSubset *etss = (ETableSubset *)etm; + + return e_table_model_value_is_empty (etss->source, col, value); +} + static void etss_thaw (ETableModel *etm) { @@ -120,6 +136,8 @@ etss_class_init (GtkObjectClass *klass) table_class->is_cell_editable = etss_is_cell_editable; table_class->duplicate_value = etss_duplicate_value; table_class->free_value = etss_free_value; + table_class->initialize_value = etss_initialize_value; + table_class->value_is_empty = etss_value_is_empty; table_class->thaw = etss_thaw; } diff --git a/widgets/e-table/test-check.c b/widgets/e-table/test-check.c index 3a32098245..300ebf7a7e 100644 --- a/widgets/e-table/test-check.c +++ b/widgets/e-table/test-check.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Test code for the ETable package * @@ -66,7 +67,7 @@ set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) g_assert (col < 2); g_assert (row < LINES); - if (col == 0){ + if (col == 0) { my_table [row].value = GPOINTER_TO_INT (val); printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); } else { @@ -84,19 +85,37 @@ is_cell_editable (ETableModel *etc, int col, int row, void *data) static void * duplicate_value (ETableModel *etc, int col, const void *value, void *data) { - if (col == 0){ - return (void *) value; - } else { - return g_strdup (value); - } + if (col == 0) { + return (void *) value; + } else { + return g_strdup (value); + } } static void free_value (ETableModel *etc, int col, void *value, void *data) { - if (col != 0){ - g_free (value); - } + if (col != 0) { + g_free (value); + } +} + +static void * +initialize_value (ETableModel *etc, int col, void *data) +{ + if (col == 0) + return NULL; + else + return g_strdup (""); +} + +static gboolean +value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + if (col == 0) + return value == NULL; + else + return !(value && *(char *)value); } static void @@ -128,7 +147,9 @@ check_test (void) e_table_model = e_table_simple_new ( col_count, row_count, value_at, set_value_at, is_cell_editable, - duplicate_value, free_value, thaw, NULL); + duplicate_value, free_value, + initialize_value, value_is_empty, + thaw, NULL); /* * Header diff --git a/widgets/e-table/test-cols.c b/widgets/e-table/test-cols.c index 6756511fb4..e34e477dae 100644 --- a/widgets/e-table/test-cols.c +++ b/widgets/e-table/test-cols.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Test code for the ETable package * @@ -84,19 +85,37 @@ is_cell_editable (ETableModel *etc, int col, int row, void *data) static void * duplicate_value (ETableModel *etc, int col, const void *value, void *data) { - if (col == 0){ - return (void *)value; - } else { - return g_strdup (value); - } + if (col == 0){ + return (void *)value; + } else { + return g_strdup (value); + } } static void free_value (ETableModel *etc, int col, void *value, void *data) { - if (col != 0){ - g_free (value); - } + if (col != 0){ + g_free (value); + } +} + +static void * +initialize_value (ETableModel *etc, int col, void *data) +{ + if (col == 0) + return NULL; + else + return g_strdup (""); +} + +static gboolean +value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + if (col == 0) + return value == NULL; + else + return !(value && *(char *)value); } static void @@ -128,6 +147,7 @@ multi_cols_test (void) col_count, row_count, value_at, set_value_at, is_cell_editable, duplicate_value, free_value, + initialize_value, value_is_empty, thaw, NULL); /* diff --git a/widgets/e-table/test-table.c b/widgets/e-table/test-table.c index a882b8dbdf..724090d904 100644 --- a/widgets/e-table/test-table.c +++ b/widgets/e-table/test-table.c @@ -190,6 +190,18 @@ free_value (ETableModel *etc, int col, void *value, void *data) g_free (value); } +static void * +initialize_value (ETableModel *etc, int col, void *data) +{ + return g_strdup (""); +} + +static gboolean +value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + return !(value && *(char *)value); +} + static void thaw (ETableModel *etc, void *data) { @@ -220,7 +232,9 @@ table_browser_test (void) e_table_model = e_table_simple_new ( col_count, row_count, value_at, set_value_at, is_cell_editable, - duplicate_value, free_value, thaw, NULL); + duplicate_value, free_value, + initialize_value, value_is_empty, + thaw, NULL); /* * Header @@ -315,7 +329,8 @@ do_e_table_demo (const char *spec) e_table_model = e_table_simple_new (col_count, row_count, value_at, set_value_at, is_cell_editable, - duplicate_value, free_value, + duplicate_value, free_value, + initialize_value, value_is_empty, thaw, NULL); full_header = e_table_header_new (); diff --git a/widgets/table/e-table-example-1.c b/widgets/table/e-table-example-1.c index 70689c2953..fbaa3389a2 100644 --- a/widgets/table/e-table-example-1.c +++ b/widgets/table/e-table-example-1.c @@ -157,6 +157,20 @@ my_free_value (ETableModel *etc, int col, void *value, void *data) g_free (value); } +/* This function creates an empty value. */ +static void * +my_initialize_value (ETableModel *etc, int col, void *data) +{ + return g_strdup (""); +} + +/* This function reports if a value is empty. */ +static gboolean +my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + return !(value && *(char *)value); +} + /* This function is for when the model is unfrozen. This can mostly be ignored for simple models. */ static void @@ -184,7 +198,9 @@ create_table (void) e_table_model = e_table_simple_new ( my_col_count, my_row_count, my_value_at, my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, my_thaw, NULL); + my_duplicate_value, my_free_value, + my_initialize_value, my_value_is_empty, + my_thaw, NULL); /* * Next we create a header. The ETableHeader is used in two * different way. The first is the full_header. This is the diff --git a/widgets/table/e-table-example-2.c b/widgets/table/e-table-example-2.c index 5bc6910437..c318507ea4 100644 --- a/widgets/table/e-table-example-2.c +++ b/widgets/table/e-table-example-2.c @@ -121,66 +121,90 @@ my_col_count (ETableModel *etc, void *data) static int my_row_count (ETableModel *etc, void *data) { - return ROWS; + return ROWS; } static void * my_value_at (ETableModel *etc, int col, int row, void *data) { - if (col == COLOR_COLUMN){ - if (importance_data[row]){ - return color1; - } else { - return color2; - } - } else if (col == IMPORTANCE_COLUMN){ - return (gpointer) importance_data[row]; - } else { - return (void *) table_data [row][col]; - } + if (col == COLOR_COLUMN){ + if (importance_data[row]){ + return color1; + } else { + return color2; + } + } else if (col == IMPORTANCE_COLUMN){ + return (gpointer) importance_data[row]; + } else { + return (void *) table_data [row][col]; + } } static void my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) { - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - importance_data[row] = (gboolean) val; - } else { - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - } + if (col == COLOR_COLUMN){ + } else if (col == IMPORTANCE_COLUMN){ + importance_data[row] = (gboolean) val; + } else { + g_free (table_data [row][col]); + table_data [row][col] = g_strdup (val); + } } static gboolean my_is_cell_editable (ETableModel *etc, int col, int row, void *data) { - if (col == IMPORTANCE_COLUMN) - return FALSE; - else - return TRUE; + if (col == IMPORTANCE_COLUMN) + return FALSE; + else + return TRUE; } static void * my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) { - if (col == COLOR_COLUMN){ - return (void *) value; - } else if (col == IMPORTANCE_COLUMN){ - return (void *) value; - } else { - return g_strdup (value); - } + if (col == COLOR_COLUMN){ + return (void *) value; + } else if (col == IMPORTANCE_COLUMN){ + return (void *) value; + } else { + return g_strdup (value); + } } static void my_free_value (ETableModel *etc, int col, void *value, void *data) { - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - } else { - g_free (value); - } + if (col == COLOR_COLUMN){ + } else if (col == IMPORTANCE_COLUMN){ + } else { + g_free (value); + } +} + +static void * +my_initialize_value (ETableModel *etc, int col, void *data) +{ + if (col == COLOR_COLUMN){ + return NULL; + } else if (col == IMPORTANCE_COLUMN){ + return NULL; + } else { + return g_strdup (""); + } +} + +static gboolean +my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + if (col == COLOR_COLUMN){ + return value == NULL; + } else if (col == IMPORTANCE_COLUMN){ + return value == NULL; + } else { + return !(value && *(char *)value); + } } static void @@ -213,7 +237,9 @@ create_table () e_table_model = e_table_simple_new ( my_col_count, my_row_count, my_value_at, my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, my_thaw, NULL); + my_duplicate_value, my_free_value, + my_initialize_value, my_value_is_empty, + my_thaw, NULL); /* Next we create a header. The ETableHeader is used in two different way. The first is the full_header. This is the diff --git a/widgets/table/e-table-model.c b/widgets/table/e-table-model.c index 3ea01c05e1..7ed8a9ba5f 100644 --- a/widgets/table/e-table-model.c +++ b/widgets/table/e-table-model.c @@ -107,6 +107,30 @@ e_table_model_free_value (ETableModel *e_table_model, int col, void *value) ETM_CLASS (e_table_model)->free_value (e_table_model, col, value); } +void * +e_table_model_initialize_value (ETableModel *e_table_model, int col) +{ + g_return_val_if_fail (e_table_model != NULL, NULL); + g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); + + if (ETM_CLASS (e_table_model)->initialize_value) + return ETM_CLASS (e_table_model)->initialize_value (e_table_model, col); + else + return NULL; +} + +gboolean +e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value) +{ + g_return_val_if_fail (e_table_model != NULL, FALSE); + g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); + + if (ETM_CLASS (e_table_model)->value_is_empty) + return ETM_CLASS (e_table_model)->value_is_empty (e_table_model, col, value); + else + return FALSE; +} + static void e_table_model_destroy (GtkObject *object) { @@ -117,6 +141,7 @@ e_table_model_destroy (GtkObject *object) static void e_table_model_class_init (GtkObjectClass *object_class) { + ETableModelClass *klass = E_TABLE_MODEL_CLASS(object_class); e_table_model_parent_class = gtk_type_class (gtk_object_get_type ()); object_class->destroy = e_table_model_destroy; @@ -162,6 +187,22 @@ e_table_model_class_init (GtkObjectClass *object_class) GTK_TYPE_NONE, 1, GTK_TYPE_INT); gtk_object_class_add_signals (object_class, e_table_model_signals, LAST_SIGNAL); + + klass->column_count = NULL; + klass->row_count = NULL; + klass->value_at = NULL; + klass->set_value_at = NULL; + klass->is_cell_editable = NULL; + klass->duplicate_value = NULL; + klass->free_value = NULL; + klass->initialize_value = NULL; + klass->value_is_empty = NULL; + klass->thaw = NULL; + klass->model_changed = NULL; + klass->model_row_changed = NULL; + klass->model_cell_changed = NULL; + klass->model_row_inserted = NULL; + klass->model_row_deleted = NULL; } diff --git a/widgets/table/e-table-model.h b/widgets/table/e-table-model.h index e542754f22..0c8d51b882 100644 --- a/widgets/table/e-table-model.h +++ b/widgets/table/e-table-model.h @@ -28,8 +28,14 @@ typedef struct { void (*set_value_at) (ETableModel *etm, int col, int row, const void *value); gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - void *(*duplicate_value) (ETableModel *etm, int col, const void *value); - void (*free_value) (ETableModel *etm, int col, void *value); + /* Allocate a copy of the given value. */ + void *(*duplicate_value) (ETableModel *etm, int col, const void *value); + /* Free an allocated value. */ + void (*free_value) (ETableModel *etm, int col, void *value); + /* Return an allocated empty value. */ + void *(*initialize_value) (ETableModel *etm, int col); + /* Return TRUE if value is equivalent to an empty cell. */ + gboolean (*value_is_empty) (ETableModel *etm, int col, const void *value); void (*thaw) (ETableModel *etm); /* @@ -62,6 +68,8 @@ gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, void *e_table_model_duplicate_value (ETableModel *e_table_model, int col, const void *value); void e_table_model_free_value (ETableModel *e_table_model, int col, void *value); +void *e_table_model_initialize_value (ETableModel *e_table_model, int col); +gboolean e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value); void e_table_model_freeze (ETableModel *e_table_model); void e_table_model_thaw (ETableModel *e_table_model); diff --git a/widgets/table/e-table-simple.c b/widgets/table/e-table-simple.c index e8c4d1debb..7e0135b21e 100644 --- a/widgets/table/e-table-simple.c +++ b/widgets/table/e-table-simple.c @@ -18,63 +18,103 @@ static int simple_column_count (ETableModel *etm) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->col_count (etm, simple->data); + if (simple->col_count) + return simple->col_count (etm, simple->data); + else + return 0; } static int simple_row_count (ETableModel *etm) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->row_count (etm, simple->data); + if (simple->row_count) + return simple->row_count (etm, simple->data); + else + return 0; } static void * simple_value_at (ETableModel *etm, int col, int row) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->value_at (etm, col, row, simple->data); + if (simple->value_at) + return simple->value_at (etm, col, row, simple->data); + else + return NULL; } static void simple_set_value_at (ETableModel *etm, int col, int row, const void *val) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - simple->set_value_at (etm, col, row, val, simple->data); + if (simple->set_value_at) + simple->set_value_at (etm, col, row, val, simple->data); } static gboolean simple_is_cell_editable (ETableModel *etm, int col, int row) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->is_cell_editable (etm, col, row, simple->data); + if (simple->is_cell_editable) + return simple->is_cell_editable (etm, col, row, simple->data); + else + return FALSE; } +/* 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 = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - return simple->duplicate_value (etm, col, value, simple->data); + 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 = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); - simple->free_value (etm, col, value, simple->data); + 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 void simple_thaw (ETableModel *etm) { - ETableSimple *simple = (ETableSimple *)etm; + ETableSimple *simple = E_TABLE_SIMPLE(etm); simple->thaw (etm, simple->data); } @@ -91,6 +131,8 @@ e_table_simple_class_init (GtkObjectClass *object_class) model_class->is_cell_editable = simple_is_cell_editable; model_class->duplicate_value = simple_duplicate_value; model_class->free_value = simple_free_value; + model_class->initialize_value = simple_initialize_value; + model_class->value_is_empty = simple_value_is_empty; model_class->thaw = simple_thaw; } @@ -125,6 +167,8 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleIsCellEditableFn is_cell_editable, ETableSimpleDuplicateValueFn duplicate_value, ETableSimpleFreeValueFn free_value, + ETableSimpleInitializeValueFn initialize_value, + ETableSimpleValueIsEmptyFn value_is_empty, ETableSimpleThawFn thaw, void *data) { @@ -137,9 +181,11 @@ e_table_simple_new (ETableSimpleColumnCountFn col_count, et->value_at = value_at; et->set_value_at = set_value_at; et->is_cell_editable = is_cell_editable; - et->thaw = thaw; et->duplicate_value = duplicate_value; et->free_value = free_value; + et->initialize_value = initialize_value; + et->value_is_empty = value_is_empty; + et->thaw = thaw; et->data = data; return (ETableModel *) et; diff --git a/widgets/table/e-table-simple.h b/widgets/table/e-table-simple.h index 51134f45aa..ab97452f10 100644 --- a/widgets/table/e-table-simple.h +++ b/widgets/table/e-table-simple.h @@ -4,14 +4,22 @@ #include "e-table-model.h" -typedef int (*ETableSimpleColumnCountFn) (ETableModel *etm, void *data); -typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *data); -typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data); -typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); -typedef void *(*ETableSimpleDuplicateValueFn) (ETableModel *etm, int col, const void *val, void *data); -typedef void (*ETableSimpleFreeValueFn) (ETableModel *etm, int col, void *val, void *data); -typedef void (*ETableSimpleThawFn) (ETableModel *etm, void *data); +#define E_TABLE_SIMPLE_TYPE (e_table_simple_get_type ()) +#define E_TABLE_SIMPLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SIMPLE_TYPE, ETableSimple)) +#define E_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SIMPLE_TYPE, ETableSimpleClass)) +#define E_IS_TABLE_SIMPLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SIMPLE_TYPE)) +#define E_IS_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SIMPLE_TYPE)) + +typedef int (*ETableSimpleColumnCountFn) (ETableModel *etm, void *data); +typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *data); +typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); +typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data); +typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); +typedef void *(*ETableSimpleDuplicateValueFn) (ETableModel *etm, int col, const void *val, void *data); +typedef void (*ETableSimpleFreeValueFn) (ETableModel *etm, int col, void *val, void *data); +typedef void *(*ETableSimpleInitializeValueFn) (ETableModel *etm, int col, void *data); +typedef gboolean (*ETableSimpleValueIsEmptyFn) (ETableModel *etm, int col, const void *val, void *data); +typedef void (*ETableSimpleThawFn) (ETableModel *etm, void *data); typedef struct { ETableModel parent; @@ -23,6 +31,8 @@ typedef struct { ETableSimpleIsCellEditableFn is_cell_editable; ETableSimpleDuplicateValueFn duplicate_value; ETableSimpleFreeValueFn free_value; + ETableSimpleInitializeValueFn initialize_value; + ETableSimpleValueIsEmptyFn value_is_empty; ETableSimpleThawFn thaw; void *data; } ETableSimple; @@ -40,6 +50,8 @@ ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, ETableSimpleIsCellEditableFn is_cell_editable, ETableSimpleDuplicateValueFn duplicate_value, ETableSimpleFreeValueFn free_value, + ETableSimpleInitializeValueFn initialize_value, + ETableSimpleValueIsEmptyFn value_is_empty, ETableSimpleThawFn thaw, void *data); diff --git a/widgets/table/e-table-size-test.c b/widgets/table/e-table-size-test.c index d12a57fbbb..058429ca64 100644 --- a/widgets/table/e-table-size-test.c +++ b/widgets/table/e-table-size-test.c @@ -157,6 +157,20 @@ my_free_value (ETableModel *etc, int col, void *value, void *data) g_free (value); } +/* This function creates an empty value. */ +static void * +my_initialize_value (ETableModel *etc, int col, void *data) +{ + return g_strdup (""); +} + +/* This function reports if a value is empty. */ +static gboolean +my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + return !(value && *(char *)value); +} + /* This function is for when the model is unfrozen. This can mostly be ignored for simple models. */ static void @@ -179,7 +193,9 @@ create_table (void) e_table_model = e_table_simple_new ( my_col_count, my_row_count, my_value_at, my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, my_thaw, NULL); + my_duplicate_value, my_free_value, + my_initialize_value, my_value_is_empty, + my_thaw, NULL); /* * Next we create a header. The ETableHeader is used in two * different way. The first is the full_header. This is the diff --git a/widgets/table/e-table-subset.c b/widgets/table/e-table-subset.c index b0c5671b65..a0add3b954 100644 --- a/widgets/table/e-table-subset.c +++ b/widgets/table/e-table-subset.c @@ -98,6 +98,22 @@ etss_free_value (ETableModel *etm, int col, void *value) e_table_model_free_value (etss->source, col, value); } +static void * +etss_initialize_value (ETableModel *etm, int col) +{ + ETableSubset *etss = (ETableSubset *)etm; + + return e_table_model_initialize_value (etss->source, col); +} + +static gboolean +etss_value_is_empty (ETableModel *etm, int col, const void *value) +{ + ETableSubset *etss = (ETableSubset *)etm; + + return e_table_model_value_is_empty (etss->source, col, value); +} + static void etss_thaw (ETableModel *etm) { @@ -120,6 +136,8 @@ etss_class_init (GtkObjectClass *klass) table_class->is_cell_editable = etss_is_cell_editable; table_class->duplicate_value = etss_duplicate_value; table_class->free_value = etss_free_value; + table_class->initialize_value = etss_initialize_value; + table_class->value_is_empty = etss_value_is_empty; table_class->thaw = etss_thaw; } diff --git a/widgets/table/test-check.c b/widgets/table/test-check.c index 3a32098245..300ebf7a7e 100644 --- a/widgets/table/test-check.c +++ b/widgets/table/test-check.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Test code for the ETable package * @@ -66,7 +67,7 @@ set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) g_assert (col < 2); g_assert (row < LINES); - if (col == 0){ + if (col == 0) { my_table [row].value = GPOINTER_TO_INT (val); printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); } else { @@ -84,19 +85,37 @@ is_cell_editable (ETableModel *etc, int col, int row, void *data) static void * duplicate_value (ETableModel *etc, int col, const void *value, void *data) { - if (col == 0){ - return (void *) value; - } else { - return g_strdup (value); - } + if (col == 0) { + return (void *) value; + } else { + return g_strdup (value); + } } static void free_value (ETableModel *etc, int col, void *value, void *data) { - if (col != 0){ - g_free (value); - } + if (col != 0) { + g_free (value); + } +} + +static void * +initialize_value (ETableModel *etc, int col, void *data) +{ + if (col == 0) + return NULL; + else + return g_strdup (""); +} + +static gboolean +value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + if (col == 0) + return value == NULL; + else + return !(value && *(char *)value); } static void @@ -128,7 +147,9 @@ check_test (void) e_table_model = e_table_simple_new ( col_count, row_count, value_at, set_value_at, is_cell_editable, - duplicate_value, free_value, thaw, NULL); + duplicate_value, free_value, + initialize_value, value_is_empty, + thaw, NULL); /* * Header diff --git a/widgets/table/test-cols.c b/widgets/table/test-cols.c index 6756511fb4..e34e477dae 100644 --- a/widgets/table/test-cols.c +++ b/widgets/table/test-cols.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Test code for the ETable package * @@ -84,19 +85,37 @@ is_cell_editable (ETableModel *etc, int col, int row, void *data) static void * duplicate_value (ETableModel *etc, int col, const void *value, void *data) { - if (col == 0){ - return (void *)value; - } else { - return g_strdup (value); - } + if (col == 0){ + return (void *)value; + } else { + return g_strdup (value); + } } static void free_value (ETableModel *etc, int col, void *value, void *data) { - if (col != 0){ - g_free (value); - } + if (col != 0){ + g_free (value); + } +} + +static void * +initialize_value (ETableModel *etc, int col, void *data) +{ + if (col == 0) + return NULL; + else + return g_strdup (""); +} + +static gboolean +value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + if (col == 0) + return value == NULL; + else + return !(value && *(char *)value); } static void @@ -128,6 +147,7 @@ multi_cols_test (void) col_count, row_count, value_at, set_value_at, is_cell_editable, duplicate_value, free_value, + initialize_value, value_is_empty, thaw, NULL); /* diff --git a/widgets/table/test-table.c b/widgets/table/test-table.c index a882b8dbdf..724090d904 100644 --- a/widgets/table/test-table.c +++ b/widgets/table/test-table.c @@ -190,6 +190,18 @@ free_value (ETableModel *etc, int col, void *value, void *data) g_free (value); } +static void * +initialize_value (ETableModel *etc, int col, void *data) +{ + return g_strdup (""); +} + +static gboolean +value_is_empty (ETableModel *etc, int col, const void *value, void *data) +{ + return !(value && *(char *)value); +} + static void thaw (ETableModel *etc, void *data) { @@ -220,7 +232,9 @@ table_browser_test (void) e_table_model = e_table_simple_new ( col_count, row_count, value_at, set_value_at, is_cell_editable, - duplicate_value, free_value, thaw, NULL); + duplicate_value, free_value, + initialize_value, value_is_empty, + thaw, NULL); /* * Header @@ -315,7 +329,8 @@ do_e_table_demo (const char *spec) e_table_model = e_table_simple_new (col_count, row_count, value_at, set_value_at, is_cell_editable, - duplicate_value, free_value, + duplicate_value, free_value, + initialize_value, value_is_empty, thaw, NULL); full_header = e_table_header_new (); |