aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/text/e-text.c
diff options
context:
space:
mode:
authorJon Trowbridge <trow@gnu.org>2001-01-30 04:27:38 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-01-30 04:27:38 +0800
commitb0046a3699f814f39e31192e21c17c15b0dd8474 (patch)
tree23e7f567903068db06a80ebcfa4187f264f611fb /widgets/text/e-text.c
parentba874ca7d0237c07b0630930eeebda613c543640 (diff)
downloadgsoc2013-evolution-b0046a3699f814f39e31192e21c17c15b0dd8474.tar
gsoc2013-evolution-b0046a3699f814f39e31192e21c17c15b0dd8474.tar.gz
gsoc2013-evolution-b0046a3699f814f39e31192e21c17c15b0dd8474.tar.bz2
gsoc2013-evolution-b0046a3699f814f39e31192e21c17c15b0dd8474.tar.lz
gsoc2013-evolution-b0046a3699f814f39e31192e21c17c15b0dd8474.tar.xz
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.c')
-rw-r--r--widgets/text/e-text.c97
1 files changed, 91 insertions, 6 deletions
diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c
index fbbe77dc0d..1427a078ca 100644
--- a/widgets/text/e-text.c
+++ b/widgets/text/e-text.c
@@ -128,6 +128,7 @@ 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 void e_text_text_model_position(ETextModel *model, gint position, EText *text);
static void _get_tep(EText *text);
@@ -331,6 +332,11 @@ e_text_init (EText *text)
"changed",
GTK_SIGNAL_FUNC(e_text_text_model_changed),
text);
+ text->model_position_signal_id =
+ gtk_signal_connect(GTK_OBJECT(text->model),
+ "position",
+ GTK_SIGNAL_FUNC(e_text_text_model_position),
+ text);
text->anchor = GTK_ANCHOR_CENTER;
text->justification = GTK_JUSTIFY_LEFT;
@@ -387,6 +393,8 @@ e_text_init (EText *text)
text->dbl_timeout = 0;
text->tpl_timeout = 0;
+ text->rgba_object = 0x0000ffff;
+
text->draw_background = FALSE;
e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(text), e_text_reflow);
@@ -406,6 +414,9 @@ e_text_destroy (GtkObject *object)
if (text->model_changed_signal_id)
gtk_signal_disconnect(GTK_OBJECT(text->model),
text->model_changed_signal_id);
+ if (text->model_position_signal_id)
+ gtk_signal_disconnect(GTK_OBJECT(text->model),
+ text->model_position_signal_id);
if (text->model)
gtk_object_unref(GTK_OBJECT(text->model));
@@ -465,16 +476,48 @@ e_text_destroy (GtkObject *object)
}
static void
+fix_selection (EText *text)
+{
+ gint len = strlen (text->text);
+
+ if (text->selection_start > len) {
+ text->selection_start = len;
+ }
+ if (text->selection_end > len) {
+ text->selection_end = len;
+ }
+}
+
+static void
e_text_text_model_changed (ETextModel *model, EText *text)
{
+ gint len;
+
text->text = e_text_model_get_text(model);
+ len = strlen (text->text);
+
+ fix_selection (text);
+
e_text_free_lines(text);
gtk_signal_emit (GTK_OBJECT (text), e_text_signals[E_TEXT_CHANGED]);
+ text->needs_redraw = 1;
text->needs_split_into_lines = 1;
e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text));
}
static void
+e_text_text_model_position (ETextModel *model, gint position, EText *text)
+{
+ /*
+ For now, something very simple. We can worry about things
+ like preserving a multi-char selection later.
+ */
+
+ text->selection_start = position;
+ text->selection_end = position;
+}
+
+static void
get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2)
{
GnomeCanvasItem *item;
@@ -798,6 +841,9 @@ text_width_with_objects (ETextModel *model, gint object_num,
gchar *c;
gint width = 0;
+ if (text == NULL)
+ return 0;
+
while (*text && numbytes > 0) {
c = text;
@@ -849,11 +895,14 @@ static void
text_draw_with_objects (ETextModel *model, gint object_num,
GdkDrawable *drawable,
EFont *font, EFontStyle style,
- GdkGC *gc,
+ GdkGC *gc, GdkGC *obj_gc,
gint x, gint y,
gchar *text, gint numbytes)
{
gchar *c;
+
+ if (text == NULL)
+ return;
while (*text && numbytes > 0) {
@@ -871,16 +920,20 @@ text_draw_with_objects (ETextModel *model, gint object_num,
const gchar *obj_str;
gint start_x = x;
gint len;
+
+ if (obj_gc == NULL)
+ obj_gc = gc;
+
g_assert (object_num < e_text_model_object_count (model));
obj_str = e_text_model_get_nth_object (model, object_num);
len = strlen (obj_str);
- e_font_draw_utf8_text (drawable, font, style, gc, x, y, obj_str, len);
+ e_font_draw_utf8_text (drawable, font, style, obj_gc, x, y, obj_str, len);
x += e_font_utf8_text_width (font, style, obj_str, len);
/* We underline our objects. */
- gdk_draw_line (drawable, gc, start_x, y+1, x, y+1);
+ gdk_draw_line (drawable, obj_gc, start_x, y+1, x, y+1);
++object_num;
++c;
@@ -1169,6 +1222,9 @@ e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
if ( text->model_changed_signal_id )
gtk_signal_disconnect(GTK_OBJECT(text->model),
text->model_changed_signal_id);
+ if ( text->model_position_signal_id )
+ gtk_signal_disconnect(GTK_OBJECT(text->model),
+ text->model_position_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));
@@ -1178,6 +1234,11 @@ e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
"changed",
GTK_SIGNAL_FUNC(e_text_text_model_changed),
text);
+ text->model_position_signal_id =
+ gtk_signal_connect(GTK_OBJECT(text->model),
+ "position",
+ GTK_SIGNAL_FUNC(e_text_text_model_position),
+ text);
e_text_free_lines(text);
@@ -1773,7 +1834,7 @@ e_text_realize (GnomeCanvasItem *item)
(* parent_class->realize) (item);
text->gc = gdk_gc_new (item->canvas->layout.bin_window);
-
+
text->i_cursor = gdk_cursor_new (GDK_XTERM);
text->default_cursor = gdk_cursor_new (GDK_LEFT_PTR);
if (text->font == NULL) {
@@ -1948,6 +2009,16 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
canvas = GNOME_CANVAS_ITEM(text)->canvas;
fg_gc = GTK_WIDGET(canvas)->style->fg_gc[text->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE];
+
+ if (text->rgba_object && text->gc_object == NULL && text->gc) {
+ GdkColor c;
+ c.pixel = gnome_canvas_get_color_pixel (item->canvas, text->rgba_object);
+
+ text->gc_object = gdk_gc_new (item->canvas->layout.bin_window);
+ gdk_gc_copy (text->gc_object, text->gc);
+ gdk_gc_set_foreground (text->gc_object, &c);
+ }
+
if (text->draw_borders || text->draw_background) {
gdouble thisx = item->x1 - x;
@@ -2071,6 +2142,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
drawable,
text->font, E_FONT_PLAIN,
text->gc,
+ text->gc_object,
xpos - x,
ypos - y,
lines->text,
@@ -2079,6 +2151,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
drawable,
text->font, E_FONT_PLAIN,
fg_gc,
+ text->gc_object,
xpos - x + text_width_with_objects (text->model, lines->first_obj,
text->font, E_FONT_PLAIN,
lines->text,
@@ -2090,6 +2163,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
drawable,
text->font, E_FONT_PLAIN,
text->gc,
+ text->gc_object,
xpos - x + text_width_with_objects (text->model, lines->first_obj,
text->font, E_FONT_PLAIN,
lines->text,
@@ -2102,6 +2176,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
drawable,
text->font, E_FONT_PLAIN,
text->gc,
+ text->gc_object,
xpos - x,
ypos - y,
lines->text,
@@ -2128,6 +2203,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
drawable,
text->font, E_FONT_PLAIN,
text->gc,
+ text->gc_object,
xpos - x,
ypos - y,
lines->text,
@@ -2144,6 +2220,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
drawable,
text->font, E_FONT_PLAIN,
text->gc,
+ text->gc_object,
xpos - x,
ypos - y,
lines->text,
@@ -3297,6 +3374,8 @@ _delete_selection(EText *text)
e_text_model_delete(text->model, text->selection_end, text->selection_start - text->selection_end);
text->selection_start = text->selection_end;
}
+
+ fix_selection (text);
}
static void
@@ -3305,8 +3384,13 @@ _insert(EText *text, char *string, int value)
if (value > 0) {
e_text_model_insert_length(text->model, text->selection_start, string, value);
- text->selection_start += value;
- text->selection_end = text->selection_start;
+ /*
+ text->selection_start += value;
+ text->selection_end = text->selection_start;
+ */
+
+ fix_selection (text);
+
}
}
@@ -3315,6 +3399,7 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp
{
EText *text = E_TEXT(data);
int sel_start, sel_end;
+
switch (command->action) {
case E_TEP_MOVE:
text->selection_start = _get_position(text, command);