aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/e-text/e-text-model.c
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-03-12 15:59:42 +0800
committerChris Lahey <clahey@src.gnome.org>2000-03-12 15:59:42 +0800
commit1f7ba945b16cd5f8c01641dd864a9671d791a651 (patch)
treeb673bc2f8f4b07554ca42cbd714ccc98efd14f9b /widgets/e-text/e-text-model.c
parentf669ff481f57cf5b609ea2e8fe30cfb8dece8587 (diff)
downloadgsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.tar
gsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.tar.gz
gsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.tar.bz2
gsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.tar.lz
gsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.tar.xz
gsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.tar.zst
gsoc2013-evolution-1f7ba945b16cd5f8c01641dd864a9671d791a651.zip
Rearranged SUBDIRS for dependencies.
2000-03-12 Christopher James Lahey <clahey@helixcode.com> * 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 <clahey@helixcode.com> * 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
Diffstat (limited to 'widgets/e-text/e-text-model.c')
-rw-r--r--widgets/e-text/e-text-model.c241
1 files changed, 241 insertions, 0 deletions
diff --git a/widgets/e-text/e-text-model.c b/widgets/e-text/e-text-model.c
new file mode 100644
index 0000000000..d571e87791
--- /dev/null
+++ b/widgets/e-text/e-text-model.c
@@ -0,0 +1,241 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETextModel - Text item model for evolution.
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Author: Chris Lahey <clahey@umich.edu>
+ *
+ * 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 <federico@nuclecu.unam.mx> */
+
+#include <config.h>
+#include <ctype.h>
+#include "e-text-model.h"
+
+enum {
+ E_TEXT_MODEL_CHANGED,
+ E_TEXT_MODEL_LAST_SIGNAL
+};
+
+static guint e_text_model_signals[E_TEXT_MODEL_LAST_SIGNAL] = { 0 };
+
+static void e_text_model_class_init (ETextModelClass *class);
+static void e_text_model_init (ETextModel *model);
+static void e_text_model_destroy (GtkObject *object);
+
+static gchar *e_text_model_real_get_text(ETextModel *model);
+static void e_text_model_real_set_text(ETextModel *model, gchar *text);
+static void e_text_model_real_insert(ETextModel *model, gint postion, gchar *text);
+static void e_text_model_real_insert_length(ETextModel *model, gint postion, gchar *text, gint length);
+static void e_text_model_real_delete(ETextModel *model, gint postion, gint length);
+
+static GtkObject *parent_class;
+
+
+
+/**
+ * e_text_model_get_type:
+ * @void:
+ *
+ * Registers the &ETextModel class if necessary, and returns the type ID
+ * associated to it.
+ *
+ * Return value: The type ID of the &ETextModel class.
+ **/
+GtkType
+e_text_model_get_type (void)
+{
+ static GtkType model_type = 0;
+
+ if (!model_type) {
+ GtkTypeInfo model_info = {
+ "ETextModel",
+ sizeof (ETextModel),
+ sizeof (ETextModelClass),
+ (GtkClassInitFunc) e_text_model_class_init,
+ (GtkObjectInitFunc) e_text_model_init,
+ NULL, /* reserved_1 */
+ NULL, /* reserved_2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ model_type = gtk_type_unique (gtk_object_get_type (), &model_info);
+ }
+
+ return model_type;
+}
+
+/* Class initialization function for the text item */
+static void
+e_text_model_class_init (ETextModelClass *klass)
+{
+ GtkObjectClass *object_class;
+
+ object_class = (GtkObjectClass *) klass;
+
+ parent_class = gtk_type_class (gtk_object_get_type ());
+
+ e_text_model_signals[E_TEXT_MODEL_CHANGED] =
+ gtk_signal_new ("changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (ETextModelClass, changed),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+
+ gtk_object_class_add_signals (object_class, e_text_model_signals, E_TEXT_MODEL_LAST_SIGNAL);
+
+ klass->changed = NULL;
+ klass->get_text = e_text_model_real_get_text;
+ klass->set_text = e_text_model_real_set_text;
+ klass->insert = e_text_model_real_insert;
+ klass->insert_length = e_text_model_real_insert_length;
+ klass->delete = e_text_model_real_delete;
+
+ object_class->destroy = e_text_model_destroy;
+}
+
+/* Object initialization function for the text item */
+static void
+e_text_model_init (ETextModel *model)
+{
+ model->text = NULL;
+}
+
+/* Destroy handler for the text item */
+static void
+e_text_model_destroy (GtkObject *object)
+{
+ ETextModel *model;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (object));
+
+ model = E_TEXT_MODEL (object);
+
+ if (model->text)
+ g_free (model->text);
+
+ if (GTK_OBJECT_CLASS (parent_class)->destroy)
+ (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+}
+
+static gchar *
+e_text_model_real_get_text(ETextModel *model)
+{
+ return model->text;
+}
+
+static void
+e_text_model_real_set_text(ETextModel *model, gchar *text)
+{
+ if (model->text)
+ g_free(model->text);
+ model->text = g_strdup(text);
+ e_text_model_changed(model);
+}
+
+static void
+e_text_model_real_insert(ETextModel *model, gint position, gchar *text)
+{
+ gchar *temp = g_strdup_printf("%.*s%s%s", position, model->text, text, model->text + position);
+ if (model->text)
+ g_free(model->text);
+ model->text = temp;
+ e_text_model_changed(model);
+}
+
+static void
+e_text_model_real_insert_length(ETextModel *model, gint position, gchar *text, gint length)
+{
+ gchar *temp = g_strdup_printf("%.*s%.*s%s", position, model->text, length, text, model->text + position);
+ if (model->text)
+ g_free(model->text);
+ model->text = temp;
+ e_text_model_changed(model);
+}
+
+static void
+e_text_model_real_delete(ETextModel *model, gint position, gint length)
+{
+ memmove(model->text + position, model->text + position + length, strlen(model->text + position + length) + 1);
+ e_text_model_changed(model);
+}
+
+void
+e_text_model_changed(ETextModel *model)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ gtk_signal_emit (GTK_OBJECT (model),
+ e_text_model_signals [E_TEXT_MODEL_CHANGED]);
+}
+
+gchar *
+e_text_model_get_text(ETextModel *model)
+{
+ g_return_val_if_fail (model != NULL, NULL);
+ g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL);
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text )
+ return E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text(model);
+ else
+ return "";
+}
+
+void
+e_text_model_set_text(ETextModel *model, gchar *text)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text(model, text);
+}
+
+void
+e_text_model_insert(ETextModel *model, gint position, gchar *text)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert(model, position, text);
+}
+
+void
+e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length(model, position, text, length);
+}
+
+void
+e_text_model_delete(ETextModel *model, gint position, gint length)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete )
+ E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete(model, position, length);
+}
+
+ETextModel *
+e_text_model_new(void)
+{
+ ETextModel *model = gtk_type_new (e_text_model_get_type ());
+ model->text = g_strdup("");
+ return model;
+}