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/text/e-text.c | 138 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 101 insertions(+), 37 deletions(-) (limited to 'widgets/text/e-text.c') diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c index ca41dc1d96..85950f149a 100644 --- a/widgets/text/e-text.c +++ b/widgets/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)); @@ -373,6 +393,15 @@ e_text_destroy (GtkObject *object) (* GTK_OBJECT_CLASS (parent_class)->destroy) (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) { @@ -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); } -- cgit