aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/e-text
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
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')
-rw-r--r--widgets/e-text/Makefile.am8
-rw-r--r--widgets/e-text/e-text-model.c241
-rw-r--r--widgets/e-text/e-text-model.h72
-rw-r--r--widgets/e-text/e-text.c138
-rw-r--r--widgets/e-text/e-text.h4
5 files changed, 423 insertions, 40 deletions
diff --git a/widgets/e-text/Makefile.am b/widgets/e-text/Makefile.am
index d0ee56e5e1..60963c9727 100644
--- a/widgets/e-text/Makefile.am
+++ b/widgets/e-text/Makefile.am
@@ -10,13 +10,15 @@ libetext_a_SOURCES = \
e-text-event-processor.c \
e-text-event-processor.h \
e-text-event-processor-emacs-like.c \
- e-text-event-processor-emacs-like.h
+ e-text-event-processor-emacs-like.h \
+ e-text-model.c \
+ e-text-model.h
noinst_PROGRAMS = \
- e-text-test
+ e-text-test
e_text_test_SOURCES = \
- e-text-test.c
+ e-text-test.c
e_text_test_LDADD = \
libetext.a \
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;
+}
diff --git a/widgets/e-text/e-text-model.h b/widgets/e-text/e-text-model.h
new file mode 100644
index 0000000000..5b15ccb117
--- /dev/null
+++ b/widgets/e-text/e-text-model.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* ETextModel - Text item 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> */
+
+#ifndef E_TEXT_MODEL_H
+#define E_TEXT_MODEL_H
+
+#include <gnome.h>
+
+
+BEGIN_GNOME_DECLS
+
+#define E_TYPE_TEXT_MODEL (e_text_model_get_type ())
+#define E_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT_MODEL, ETextModel))
+#define E_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT_MODEL, ETextModelClass))
+#define E_IS_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT_MODEL))
+#define E_IS_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT_MODEL))
+
+typedef struct _ETextModel ETextModel;
+typedef struct _ETextModelClass ETextModelClass;
+
+struct _ETextModel {
+ GtkObject item;
+
+ char *text; /* Text to display */
+ int length;
+};
+
+struct _ETextModelClass {
+ GtkObjectClass parent_class;
+
+ /* Signal */
+ void (* changed) (ETextModel *model);
+
+ /* Virtual methods */
+ char *(* get_text) (ETextModel *model);
+ void (* set_text) (ETextModel *model, gchar *text);
+ void (* insert) (ETextModel *model, gint position, gchar *text);
+ void (* insert_length) (ETextModel *model, gint position, gchar *text, gint length);
+ void (* delete) (ETextModel *model, gint position, gint length);
+};
+
+
+/* Standard Gtk function */
+GtkType e_text_model_get_type (void);
+ETextModel *e_text_model_new(void);
+
+void e_text_model_changed(ETextModel *model);
+gchar *e_text_model_get_text(ETextModel *model);
+void e_text_model_set_text(ETextModel *model, gchar *text);
+void e_text_model_insert(ETextModel *model, gint position, gchar *text);
+void e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length);
+void e_text_model_delete(ETextModel *model, gint position, gint length);
+
+
+END_GNOME_DECLS
+
+#endif
diff --git a/widgets/e-text/e-text.c b/widgets/e-text/e-text.c
index ca41dc1d96..85950f149a 100644
--- a/widgets/e-text/e-text.c
+++ b/widgets/e-text/e-text.c
@@ -52,6 +52,7 @@ struct line {
/* Object argument IDs */
enum {
ARG_0,
+ ARG_MODEL,
ARG_TEXT,
ARG_X,
ARG_Y,
@@ -117,6 +118,8 @@ static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand
static void e_text_get_selection(EText *text, GdkAtom selection, guint32 time);
static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length);
+static void e_text_text_model_changed(ETextModel *model, EText *text);
+
static GtkWidget *e_text_get_invisible(EText *text);
static void _selection_clear_event (GtkInvisible *invisible,
GdkEventSelection *event,
@@ -133,6 +136,7 @@ static void _selection_received (GtkInvisible *invisible,
static ETextSuckFont *e_suck_font (GdkFont *font);
static void e_suck_font_free (ETextSuckFont *suckfont);
+static void e_text_free_lines(EText *text);
static GnomeCanvasItemClass *parent_class;
@@ -203,7 +207,9 @@ e_text_class_init (ETextClass *klass)
gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL);
-
+
+ gtk_object_add_arg_type ("EText::model",
+ GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_MODEL);
gtk_object_add_arg_type ("EText::text",
GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT);
gtk_object_add_arg_type ("EText::x",
@@ -285,6 +291,16 @@ e_text_class_init (ETextClass *klass)
static void
e_text_init (EText *text)
{
+ text->text = NULL;
+ text->model = e_text_model_new();
+ gtk_object_ref(GTK_OBJECT(text->model));
+ gtk_object_sink(GTK_OBJECT(text->model));
+ text->model_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(text->model),
+ "changed",
+ GTK_SIGNAL_FUNC(e_text_text_model_changed),
+ text);
+
text->x = 0.0;
text->y = 0.0;
text->anchor = GTK_ANCHOR_CENTER;
@@ -348,8 +364,12 @@ e_text_destroy (GtkObject *object)
text = E_TEXT (object);
- if (text->text)
- g_free (text->text);
+ if (text->model_changed_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(text->model),
+ text->model_changed_signal_id);
+
+ if (text->model)
+ gtk_object_unref(GTK_OBJECT(text->model));
if (text->tep)
gtk_object_unref (GTK_OBJECT(text->tep));
@@ -374,6 +394,15 @@ e_text_destroy (GtkObject *object)
}
static void
+e_text_text_model_changed (ETextModel *model, EText *text)
+{
+ text->text = e_text_model_get_text(model);
+ e_text_free_lines(text);
+ text->needs_split_into_lines = 1;
+ e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
+}
+
+static void
get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2)
{
GnomeCanvasItem *item;
@@ -663,8 +692,6 @@ split_into_lines (EText *text)
/* Free old array of lines */
e_text_free_lines(text);
- text->num_lines = 0;
-
if (!text->text)
return;
@@ -870,16 +897,31 @@ e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
have_pixel = FALSE;
switch (arg_id) {
- case ARG_TEXT:
- if (text->text)
- g_free (text->text);
+ case ARG_MODEL:
+ if ( text->model_changed_signal_id )
+ gtk_signal_disconnect(GTK_OBJECT(text->model),
+ text->model_changed_signal_id);
+ gtk_object_unref(GTK_OBJECT(text->model));
+ text->model = E_TEXT_MODEL(GTK_VALUE_OBJECT (*arg));
+ gtk_object_ref(GTK_OBJECT(text->model));
+
+ text->model_changed_signal_id =
+ gtk_signal_connect(GTK_OBJECT(text->model),
+ "changed",
+ GTK_SIGNAL_FUNC(e_text_text_model_changed),
+ text);
- text->text = g_strdup (GTK_VALUE_STRING (*arg));
e_text_free_lines(text);
+ text->text = e_text_model_get_text(text->model);
+
text->needs_split_into_lines = 1;
needs_reflow = 1;
break;
+ case ARG_TEXT:
+ e_text_model_set_text(text->model, GTK_VALUE_STRING (*arg));
+ break;
+
case ARG_X:
text->x = GTK_VALUE_DOUBLE (*arg);
text->needs_recalc_bounds = 1;
@@ -1134,6 +1176,10 @@ e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
text = E_TEXT (object);
switch (arg_id) {
+ case ARG_MODEL:
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(text->model);
+ break;
+
case ARG_TEXT:
GTK_VALUE_STRING (*arg) = g_strdup (text->text);
break;
@@ -1253,10 +1299,36 @@ e_text_reflow (GnomeCanvasItem *item, int flags)
text->needs_calc_line_widths = 1;
}
if ( text->needs_calc_line_widths ) {
+ int x;
+ int i;
+ struct line *lines;
calc_line_widths(text);
text->needs_calc_line_widths = 0;
text->needs_calc_height = 1;
text->needs_redraw = 1;
+
+ lines = text->lines;
+ if ( !lines )
+ return;
+
+ for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) {
+ if (lines->text - text->text > text->selection_end) {
+ break;
+ }
+ }
+ lines --;
+ x = gdk_text_width(text->font,
+ lines->text,
+ text->selection_end - (lines->text - text->text));
+
+
+ if (x < text->xofs_edit) {
+ text->xofs_edit = x;
+ }
+
+ if (2 + x - text->clip_width > text->xofs_edit) {
+ text->xofs_edit = 2 + x - text->clip_width;
+ }
}
if ( text->needs_calc_height ) {
calc_height (text);
@@ -1489,8 +1561,10 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
return;
lines = text->lines;
- if ( !lines )
- return;
+ if ( !lines ) {
+ text->needs_split_into_lines = 1;
+ e_canvas_item_request_reflow (item);
+ }
clip_rect = NULL;
if (text->clip) {
@@ -2159,6 +2233,7 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
gtk_widget_destroy (text->tooltip_window);
text->tooltip_window = NULL;
}
+#if 0
if ((!text->editing)
&& text->editable
&& event->type == GDK_BUTTON_RELEASE
@@ -2177,6 +2252,13 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
&e_tep_event);
e_tep_event.type = GDK_BUTTON_RELEASE;
}
+#else
+ if ((!text->editing)
+ && text->editable
+ && event->button.button == 1) {
+ gnome_canvas_item_grab_focus (item);
+ }
+#endif
if (text->editing) {
GdkEventButton button = event->button;
e_tep_event.button.time = button.time;
@@ -2346,33 +2428,21 @@ _get_position(EText *text, ETextEventProcessorCommand *command)
static void
_delete_selection(EText *text)
{
- gint length = strlen(text->text);
- if (text->selection_end == text->selection_start)
- return;
- if (text->selection_end < text->selection_start) {
- text->selection_end ^= text->selection_start;
- text->selection_start ^= text->selection_end;
- text->selection_end ^= text->selection_start;
+ if ( text->selection_start < text->selection_end ) {
+ e_text_model_delete(text->model, text->selection_start, text->selection_end - text->selection_start);
+ text->selection_end = text->selection_start;
+ } else {
+ e_text_model_delete(text->model, text->selection_end, text->selection_start - text->selection_end);
+ text->selection_start = text->selection_end;
}
- memmove( text->text + text->selection_start,
- text->text + text->selection_end,
- length - text->selection_end + 1 );
- length -= text->selection_end - text->selection_start;
- text->selection_end = text->selection_start;
}
static void
_insert(EText *text, char *string, int value)
{
if (value > 0) {
- char *temp;
- gint length = strlen(text->text);
- temp = g_new(gchar, length + value + 1);
- strncpy(temp, text->text, text->selection_start);
- strncpy(temp + text->selection_start, string, value);
- strcpy(temp + text->selection_start + value, text->text + text->selection_start);
- g_free(text->text);
- text->text = temp;
+ e_text_model_insert_length(text->model, text->selection_start, string, value);
+
text->selection_start += value;
text->selection_end = text->selection_start;
}
@@ -2406,9 +2476,6 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp
text->selection_end = _get_position(text, command);
}
_delete_selection(text);
- e_text_free_lines(text);
- text->needs_split_into_lines = 1;
- e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
if (text->timer) {
g_timer_reset(text->timer);
}
@@ -2419,9 +2486,6 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp
_delete_selection(text);
}
_insert(text, command->string, command->value);
- e_text_free_lines(text);
- text->needs_split_into_lines = 1;
- e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
if (text->timer) {
g_timer_reset(text->timer);
}
diff --git a/widgets/e-text/e-text.h b/widgets/e-text/e-text.h
index 52fb951bc2..a4bc06d820 100644
--- a/widgets/e-text/e-text.h
+++ b/widgets/e-text/e-text.h
@@ -21,6 +21,7 @@
#include <gnome.h>
#include "e-text-event-processor.h"
+#include "e-text-model.h"
BEGIN_GNOME_DECLS
@@ -101,6 +102,9 @@ struct _ETextSuckFont {
struct _EText {
GnomeCanvasItem item;
+
+ ETextModel *model;
+ gint model_changed_signal_id;
char *text; /* Text to display */
gpointer lines; /* Text split into lines (private field) */