From 1f7ba945b16cd5f8c01641dd864a9671d791a651 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Sun, 12 Mar 2000 07:59:42 +0000 Subject: Rearranged SUBDIRS for dependencies. 2000-03-12 Christopher James Lahey * widgets/Makefile.am: Rearranged SUBDIRS for dependencies. * widgets/e-text/e-text-model.c, widgets/e-text-model.h: New object which stores a piece of text data. All methods are virtual. * widgets/e-text/e-text.c, widgets/e-text/e-text.h: Modified this to use an ETextModel for its data. * widgets/e-text/Makefile.am: Added e-text-model.c and e-text-model.h. * widgets/e-minicard/test-minicard-label.c: Made this work again. * widgets/e-minicard/e-minicard.c, widgets/e-minicard/e-minicard.h: Made this use an ETableModel to get its data. * widgets/e-minicard/e-minicard-label.c, widgets/e-minicard/e-minicard-label.h: Added the ability to set the text model used for the contained text widget. * widgets/e-minicard/Makefile.am: Added e-table since e-minicard is now dependent on an e-table-model for its data. * e-util/e-canvas.c, e-util/e-canvas.h: Fixed some bugs here to speed up reflow and to make it fail less often. * addressbook/demo, addressbook/demo/.cvsignore, addressbook/demo/Makefile.am, addressbook/demo/demo.c, addressbook/demo/spec: A new program to test ETable and EMinicard integration. * configure.in: Added addressbook/demo/Makefile. * addressbook/Makefile.am: Added the demo/ subdirectory. in widgets/e-table/: 2000-03-12 Christopher James Lahey * e-table.c: Made this use an ECanvas. Fixed a bug where e_table_new_from_spec_file was calling e_table_construct instead of e_table_construct_from_spec_file. * e-table-item.c, e-table-header-item.c, e-table-column-item.c: Switched these to use GTK_TYPE_OBJECT and GTK_VALUE_OBJECT instead of GTK_TYPE_POINTER and GTK_TYPE_OBJECT. * e-cell-text.c: Got rid of a crashing bug. * e-table-text-model.c, e-table-text-model.h: A new object which is an e-text-model which uses an e-table-model for its data. * Makefile.am: Added e-table-text-model.c and e-table-text-model.h. * .cvsignore: Added table-example-1 and table-example-2. svn path=/trunk/; revision=2101 --- widgets/table/.cvsignore | 2 + widgets/table/e-cell-text.c | 10 +- widgets/table/e-table-column-item.c | 4 +- widgets/table/e-table-header-item.c | 4 +- widgets/table/e-table-item.c | 8 +- widgets/table/e-table-text-model.c | 217 ++++++++++++++++++++++++++++++++++++ widgets/table/e-table-text-model.h | 61 ++++++++++ widgets/table/e-table.c | 4 +- 8 files changed, 297 insertions(+), 13 deletions(-) create mode 100644 widgets/table/e-table-text-model.c create mode 100644 widgets/table/e-table-text-model.h (limited to 'widgets/table') diff --git a/widgets/table/.cvsignore b/widgets/table/.cvsignore index 0963d457d9..ca61202868 100644 --- a/widgets/table/.cvsignore +++ b/widgets/table/.cvsignore @@ -5,3 +5,5 @@ Makefile.in *.lo *.la table-test +table-example-1 +table-example-2 diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c index 191ac86023..422b27ff93 100644 --- a/widgets/table/e-cell-text.c +++ b/widgets/table/e-cell-text.c @@ -319,8 +319,8 @@ static void ect_kill_view (ECellView *ecv) { ECellTextView *text_view = (ECellTextView *) ecv; - - g_free (text_view); + + g_free(text_view); } /* @@ -351,7 +351,11 @@ ect_unrealize (ECellView *ecv) gdk_gc_unref (text_view->gc); text_view->gc = NULL; - + + if ( text_view->edit ) { + ect_cancel_edit (text_view); + } + if (text_view->font) gdk_font_unref (text_view->font); diff --git a/widgets/table/e-table-column-item.c b/widgets/table/e-table-column-item.c index 0616327a93..1138c4afe4 100644 --- a/widgets/table/e-table-column-item.c +++ b/widgets/table/e-table-column-item.c @@ -55,7 +55,7 @@ etci_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) switch (arg_id){ case ARG_TABLE_COLUMN: - etci->etci = GTK_VALUE_POINTER (*arg); + etci->etci = GTK_VALUE_OBJECT (*arg); break; } etci_update (item, NULL, NULL, 0); @@ -159,7 +159,7 @@ etci_class_init (GtkObjectClass *object_class) item_class->point = etci_point; item_class->event = etci_event; - gtk_object_add_arg_type ("ETableColumnItem::ETableColumn", GTK_TYPE_POINTER, + gtk_object_add_arg_type ("ETableColumnItem::ETableColumn", GTK_TYPE_OBJECT, GTK_ARG_WRITABLE, ARG_TABLE_COLUMN); } diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c index e6001d24de..b079debb1a 100644 --- a/widgets/table/e-table-header-item.c +++ b/widgets/table/e-table-header-item.c @@ -191,7 +191,7 @@ ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) switch (arg_id){ case ARG_TABLE_HEADER: ethi_drop_table_header (ethi); - ethi_add_table_header (ethi, GTK_VALUE_POINTER (*arg)); + ethi_add_table_header (ethi, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); break; case ARG_TABLE_X: @@ -990,7 +990,7 @@ ethi_class_init (GtkObjectClass *object_class) item_class->point = ethi_point; item_class->event = ethi_event; - gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_POINTER, + gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_OBJECT, GTK_ARG_WRITABLE, ARG_TABLE_HEADER); gtk_object_add_arg_type ("ETableHeaderItem::x", GTK_TYPE_INT, GTK_ARG_WRITABLE, ARG_TABLE_X); diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c index 095a14ea90..59df09e5bb 100644 --- a/widgets/table/e-table-item.c +++ b/widgets/table/e-table-item.c @@ -545,12 +545,12 @@ eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) switch (arg_id){ case ARG_TABLE_HEADER: eti_remove_header_model (eti); - eti_add_header_model (eti, GTK_VALUE_POINTER (*arg)); + eti_add_header_model (eti, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); break; case ARG_TABLE_MODEL: eti_remove_table_model (eti); - eti_add_table_model (eti, GTK_VALUE_POINTER (*arg)); + eti_add_table_model (eti, E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg))); break; case ARG_LENGHT_THRESHOLD: @@ -1137,9 +1137,9 @@ eti_class_init (GtkObjectClass *object_class) eti_class->row_selection = eti_row_selection; - gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_POINTER, + gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_OBJECT, GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_POINTER, + gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_OBJECT, GTK_ARG_WRITABLE, ARG_TABLE_MODEL); gtk_object_add_arg_type ("ETableItem::drawgrid", GTK_TYPE_BOOL, GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); diff --git a/widgets/table/e-table-text-model.c b/widgets/table/e-table-text-model.c new file mode 100644 index 0000000000..69ffdc3568 --- /dev/null +++ b/widgets/table/e-table-text-model.c @@ -0,0 +1,217 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* ETableTextModel - Text item model for evolution. + * Copyright (C) 2000 Helix Code, Inc. + * + * Author: Chris Lahey + * + * A majority of code taken from: + * + * Text item type for GnomeCanvas widget + * + * GnomeCanvas is basically a port of the Tk toolkit's most excellent + * canvas widget. Tk is copyrighted by the Regents of the University + * of California, Sun Microsystems, and other parties. + * + * Copyright (C) 1998 The Free Software Foundation + * + * Author: Federico Mena */ + +#include +#include +#include "e-table-text-model.h" + +static void e_table_text_model_class_init (ETableTextModelClass *class); +static void e_table_text_model_init (ETableTextModel *model); +static void e_table_text_model_destroy (GtkObject *object); + +static gchar *e_table_text_model_get_text(ETextModel *model); +static void e_table_text_model_set_text(ETextModel *model, gchar *text); +static void e_table_text_model_insert(ETextModel *model, gint postion, gchar *text); +static void e_table_text_model_insert_length(ETextModel *model, gint postion, gchar *text, gint length); +static void e_table_text_model_delete(ETextModel *model, gint postion, gint length); + +static GtkObject *parent_class; + + + +/** + * e_table_text_model_get_type: + * @void: + * + * Registers the &ETableTextModel class if necessary, and returns the type ID + * associated to it. + * + * Return value: The type ID of the &ETableTextModel class. + **/ +GtkType +e_table_text_model_get_type (void) +{ + static GtkType model_type = 0; + + if (!model_type) { + GtkTypeInfo model_info = { + "ETableTextModel", + sizeof (ETableTextModel), + sizeof (ETableTextModelClass), + (GtkClassInitFunc) e_table_text_model_class_init, + (GtkObjectInitFunc) e_table_text_model_init, + NULL, /* reserved_1 */ + NULL, /* reserved_2 */ + (GtkClassInitFunc) NULL + }; + + model_type = gtk_type_unique (e_text_model_get_type (), &model_info); + } + + return model_type; +} + +/* Class initialization function for the text item */ +static void +e_table_text_model_class_init (ETableTextModelClass *klass) +{ + GtkObjectClass *object_class; + ETextModelClass *model_class; + + object_class = (GtkObjectClass *) klass; + model_class = (ETextModelClass *) klass; + + parent_class = gtk_type_class (e_text_model_get_type ()); + + model_class->get_text = e_table_text_model_get_text; + model_class->set_text = e_table_text_model_set_text; + model_class->insert = e_table_text_model_insert; + model_class->insert_length = e_table_text_model_insert_length; + model_class->delete = e_table_text_model_delete; + + object_class->destroy = e_table_text_model_destroy; +} + +/* Object initialization function for the text item */ +static void +e_table_text_model_init (ETableTextModel *model) +{ + model->model = NULL; + model->row = 0; + model->model_col = 0; + model->cell_changed_signal_id = 0; + model->row_changed_signal_id = 0; +} + +/* Destroy handler for the text item */ +static void +e_table_text_model_destroy (GtkObject *object) +{ + ETableTextModel *model; + + g_return_if_fail (object != NULL); + g_return_if_fail (E_IS_TEXT_MODEL (object)); + + model = E_TABLE_TEXT_MODEL (object); + + if (model->cell_changed_signal_id) + gtk_signal_disconnect(GTK_OBJECT(model->model), + model->cell_changed_signal_id); + + if (model->row_changed_signal_id) + gtk_signal_disconnect(GTK_OBJECT(model->model), + model->row_changed_signal_id); + + if (model->model) + gtk_object_unref(GTK_OBJECT(model->model)); + + if (GTK_OBJECT_CLASS (parent_class)->destroy) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} +static gchar * +e_table_text_model_get_text(ETextModel *text_model) +{ + ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); + if ( model->model ) + return (gchar *)e_table_model_value_at(model->model, model->model_col, model->row); + else + return ""; +} + +static void +e_table_text_model_set_text(ETextModel *text_model, gchar *text) +{ + ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); + if ( model->model ) + e_table_model_set_value_at(model->model, model->model_col, model->row, (void *) text); +} + +static void +e_table_text_model_insert(ETextModel *text_model, gint position, gchar *text) +{ + ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); + if ( model->model ) { + gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row); + temp = g_strdup_printf("%.*s%s%s", position, temp, text, temp + position); + e_table_model_set_value_at(model->model, model->model_col, model->row, temp); + g_free(temp); + } +} + +static void +e_table_text_model_insert_length(ETextModel *text_model, gint position, gchar *text, gint length) +{ + ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); + if ( model->model ) { + gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row); + temp = g_strdup_printf("%.*s%.*s%s", position, temp, length, text, temp + position); + e_table_model_set_value_at(model->model, model->model_col, model->row, temp); + g_free(temp); + } +} + +static void +e_table_text_model_delete(ETextModel *text_model, gint position, gint length) +{ + ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); + if ( model->model ) { + gchar *temp = (gchar *)e_table_model_value_at(model->model, model->model_col, model->row); + temp = g_strdup_printf("%.*s%s", position, temp, temp + position + length); + e_table_model_set_value_at(model->model, model->model_col, model->row, temp); + g_free(temp); + } +} + +static void +cell_changed(ETableModel *table_model, int model_col, int row, ETableTextModel *model) +{ + if (model->model_col == model_col && + model->row == row) + e_text_model_changed(E_TEXT_MODEL(model)); +} + +static void +row_changed(ETableModel *table_model, int row, ETableTextModel *model) +{ + if (model->row == row) + e_text_model_changed(E_TEXT_MODEL(model)); +} + +ETableTextModel * +e_table_text_model_new(ETableModel *table_model, int row, int model_col) +{ + ETableTextModel *model = gtk_type_new (e_table_text_model_get_type ()); + model->model = table_model; + if ( model->model ) { + gtk_object_ref(GTK_OBJECT(model->model)); + model->cell_changed_signal_id = + gtk_signal_connect(GTK_OBJECT(model->model), + "model_cell_changed", + GTK_SIGNAL_FUNC(cell_changed), + model); + model->row_changed_signal_id = + gtk_signal_connect(GTK_OBJECT(model->model), + "model_row_changed", + GTK_SIGNAL_FUNC(row_changed), + model); + } + model->row = row; + model->model_col = model_col; + return model; +} + diff --git a/widgets/table/e-table-text-model.h b/widgets/table/e-table-text-model.h new file mode 100644 index 0000000000..43c82b6bcc --- /dev/null +++ b/widgets/table/e-table-text-model.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* ETableTextModel - Text item for evolution. + * Copyright (C) 2000 Helix Code, Inc. + * + * Author: Chris Lahey + * + * A majority of code taken from: + * + * Text item type for GnomeCanvas widget + * + * GnomeCanvas is basically a port of the Tk toolkit's most excellent + * canvas widget. Tk is copyrighted by the Regents of the University + * of California, Sun Microsystems, and other parties. + * + * Copyright (C) 1998 The Free Software Foundation + * + * Author: Federico Mena */ + +#ifndef E_TABLE_TEXT_MODEL_H +#define E_TABLE_TEXT_MODEL_H + +#include +#include "e-text-model.h" +#include "e-table-model.h" + + +BEGIN_GNOME_DECLS + +#define E_TYPE_TABLE_TEXT_MODEL (e_table_text_model_get_type ()) +#define E_TABLE_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TABLE_TEXT_MODEL, ETableTextModel)) +#define E_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TABLE_TEXT_MODEL, ETableTextModelClass)) +#define E_IS_TABLE_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TABLE_TEXT_MODEL)) +#define E_IS_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TABLE_TEXT_MODEL)) + +typedef struct _ETableTextModel ETableTextModel; +typedef struct _ETableTextModelClass ETableTextModelClass; + +struct _ETableTextModel { + ETextModel parent; + + ETableModel *model; + int row; + int model_col; + + int cell_changed_signal_id; + int row_changed_signal_id; +}; + +struct _ETableTextModelClass { + ETextModelClass parent_class; + +}; + + +/* Standard Gtk function */ +GtkType e_table_text_model_get_type (void); +ETableTextModel *e_table_text_model_new(ETableModel *table_model, int row, int model_col); + +END_GNOME_DECLS + +#endif diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c index 36f7d5a776..ed1260fa44 100644 --- a/widgets/table/e-table.c +++ b/widgets/table/e-table.c @@ -675,7 +675,7 @@ et_table_cell_changed (ETableModel *table_model, int view_col, int row, ETable * static void e_table_setup_table (ETable *e_table, ETableHeader *full_header, ETableHeader *header, ETableModel *model, xmlNode *xml_grouping) { - e_table->table_canvas = GNOME_CANVAS(gnome_canvas_new ()); + e_table->table_canvas = GNOME_CANVAS(e_canvas_new ()); gtk_signal_connect ( GTK_OBJECT (e_table->table_canvas), "size_allocate", GTK_SIGNAL_FUNC (table_canvas_size_allocate), e_table); @@ -809,7 +809,7 @@ e_table_new_from_spec_file (ETableHeader *full_header, ETableModel *etm, const c e_table = gtk_type_new (e_table_get_type ()); - e_table_construct (e_table, full_header, etm, filename); + e_table_construct_from_spec_file (e_table, full_header, etm, filename); return (GtkWidget *) e_table; } -- cgit v1.2.3