diff options
author | Jon Trowbridge <trow@gnu.org> | 2001-01-30 04:27:38 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-01-30 04:27:38 +0800 |
commit | b0046a3699f814f39e31192e21c17c15b0dd8474 (patch) | |
tree | 23e7f567903068db06a80ebcfa4187f264f611fb /widgets/text/e-text-model.c | |
parent | ba874ca7d0237c07b0630930eeebda613c543640 (diff) | |
download | gsoc2013-evolution-b0046a3699f814f39e31192e21c17c15b0dd8474.tar.gz gsoc2013-evolution-b0046a3699f814f39e31192e21c17c15b0dd8474.tar.zst gsoc2013-evolution-b0046a3699f814f39e31192e21c17c15b0dd8474.zip |
Connect to the model's "position" signal. (e_text_init): Set default value
2001-01-29 Jon Trowbridge <trow@gnu.org>
* gal/e-text/e-text.c (e_text_init): Connect to the model's
"position" signal.
(e_text_init): Set default value for rgba_object as blue.
(e_text_destroy): Disconnect model position signal.
(fix_selection): Some extra sanity checking to keep the selection
from spilling outside of the bounds of the text string as it
expands or contracts. Should be obsolete due to the changes to
objectify_uris --- but I'll leave this in here for now, in an
attempt to avoid non-\0-terminated strings, segfaults, and all of
that fun stuff.
(e_text_text_model_position): Move our cursor according to the
suggestions made by our ETextModel, via the "position" signal.
(text_width_with_objects): Check that text is not NULL.
(text_draw_with_objects): Accept an extra GdkGC for use in drawing
objects.
(e_text_set_arg): Properly handle the "position" signal when
changing models.
(e_text_draw): Initialize the GC for drawing objects, if
necessary.
(_insert): Comment out the code that adjustes text->selection_*.
The cursor is now moved by the ETextModel directly via the
position signal, not by the view.
* gal/e-text/e-text-model-uri.c (objectify_uris): Add more
sophisticated uri recognition via regular expressions.
(objectify_uris): Changed to track position changes as model->text
expands and contracts along with the objects. Block the
objectification of any chunks of text that straddle our current
position.
(e_text_model_uri_set_text): Added position info to objectify_uris
call.
(e_text_model_uri_insert): Added position info to objectify_uris
call.
(e_text_model_uri_insert_length): Added position info to
objectify_uris call.
(e_text_model_uri_delete): Added position info to objectify_uris
call.
* gal/e-text/e-text-model.c (e_text_model_class_init): Added a
"position" signal that allows the ETextModel to send cursor
positioning information back to any view. We need this for text
with objects, where the text string can grow and shrink in ways
that the view doesn't expect.
(e_text_model_real_insert): Added sanity checking of args and a
position emission.
(e_text_model_real_insert_length): Added sanity checking of args
and a position emission.
(e_text_model_real_delete): Added sanity checking of args.
(e_text_model_suggest_position): A wrapper around the "position"
signal emitter.
svn path=/trunk/; revision=7894
Diffstat (limited to 'widgets/text/e-text-model.c')
-rw-r--r-- | widgets/text/e-text-model.c | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/widgets/text/e-text-model.c b/widgets/text/e-text-model.c index acd08ecb04..bbd442b46c 100644 --- a/widgets/text/e-text-model.c +++ b/widgets/text/e-text-model.c @@ -22,6 +22,7 @@ enum { E_TEXT_MODEL_CHANGED, + E_TEXT_MODEL_POSITION, E_TEXT_MODEL_LAST_SIGNAL }; @@ -33,9 +34,9 @@ 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 void e_text_model_real_insert(ETextModel *model, gint position, gchar *text); +static void e_text_model_real_insert_length(ETextModel *model, gint position, gchar *text, gint length); +static void e_text_model_real_delete(ETextModel *model, gint position, gint length); static gint e_text_model_real_object_count(ETextModel *model); static const gchar *e_text_model_real_get_nth_object(ETextModel *model, gint n); @@ -95,6 +96,14 @@ e_text_model_class_init (ETextModelClass *klass) GTK_SIGNAL_OFFSET (ETextModelClass, changed), gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0); + + e_text_model_signals[E_TEXT_MODEL_POSITION] = + gtk_signal_new ("position", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (ETextModelClass, position), + gtk_marshal_NONE__INT, + GTK_TYPE_NONE, 1, GTK_TYPE_INT); gtk_object_class_add_signals (object_class, e_text_model_signals, E_TEXT_MODEL_LAST_SIGNAL); @@ -157,26 +166,42 @@ e_text_model_real_set_text(ETextModel *model, gchar *text) 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); + gchar *temp; + + g_return_if_fail (0<= position && position <= strlen (model->text)); + + 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); + + e_text_model_suggest_position (model, position + strlen(text)); } 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); + gchar *temp; + + g_return_if_fail (0 <= position && position <= strlen (model->text)); + + 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); + + e_text_model_suggest_position (model, position + length); } static void e_text_model_real_delete(ETextModel *model, gint position, gint length) { + g_return_if_fail (0 <= position && position <= strlen (model->text)); + memmove(model->text + position, model->text + position + length, strlen(model->text + position + length) + 1); e_text_model_changed(model); } @@ -271,6 +296,17 @@ e_text_model_delete(ETextModel *model, gint position, gint length) E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete(model, position, length); } +void +e_text_model_suggest_position(ETextModel *model, gint position) +{ + g_return_if_fail (model != NULL); + g_return_if_fail (E_IS_TEXT_MODEL (model)); + g_return_if_fail (0 <= position); + g_return_if_fail (position <= strlen (model->text)); + + gtk_signal_emit (GTK_OBJECT (model), e_text_model_signals[E_TEXT_MODEL_POSITION], position); +} + gint e_text_model_object_count(ETextModel *model) { @@ -330,11 +366,10 @@ e_text_model_strdup_expanded_text(ETextModel *model) len -= N; /* Subtract out the \1s that signify the objects. */ for (i=0; i<N; ++i) - len += strlen (e_text_model_get_nth_object (model ,i)); - + len += strlen (e_text_model_get_nth_object (model, i)); /* Next, allocate and build the expanded string. */ - expanded = g_new0 (gchar, len+1); + expanded = g_new0 (gchar, len+2); src = model->text; dest = expanded; |