2001-10-26 Christopher James Lahey <clahey@ximian.com> * e-cell-checkbox.c, e-cell-checkbox.h, e-cell-combo.c, e-cell-combo.h, e-cell-date.c, e-cell-date.h, e-cell-number.c, e-cell-number.h, e-cell-pixbuf.c, e-cell-pixbuf.h, e-cell-popup.c, e-cell-popup.h, e-cell-size.c, e-cell-size.h, e-cell-spin-button.c, e-cell-spin-button.h, e-cell-string.c, e-cell-text.c, e-cell-text.h, e-cell-toggle.c, e-cell-toggle.h, e-cell-tree.c, e-cell-tree.h, e-cell.c, e-cell.h, e-table-click-to-add.c, e-table-click-to-add.h, e-table-col-dnd.h, e-table-col.c, e-table-col.h, e-table-column-specification.c, e-table-column-specification.h, e-table-column.c, e-table-config-field.c, e-table-config-field.h, e-table-config.c, e-table-config.h, e-table-defines.h, e-table-example-1.c, e-table-example-2.c, e-table-extras.c, e-table-extras.h, e-table-field-chooser-dialog.c, e-table-field-chooser-dialog.h, e-table-field-chooser-item.c, e-table-field-chooser-item.h, e-table-field-chooser.c, e-table-field-chooser.h, e-table-group-container.c, e-table-group-container.h, e-table-group-leaf.c, e-table-group-leaf.h, e-table-group.c, e-table-group.h, e-table-header-item.c, e-table-header-item.h, e-table-header-utils.c, e-table-header-utils.h, e-table-header.c, e-table-header.h, e-table-item.c, e-table-item.h, e-table-memory-callbacks.c, e-table-memory-callbacks.h, e-table-memory.c, e-table-memory.h, e-table-model.c, e-table-model.h, e-table-one.c, e-table-one.h, e-table-scrolled.c, e-table-scrolled.h, e-table-selection-model.c, e-table-selection-model.h, e-table-simple.c, e-table-simple.h, e-table-size-test.c, e-table-sort-info.c, e-table-sort-info.h, e-table-sorted-variable.c, e-table-sorted-variable.h, e-table-sorted.c, e-table-sorted.h, e-table-sorter.c, e-table-sorter.h, e-table-sorting-utils.c, e-table-sorting-utils.h, e-table-specification.c, e-table-specification.h, e-table-state.c, e-table-state.h, e-table-subset-variable.c, e-table-subset-variable.h, e-table-subset.c, e-table-subset.h, e-table-tooltip.h, e-table-tree.h, e-table-utils.c, e-table-utils.h, e-table-without.c, e-table-without.h, e-table.c, e-table.h, e-tree-memory-callbacks.c, e-tree-memory-callbacks.h, e-tree-memory.c, e-tree-memory.h, e-tree-model.c, e-tree-model.h, e-tree-scrolled.c, e-tree-scrolled.h, e-tree-selection-model.c, e-tree-selection-model.h, e-tree-simple.c, e-tree-simple.h, e-tree-sorted-variable.c, e-tree-sorted-variable.h, e-tree-sorted.c, e-tree-sorted.h, e-tree-table-adapter.c, e-tree-table-adapter.h, e-tree.c, e-tree.h, table-test.c, table-test.h, test-check.c, test-cols.c, test-table.c: Changed the license announcement at the top of these files. * e-cell-string.c: Removed unused file. svn path=/trunk/; revision=14154
255 lines
5.5 KiB
C
255 lines
5.5 KiB
C
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
/*
|
|
* e-table-one.c
|
|
* Copyright 2000, 2001, Ximian, Inc.
|
|
*
|
|
* Authors:
|
|
* Chris Lahey <clahey@ximian.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License, version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This library is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
* 02111-1307, USA.
|
|
*/
|
|
|
|
#include <config.h>
|
|
#include "e-table-one.h"
|
|
|
|
#define PARENT_TYPE e_table_model_get_type ()
|
|
|
|
static ETableModelClass *parent_class = NULL;
|
|
|
|
static int
|
|
one_column_count (ETableModel *etm)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(etm);
|
|
|
|
if (one->source)
|
|
return e_table_model_column_count(one->source);
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
one_row_count (ETableModel *etm)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
static void *
|
|
one_value_at (ETableModel *etm, int col, int row)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(etm);
|
|
|
|
if (one->data)
|
|
return one->data[col];
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
static void
|
|
one_set_value_at (ETableModel *etm, int col, int row, const void *val)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(etm);
|
|
|
|
if (one->data && one->source) {
|
|
e_table_model_free_value(one->source, col, one->data[col]);
|
|
one->data[col] = e_table_model_duplicate_value(one->source, col, val);
|
|
}
|
|
}
|
|
|
|
static gboolean
|
|
one_is_cell_editable (ETableModel *etm, int col, int row)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(etm);
|
|
|
|
if (one->source)
|
|
return e_table_model_is_cell_editable(one->source, col, -1);
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
/* The default for one_duplicate_value is to return the raw value. */
|
|
static void *
|
|
one_duplicate_value (ETableModel *etm, int col, const void *value)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(etm);
|
|
|
|
if (one->source)
|
|
return e_table_model_duplicate_value(one->source, col, value);
|
|
else
|
|
return (void *)value;
|
|
}
|
|
|
|
static void
|
|
one_free_value (ETableModel *etm, int col, void *value)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(etm);
|
|
|
|
if (one->source)
|
|
e_table_model_free_value(one->source, col, value);
|
|
}
|
|
|
|
static void *
|
|
one_initialize_value (ETableModel *etm, int col)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(etm);
|
|
|
|
if (one->source)
|
|
return e_table_model_initialize_value (one->source, col);
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
static gboolean
|
|
one_value_is_empty (ETableModel *etm, int col, const void *value)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(etm);
|
|
|
|
if (one->source)
|
|
return e_table_model_value_is_empty (one->source, col, value);
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
static char *
|
|
one_value_to_string (ETableModel *etm, int col, const void *value)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(etm);
|
|
|
|
if (one->source)
|
|
return e_table_model_value_to_string (one->source, col, value);
|
|
else
|
|
return g_strdup("");
|
|
}
|
|
|
|
static void
|
|
one_destroy (GtkObject *object)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(object);
|
|
|
|
if (one->source) {
|
|
int i;
|
|
int col_count;
|
|
|
|
col_count = e_table_model_column_count(one->source);
|
|
|
|
if (one->data) {
|
|
for (i = 0; i < col_count; i++) {
|
|
e_table_model_free_value(one->source, i, one->data[i]);
|
|
}
|
|
}
|
|
|
|
gtk_object_unref(GTK_OBJECT(one->source));
|
|
}
|
|
|
|
g_free(one->data);
|
|
|
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
|
}
|
|
|
|
static void
|
|
e_table_one_class_init (GtkObjectClass *object_class)
|
|
{
|
|
ETableModelClass *model_class = (ETableModelClass *) object_class;
|
|
|
|
parent_class = gtk_type_class (E_TABLE_MODEL_TYPE);
|
|
|
|
model_class->column_count = one_column_count;
|
|
model_class->row_count = one_row_count;
|
|
model_class->value_at = one_value_at;
|
|
model_class->set_value_at = one_set_value_at;
|
|
model_class->is_cell_editable = one_is_cell_editable;
|
|
model_class->duplicate_value = one_duplicate_value;
|
|
model_class->free_value = one_free_value;
|
|
model_class->initialize_value = one_initialize_value;
|
|
model_class->value_is_empty = one_value_is_empty;
|
|
model_class->value_to_string = one_value_to_string;
|
|
|
|
object_class->destroy = one_destroy;
|
|
}
|
|
|
|
static void
|
|
e_table_one_init (GtkObject *object)
|
|
{
|
|
ETableOne *one = E_TABLE_ONE(object);
|
|
|
|
one->source = NULL;
|
|
one->data = NULL;
|
|
}
|
|
|
|
GtkType
|
|
e_table_one_get_type (void)
|
|
{
|
|
static GtkType type = 0;
|
|
|
|
if (!type){
|
|
GtkTypeInfo info = {
|
|
"ETableOne",
|
|
sizeof (ETableOne),
|
|
sizeof (ETableOneClass),
|
|
(GtkClassInitFunc) e_table_one_class_init,
|
|
(GtkObjectInitFunc) e_table_one_init,
|
|
NULL, /* reserved 1 */
|
|
NULL, /* reserved 2 */
|
|
(GtkClassInitFunc) NULL
|
|
};
|
|
|
|
type = gtk_type_unique (PARENT_TYPE, &info);
|
|
}
|
|
|
|
return type;
|
|
}
|
|
|
|
ETableModel *
|
|
e_table_one_new (ETableModel *source)
|
|
{
|
|
ETableOne *eto;
|
|
int col_count;
|
|
int i;
|
|
|
|
eto = gtk_type_new (e_table_one_get_type ());
|
|
|
|
eto->source = source;
|
|
|
|
col_count = e_table_model_column_count(source);
|
|
eto->data = g_new(void *, col_count);
|
|
for (i = 0; i < col_count; i++) {
|
|
eto->data[i] = e_table_model_initialize_value(source, i);
|
|
}
|
|
|
|
if (source)
|
|
gtk_object_ref(GTK_OBJECT(source));
|
|
|
|
return (ETableModel *) eto;
|
|
}
|
|
|
|
void
|
|
e_table_one_commit (ETableOne *one)
|
|
{
|
|
if (one->source) {
|
|
int empty = TRUE;
|
|
int col;
|
|
int cols = e_table_model_column_count(one->source);
|
|
for (col = 0; col < cols; col++) {
|
|
if (!e_table_model_value_is_empty(one->source, col, one->data[col])) {
|
|
empty = FALSE;
|
|
break;
|
|
}
|
|
}
|
|
if (!empty) {
|
|
e_table_model_append_row(one->source, E_TABLE_MODEL(one), 0);
|
|
}
|
|
}
|
|
}
|