diff options
Diffstat (limited to 'widgets/text')
-rw-r--r-- | widgets/text/.cvsignore | 11 | ||||
-rw-r--r-- | widgets/text/e-completion-match.c | 186 | ||||
-rw-r--r-- | widgets/text/e-completion-match.h | 69 | ||||
-rw-r--r-- | widgets/text/e-completion-test.c | 220 | ||||
-rw-r--r-- | widgets/text/e-completion-view.c | 907 | ||||
-rw-r--r-- | widgets/text/e-completion-view.h | 103 | ||||
-rw-r--r-- | widgets/text/e-completion.c | 644 | ||||
-rw-r--r-- | widgets/text/e-completion.h | 103 | ||||
-rw-r--r-- | widgets/text/e-entry-test.c | 83 | ||||
-rw-r--r-- | widgets/text/e-entry.c | 1350 | ||||
-rw-r--r-- | widgets/text/e-entry.h | 88 | ||||
-rw-r--r-- | widgets/text/e-table-text-model.c | 246 | ||||
-rw-r--r-- | widgets/text/e-table-text-model.h | 65 | ||||
-rw-r--r-- | widgets/text/e-text-model-repos.c | 87 | ||||
-rw-r--r-- | widgets/text/e-text-model-repos.h | 69 | ||||
-rw-r--r-- | widgets/text/e-text-model-test.c | 93 | ||||
-rw-r--r-- | widgets/text/e-text-model-uri.c | 359 | ||||
-rw-r--r-- | widgets/text/e-text-model-uri.h | 56 | ||||
-rw-r--r-- | widgets/text/e-text-model.c | 645 | ||||
-rw-r--r-- | widgets/text/e-text-model.h | 119 | ||||
-rw-r--r-- | widgets/text/e-text-test.c | 171 | ||||
-rw-r--r-- | widgets/text/e-text.c | 4224 | ||||
-rw-r--r-- | widgets/text/e-text.h | 272 |
23 files changed, 0 insertions, 10170 deletions
diff --git a/widgets/text/.cvsignore b/widgets/text/.cvsignore deleted file mode 100644 index 792b9f5af2..0000000000 --- a/widgets/text/.cvsignore +++ /dev/null @@ -1,11 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -e-text-test -e-entry-test -e-text-model-test -e-completion-test
\ No newline at end of file diff --git a/widgets/text/e-completion-match.c b/widgets/text/e-completion-match.c deleted file mode 100644 index e61362a561..0000000000 --- a/widgets/text/e-completion-match.c +++ /dev/null @@ -1,186 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-completion-match.c - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> -#include <string.h> -#include <gal/unicode/gunicode.h> -#include <gal/widgets/e-unicode.h> -#include "e-completion-match.h" - -static void -e_completion_match_destroy (ECompletionMatch *match) -{ - if (match) { - g_free (match->match_text); - g_free (match->menu_text); - if (match->destroy) - match->destroy (match); - g_free (match); - } -} - -void -e_completion_match_construct (ECompletionMatch *match) -{ - g_return_if_fail (match != NULL); - - match->match_text = NULL; - match->menu_text = NULL; - match->score = 0; - match->sort_major = 0; - match->sort_minor = 0; - match->user_data = NULL; - match->ref = 1; - match->hit_count = 0; - match->destroy = NULL; -} - -void -e_completion_match_ref (ECompletionMatch *match) -{ - g_return_if_fail (match != NULL); - g_return_if_fail (match->ref > 0); - - ++match->ref; -} - -void -e_completion_match_unref (ECompletionMatch *match) -{ - if (match) { - g_return_if_fail (match->ref > 0); - - --match->ref; - if (match->ref == 0) { - e_completion_match_destroy (match); - } - } -} - -void -e_completion_match_set_text (ECompletionMatch *match, - const gchar *match_text, - const gchar *menu_text) -{ - g_return_if_fail (match != NULL); - - /* We silently drop any entries w/ invalid utf8. - This is not optimal behavior. */ - - if (match_text && ! g_utf8_validate (match_text, -1, NULL)) { - match_text = NULL; - } - - if (menu_text && ! g_utf8_validate (menu_text, -1, NULL)) { - menu_text = NULL; - } - - if (match->match_text && match->match_text != match_text) { - g_free (match->match_text); - } - match->match_text = g_strdup (match_text); - - if (match->menu_text && match->menu_text != menu_text) { - g_free (match->menu_text); - } - match->menu_text = g_strdup (menu_text); -} - -const gchar * -e_completion_match_get_match_text (ECompletionMatch *match) -{ - g_return_val_if_fail (match != NULL, NULL); - return match->match_text; -} - -const gchar * -e_completion_match_get_menu_text (ECompletionMatch *match) -{ - g_return_val_if_fail (match != NULL, NULL); - return match->menu_text; -} - -gint -e_completion_match_compare (const ECompletionMatch *a, const ECompletionMatch *b) -{ - gint rv; - - /* Deal with NULL arguments. */ - if (!(a || b)) { - if (!(a && b)) - return 0; - return a ? -1 : 1; - } - - if ( (rv = (b->sort_major < a->sort_major) - (a->sort_major < b->sort_major)) ) - return rv; - - /* Sort the scores high->low. */ - if ( (rv = (b->score > a->score) - (a->score > b->score)) ) - return rv; - - if ( (rv = (b->sort_minor < a->sort_minor) - (a->sort_minor < b->sort_minor)) ) - return rv; - - return 0; -} - -gint -e_completion_match_compare_alpha (const ECompletionMatch *a, const ECompletionMatch *b) -{ - gint rv, rv2; - - /* Deal with NULL arguments. */ - if (!(a || b)) { - if (!(a && b)) - return 0; - return a ? -1 : 1; - } - - /* The sort_major trumps everything. */ - if ( (rv = (b->sort_major < a->sort_major) - (a->sort_major < b->sort_major)) ) - return rv; - - /* Sort the scores high->low. */ - if ( (rv = (b->score > a->score) - (a->score > b->score)) ) - return rv; - - /* When the match text is the same, we use the minor fields */ - rv2 = strcmp (a->match_text, b->match_text); - if ( !rv2 && (rv = (b->sort_minor < a->sort_minor) - (a->sort_minor < b->sort_minor)) ) - return rv; - - return strcmp (a->menu_text, b->menu_text); -} - -ECompletionMatch * -e_completion_match_new (const gchar *match_text, const gchar *menu_text, double score) -{ - ECompletionMatch *match = g_new0 (ECompletionMatch, 1); - - e_completion_match_construct (match); - e_completion_match_set_text (match, match_text, menu_text); - match->score = score; - - return match; -} diff --git a/widgets/text/e-completion-match.h b/widgets/text/e-completion-match.h deleted file mode 100644 index ba93e53172..0000000000 --- a/widgets/text/e-completion-match.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-completion-match.h - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef __E_COMPLETION_MATCH_H__ -#define __E_COMPLETION_MATCH_H__ - -#include <glib.h> -#include <libgnome/gnome-defs.h> -#include <gtk/gtkwidget.h> - -BEGIN_GNOME_DECLS - -typedef struct _ECompletionMatch ECompletionMatch; - -struct _ECompletionMatch { - gchar *match_text; /* in utf8 */ - gchar *menu_text; /* in utf8 */ - double score; - gint sort_major; - gint sort_minor; - gpointer user_data; - - gint ref; - gint hit_count; - void (*destroy) (ECompletionMatch *); -}; - -typedef void (*ECompletionMatchFn) (ECompletionMatch *, gpointer closure); - -void e_completion_match_construct (ECompletionMatch *); -void e_completion_match_ref (ECompletionMatch *); -void e_completion_match_unref (ECompletionMatch *); - -void e_completion_match_set_text (ECompletionMatch *, const gchar *match_text, const gchar *label_text); -const gchar *e_completion_match_get_match_text (ECompletionMatch *); -const gchar *e_completion_match_get_menu_text (ECompletionMatch *); - -gint e_completion_match_compare (const ECompletionMatch *, const ECompletionMatch *); -gint e_completion_match_compare_alpha (const ECompletionMatch *, const ECompletionMatch *); - -ECompletionMatch *e_completion_match_new (const gchar *match_text, const gchar *menu_text, double score); - - - - -END_GNOME_DECLS - -#endif /* __E_COMPLETION_MATCH_H__ */ - diff --git a/widgets/text/e-completion-test.c b/widgets/text/e-completion-test.c deleted file mode 100644 index bfa53982a3..0000000000 --- a/widgets/text/e-completion-test.c +++ /dev/null @@ -1,220 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-completion-test.c - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <gnome.h> -#include "e-completion.h" -#include "e-entry.h" - -#define TIMEOUT 10 - -/* Dictionary Lookup test */ - -static gint word_count = 0; -static gchar **word_array = NULL; - -static void -read_dict (void) -{ - FILE *in = fopen ("/usr/share/dict/words", "r"); - gchar buffer[128]; - GList *word_list = NULL, *iter; - gint i; - - while (fgets (buffer, 128, in)) { - gint len = strlen (buffer); - if (len > 0 && buffer[len-1] == '\n') - buffer[len-1] = '\0'; - word_list = g_list_prepend (word_list, g_strdup (buffer)); - ++word_count; - } - fclose (in); - - word_array = g_new (gchar *, word_count); - i = word_count-1; - for (iter = word_list; iter != NULL; iter = g_list_next (iter)) { - word_array[i] = (gchar *)iter->data; - --i; - } -} - -static gint -find_word (const gchar *str) -{ - gint a, b; - - if (word_array == NULL) - read_dict (); - - a = 0; - b = word_count-1; - - while (b-a > 1) { - gint m = (a+b)/2; - gint cmp = g_strcasecmp (str, word_array[m]); - - if (cmp < 0) - b = m; - else if (cmp > 0) - a = m; - else - return m; - } - - return b; -} - -struct { - ECompletion *complete; - const gchar *txt; - gint start; - gint current; - gint len; - gint limit; - gint count; -} dict_info; -static guint dict_tag = 0; - -static gboolean -dict_check (gpointer ptr) -{ - gint limit = dict_info.limit; - gint i; - - /* If this is the first iteration, do the binary search in our word list to figure out - where to start. We do less work on the first iteration, to give more of a sense of - immediate feedback. */ - if (dict_info.start < 0) { - dict_info.start = dict_info.current = find_word (dict_info.txt); - } - - i = dict_info.current; - while (limit > 0 - && i < word_count - && dict_info.count < 50 - && g_strncasecmp (dict_info.txt, word_array[i], dict_info.len) == 0) { - - ECompletionMatch *match = g_new (ECompletionMatch, 1); - e_completion_match_construct (match); - e_completion_match_set_text (match, word_array[i], NULL); - match->score = dict_info.len / (double)strlen (word_array[i]); - e_completion_found_match (dict_info.complete, match); - - ++i; - --limit; - ++dict_info.count; - } - dict_info.current = i; - dict_info.limit = MIN (dict_info.limit*2, 400); - - if (limit != 0) { - dict_tag = 0; - e_completion_end_search (dict_info.complete); - return FALSE; - } - - - - return TRUE; -} - -static void -request_dict_search (ECompletion *complete, const gchar *txt, gint pos, gint limit, gpointer user_data) -{ - gint len = strlen (txt); - - if (dict_tag != 0) { - gtk_timeout_remove (dict_tag); - dict_tag = 0; - } - - if (len > 0) { - dict_info.complete = complete; - dict_info.txt = txt; - dict_info.start = -1; - dict_info.current = -1; - dict_info.len = len; - dict_info.limit = 100; - dict_info.count = 0; - dict_tag = gtk_timeout_add (TIMEOUT, dict_check, NULL); - } else { - e_completion_end_search (complete); - } -} - -static void -end_dict_search (ECompletion *complete, gpointer user_data) -{ - if (dict_tag != 0) { - gtk_timeout_remove (dict_tag); - dict_tag = 0; - } -} - -static void -popup_cb (EEntry *popup, GdkEventButton *ev, gint pos, gpointer user_data) -{ - g_print ("popup at pos %d\n", pos); -} - -int -main (int argc, gchar **argv) -{ - ECompletion* complete; - GtkWidget *entry; - GtkWidget *win; - - gnome_init ("ETextModelTest", "0.0", argc, argv); - - read_dict (); - - complete = e_completion_new (); - gtk_signal_connect (GTK_OBJECT (complete), - "request_completion", - GTK_SIGNAL_FUNC (request_dict_search), - NULL); - gtk_signal_connect (GTK_OBJECT (complete), - "end_completion", - GTK_SIGNAL_FUNC (end_dict_search), - NULL); - gtk_signal_connect (GTK_OBJECT (complete), - "cancel_completion", - GTK_SIGNAL_FUNC (end_dict_search), - NULL); - - win = gtk_window_new (GTK_WINDOW_TOPLEVEL); - entry = e_entry_new (); - e_entry_enable_completion_full (E_ENTRY (entry), complete, 0, NULL); - e_entry_set_editable (E_ENTRY (entry), TRUE); - - gtk_signal_connect (GTK_OBJECT (entry), - "popup", - GTK_SIGNAL_FUNC (popup_cb), - NULL); - - gtk_container_add (GTK_CONTAINER (win), entry); - gtk_widget_show_all (win); - - gtk_main (); - - return 0; -} diff --git a/widgets/text/e-completion-view.c b/widgets/text/e-completion-view.c deleted file mode 100644 index a206d5da0b..0000000000 --- a/widgets/text/e-completion-view.c +++ /dev/null @@ -1,907 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-completion-view.c - A text completion selection widget - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Adapted by Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> -#include <math.h> -#include <gdk/gdkkeysyms.h> -#include <gal/e-table/e-table-simple.h> -#include <gal/e-table/e-table-scrolled.h> -#include "e-completion-view.h" - -enum { - E_COMPLETION_VIEW_NONEMPTY, - E_COMPLETION_VIEW_ADDED, - E_COMPLETION_VIEW_FULL, - E_COMPLETION_VIEW_BROWSE, - E_COMPLETION_VIEW_UNBROWSE, - E_COMPLETION_VIEW_ACTIVATE, - E_COMPLETION_VIEW_LAST_SIGNAL -}; - -static guint e_completion_view_signals[E_COMPLETION_VIEW_LAST_SIGNAL] = { 0 }; - -static void e_completion_view_disconnect (ECompletionView *cv); -static ETable *e_completion_view_table (ECompletionView *cv); -static void e_completion_view_clear_choices (ECompletionView *cv); -static void e_completion_view_set_cursor_row (ECompletionView *cv, gint r); -static void e_completion_view_select (ECompletionView *cv, gint r); - -static gint e_completion_view_key_press_handler (GtkWidget *w, GdkEventKey *key_event, gpointer user_data); - -static void e_completion_view_class_init (ECompletionViewClass *klass); -static void e_completion_view_init (ECompletionView *completion); -static void e_completion_view_destroy (GtkObject *object); - -static GtkObjectClass *parent_class; - - - -static gint -e_completion_view_local_key_press_handler (GtkWidget *w, GdkEventKey *ev) -{ - return e_completion_view_key_press_handler (w, ev, w); -} - -static void -e_completion_view_paint (GtkWidget *widget, GdkRectangle *area) -{ - gint i; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (widget)); - g_return_if_fail (area != NULL); - - if (!GTK_WIDGET_DRAWABLE (widget)) - return; - - for (i = 0; i < E_COMPLETION_VIEW (widget)->border_width; ++i) { - - gdk_draw_rectangle (widget->window, - widget->style->black_gc, - FALSE, i, i, - widget->allocation.width-1-2*i, - widget->allocation.height-1-2*i); - - } - -} - -static void -e_completion_view_draw (GtkWidget *widget, GdkRectangle *area) -{ - GtkBin *bin; - GdkRectangle child_area; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (widget)); - g_return_if_fail (area != NULL); - - if (GTK_WIDGET_DRAWABLE (widget)) { - bin = GTK_BIN (widget); - - e_completion_view_paint (widget, area); - - if (bin->child && gtk_widget_intersect (bin->child, area, &child_area)) - gtk_widget_draw (bin->child, &child_area); - } -} - -static gint -e_completion_view_expose_event (GtkWidget *widget, GdkEventExpose *event) -{ - GtkBin *bin; - GdkEventExpose child_event; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_COMPLETION_VIEW (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (GTK_WIDGET_DRAWABLE (widget)) { - bin = GTK_BIN (widget); - - e_completion_view_paint (widget, &event->area); - - child_event = *event; - if (bin->child && - GTK_WIDGET_NO_WINDOW (bin->child) && - gtk_widget_intersect (bin->child, &event->area, &child_event.area)) - gtk_widget_event (bin->child, (GdkEvent*) &child_event); - } - - return FALSE; -} - -static void -e_completion_view_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - GtkBin *bin; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (widget)); - g_return_if_fail (requisition != NULL); - - bin = GTK_BIN (widget); - - requisition->width = 2 * E_COMPLETION_VIEW (widget)->border_width; - requisition->height = 2 * E_COMPLETION_VIEW (widget)->border_width; - - if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { - GtkRequisition child_requisition; - - gtk_widget_size_request (bin->child, &child_requisition); - - requisition->width += child_requisition.width; - requisition->height += child_requisition.height; - } -} - -static void -e_completion_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - GtkBin *bin; - GtkAllocation child_allocation; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (widget)); - g_return_if_fail (allocation != NULL); - - bin = GTK_BIN (widget); - widget->allocation = *allocation; - - child_allocation.x = E_COMPLETION_VIEW (widget)->border_width; - child_allocation.width = MAX(0, (gint)allocation->width - child_allocation.x * 2); - - child_allocation.y = E_COMPLETION_VIEW (widget)->border_width; - child_allocation.height = MAX (0, (gint)allocation->height - child_allocation.y * 2); - - if (GTK_WIDGET_REALIZED (widget)) { - gdk_window_move_resize (widget->window, - allocation->x, - allocation->y, - allocation->width, - allocation->height); - } - - if (bin->child) { - gtk_widget_size_allocate (bin->child, &child_allocation); - } -} - -GtkType -e_completion_view_get_type (void) -{ - static GtkType completion_view_type = 0; - - if (!completion_view_type) { - GtkTypeInfo completion_view_info = { - "ECompletionView", - sizeof (ECompletionView), - sizeof (ECompletionViewClass), - (GtkClassInitFunc) e_completion_view_class_init, - (GtkObjectInitFunc) e_completion_view_init, - NULL, NULL, /* reserved */ - (GtkClassInitFunc) NULL - }; - - completion_view_type = gtk_type_unique (gtk_event_box_get_type (), &completion_view_info); - } - - return completion_view_type; -} - -static void -e_completion_view_class_init (ECompletionViewClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - parent_class = GTK_OBJECT_CLASS (gtk_type_class (gtk_event_box_get_type ())); - - e_completion_view_signals[E_COMPLETION_VIEW_NONEMPTY] = - gtk_signal_new ("nonempty", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionViewClass, nonempty), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_completion_view_signals[E_COMPLETION_VIEW_ADDED] = - gtk_signal_new ("added", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionViewClass, added), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_completion_view_signals[E_COMPLETION_VIEW_FULL] = - gtk_signal_new ("full", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionViewClass, full), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_completion_view_signals[E_COMPLETION_VIEW_BROWSE] = - gtk_signal_new ("browse", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionViewClass, browse), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - e_completion_view_signals[E_COMPLETION_VIEW_UNBROWSE] = - gtk_signal_new ("unbrowse", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionViewClass, unbrowse), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_completion_view_signals[E_COMPLETION_VIEW_ACTIVATE] = - gtk_signal_new ("activate", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionViewClass, activate), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - E_OBJECT_CLASS_ADD_SIGNALS (object_class, e_completion_view_signals, E_COMPLETION_VIEW_LAST_SIGNAL); - - object_class->destroy = e_completion_view_destroy; - - widget_class->key_press_event = e_completion_view_local_key_press_handler; - widget_class->draw = e_completion_view_draw; - widget_class->expose_event = e_completion_view_expose_event; - widget_class->size_request = e_completion_view_size_request; - widget_class->size_allocate = e_completion_view_size_allocate; -} - -static void -e_completion_view_init (ECompletionView *completion) -{ - completion->border_width = 2; - completion->choices = g_ptr_array_new (); -} - -static void -e_completion_view_destroy (GtkObject *object) -{ - ECompletionView *cv = E_COMPLETION_VIEW (object); - - e_completion_view_disconnect (cv); - e_completion_view_clear_choices (cv); - - g_ptr_array_free (cv->choices, TRUE); - - if (cv->key_widget) { - gtk_signal_disconnect (GTK_OBJECT (cv->key_widget), cv->key_signal_id); - gtk_object_unref (GTK_OBJECT (cv->key_widget)); - } - - if (cv->completion) - gtk_object_unref (GTK_OBJECT (cv->completion)); - - - if (parent_class->destroy) - (parent_class->destroy) (object); -} - -static void -e_completion_view_disconnect (ECompletionView *cv) -{ - g_return_if_fail (cv != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (cv)); - - if (cv->begin_signal_id) - gtk_signal_disconnect (GTK_OBJECT (cv->completion), cv->begin_signal_id); - if (cv->comp_signal_id) - gtk_signal_disconnect (GTK_OBJECT (cv->completion), cv->comp_signal_id); - if (cv->restart_signal_id) - gtk_signal_disconnect (GTK_OBJECT (cv->completion), cv->restart_signal_id); - if (cv->cancel_signal_id) - gtk_signal_disconnect (GTK_OBJECT (cv->completion), cv->cancel_signal_id); - if (cv->end_signal_id) - gtk_signal_disconnect (GTK_OBJECT (cv->completion), cv->end_signal_id); - if (cv->clear_signal_id) - gtk_signal_disconnect (GTK_OBJECT (cv->completion), cv->clear_signal_id); - if (cv->lost_signal_id) - gtk_signal_disconnect (GTK_OBJECT (cv->completion), cv->lost_signal_id); - - cv->begin_signal_id = 0; - cv->comp_signal_id = 0; - cv->restart_signal_id = 0; - cv->end_signal_id = 0; - cv->clear_signal_id = 0; - cv->lost_signal_id = 0; -} - -static ETable * -e_completion_view_table (ECompletionView *cv) -{ - return e_table_scrolled_get_table (E_TABLE_SCROLLED (cv->table)); -} - -static void -e_completion_view_clear_choices (ECompletionView *cv) -{ - ECompletionMatch *match; - GPtrArray *m; - int i; - - g_return_if_fail (E_IS_COMPLETION_VIEW (cv)); - - m = cv->choices; - for (i = 0; i < m->len; i++) { - match = g_ptr_array_index (m, i); - e_completion_match_unref (match); - } - g_ptr_array_set_size (m, 0); -} - -static void -e_completion_view_set_cursor_row (ECompletionView *cv, gint r) -{ - ETable *table; - GtkAdjustment *adj; - gint x, y1, y2, r1, r2, c; - double fracline; - gint iteration_count=0; - - g_return_if_fail (cv != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (cv)); -#ifndef G_DISABLE_CHECKS - /* choices->len is unsigned, but it is reasonable for r to be - * < 0 */ - if (r > 0) { - g_return_if_fail (r < cv->choices->len); - } -#endif - - adj = e_scroll_frame_get_vadjustment (E_SCROLL_FRAME (cv->table)); - - table = e_completion_view_table (cv); - - if (r < 0) { - e_selection_model_clear (E_SELECTION_MODEL(table->selection)); - - /* Move back to the top when we clear the selection */ - gtk_adjustment_set_value (adj, adj->lower); - return; - } - - e_table_set_cursor_row (table, r); - - /* OK, now the tricky bit. We try to insure that this row is - visible. */ - - /* If we are selecting the first or last row, then it is easy. We just - cram the vadjustment all the way up/down. */ - if (r == 0) { - gtk_adjustment_set_value (adj, adj->lower); - return; - } else if (r == cv->choices->len - 1) { - gtk_adjustment_set_value (adj, adj->upper - adj->page_size); - return; - } - - fracline = ((adj->upper - adj->lower - adj->page_size) / (gint)cv->choices->len) / 4; - - while (iteration_count < 100) { - x = GTK_LAYOUT(table->table_canvas)->hadjustment->value; - y1 = GTK_LAYOUT(table->table_canvas)->vadjustment->value; - - y2 = y1 + cv->table->allocation.height; - - e_table_group_compute_location (e_completion_view_table (cv)->group, &x, &y1, &r1, &c); - e_table_group_compute_location (e_completion_view_table (cv)->group, &x, &y2, &r2, &c); - - if (r <= r1) { - gtk_adjustment_set_value (adj, adj->value - fracline); - } else if (r >= r2) { - gtk_adjustment_set_value (adj, adj->value + fracline); - } else - return; - - ++iteration_count; - } - - g_assert_not_reached (); -} - -static void -e_completion_view_select (ECompletionView *cv, gint r) -{ - ECompletionMatch *match; - - match = g_ptr_array_index (cv->choices, r); - - cv->selection = r; - e_completion_view_set_cursor_row (cv, r); - gtk_signal_emit (GTK_OBJECT (cv), e_completion_view_signals[E_COMPLETION_VIEW_ACTIVATE], match); -} - -static gint -e_completion_view_key_press_handler (GtkWidget *w, GdkEventKey *key_event, gpointer user_data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (user_data); - gint dir = 0; - gboolean key_handled = TRUE, complete_key = FALSE, uncomplete_key = FALSE; - - /* FIXME: This is totally lame. - The ECompletionView should be able to specify multiple completion/uncompletion keys, or just - have sensible defaults. */ - - if ((cv->complete_key && key_event->keyval == cv->complete_key) - || ((key_event->keyval == GDK_n || key_event->keyval == GDK_N) && (key_event->state & GDK_CONTROL_MASK))) - complete_key = TRUE; - - if ((cv->uncomplete_key && key_event->keyval == cv->uncomplete_key) - || ((key_event->keyval == GDK_p || key_event->keyval == GDK_P) && (key_event->state & GDK_CONTROL_MASK))) - uncomplete_key = TRUE; - - /* Start up a completion.*/ - if (complete_key && !cv->editable) { - gtk_signal_emit (GTK_OBJECT (cv), e_completion_view_signals[E_COMPLETION_VIEW_BROWSE], NULL); - goto stop_emission; - } - - /* Stop our completion. */ - if (uncomplete_key && cv->editable && cv->selection < 0) { - e_completion_view_set_cursor_row (cv, -1); - gtk_signal_emit (GTK_OBJECT (cv), e_completion_view_signals[E_COMPLETION_VIEW_UNBROWSE]); - goto stop_emission; - } - - if (!cv->editable) - return FALSE; - - switch (key_event->keyval) { - - case GDK_n: - case GDK_N: - /* We (heart) emacs: treat ctrl-n as down */ - if (! (key_event->state & GDK_CONTROL_MASK)) - return FALSE; - - case GDK_Down: - case GDK_KP_Down: - dir = 1; - break; - - case GDK_p: - case GDK_P: - /* Treat ctrl-p as up */ - if (! (key_event->state & GDK_CONTROL_MASK)) - return FALSE; - - case GDK_Up: - case GDK_KP_Up: - dir = -1; - break; - - case GDK_Tab: - /* Unbrowse, unhandled. */ - cv->selection = -1; - dir = 0; - key_handled = FALSE; - break; - - case GDK_Return: - case GDK_KP_Enter: - case GDK_space: - case GDK_KP_Space: - /* Only handle these key presses if we have an active selection; - otherwise, pass them on. */ - if (cv->selection >= 0) { - e_completion_view_select (cv, cv->selection); - goto stop_emission; - } - return FALSE; - - case GDK_Escape: - /* Unbrowse hack */ - cv->selection = -1; - dir = 0; - break; - - default: - return FALSE; - } - - cv->selection += dir; - - if (cv->selection >= (int)cv->choices->len) { - cv->selection = cv->choices->len - 1; - /* Don't re-emit the browse signal */ - goto stop_emission; - } - - e_completion_view_set_cursor_row (cv, cv->selection); - - if (cv->selection >= 0) - gtk_signal_emit (GTK_OBJECT (cv), e_completion_view_signals[E_COMPLETION_VIEW_BROWSE], - g_ptr_array_index (cv->choices, cv->selection)); - else - gtk_signal_emit (GTK_OBJECT (cv), e_completion_view_signals[E_COMPLETION_VIEW_UNBROWSE]); - - stop_emission: - - if (key_handled) - gtk_signal_emit_stop_by_name (GTK_OBJECT (w), "key_press_event"); - - return key_handled; -} - -static void -begin_completion_cb (ECompletion *completion, const gchar *txt, gint pos, gint limit, gpointer user_data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (user_data); - - e_completion_view_clear_choices (cv); - cv->have_all_choices = FALSE; - - e_table_model_changed (cv->model); -} - -static void -restart_completion_cb (ECompletion *completion, gpointer user_data) -{ - /* For now, handle restarts like the beginning of a new completion. */ - begin_completion_cb (completion, NULL, 0, 0, user_data); -} - -static void -cancel_completion_cb (ECompletion *completion, gpointer user_data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (user_data); - - /* On a cancel, clear our choices and issue an "unbrowse" signal. */ - e_completion_view_clear_choices (cv); - cv->have_all_choices = TRUE; - e_completion_view_set_cursor_row (cv, -1); - e_table_model_changed (cv->model); - - gtk_signal_emit (GTK_OBJECT (cv), e_completion_view_signals[E_COMPLETION_VIEW_UNBROWSE]); -} - -static void -completion_cb (ECompletion *completion, ECompletionMatch *match, gpointer user_data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (user_data); - gint r = cv->choices->len; - gboolean first = (cv->choices->len == 0); - - e_completion_match_ref (match); - g_ptr_array_add (cv->choices, match); - - e_table_model_row_inserted (cv->model, r); - - if (first) - gtk_signal_emit (GTK_OBJECT (cv), e_completion_view_signals[E_COMPLETION_VIEW_NONEMPTY]); - - gtk_signal_emit (GTK_OBJECT (cv), e_completion_view_signals[E_COMPLETION_VIEW_ADDED]); -} - -static void -end_completion_cb (ECompletion *completion, gpointer user_data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (user_data); - - /* Do a final refresh of the table. */ - e_table_model_changed (cv->model); - - cv->have_all_choices = TRUE; - gtk_signal_emit (GTK_OBJECT (cv), e_completion_view_signals[E_COMPLETION_VIEW_FULL]); -} - -static void -clear_completion_cb (ECompletion *completion, gpointer user_data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (user_data); - - e_completion_view_clear_choices (cv); - cv->have_all_choices = FALSE; - - e_table_model_changed (cv->model); -} - -static void -lost_completion_cb (ECompletion *completion, ECompletionMatch *match, gpointer user_data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (user_data); - int i; - GPtrArray *c = cv->choices; - - for (i = 0; i < c->len; i++) - if (g_ptr_array_index (c, i) == match) - break; - - g_return_if_fail (i == c->len); - - /* FIXME: do remove_index_fast(), then row_changed and - * row_deleted (if there are more than 1 row still) */ - g_ptr_array_remove_index (c, i); - e_table_model_row_deleted (cv->model, i); - - e_completion_match_unref (match); -} - -/*** Table Callbacks ***/ - -static char *simple_spec = -"<ETableSpecification no-headers=\"true\" draw-grid=\"false\" cursor-mode=\"line\" alternating-row-colors=\"false\">" -" <ETableColumn model_col=\"0\" _title=\"Node\" expansion=\"1.0\" " -" minimum_width=\"16\" resizable=\"true\" cell=\"string\" " -" compare=\"string\"/> " -" <ETableState> " -" <column source=\"0\"/> " -" <grouping></grouping> " -" </ETableState> " -"</ETableSpecification>"; - -static gint -table_col_count (ETableModel *etm, gpointer data) -{ - return 1; -} - -static gint -table_row_count (ETableModel *etm, gpointer data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (data); - return cv->choices->len; -} - -static gboolean -table_is_cell_editable (ETableModel *etm, gint c, gint r, gpointer data) -{ - return FALSE; -} - -static gpointer -table_value_at (ETableModel *etm, gint c, gint r, gpointer data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (data); - ECompletionMatch *match; - - match = g_ptr_array_index (cv->choices, r); - - return (gpointer) e_completion_match_get_menu_text (match); -} - -static gchar * -table_value_to_string (ETableModel *em, gint col, gconstpointer val, gpointer data) -{ - return (gchar *) val; -} - -static void -table_click_cb (ETable *et, gint r, gint c, GdkEvent *ev, gpointer data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (data); - - e_completion_view_select (cv, r); -} - -void -e_completion_view_construct (ECompletionView *cv, ECompletion *completion) -{ - g_return_if_fail (cv != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (cv)); - g_return_if_fail (completion != NULL); - g_return_if_fail (E_IS_COMPLETION (completion)); - - /* Make sure we don't call construct twice. */ - g_return_if_fail (cv->completion == NULL); - - GTK_WIDGET_SET_FLAGS (GTK_WIDGET (cv), GTK_CAN_FOCUS); - - cv->completion = completion; - gtk_object_ref (GTK_OBJECT (completion)); - - cv->begin_signal_id = gtk_signal_connect (GTK_OBJECT (completion), - "begin_completion", - GTK_SIGNAL_FUNC (begin_completion_cb), - cv); - cv->comp_signal_id = gtk_signal_connect (GTK_OBJECT (completion), - "completion", - GTK_SIGNAL_FUNC (completion_cb), - cv); - cv->restart_signal_id = gtk_signal_connect (GTK_OBJECT (completion), - "restart_completion", - GTK_SIGNAL_FUNC (restart_completion_cb), - cv); - cv->cancel_signal_id = gtk_signal_connect (GTK_OBJECT (completion), - "cancel_completion", - GTK_SIGNAL_FUNC (cancel_completion_cb), - cv); - cv->end_signal_id = gtk_signal_connect (GTK_OBJECT (completion), - "end_completion", - GTK_SIGNAL_FUNC (end_completion_cb), - cv); - cv->clear_signal_id = gtk_signal_connect (GTK_OBJECT (completion), - "clear_completion", - GTK_SIGNAL_FUNC (clear_completion_cb), - cv); - cv->lost_signal_id = gtk_signal_connect (GTK_OBJECT (completion), - "lost_completion", - GTK_SIGNAL_FUNC (lost_completion_cb), - cv); - - cv->model = e_table_simple_new (table_col_count, - table_row_count, - NULL, - - table_value_at, - NULL, - table_is_cell_editable, - - NULL, NULL, - - NULL, NULL, NULL, NULL, - table_value_to_string, - cv); - - cv->table = e_table_scrolled_new (cv->model, NULL, simple_spec, NULL); - gtk_object_unref (GTK_OBJECT (cv->model)); - - e_scroll_frame_set_shadow_type (E_SCROLL_FRAME (cv->table), GTK_SHADOW_NONE); - e_scroll_frame_set_scrollbar_spacing (E_SCROLL_FRAME (cv->table), 0); - e_scroll_frame_set_policy (E_SCROLL_FRAME (cv->table), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - - gtk_container_add (GTK_CONTAINER (cv), cv->table); - gtk_widget_show_all (cv->table); - - gtk_signal_connect (GTK_OBJECT (e_completion_view_table (cv)), - "click", - GTK_SIGNAL_FUNC (table_click_cb), - cv); - - cv->selection = -1; -} - -GtkWidget * -e_completion_view_new (ECompletion *completion) -{ - gpointer p; - - g_return_val_if_fail (completion != NULL, NULL); - g_return_val_if_fail (E_IS_COMPLETION (completion), NULL); - - p = gtk_type_new (e_completion_view_get_type ()); - - e_completion_view_construct (E_COMPLETION_VIEW (p), completion); - - return GTK_WIDGET (p); -} - -void -e_completion_view_connect_keys (ECompletionView *cv, GtkWidget *w) -{ - g_return_if_fail (cv != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (cv)); - g_return_if_fail (w == NULL || GTK_IS_WIDGET (w)); - - if (cv->key_widget) { - gtk_signal_disconnect (GTK_OBJECT (cv->key_widget), cv->key_signal_id); - gtk_object_unref (GTK_OBJECT (cv->key_widget)); - } - - if (w) { - cv->key_widget = w; - gtk_object_ref (GTK_OBJECT (w)); - - cv->key_signal_id = gtk_signal_connect (GTK_OBJECT (w), - "key_press_event", - GTK_SIGNAL_FUNC (e_completion_view_key_press_handler), - cv); - } else { - cv->key_widget = NULL; - cv->key_signal_id = 0; - } -} - -void -e_completion_view_set_complete_key (ECompletionView *cv, gint keyval) -{ - g_return_if_fail (cv != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (cv)); - - cv->complete_key = keyval; -} - -void -e_completion_view_set_uncomplete_key (ECompletionView *cv, gint keyval) -{ - g_return_if_fail (cv != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (cv)); - - cv->uncomplete_key = keyval; -} - -void -e_completion_view_set_width (ECompletionView *cv, gint width) -{ - GtkWidget *w; - gint y, r, dummy, line_height, final_height; - double drop_room, lines; - - g_return_if_fail (cv != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (cv)); - g_return_if_fail (width > 0); - - w = GTK_WIDGET (cv); - - if (! GTK_WIDGET_REALIZED (w)) { - gtk_widget_set_usize (w, width, -1); - return; - } - - /* A Horrible Hack(tm) to figure out the height of a single table row */ - - for (line_height=5, r=0; r == 0 && line_height < 1000; line_height += 2) { - dummy = 0; - e_table_group_compute_location (e_completion_view_table (cv)->group, - &dummy, &line_height, &r, &dummy); - } - - if (line_height >= 1000) { - /* Something went wrong, so we make a (possibly very lame) guess */ - line_height = 30; - } - - - gdk_window_get_origin (w->window, NULL, &y); - y += w->allocation.y; - - lines = 5; /* default maximum */ - lines = MIN (lines, cv->choices->len); - - drop_room = (gdk_screen_height () - y) / (double)line_height; - drop_room = MAX (drop_room, 1); - - lines = MIN (lines, drop_room); - - /* We reduce the total height by a bit; in practice, this seems to work out well. */ - final_height = (gint) floor (line_height * (0.5 + (float)lines) * 0.97); - gtk_widget_set_usize (w, width, final_height); -} - -void -e_completion_view_set_editable (ECompletionView *cv, gboolean x) -{ - g_return_if_fail (cv != NULL); - g_return_if_fail (E_IS_COMPLETION_VIEW (cv)); - - if (x == cv->editable) - return; - - cv->editable = x; - cv->selection = -1; - e_completion_view_set_cursor_row (cv, -1); -} - - diff --git a/widgets/text/e-completion-view.h b/widgets/text/e-completion-view.h deleted file mode 100644 index f58050a564..0000000000 --- a/widgets/text/e-completion-view.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-completion-view.h - A text completion selection widget - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Adapted by Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef E_COMPLETION_VIEW_H -#define E_COMPLETION_VIEW_H - -#include <libgnome/gnome-defs.h> -#include <gtk/gtk.h> -#include <gal/e-table/e-table.h> -#include "e-completion.h" - -BEGIN_GNOME_DECLS - -#define E_COMPLETION_VIEW_TYPE (e_completion_view_get_type ()) -#define E_COMPLETION_VIEW(o) (GTK_CHECK_CAST ((o), E_COMPLETION_VIEW_TYPE, ECompletionView)) -#define E_COMPLETION_VIEW_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), E_COMPLETION_VIEW_TYPE, ECompletionViewClass)) -#define E_IS_COMPLETION_VIEW(o) (GTK_CHECK_TYPE ((o), E_COMPLETION_VIEW_TYPE)) -#define E_IS_COMPLETION_VIEW_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_COMPLETION_VIEW_TYPE)) - -typedef struct _ECompletionView ECompletionView; -typedef struct _ECompletionViewClass ECompletionViewClass; - -struct _ECompletionView { - GtkEventBox parent; - - ETableModel *model; - GtkWidget *table; - - GPtrArray *choices; - - ECompletion *completion; - guint begin_signal_id; - guint comp_signal_id; - guint restart_signal_id; - guint cancel_signal_id; - guint end_signal_id; - guint clear_signal_id; - guint lost_signal_id; - - GtkWidget *key_widget; - guint key_signal_id; - - gint complete_key; - gint uncomplete_key; - - gboolean have_all_choices; - - gboolean editable; - gint selection; - - gint border_width; -}; - -struct _ECompletionViewClass { - GtkEventBoxClass parent_class; - - /* Signals */ - void (*nonempty) (ECompletionView *cv); - void (*added) (ECompletionView *cv); - void (*full) (ECompletionView *cv); - void (*browse) (ECompletionView *cv, ECompletionMatch *match); - void (*unbrowse) (ECompletionView *cv); - void (*activate) (ECompletionView *cv, ECompletionMatch *match); -}; - -GtkType e_completion_view_get_type (void); - -void e_completion_view_construct (ECompletionView *cv, ECompletion *completion); -GtkWidget *e_completion_view_new (ECompletion *completion); - -void e_completion_view_connect_keys (ECompletionView *cv, GtkWidget *w); - -void e_completion_view_set_complete_key (ECompletionView *cv, gint keyval); -void e_completion_view_set_uncomplete_key (ECompletionView *cv, gint keyval); - -void e_completion_view_set_width (ECompletionView *cv, gint width); -void e_completion_view_set_editable (ECompletionView *cv, gboolean); - -END_GNOME_DECLS - - -#endif /* E_COMPLETION_H */ diff --git a/widgets/text/e-completion.c b/widgets/text/e-completion.c deleted file mode 100644 index 975bc9e112..0000000000 --- a/widgets/text/e-completion.c +++ /dev/null @@ -1,644 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-completion.c - A base class for text completion. - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Adapted by Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> -#include <string.h> -#include <stdio.h> -#include <gtk/gtk.h> -#include "e-completion.h" -#include "gal/util/e-util.h" - -enum { - E_COMPLETION_REQUEST_COMPLETION, - E_COMPLETION_BEGIN_COMPLETION, - E_COMPLETION_COMPLETION, - E_COMPLETION_RESTART_COMPLETION, - E_COMPLETION_CANCEL_COMPLETION, - E_COMPLETION_END_COMPLETION, - E_COMPLETION_CLEAR_COMPLETION, - E_COMPLETION_LOST_COMPLETION, - E_COMPLETION_LAST_SIGNAL -}; - -static guint e_completion_signals[E_COMPLETION_LAST_SIGNAL] = { 0 }; - -struct _ECompletionPrivate { - gboolean searching; - gboolean done_search; - gboolean refining; - gchar *search_text; - GPtrArray *matches; - gint match_count; - gint pos; - gint limit; - double min_score, max_score; - gint refinement_count; - GList *search_stack; -}; - -typedef struct { - gchar *text; - gint pos; -} ECompletionSearch; - -static void e_completion_class_init (ECompletionClass *klass); -static void e_completion_init (ECompletion *complete); -static void e_completion_destroy (GtkObject *object); - -static void e_completion_add_match (ECompletion *complete, ECompletionMatch *); -static void e_completion_clear_search_stack (ECompletion *complete); -static void e_completion_clear_matches (ECompletion *complete); -static gboolean e_completion_sort (ECompletion *complete); -static void e_completion_restart (ECompletion *complete); - -static GtkObjectClass *parent_class; - - - -GtkType -e_completion_get_type (void) -{ - static GtkType complete_type = 0; - - if (!complete_type) { - GtkTypeInfo complete_info = { - "ECompletion", - sizeof (ECompletion), - sizeof (ECompletionClass), - (GtkClassInitFunc) e_completion_class_init, - (GtkObjectInitFunc) e_completion_init, - NULL, NULL, /* reserved */ - (GtkClassInitFunc) NULL - }; - - complete_type = gtk_type_unique (gtk_object_get_type (), &complete_info); - } - - return complete_type; -} - -static void -e_completion_class_init (ECompletionClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - parent_class = GTK_OBJECT_CLASS (gtk_type_class (gtk_object_get_type ())); - - e_completion_signals[E_COMPLETION_REQUEST_COMPLETION] = - gtk_signal_new ("request_completion", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionClass, request_completion), - gtk_marshal_NONE__POINTER_INT_INT, - GTK_TYPE_NONE, 3, - GTK_TYPE_POINTER, GTK_TYPE_INT, GTK_TYPE_INT); - - e_completion_signals[E_COMPLETION_BEGIN_COMPLETION] = - gtk_signal_new ("begin_completion", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionClass, begin_completion), - gtk_marshal_NONE__POINTER_INT_INT, - GTK_TYPE_NONE, 3, - GTK_TYPE_POINTER, GTK_TYPE_INT, GTK_TYPE_INT); - - e_completion_signals[E_COMPLETION_COMPLETION] = - gtk_signal_new ("completion", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionClass, completion), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - e_completion_signals[E_COMPLETION_RESTART_COMPLETION] = - gtk_signal_new ("restart_completion", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionClass, restart_completion), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_completion_signals[E_COMPLETION_CANCEL_COMPLETION] = - gtk_signal_new ("cancel_completion", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionClass, cancel_completion), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_completion_signals[E_COMPLETION_END_COMPLETION] = - gtk_signal_new ("end_completion", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionClass, end_completion), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_completion_signals[E_COMPLETION_CLEAR_COMPLETION] = - gtk_signal_new ("clear_completion", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionClass, clear_completion), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_completion_signals[E_COMPLETION_LOST_COMPLETION] = - gtk_signal_new ("lost_completion", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ECompletionClass, lost_completion), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - - E_OBJECT_CLASS_ADD_SIGNALS (object_class, e_completion_signals, E_COMPLETION_LAST_SIGNAL); - - object_class->destroy = e_completion_destroy; -} - -static void -e_completion_init (ECompletion *complete) -{ - complete->priv = g_new0 (struct _ECompletionPrivate, 1); - complete->priv->matches = g_ptr_array_new (); -} - -static void -e_completion_destroy (GtkObject *object) -{ - ECompletion *complete = E_COMPLETION (object); - - g_free (complete->priv->search_text); - complete->priv->search_text = NULL; - - e_completion_clear_matches (complete); - e_completion_clear_search_stack (complete); - - g_ptr_array_free (complete->priv->matches, TRUE); - complete->priv->matches = NULL; - - g_free (complete->priv); - complete->priv = NULL; - - if (parent_class->destroy) - (parent_class->destroy) (object); -} - -static void -e_completion_add_match (ECompletion *complete, ECompletionMatch *match) -{ - g_return_if_fail (complete && E_IS_COMPLETION (complete)); - g_return_if_fail (match != NULL); - - g_ptr_array_add (complete->priv->matches, match); - - if (complete->priv->matches->len == 1) { - - complete->priv->min_score = complete->priv->max_score = match->score; - - } else { - - complete->priv->min_score = MIN (complete->priv->min_score, match->score); - complete->priv->max_score = MAX (complete->priv->max_score, match->score); - - } -} - -static void -e_completion_clear_matches (ECompletion *complete) -{ - ECompletionMatch *match; - GPtrArray *m; - int i; - - g_return_if_fail (E_IS_COMPLETION (complete)); - - m = complete->priv->matches; - for (i = 0; i < m->len; i++) { - match = g_ptr_array_index (m, i); - e_completion_match_unref (match); - } - g_ptr_array_set_size (m, 0); - - complete->priv->min_score = 0; - complete->priv->max_score = 0; -} - -void -e_completion_clear (ECompletion *complete) -{ - g_return_if_fail (E_IS_COMPLETION (complete)); - - /* FIXME: do we really want _clear and _clear_matches() ? */ - - /* I think yes, because it is convenient to be able to clear our match cache - without emitting a "clear_completion" signal. -JT */ - - e_completion_clear_matches (complete); - e_completion_clear_search_stack (complete); - complete->priv->refinement_count = 0; - complete->priv->match_count = 0; - gtk_signal_emit (GTK_OBJECT (complete), e_completion_signals[E_COMPLETION_CLEAR_COMPLETION]); -} - -static void -e_completion_push_search (ECompletion *complete, const gchar *text, gint pos) -{ - ECompletionSearch *search; - - g_return_if_fail (E_IS_COMPLETION (complete)); - - search = g_new (ECompletionSearch, 1); - search->text = complete->priv->search_text; - search->pos = complete->priv->pos; - complete->priv->search_stack = g_list_prepend (complete->priv->search_stack, search); - - complete->priv->search_text = g_strdup (text); - complete->priv->pos = pos; -} - -static void -e_completion_pop_search (ECompletion *complete) -{ - ECompletionSearch *search; - GList *old_link = complete->priv->search_stack; - - g_return_if_fail (E_IS_COMPLETION (complete)); - g_return_if_fail (complete->priv->search_stack != NULL); - - g_free (complete->priv->search_text); - - search = complete->priv->search_stack->data; - complete->priv->search_text = search->text; - complete->priv->pos = search->pos; - - g_free (search); - complete->priv->search_stack = g_list_remove_link (complete->priv->search_stack, - complete->priv->search_stack); - g_list_free_1 (old_link); -} - -static void -e_completion_clear_search_stack (ECompletion *complete) -{ - GList *iter; - - g_return_if_fail (E_IS_COMPLETION (complete)); - - for (iter = complete->priv->search_stack; iter != NULL; iter = g_list_next (iter)) { - ECompletionSearch *search = iter->data; - g_free (search->text); - g_free (search); - } - g_list_free (complete->priv->search_stack); - complete->priv->search_stack = NULL; -} - -static void -e_completion_refine_search (ECompletion *comp, const gchar *text, gint pos, ECompletionRefineFn refine_fn) -{ - GPtrArray *m; - gint i; - - comp->priv->refining = TRUE; - - e_completion_push_search (comp, text, pos); - - gtk_signal_emit (GTK_OBJECT (comp), e_completion_signals[E_COMPLETION_BEGIN_COMPLETION], text, pos, comp->priv->limit); - - comp->priv->match_count = 0; - - comp->priv->searching = TRUE; - - m = comp->priv->matches; - for (i = 0; i < m->len; ++i) { - ECompletionMatch *match = g_ptr_array_index (m, i); - if (comp->priv->refinement_count == match->hit_count - && refine_fn (comp, match, text, pos)) { - ++match->hit_count; - gtk_signal_emit (GTK_OBJECT (comp), e_completion_signals[E_COMPLETION_COMPLETION], match); - ++comp->priv->match_count; - } - } - - ++comp->priv->refinement_count; - - gtk_signal_emit (GTK_OBJECT (comp), e_completion_signals[E_COMPLETION_END_COMPLETION]); - - comp->priv->searching = FALSE; - comp->priv->refining = FALSE; -} - -static void -e_completion_unrefine_search (ECompletion *comp) -{ - GPtrArray *m; - gint i; - - comp->priv->refining = TRUE; - - e_completion_pop_search (comp); - - gtk_signal_emit (GTK_OBJECT (comp), e_completion_signals[E_COMPLETION_BEGIN_COMPLETION], comp->priv->search_text, comp->priv->pos, comp->priv->limit); - - comp->priv->match_count = 0; - --comp->priv->refinement_count; - - comp->priv->searching = TRUE; - - m = comp->priv->matches; - for (i = 0; i < m->len; ++i) { - ECompletionMatch *match = g_ptr_array_index (m, i); - if (comp->priv->refinement_count <= match->hit_count) { - match->hit_count = comp->priv->refinement_count; - gtk_signal_emit (GTK_OBJECT (comp), e_completion_signals[E_COMPLETION_COMPLETION], match); - ++comp->priv->match_count; - } - } - - gtk_signal_emit (GTK_OBJECT (comp), e_completion_signals[E_COMPLETION_END_COMPLETION]); - - comp->priv->searching = FALSE; - comp->priv->refining = FALSE; -} - -void -e_completion_begin_search (ECompletion *complete, const gchar *text, gint pos, gint limit) -{ - ECompletionClass *klass; - ECompletionRefineFn refine_fn; - - g_return_if_fail (complete != NULL); - g_return_if_fail (E_IS_COMPLETION (complete)); - g_return_if_fail (text != NULL); - - klass = E_COMPLETION_CLASS (GTK_OBJECT (complete)->klass); - - if (!complete->priv->searching && complete->priv->done_search) { - - /* If the search we are requesting is the same as what we had before our last refinement, - treat the request as an unrefine. */ - if (complete->priv->search_stack != NULL) { - ECompletionSearch *search = complete->priv->search_stack->data; - if ((klass->ignore_pos_on_auto_unrefine || search->pos == pos) - && !strcmp (search->text, text)) { - e_completion_unrefine_search (complete); - return; - } - } - - if (klass->auto_refine - && (refine_fn = klass->auto_refine (complete, - complete->priv->search_text, complete->priv->pos, - text, pos))) { - e_completion_refine_search (complete, text, pos, refine_fn); - return; - } - - } - - /* Stop any prior search. */ - if (complete->priv->searching) - e_completion_cancel_search (complete); - - e_completion_clear_search_stack (complete); - - g_free (complete->priv->search_text); - complete->priv->search_text = g_strdup (text); - - complete->priv->pos = pos; - complete->priv->searching = TRUE; - complete->priv->done_search = FALSE; - - e_completion_clear_matches (complete); - - complete->priv->limit = limit > 0 ? limit : G_MAXINT; - complete->priv->refinement_count = 0; - - gtk_signal_emit (GTK_OBJECT (complete), e_completion_signals[E_COMPLETION_BEGIN_COMPLETION], text, pos, limit); - gtk_signal_emit (GTK_OBJECT (complete), e_completion_signals[E_COMPLETION_REQUEST_COMPLETION], text, pos, limit); -} - -void -e_completion_cancel_search (ECompletion *complete) -{ - g_return_if_fail (complete != NULL); - g_return_if_fail (E_IS_COMPLETION (complete)); - - /* If there is no search to cancel, just silently return. */ - if (!complete->priv->searching) - return; - - gtk_signal_emit (GTK_OBJECT (complete), e_completion_signals[E_COMPLETION_CANCEL_COMPLETION]); - - complete->priv->searching = FALSE; -} - -gboolean -e_completion_searching (ECompletion *complete) -{ - g_return_val_if_fail (complete != NULL, FALSE); - g_return_val_if_fail (E_IS_COMPLETION (complete), FALSE); - - return complete->priv->searching; -} - -gboolean -e_completion_refining (ECompletion *complete) -{ - g_return_val_if_fail (complete != NULL, FALSE); - g_return_val_if_fail (E_IS_COMPLETION (complete), FALSE); - - return complete->priv->refining; -} - -const gchar * -e_completion_search_text (ECompletion *complete) -{ - g_return_val_if_fail (complete != NULL, NULL); - g_return_val_if_fail (E_IS_COMPLETION (complete), NULL); - - return complete->priv->search_text; -} - -gint -e_completion_search_text_pos (ECompletion *complete) -{ - g_return_val_if_fail (complete != NULL, -1); - g_return_val_if_fail (E_IS_COMPLETION (complete), -1); - - return complete->priv->pos; -} - -gint -e_completion_match_count (ECompletion *complete) -{ - g_return_val_if_fail (complete != NULL, 0); - g_return_val_if_fail (E_IS_COMPLETION (complete), 0); - - return complete->priv->refinement_count > 0 ? complete->priv->match_count : complete->priv->matches->len; -} - -void -e_completion_foreach_match (ECompletion *complete, ECompletionMatchFn fn, gpointer closure) -{ - GPtrArray *m; - int i; - - g_return_if_fail (complete != NULL); - g_return_if_fail (E_IS_COMPLETION (complete)); - - if (fn == NULL) - return; - - m = complete->priv->matches; - for (i = 0; i < m->len; i++) { - ECompletionMatch *match = g_ptr_array_index (m, i); - if (match->hit_count == complete->priv->refinement_count) { - fn (match, closure); - } - } -} - -ECompletion * -e_completion_new (void) -{ - return E_COMPLETION (gtk_type_new (e_completion_get_type ())); -} - -static gboolean -e_completion_sort (ECompletion *complete) -{ - GPtrArray *m; - int i; - GList *sort_list = NULL, *j; - gboolean diff; - - m = complete->priv->matches; - - for (i = 0; i < m->len; i++) - sort_list = g_list_append (sort_list, - g_ptr_array_index (m, i)); - - sort_list = g_list_sort (sort_list, (GCompareFunc) e_completion_match_compare_alpha); - - diff = FALSE; - - for (i=0, j=sort_list; i < m->len; i++, j = g_list_next (j)) { - if (g_ptr_array_index (m, i) == j->data) - continue; - - diff = TRUE; - g_ptr_array_index (m, i) = j->data; - } - - g_list_free (sort_list); - - return diff; -} - -/* Emit a restart signal and re-declare our matches, up to the limit. */ -static void -e_completion_restart (ECompletion *complete) -{ - GPtrArray *m; - gint i, count; - - gtk_signal_emit (GTK_OBJECT (complete), e_completion_signals[E_COMPLETION_RESTART_COMPLETION]); - - m = complete->priv->matches; - for (i = count = 0; - i < m->len && count < complete->priv->limit; - i++, count++) { - gtk_signal_emit (GTK_OBJECT (complete), - e_completion_signals[E_COMPLETION_COMPLETION], - g_ptr_array_index (m, i)); - } -} - -void -e_completion_found_match (ECompletion *complete, ECompletionMatch *match) -{ - g_return_if_fail (complete); - g_return_if_fail (E_IS_COMPLETION (complete)); - g_return_if_fail (match != NULL); - - if (! complete->priv->searching) { - g_warning ("e_completion_found_match(...,\"%s\",...) called outside of a search", match->match_text); - return; - } - - /* For now, do nothing when we hit the limit --- just don't - * announce the incoming matches. */ - if (complete->priv->matches->len >= complete->priv->limit) { - e_completion_match_unref (match); - return; - } - - e_completion_add_match (complete, match); - - gtk_signal_emit (GTK_OBJECT (complete), e_completion_signals[E_COMPLETION_COMPLETION], match); -} - -/* to optimize this, make the match a hash table */ -void -e_completion_lost_match (ECompletion *complete, ECompletionMatch *match) -{ - gboolean removed; - - g_return_if_fail (E_IS_COMPLETION (complete)); - g_return_if_fail (match != NULL); - - /* FIXME: remove fast */ - removed = g_ptr_array_remove (complete->priv->matches, - match); - - /* maybe just return here? */ - g_return_if_fail (removed); - - gtk_signal_emit (GTK_OBJECT (complete), e_completion_signals[E_COMPLETION_LOST_COMPLETION], match); - - e_completion_match_unref (match); -} - -void -e_completion_end_search (ECompletion *complete) -{ - g_return_if_fail (complete != NULL); - g_return_if_fail (E_IS_COMPLETION (complete)); - g_return_if_fail (complete->priv->searching); - - /* our table model should be sorted by a non-visible column of - * doubles (the score) rather than whatever we are doing - */ - /* If sorting by score accomplishes anything, issue a restart right before we end. */ - if (e_completion_sort (complete)) - e_completion_restart (complete); - - gtk_signal_emit (GTK_OBJECT (complete), e_completion_signals[E_COMPLETION_END_COMPLETION]); - - complete->priv->searching = FALSE; - complete->priv->done_search = TRUE; -} - diff --git a/widgets/text/e-completion.h b/widgets/text/e-completion.h deleted file mode 100644 index 9e7b5ab4b3..0000000000 --- a/widgets/text/e-completion.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-completion.h - A base class for text completion. - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Adapted by Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef E_COMPLETION_H -#define E_COMPLETION_H - -#include <libgnome/gnome-defs.h> -#include <gtk/gtkobject.h> -#include "e-completion-match.h" - -BEGIN_GNOME_DECLS - -#define E_COMPLETION_TYPE (e_completion_get_type ()) -#define E_COMPLETION(o) (GTK_CHECK_CAST ((o), E_COMPLETION_TYPE, ECompletion)) -#define E_COMPLETION_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), E_COMPLETION_TYPE, ECompletionClass)) -#define E_IS_COMPLETION(o) (GTK_CHECK_TYPE ((o), E_COMPLETION_TYPE)) -#define E_IS_COMPLETION_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_COMPLETION_TYPE)) - -typedef struct _ECompletion ECompletion; -typedef struct _ECompletionClass ECompletionClass; -struct _ECompletionPrivate; - -typedef gboolean (*ECompletionRefineFn) (ECompletion *, ECompletionMatch *, const gchar *search_text, gint pos); - -struct _ECompletion { - GtkObject parent; - - struct _ECompletionPrivate *priv; -}; - -struct _ECompletionClass { - GtkObjectClass parent_class; - - /* virtual functions */ - ECompletionRefineFn (*auto_refine) (ECompletion *comp, - const gchar *old_text, gint old_pos, - const gchar *new_text, gint new_pos); - gboolean ignore_pos_on_auto_unrefine; - - /* Signals */ - void (*request_completion) (ECompletion *comp, const gchar *search_text, gint pos, gint limit); - - void (*begin_completion) (ECompletion *comp, const gchar *search_text, gint pos, gint limit); - void (*restart_completion) (ECompletion *comp); - - void (*completion) (ECompletion *comp, ECompletionMatch *match); - void (*lost_completion) (ECompletion *comp, ECompletionMatch *match); - - void (*cancel_completion) (ECompletion *comp); - void (*end_completion) (ECompletion *comp); - void (*clear_completion) (ECompletion *comp); -}; - -GtkType e_completion_get_type (void); - -void e_completion_begin_search (ECompletion *comp, const gchar *text, gint pos, gint limit); -void e_completion_cancel_search (ECompletion *comp); - -gboolean e_completion_searching (ECompletion *comp); -gboolean e_completion_refining (ECompletion *comp); -const gchar *e_completion_search_text (ECompletion *comp); -gint e_completion_search_text_pos (ECompletion *comp); -gint e_completion_match_count (ECompletion *comp); -void e_completion_foreach_match (ECompletion *comp, ECompletionMatchFn fn, gpointer user_data); - -ECompletion *e_completion_new (void); - - - -/* These functions should only be called by derived classes or search callbacks, - or very bad things might happen. */ - -void e_completion_found_match (ECompletion *comp, ECompletionMatch *); -void e_completion_lost_match (ECompletion *comp, ECompletionMatch *); -void e_completion_clear (ECompletion *comp); -void e_completion_end_search (ECompletion *comp); - -END_GNOME_DECLS - - -#endif /* E_COMPLETION_H */ - diff --git a/widgets/text/e-entry-test.c b/widgets/text/e-entry-test.c deleted file mode 100644 index 94f490113b..0000000000 --- a/widgets/text/e-entry-test.c +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-entry-test.c - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include "config.h" - -#include <gnome.h> -#include "e-entry.h" - -static void destroy_callback(GtkWidget *app, gpointer data) -{ - exit(0); -} - -#if 0 -static void about_callback( GtkWidget *widget, gpointer data ) -{ - - const gchar *authors[] = - { - "Christopher James Lahey <clahey@umich.edu>", - NULL - }; - - GtkWidget *about = - gnome_about_new ( _( "Minicard Test" ), VERSION, - _( "Copyright (C) 2000, Helix Code, Inc." ), - authors, - _( "This should test the minicard canvas item" ), - NULL); - gtk_widget_show (about); -} -#endif - -int main( int argc, char *argv[] ) -{ - GtkWidget *app; - GtkWidget *entry; - - /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE);*/ - - gnome_init( "EEntry Test", VERSION, argc, argv); - app = gnome_app_new("EEntry Test", NULL); - - entry = e_entry_new(); - gtk_object_set(GTK_OBJECT(entry), - "editable", TRUE, - "use_ellipsis", TRUE, - NULL); - gnome_app_set_contents( GNOME_APP( app ), entry ); - - /* Connect the signals */ - gtk_signal_connect( GTK_OBJECT( app ), "destroy", - GTK_SIGNAL_FUNC( destroy_callback ), - ( gpointer ) app ); - - gtk_widget_show_all( app ); - - gtk_main(); - - /* Not reached. */ - return 0; -} diff --git a/widgets/text/e-entry.c b/widgets/text/e-entry.c deleted file mode 100644 index 6301672124..0000000000 --- a/widgets/text/e-entry.c +++ /dev/null @@ -1,1350 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-entry.c - An EText-based entry widget - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif -#include <stdio.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include <libgnomeui/gnome-canvas.h> -#include "gal/util/e-util.h" -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-canvas-utils.h" -#include "e-completion-view.h" -#include "e-text.h" -#include "e-entry.h" - -#define MOVE_RIGHT_AND_UP 0 - -#define EVIL_POINTER_WARPING_HACK - -#ifdef EVIL_POINTER_WARPING_HACK -#include <gdk/gdkx.h> -#endif - -#define MIN_ENTRY_WIDTH 150 - -#define d(x) - -#define PARENT_TYPE gtk_table_get_type () - -static GtkObjectClass *parent_class; - -enum { - E_ENTRY_CHANGED, - E_ENTRY_ACTIVATE, - E_ENTRY_POPUP, - E_ENTRY_COMPLETION_POPUP, - E_ENTRY_LAST_SIGNAL -}; - -static guint e_entry_signals[E_ENTRY_LAST_SIGNAL] = { 0 }; - -/* Object argument IDs */ -enum { - ARG_0, - ARG_MODEL, - ARG_EVENT_PROCESSOR, - ARG_TEXT, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_LINE_WRAP, - ARG_BREAK_CHARACTERS, - ARG_MAX_LINES, - ARG_ALLOW_NEWLINES, - ARG_DRAW_BORDERS, - ARG_DRAW_BACKGROUND, - ARG_DRAW_BUTTON, - ARG_EMULATE_LABEL_RESIZE, - ARG_CURSOR_POS, -}; - -typedef struct _EEntryPrivate EEntryPrivate; -struct _EEntryPrivate { - GtkJustification justification; - - guint changed_proxy_tag; - guint activate_proxy_tag; - guint popup_proxy_tag; - /* Data related to completions */ - ECompletion *completion; - EEntryCompletionHandler handler; - GtkWidget *completion_view; - guint nonempty_signal_id; - guint added_signal_id; - guint full_signal_id; - guint browse_signal_id; - guint unbrowse_signal_id; - guint activate_signal_id; - GtkWidget *completion_view_popup; - gboolean popup_is_visible; - gchar *pre_browse_text; - gint completion_delay; - guint completion_delay_tag; - gboolean ptr_grab; - gboolean changed_since_keypress; - guint changed_since_keypress_tag; - gint last_completion_pos; - - guint draw_borders : 1; - guint emulate_label_resize : 1; - guint have_set_transient : 1; - gint last_width; -}; - -static gboolean e_entry_is_empty (EEntry *entry); -static void e_entry_show_popup (EEntry *entry, gboolean x); -static void e_entry_start_completion (EEntry *entry); -static void e_entry_start_delayed_completion (EEntry *entry, gint delay); -static void e_entry_cancel_delayed_completion (EEntry *entry); - -static void -canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, - EEntry *entry) -{ - gnome_canvas_set_scroll_region (entry->canvas, - 0, 0, alloc->width, alloc->height); - gtk_object_set (GTK_OBJECT (entry->item), - "clip_width", (double) (alloc->width), - "clip_height", (double) (alloc->height), - NULL); - - switch (entry->priv->justification) { - case GTK_JUSTIFY_RIGHT: - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->item), - alloc->width, 0); - break; - case GTK_JUSTIFY_CENTER: - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->item), - alloc->width / 2, 0); - break; - default: - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->item), - 0, 0); - break; - } -} - -static void -canvas_size_request (GtkWidget *widget, GtkRequisition *requisition, - EEntry *entry) -{ - int xthick, ythick; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNOME_IS_CANVAS (widget)); - g_return_if_fail (requisition != NULL); - - if (entry->priv->draw_borders) { - xthick = 2 * widget->style->klass->xthickness; - ythick = 2 * widget->style->klass->ythickness; - } else { - xthick = ythick = 0; - } - - if (entry->priv->emulate_label_resize) { - gdouble width; - gtk_object_get (GTK_OBJECT (entry->item), - "text_width", &width, - NULL); - requisition->width = 2 + xthick + width; - } else { - requisition->width = 2 + MIN_ENTRY_WIDTH + xthick; - } - if (entry->priv->last_width != requisition->width) - gtk_widget_queue_resize (widget); - entry->priv->last_width = requisition->width; - - d(g_print("%s: width = %d\n", __FUNCTION__, requisition->width)); - - requisition->height = (2 + widget->style->font->ascent + - widget->style->font->descent + - ythick); -} - -static gint -canvas_focus_in_event (GtkWidget *widget, GdkEventFocus *focus, EEntry *entry) -{ - if (entry->canvas->focused_item != GNOME_CANVAS_ITEM(entry->item)) - gnome_canvas_item_grab_focus(GNOME_CANVAS_ITEM(entry->item)); - - return FALSE; -} - -static void -e_entry_text_keypress (EText *text, guint keyval, guint state, EEntry *entry) -{ - if (entry->priv->changed_since_keypress_tag) { - gtk_timeout_remove (entry->priv->changed_since_keypress_tag); - entry->priv->changed_since_keypress_tag = 0; - } - - if (entry->priv->changed_since_keypress - || (entry->priv->popup_is_visible && e_entry_get_position (entry) != entry->priv->last_completion_pos)) { - if (e_entry_is_empty (entry)) { - e_entry_cancel_delayed_completion (entry); - e_entry_show_popup (entry, FALSE); - } else if (entry->priv->completion_delay >= 0) { - int delay; - delay = entry->priv->popup_is_visible - ? 1 - : entry->priv->completion_delay; - e_entry_start_delayed_completion (entry, delay); - } - } - entry->priv->changed_since_keypress = FALSE; -} - -static gint -changed_since_keypress_timeout_fn (gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - entry->priv->changed_since_keypress = FALSE; - entry->priv->changed_since_keypress_tag = 0; - return FALSE; -} - -static void -e_entry_proxy_changed (EText *text, EEntry *entry) -{ - if (entry->priv->changed_since_keypress_tag) - gtk_timeout_remove (entry->priv->changed_since_keypress_tag); - entry->priv->changed_since_keypress = TRUE; - entry->priv->changed_since_keypress_tag = gtk_timeout_add (20, changed_since_keypress_timeout_fn, entry); - - gtk_signal_emit (GTK_OBJECT (entry), e_entry_signals [E_ENTRY_CHANGED]); -} - -static void -e_entry_proxy_activate (EText *text, EEntry *entry) -{ - gtk_signal_emit (GTK_OBJECT (entry), e_entry_signals [E_ENTRY_ACTIVATE]); -} - -static void -e_entry_proxy_popup (EText *text, GdkEventButton *ev, gint pos, EEntry *entry) -{ - gtk_signal_emit (GTK_OBJECT (entry), e_entry_signals [E_ENTRY_POPUP], ev, pos); -} - -static void -e_entry_init (GtkObject *object) -{ - EEntry *entry = E_ENTRY (object); - GtkTable *gtk_table = GTK_TABLE (object); - - entry->priv = g_new0 (EEntryPrivate, 1); - - entry->priv->emulate_label_resize = FALSE; - - entry->canvas = GNOME_CANVAS (e_canvas_new ()); - - gtk_signal_connect (GTK_OBJECT (entry->canvas), - "size_allocate", - GTK_SIGNAL_FUNC (canvas_size_allocate), - entry); - - gtk_signal_connect (GTK_OBJECT (entry->canvas), - "size_request", - GTK_SIGNAL_FUNC (canvas_size_request), - entry); - - gtk_signal_connect(GTK_OBJECT (entry->canvas), - "focus_in_event", - GTK_SIGNAL_FUNC(canvas_focus_in_event), - entry); - - entry->priv->draw_borders = TRUE; - entry->priv->last_width = -1; - - entry->item = E_TEXT(gnome_canvas_item_new( - gnome_canvas_root (entry->canvas), - e_text_get_type(), - "clip", TRUE, - "fill_clip_rectangle", TRUE, - "anchor", GTK_ANCHOR_NW, - "draw_borders", TRUE, - "draw_background", TRUE, - "draw_button", FALSE, - "max_lines", 1, - "editable", TRUE, - "allow_newlines", FALSE, - NULL)); - - gtk_signal_connect (GTK_OBJECT (entry->item), - "keypress", - GTK_SIGNAL_FUNC (e_entry_text_keypress), - entry); - - entry->priv->justification = GTK_JUSTIFY_LEFT; - gtk_table_attach (gtk_table, GTK_WIDGET (entry->canvas), - 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_widget_show (GTK_WIDGET (entry->canvas)); - - /* - * Proxy functions: we proxy the changed and activate signals - * from the item to ourselves - */ - entry->priv->changed_proxy_tag = gtk_signal_connect ( - GTK_OBJECT (entry->item), - "changed", - GTK_SIGNAL_FUNC (e_entry_proxy_changed), - entry); - entry->priv->activate_proxy_tag = gtk_signal_connect ( - GTK_OBJECT (entry->item), - "activate", - GTK_SIGNAL_FUNC (e_entry_proxy_activate), - entry); - entry->priv->popup_proxy_tag = gtk_signal_connect ( - GTK_OBJECT (entry->item), - "popup", - GTK_SIGNAL_FUNC (e_entry_proxy_popup), - entry); - - entry->priv->completion_delay = 1; -} - -/** - * e_entry_construct - * - * Constructs the given EEntry. - * - **/ -void -e_entry_construct (EEntry *entry) -{ - /* Do nothing */ -} - - -/** - * e_entry_new - * - * Creates a new EEntry. - * - * Returns: The new EEntry - **/ -GtkWidget * -e_entry_new (void) -{ - EEntry *entry; - entry = gtk_type_new (e_entry_get_type ()); - e_entry_construct (entry); - - return GTK_WIDGET (entry); -} - -const gchar * -e_entry_get_text (EEntry *entry) -{ - g_return_val_if_fail (entry != NULL && E_IS_ENTRY (entry), NULL); - - return e_text_model_get_text (entry->item->model); -} - -void -e_entry_set_text (EEntry *entry, const gchar *txt) -{ - g_return_if_fail (entry != NULL && E_IS_ENTRY (entry)); - - e_text_model_set_text (entry->item->model, txt); -} - -static void -e_entry_set_text_quiet (EEntry *entry, const gchar *txt) -{ - g_return_if_fail (entry != NULL && E_IS_ENTRY (entry)); - - gtk_signal_handler_block (GTK_OBJECT (entry->item), entry->priv->changed_proxy_tag); - e_entry_set_text (entry, txt); - gtk_signal_handler_unblock (GTK_OBJECT (entry->item), entry->priv->changed_proxy_tag); -} - - -void -e_entry_set_editable (EEntry *entry, gboolean am_i_editable) -{ - g_return_if_fail (entry != NULL && E_IS_ENTRY (entry)); - - gtk_object_set (GTK_OBJECT (entry->item), "editable", am_i_editable, NULL); -} - -gint -e_entry_get_position (EEntry *entry) -{ - g_return_val_if_fail (entry != NULL && E_IS_ENTRY (entry), -1); - - return entry->item->selection_start; -} - -void -e_entry_set_position (EEntry *entry, gint pos) -{ - g_return_if_fail (entry != NULL && E_IS_ENTRY (entry)); - if (pos < 0) - pos = 0; - else if (pos > e_text_model_get_text_length (entry->item->model)) - pos = e_text_model_get_text_length (entry->item->model); - - entry->item->selection_start = entry->item->selection_end = pos; -} - -void -e_entry_select_region (EEntry *entry, gint pos1, gint pos2) -{ - gint len; - - g_return_if_fail (entry != NULL && E_IS_ENTRY (entry)); - - len = e_text_model_get_text_length (entry->item->model); - pos1 = CLAMP (pos1, 0, len); - pos2 = CLAMP (pos2, 0, len); - - entry->item->selection_start = MIN (pos1, pos2); - entry->item->selection_end = MAX (pos1, pos2); -} - -/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ - -/*** Completion-related code ***/ - -static gboolean -e_entry_is_empty (EEntry *entry) -{ - const gchar *txt = e_entry_get_text (entry); - - if (txt == NULL) - return TRUE; - - while (*txt) { - if (!isspace ((gint) *txt)) - return FALSE; - ++txt; - } - - return TRUE; -} - -static void -e_entry_show_popup (EEntry *entry, gboolean visible) -{ - GtkWidget *pop = entry->priv->completion_view_popup; - - if (pop == NULL) - return; - - if (visible) { - GtkAllocation *dim = &(GTK_WIDGET (entry)->allocation); - gint x, y, xo, yo, fudge; - const GdkEventMask grab_mask = (GdkEventMask)GDK_BUTTON_PRESS_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK; - - /* Figure out where to put our popup. */ - gdk_window_get_origin (GTK_WIDGET (entry)->window, &xo, &yo); - x = xo + dim->x; - y = yo + dim->height + dim->y; - -#if MOVE_RIGHT_AND_UP - /* Put our popup slightly to the right and up, to try to give a visual cue that this popup - is tied to this entry. Otherwise one-row popups can sort of "blend" with an entry - directly below. */ - fudge = MAX (dim->height/10, 3); /* just in case we are using a really big font, etc. */ - x += 2*fudge; - y -= fudge; -#else - fudge = 1; - y -= fudge; -#endif - gtk_widget_set_uposition (pop, x, y); - e_completion_view_set_width (E_COMPLETION_VIEW (entry->priv->completion_view), dim->width); - -#ifdef EVIL_POINTER_WARPING_HACK - /* - I should have learned by now to listen to Havoc... - http://developer.gnome.org/doc/GGAD/faqs.html - */ - - if (! entry->priv->popup_is_visible) { - GdkWindow *gwin = GTK_WIDGET (entry)->window; - gint xx, yy; - gdk_window_get_pointer (gwin, &xx, &yy, NULL); - xx += xo; - yy += yo; - - /* If we are inside the "zone of death" where the popup will appear, warp the pointer to safety. - This is a horrible thing to do. */ - if (y <= yy && yy < yy + dim->height && x <= xx && xx < xx + dim->width) { - XWarpPointer (GDK_WINDOW_XDISPLAY (gwin), None, GDK_WINDOW_XWINDOW (gwin), - 0, 0, 0, 0, - xx - xo, (y-1) - yo); - } - } -#endif - - gtk_widget_show (pop); - - - if (getenv ("GAL_E_ENTRY_NO_GRABS_HACK") == NULL && !entry->priv->ptr_grab) { - entry->priv->ptr_grab = (0 == gdk_pointer_grab (GTK_WIDGET (entry->priv->completion_view)->window, TRUE, - grab_mask, NULL, NULL, GDK_CURRENT_TIME)); - if (entry->priv->ptr_grab) { - gtk_grab_add (GTK_WIDGET (entry->priv->completion_view)); - } - } - - - } else { - - gtk_widget_hide (pop); - - if (entry->priv->ptr_grab) { - gdk_pointer_ungrab (GDK_CURRENT_TIME); - gtk_grab_remove (GTK_WIDGET (entry->priv->completion_view)); - } - - entry->priv->ptr_grab = FALSE; - - entry->priv->last_completion_pos = -1; - } - - e_completion_view_set_editable (E_COMPLETION_VIEW (entry->priv->completion_view), visible); - - if (entry->priv->popup_is_visible != visible) { - entry->priv->popup_is_visible = visible; - gtk_signal_emit (GTK_OBJECT (entry), e_entry_signals[E_ENTRY_COMPLETION_POPUP], (gint) visible); - } -} - -static void -e_entry_refresh_popup (EEntry *entry) -{ - if (entry->priv->popup_is_visible) - e_entry_show_popup (entry, TRUE); -} - -static void -e_entry_start_completion (EEntry *entry) -{ - if (entry->priv->completion == NULL) - return; - - e_entry_cancel_delayed_completion (entry); - - if (e_entry_is_empty (entry)) - return; - - e_completion_begin_search (entry->priv->completion, - e_entry_get_text (entry), - entry->priv->last_completion_pos = e_entry_get_position (entry), - 0); /* No limit. Probably a bad idea. */ -} - -static gboolean -start_delayed_cb (gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - entry->priv->completion_delay_tag = 0; - e_entry_start_completion (entry); - return FALSE; -} - -static void -e_entry_start_delayed_completion (EEntry *entry, gint delay) -{ - if (delay < 0) - return; - - e_entry_cancel_delayed_completion (entry); - entry->priv->completion_delay_tag = gtk_timeout_add (MAX (delay, 1), start_delayed_cb, entry); -} - -static void -e_entry_cancel_delayed_completion (EEntry *entry) -{ - if (entry->priv->completion == NULL) - return; - - if (entry->priv->completion_delay_tag) { - gtk_timeout_remove (entry->priv->completion_delay_tag); - entry->priv->completion_delay_tag = 0; - } -} - -static void -nonempty_cb (ECompletionView *view, gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - - e_entry_show_popup (entry, TRUE); -} - -static void -added_cb (ECompletionView *view, gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - e_entry_refresh_popup (entry); -} - -static void -full_cb (ECompletionView *view, gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - gboolean show; - - show = GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (entry->canvas)) && view->choices->len > 0; - e_entry_show_popup (entry, show); -} - -static void -browse_cb (ECompletionView *view, ECompletionMatch *match, gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - - if (match == NULL) { - /* Requesting a completion. */ - e_entry_start_completion (entry); - return; - } - - if (entry->priv->pre_browse_text == NULL) - entry->priv->pre_browse_text = g_strdup (e_entry_get_text (entry)); - - /* If there is no other handler in place, echo the selected completion in - the entry. */ - if (entry->priv->handler == NULL) - e_entry_set_text_quiet (entry, e_completion_match_get_match_text (match)); -} - -static void -unbrowse_cb (ECompletionView *view, gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - - if (entry->priv->pre_browse_text) { - - if (entry->priv->handler == NULL) - e_entry_set_text_quiet (entry, entry->priv->pre_browse_text); - - g_free (entry->priv->pre_browse_text); - entry->priv->pre_browse_text = NULL; - } - - e_entry_show_popup (entry, FALSE); -} - -static void -activate_cb (ECompletionView *view, ECompletionMatch *match, gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - - e_entry_cancel_delayed_completion (entry); - - g_free (entry->priv->pre_browse_text); - entry->priv->pre_browse_text = NULL; - e_entry_show_popup (entry, FALSE); - - if (entry->priv->handler) - entry->priv->handler (entry, match); - else - e_entry_set_text (entry, match->match_text); - - e_entry_cancel_delayed_completion (entry); -} - -void -e_entry_enable_completion (EEntry *entry, ECompletion *completion) -{ - g_return_if_fail (entry != NULL && E_IS_ENTRY (entry)); - g_return_if_fail (completion != NULL && E_IS_COMPLETION (completion)); - - e_entry_enable_completion_full (entry, completion, -1, NULL); -} - -static void -button_press_cb (GtkWidget *w, GdkEvent *ev, gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - GtkWidget *child; - - /* Bail out if our click happened inside of our widget. */ - child = gtk_get_event_widget (ev); - if (child != w) { - while (child) { - if (child == w) - return; - child = child->parent; - } - } - - /* Treat this as an unbrowse */ - unbrowse_cb (E_COMPLETION_VIEW (w), entry); -} - -static void -cancel_completion_cb (ETextModel *model, gpointer user_data) -{ - EEntry *entry = E_ENTRY (user_data); - - /* If we get the signal from the underlying text model, unbrowse. - This usually means that the text model itself has done some - sort of completion, or has otherwise transformed its contents - in some way that would render any previous completion invalid. */ - unbrowse_cb (E_COMPLETION_VIEW (entry->priv->completion_view), entry); -} - -static gint -key_press_cb (GtkWidget *w, GdkEventKey *ev, gpointer user_data) -{ - gint rv = 0; - /* Forward signal */ - gtk_signal_emit_by_name (GTK_OBJECT (user_data), "key_press_event", ev, &rv); - return rv; -} - -static gint -key_release_cb (GtkWidget *w, GdkEventKey *ev, gpointer user_data) -{ - gint rv = 0; - /* Forward signal */ - gtk_signal_emit_by_name (GTK_OBJECT (user_data), "key_release_event", ev, &rv); - return rv; -} - -static void -e_entry_make_completion_window_transient (EEntry *entry) -{ - GtkWidget *w; - - if (entry->priv->have_set_transient || entry->priv->completion_view_popup == NULL) - return; - - w = GTK_WIDGET (entry)->parent; - while (w && ! GTK_IS_WINDOW (w)) - w = w->parent; - - if (w) { - gtk_window_set_transient_for (GTK_WINDOW (entry->priv->completion_view_popup), - GTK_WINDOW (w)); - entry->priv->have_set_transient = 1; - } -} - -void -e_entry_enable_completion_full (EEntry *entry, ECompletion *completion, gint delay, EEntryCompletionHandler handler) -{ - g_return_if_fail (entry != NULL && E_IS_ENTRY (entry)); - g_return_if_fail (completion != NULL && E_IS_COMPLETION (completion)); - - /* For now, completion can't be changed mid-stream. */ - g_return_if_fail (entry->priv->completion == NULL); - - entry->priv->completion = completion; - gtk_object_ref (GTK_OBJECT (completion)); - gtk_object_sink (GTK_OBJECT (completion)); - - entry->priv->completion_delay = delay; - entry->priv->handler = handler; - - entry->priv->completion_view = e_completion_view_new (completion); - /* Make the up and down keys enable and disable completions. */ - e_completion_view_set_complete_key (E_COMPLETION_VIEW (entry->priv->completion_view), GDK_Down); - e_completion_view_set_uncomplete_key (E_COMPLETION_VIEW (entry->priv->completion_view), GDK_Up); - - gtk_signal_connect_after (GTK_OBJECT (entry->priv->completion_view), - "button_press_event", - GTK_SIGNAL_FUNC (button_press_cb), - entry); - - entry->priv->nonempty_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view), - "nonempty", - GTK_SIGNAL_FUNC (nonempty_cb), - entry); - - entry->priv->added_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view), - "added", - GTK_SIGNAL_FUNC (added_cb), - entry); - - entry->priv->full_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view), - "full", - GTK_SIGNAL_FUNC (full_cb), - entry); - - entry->priv->browse_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view), - "browse", - GTK_SIGNAL_FUNC (browse_cb), - entry); - - entry->priv->unbrowse_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view), - "unbrowse", - GTK_SIGNAL_FUNC (unbrowse_cb), - entry); - - entry->priv->activate_signal_id = gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view), - "activate", - GTK_SIGNAL_FUNC (activate_cb), - entry); - - entry->priv->completion_view_popup = gtk_window_new (GTK_WINDOW_POPUP); - - e_entry_make_completion_window_transient (entry); - - gtk_signal_connect (GTK_OBJECT (entry->item->model), - "cancel_completion", - GTK_SIGNAL_FUNC (cancel_completion_cb), - entry); - - gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view_popup), - "key_press_event", - GTK_SIGNAL_FUNC (key_press_cb), - entry->canvas); - gtk_signal_connect (GTK_OBJECT (entry->priv->completion_view_popup), - "key_release_event", - GTK_SIGNAL_FUNC (key_release_cb), - entry->canvas); - - e_completion_view_connect_keys (E_COMPLETION_VIEW (entry->priv->completion_view), - GTK_WIDGET (entry->canvas)); - - gtk_object_ref (GTK_OBJECT (entry->priv->completion_view_popup)); - gtk_object_sink (GTK_OBJECT (entry->priv->completion_view_popup)); - gtk_window_set_policy (GTK_WINDOW (entry->priv->completion_view_popup), TRUE, TRUE, TRUE); - gtk_container_add (GTK_CONTAINER (entry->priv->completion_view_popup), entry->priv->completion_view); - gtk_widget_show (entry->priv->completion_view); -} - -gboolean -e_entry_completion_popup_is_visible (EEntry *entry) -{ - g_return_val_if_fail (E_IS_ENTRY (entry), FALSE); - - return entry->priv->popup_is_visible; -} - -/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ - -static void -et_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - EEntry *entry = E_ENTRY (o); - GtkObject *item = GTK_OBJECT (entry->item); - - switch (arg_id){ - case ARG_MODEL: - gtk_object_get(item, - "model", >K_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_EVENT_PROCESSOR: - gtk_object_get(item, - "event_processor", >K_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_TEXT: - gtk_object_get(item, - "text", >K_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FONT_GDK: - gtk_object_get(item, - "font_gdk", >K_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_JUSTIFICATION: - gtk_object_get(item, - "justification", >K_VALUE_ENUM (*arg), - NULL); - break; - - case ARG_FILL_COLOR_GDK: - gtk_object_get(item, - "fill_color_gdk", >K_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_FILL_COLOR_RGBA: - gtk_object_get(item, - "fill_color_rgba", >K_VALUE_UINT (*arg), - NULL); - break; - - case ARG_FILL_STIPPLE: - gtk_object_get(item, - "fill_stiple", >K_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_EDITABLE: - gtk_object_get(item, - "editable", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_USE_ELLIPSIS: - gtk_object_get(item, - "use_ellipsis", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_ELLIPSIS: - gtk_object_get(item, - "ellipsis", >K_VALUE_STRING (*arg), - NULL); - break; - - case ARG_LINE_WRAP: - gtk_object_get(item, - "line_wrap", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_BREAK_CHARACTERS: - gtk_object_get(item, - "break_characters", >K_VALUE_STRING (*arg), - NULL); - break; - - case ARG_MAX_LINES: - gtk_object_get(item, - "max_lines", >K_VALUE_INT (*arg), - NULL); - break; - case ARG_ALLOW_NEWLINES: - gtk_object_get(item, - "allow_newlines", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_DRAW_BORDERS: - GTK_VALUE_BOOL (*arg) = entry->priv->draw_borders; - break; - - case ARG_DRAW_BACKGROUND: - gtk_object_get (item, - "draw_background", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_DRAW_BUTTON: - gtk_object_get (item, - "draw_button", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_EMULATE_LABEL_RESIZE: - GTK_VALUE_BOOL (*arg) = entry->priv->emulate_label_resize; - break; - - case ARG_CURSOR_POS: - gtk_object_get (item, - "cursor_pos", >K_VALUE_INT (*arg), - NULL); - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -et_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - EEntry *entry = E_ENTRY (o); - GtkObject *item = GTK_OBJECT (entry->item); - GtkAnchorType anchor; - double width, height; - gint xthick; - gint ythick; - GtkWidget *widget = GTK_WIDGET(entry->canvas); - - d(g_print("%s: arg_id: %d\n", __FUNCTION__, arg_id)); - - switch (arg_id){ - case ARG_MODEL: - gtk_object_set(item, - "model", GTK_VALUE_OBJECT (*arg), - NULL); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_EVENT_PROCESSOR: - gtk_object_set(item, - "event_processor", GTK_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_TEXT: - gtk_object_set(item, - "text", GTK_VALUE_STRING (*arg), - NULL); - d(g_print("%s: text: %s\n", __FUNCTION__, GTK_VALUE_STRING (*arg))); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_FONT: - gtk_object_set(item, - "font", GTK_VALUE_STRING (*arg), - NULL); - d(g_print("%s: font: %s\n", __FUNCTION__, GTK_VALUE_STRING (*arg))); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_FONTSET: - gtk_object_set(item, - "fontset", GTK_VALUE_STRING (*arg), - NULL); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_FONT_GDK: - gtk_object_set(item, - "font_gdk", GTK_VALUE_BOXED (*arg), - NULL); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_JUSTIFICATION: - entry->priv->justification = GTK_VALUE_ENUM (*arg); - gtk_object_get(item, - "clip_width", &width, - "clip_height", &height, - NULL); - - if (entry->priv->draw_borders) { - xthick = 0; - ythick = 0; - } else { - xthick = widget->style->klass->xthickness; - ythick = widget->style->klass->ythickness; - } - - switch (entry->priv->justification) { - case GTK_JUSTIFY_CENTER: - anchor = GTK_ANCHOR_N; - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->item), width / 2, ythick); - break; - case GTK_JUSTIFY_RIGHT: - anchor = GTK_ANCHOR_NE; - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->item), width - xthick, ythick); - break; - default: - anchor = GTK_ANCHOR_NW; - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(entry->item), xthick, ythick); - break; - } - gtk_object_set(item, - "justification", entry->priv->justification, - "anchor", anchor, - NULL); - break; - - case ARG_FILL_COLOR: - gtk_object_set(item, - "fill_color", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FILL_COLOR_GDK: - gtk_object_set(item, - "fill_color_gdk", GTK_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_FILL_COLOR_RGBA: - gtk_object_set(item, - "fill_color_rgba", GTK_VALUE_UINT (*arg), - NULL); - break; - - case ARG_FILL_STIPPLE: - gtk_object_set(item, - "fill_stiple", GTK_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_EDITABLE: - gtk_object_set(item, - "editable", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_USE_ELLIPSIS: - gtk_object_set(item, - "use_ellipsis", GTK_VALUE_BOOL (*arg), - NULL); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_ELLIPSIS: - gtk_object_set(item, - "ellipsis", GTK_VALUE_STRING (*arg), - NULL); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_LINE_WRAP: - gtk_object_set(item, - "line_wrap", GTK_VALUE_BOOL (*arg), - NULL); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_BREAK_CHARACTERS: - gtk_object_set(item, - "break_characters", GTK_VALUE_STRING (*arg), - NULL); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_MAX_LINES: - gtk_object_set(item, - "max_lines", GTK_VALUE_INT (*arg), - NULL); - if (entry->priv->emulate_label_resize) - gtk_widget_queue_resize (widget); - break; - - case ARG_ALLOW_NEWLINES: - gtk_object_set(item, - "allow_newlines", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_DRAW_BORDERS: - if (entry->priv->draw_borders != GTK_VALUE_BOOL (*arg)) { - entry->priv->draw_borders = GTK_VALUE_BOOL (*arg); - gtk_object_set (item, - "draw_borders", entry->priv->draw_borders, - NULL); - gtk_widget_queue_resize (GTK_WIDGET (entry)); - } - break; - - case ARG_CURSOR_POS: - gtk_object_set (item, - "cursor_pos", GTK_VALUE_INT (*arg), NULL); - break; - - case ARG_DRAW_BACKGROUND: - gtk_object_set (item, "draw_background", - GTK_VALUE_BOOL (*arg), NULL); - break; - - case ARG_DRAW_BUTTON: - gtk_object_set (item, "draw_button", - GTK_VALUE_BOOL (*arg), NULL); - break; - - case ARG_EMULATE_LABEL_RESIZE: - if (entry->priv->emulate_label_resize != GTK_VALUE_BOOL (*arg)) { - entry->priv->emulate_label_resize = GTK_VALUE_BOOL (*arg); - gtk_widget_queue_resize (widget); - } - break; - } -} - -static void -e_entry_destroy (GtkObject *object) -{ - EEntry *entry = E_ENTRY (object); - - if (entry->priv->completion_delay_tag) - gtk_timeout_remove (entry->priv->completion_delay_tag); - - if (entry->priv->completion) - gtk_object_unref (GTK_OBJECT (entry->priv->completion)); - if (entry->priv->completion_view_popup) { - gtk_widget_destroy (GTK_WIDGET (entry->priv->completion_view_popup)); - gtk_object_unref (GTK_OBJECT (entry->priv->completion_view_popup)); - } - g_free (entry->priv->pre_browse_text); - - if (entry->priv->changed_since_keypress_tag) - gtk_timeout_remove (entry->priv->changed_since_keypress_tag); - - if (entry->priv->ptr_grab) - gdk_pointer_ungrab (GDK_CURRENT_TIME); - - g_free (entry->priv); - entry->priv = NULL; - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -e_entry_realize (GtkWidget *widget) -{ - EEntry *entry; - - if (GTK_WIDGET_CLASS (parent_class)->realize) - (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); - - entry = E_ENTRY (widget); - - e_entry_make_completion_window_transient (entry); - - if (entry->priv->emulate_label_resize) { - d(g_print("%s: queue_resize\n", __FUNCTION__)); - gtk_widget_queue_resize (GTK_WIDGET (entry->canvas)); - } -} - -static void -e_entry_class_init (GtkObjectClass *object_class) -{ - EEntryClass *klass = E_ENTRY_CLASS(object_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(object_class); - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->set_arg = et_set_arg; - object_class->get_arg = et_get_arg; - object_class->destroy = e_entry_destroy; - - widget_class->realize = e_entry_realize; - - klass->changed = NULL; - klass->activate = NULL; - - e_entry_signals[E_ENTRY_CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (EEntryClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_entry_signals[E_ENTRY_ACTIVATE] = - gtk_signal_new ("activate", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (EEntryClass, activate), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_entry_signals[E_ENTRY_POPUP] = - gtk_signal_new ("popup", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (EEntryClass, popup), - gtk_marshal_NONE__POINTER_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_INT); - - e_entry_signals[E_ENTRY_COMPLETION_POPUP] = - gtk_signal_new ("completion_popup", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (EEntryClass, completion_popup), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - - E_OBJECT_CLASS_ADD_SIGNALS (object_class, e_entry_signals, E_ENTRY_LAST_SIGNAL); - - gtk_object_add_arg_type ("EEntry::model", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("EEntry::event_processor", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_EVENT_PROCESSOR); - gtk_object_add_arg_type ("EEntry::text", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); - gtk_object_add_arg_type ("EEntry::font", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT); - gtk_object_add_arg_type ("EEntry::fontset", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET); - gtk_object_add_arg_type ("EEntry::font_gdk", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT_GDK); - gtk_object_add_arg_type ("EEntry::justification", - GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION); - gtk_object_add_arg_type ("EEntry::fill_color", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("EEntry::fill_color_gdk", - GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK); - gtk_object_add_arg_type ("EEntry::fill_color_rgba", - GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA); - gtk_object_add_arg_type ("EEntry::fill_stipple", - GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE); - gtk_object_add_arg_type ("EEntry::editable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE); - gtk_object_add_arg_type ("EEntry::use_ellipsis", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS); - gtk_object_add_arg_type ("EEntry::ellipsis", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); - gtk_object_add_arg_type ("EEntry::line_wrap", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP); - gtk_object_add_arg_type ("EEntry::break_characters", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_BREAK_CHARACTERS); - gtk_object_add_arg_type ("EEntry::max_lines", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); - gtk_object_add_arg_type ("EEntry::allow_newlines", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_ALLOW_NEWLINES); - gtk_object_add_arg_type ("EEntry::draw_borders", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BORDERS); - gtk_object_add_arg_type ("EEntry::draw_background", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BACKGROUND); - gtk_object_add_arg_type ("EEntry::draw_button", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BUTTON); - gtk_object_add_arg_type ("EEntry::emulate_label_resize", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EMULATE_LABEL_RESIZE); - gtk_object_add_arg_type ("EEntry::cursor_pos", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_CURSOR_POS); -} - -E_MAKE_TYPE(e_entry, "EEntry", EEntry, e_entry_class_init, e_entry_init, PARENT_TYPE); diff --git a/widgets/text/e-entry.h b/widgets/text/e-entry.h deleted file mode 100644 index cba4d784be..0000000000 --- a/widgets/text/e-entry.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-entry.h - An EText-based entry widget - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef _E_ENTRY_H_ -#define _E_ENTRY_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtktable.h> -#include <gnome-xml/tree.h> -#include <gal/e-text/e-text.h> -#include "e-completion.h" - - -BEGIN_GNOME_DECLS - -#define E_ENTRY_TYPE (e_entry_get_type ()) -#define E_ENTRY(o) (GTK_CHECK_CAST ((o), E_ENTRY_TYPE, EEntry)) -#define E_ENTRY_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_ENTRY_TYPE, EEntryClass)) -#define E_IS_ENTRY(o) (GTK_CHECK_TYPE ((o), E_ENTRY_TYPE)) -#define E_IS_ENTRY_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_ENTRY_TYPE)) - -typedef struct _EEntry EEntry; -typedef struct _EEntryClass EEntryClass; -struct _EEntryPrivate; - -typedef void (*EEntryCompletionHandler) (EEntry *entry, ECompletionMatch *match); - -struct _EEntry { - GtkTable parent; - - GnomeCanvas *canvas; - EText *item; - - struct _EEntryPrivate *priv; -}; - -struct _EEntryClass { - GtkTableClass parent_class; - - void (* changed) (EEntry *entry); - void (* activate) (EEntry *entry); - void (* popup) (EEntry *entry, GdkEventButton *ev, gint pos); - void (* completion_popup) (EEntry *entry, gint visible); -}; - -GtkType e_entry_get_type (void); - -void e_entry_construct (EEntry *entry); -GtkWidget *e_entry_new (void); - -const gchar *e_entry_get_text (EEntry *entry); -void e_entry_set_text (EEntry *entry, const gchar *text); - -gint e_entry_get_position (EEntry *entry); -void e_entry_set_position (EEntry *entry, gint); -void e_entry_select_region (EEntry *entry, gint start, gint end); - -void e_entry_set_editable (EEntry *entry, gboolean editable); - -void e_entry_enable_completion (EEntry *entry, ECompletion *completion); -void e_entry_enable_completion_full (EEntry *entry, ECompletion *completion, gint autocomplete_delay, - EEntryCompletionHandler handler); -gboolean e_entry_completion_popup_is_visible (EEntry *entry); - -END_GNOME_DECLS - -#endif /* _E_ENTRY_H_ */ diff --git a/widgets/text/e-table-text-model.c b/widgets/text/e-table-text-model.c deleted file mode 100644 index 6b195136f2..0000000000 --- a/widgets/text/e-table-text-model.c +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-text-model.c - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> -#include <ctype.h> -#include <gtk/gtksignal.h> -#include <gal/util/e-util.h> -#include "e-table-text-model.h" - -static void e_table_text_model_class_init (ETableTextModelClass *class); -static void e_table_text_model_init (ETableTextModel *model); -static void e_table_text_model_destroy (GtkObject *object); - -static const gchar *e_table_text_model_get_text (ETextModel *model); -static void e_table_text_model_set_text (ETextModel *model, const gchar *text); -static void e_table_text_model_insert (ETextModel *model, gint postion, const gchar *text); -static void e_table_text_model_insert_length (ETextModel *model, gint postion, const gchar *text, gint length); -static void e_table_text_model_delete (ETextModel *model, gint postion, gint length); - -static GtkObject *parent_class; - - - -/** - * e_table_text_model_get_type: - * @void: - * - * Registers the &ETableTextModel class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ETableTextModel class. - **/ -GtkType -e_table_text_model_get_type (void) -{ - static GtkType model_type = 0; - - if (!model_type) { - GtkTypeInfo model_info = { - "ETableTextModel", - sizeof (ETableTextModel), - sizeof (ETableTextModelClass), - (GtkClassInitFunc) e_table_text_model_class_init, - (GtkObjectInitFunc) e_table_text_model_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_type = gtk_type_unique (e_text_model_get_type (), &model_info); - } - - return model_type; -} - -/* Class initialization function for the text item */ -static void -e_table_text_model_class_init (ETableTextModelClass *klass) -{ - GtkObjectClass *object_class; - ETextModelClass *model_class; - - object_class = (GtkObjectClass *) klass; - model_class = (ETextModelClass *) klass; - - parent_class = gtk_type_class (e_text_model_get_type ()); - - model_class->get_text = e_table_text_model_get_text; - model_class->set_text = e_table_text_model_set_text; - model_class->insert = e_table_text_model_insert; - model_class->insert_length = e_table_text_model_insert_length; - model_class->delete = e_table_text_model_delete; - - object_class->destroy = e_table_text_model_destroy; -} - -/* Object initialization function for the text item */ -static void -e_table_text_model_init (ETableTextModel *model) -{ - model->model = NULL; - model->row = 0; - model->model_col = 0; - model->cell_changed_signal_id = 0; - model->row_changed_signal_id = 0; -} - -/* Destroy handler for the text item */ -static void -e_table_text_model_destroy (GtkObject *object) -{ - ETableTextModel *model; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TABLE_TEXT_MODEL (object)); - - model = E_TABLE_TEXT_MODEL (object); - - if (model->model) - g_assert (GTK_IS_OBJECT (model->model)); - - if (model->cell_changed_signal_id) - gtk_signal_disconnect (GTK_OBJECT(model->model), - model->cell_changed_signal_id); - - if (model->row_changed_signal_id) - gtk_signal_disconnect (GTK_OBJECT(model->model), - model->row_changed_signal_id); - - if (model->model) - gtk_object_unref (GTK_OBJECT(model->model)); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} -static const gchar * -e_table_text_model_get_text (ETextModel *text_model) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model) - return (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - else - return ""; -} - -static void -e_table_text_model_set_text (ETextModel *text_model, const gchar *text) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model) - e_table_model_set_value_at (model->model, model->model_col, model->row, (void *) text); -} - -static void -e_table_text_model_insert (ETextModel *text_model, gint position, const gchar *text) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - /* Can't use g_strdup_printf here because on some - systems printf ("%.*s"); is locale dependent. */ - temp = e_strdup_append_strings (temp, position, - text, -1, - temp + position, -1, - NULL); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -e_table_text_model_insert_length (ETextModel *text_model, gint position, const gchar *text, gint length) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - /* Can't use g_strdup_printf here because on some - systems printf ("%.*s"); is locale dependent. */ - temp = e_strdup_append_strings (temp, position, - text, length, - temp + position, -1, - NULL); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -e_table_text_model_delete (ETextModel *text_model, gint position, gint length) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - /* Can't use g_strdup_printf here because on some - systems printf ("%.*s"); is locale dependent. */ - temp = e_strdup_append_strings (temp, position, - temp + position + length, -1, - NULL); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -cell_changed (ETableModel *table_model, int model_col, int row, ETableTextModel *model) -{ - if (model->model_col == model_col && - model->row == row) - e_text_model_changed (E_TEXT_MODEL(model)); -} - -static void -row_changed (ETableModel *table_model, int row, ETableTextModel *model) -{ - if (model->row == row) - e_text_model_changed (E_TEXT_MODEL(model)); -} - -ETableTextModel * -e_table_text_model_new (ETableModel *table_model, int row, int model_col) -{ - ETableTextModel *model; - - g_return_val_if_fail(table_model != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_MODEL(table_model), NULL); - - model = gtk_type_new (e_table_text_model_get_type ()); - model->model = table_model; - if (model->model){ - gtk_object_ref (GTK_OBJECT(model->model)); - model->cell_changed_signal_id = - gtk_signal_connect (GTK_OBJECT(model->model), - "model_cell_changed", - GTK_SIGNAL_FUNC(cell_changed), - model); - model->row_changed_signal_id = - gtk_signal_connect (GTK_OBJECT(model->model), - "model_row_changed", - GTK_SIGNAL_FUNC(row_changed), - model); - } - model->row = row; - model->model_col = model_col; - return model; -} - diff --git a/widgets/text/e-table-text-model.h b/widgets/text/e-table-text-model.h deleted file mode 100644 index 405c722b36..0000000000 --- a/widgets/text/e-table-text-model.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-text-model.h - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef E_TABLE_TEXT_MODEL_H -#define E_TABLE_TEXT_MODEL_H - -#include <gal/e-text/e-text-model.h> -#include <gal/e-table/e-table-model.h> - - -BEGIN_GNOME_DECLS - -#define E_TYPE_TABLE_TEXT_MODEL (e_table_text_model_get_type ()) -#define E_TABLE_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TABLE_TEXT_MODEL, ETableTextModel)) -#define E_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TABLE_TEXT_MODEL, ETableTextModelClass)) -#define E_IS_TABLE_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TABLE_TEXT_MODEL)) -#define E_IS_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TABLE_TEXT_MODEL)) - -typedef struct _ETableTextModel ETableTextModel; -typedef struct _ETableTextModelClass ETableTextModelClass; - -struct _ETableTextModel { - ETextModel parent; - - ETableModel *model; - int row; - int model_col; - - int cell_changed_signal_id; - int row_changed_signal_id; -}; - -struct _ETableTextModelClass { - ETextModelClass parent_class; - -}; - - -/* Standard Gtk function */ -GtkType e_table_text_model_get_type (void); -ETableTextModel *e_table_text_model_new (ETableModel *table_model, int row, int model_col); - -END_GNOME_DECLS - -#endif diff --git a/widgets/text/e-text-model-repos.c b/widgets/text/e-text-model-repos.c deleted file mode 100644 index 17ffe07578..0000000000 --- a/widgets/text/e-text-model-repos.c +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text-model-repos.c - Standard ETextModelReposFn definitions - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include "e-text-model-repos.h" - -#define MODEL_CLAMP(model, pos) (CLAMP((pos), 0, strlen((model)->text))) - -gint -e_repos_shift (gint pos, gpointer data) -{ - EReposShift *info = (EReposShift *) data; - g_return_val_if_fail (data, -1); - - return e_text_model_validate_position (info->model, pos + info->change); -} - -gint -e_repos_absolute (gint pos, gpointer data) -{ - EReposAbsolute *info = (EReposAbsolute *) data; - g_return_val_if_fail (data, -1); - - pos = info->pos; - if (pos < 0) { - gint len = e_text_model_get_text_length (info->model); - pos += len + 1; - } - - return e_text_model_validate_position (info->model, pos); -} - -gint -e_repos_insert_shift (gint pos, gpointer data) -{ - EReposInsertShift *info = (EReposInsertShift *) data; - g_return_val_if_fail (data, -1); - - if (pos >= info->pos) - pos += info->len; - - return e_text_model_validate_position (info->model, pos); -} - -gint -e_repos_delete_shift (gint pos, gpointer data) -{ - EReposDeleteShift *info = (EReposDeleteShift *) data; - g_return_val_if_fail (data, -1); - - if (pos > info->pos + info->len) - pos -= info->len; - else if (pos > info->pos) - pos = info->pos; - - return e_text_model_validate_position (info->model, pos); -} - -gint -e_repos_clamp (gint pos, gpointer data) -{ - ETextModel *model; - - g_return_val_if_fail (data != NULL && E_IS_TEXT_MODEL (data), -1); - model = E_TEXT_MODEL (data); - - return e_text_model_validate_position (model, pos); -} diff --git a/widgets/text/e-text-model-repos.h b/widgets/text/e-text-model-repos.h deleted file mode 100644 index 5f0c93ee6a..0000000000 --- a/widgets/text/e-text-model-repos.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text-model-repos.h - Standard ETextModelReposFn definitions - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef E_TEXT_MODEL_REPOS_H -#define E_TEXT_MODEL_REPOS_H - -#include "e-text-model.h" - -typedef struct { - ETextModel *model; - gint change; /* Relative change to position. */ -} EReposShift; - -gint e_repos_shift (gint pos, gpointer data); - - -typedef struct { - ETextModel *model; - gint pos; /* Position to move to. Negative values count from the end buffer. - (i.e. -1 puts cursor at the end, -2 one character from end, etc.) */ -} EReposAbsolute; - -gint e_repos_absolute (gint pos, gpointer data); - - -typedef struct { - ETextModel *model; - gint pos; /* Location of first inserted character. */ - gint len; /* Number of characters inserted. */ -} EReposInsertShift; - -gint e_repos_insert_shift (gint pos, gpointer data); - - -typedef struct { - ETextModel *model; - gint pos; /* Location of first deleted character. */ - gint len; /* Number of characters deleted. */ -} EReposDeleteShift; - -gint e_repos_delete_shift (gint pos, gpointer data); - - -/* For e_repos_clamp, data is a pointer to an ETextModel. The only repositioning - that occurs is to avoid buffer overruns. */ - -gint e_repos_clamp (gint pos, gpointer data); - -#endif diff --git a/widgets/text/e-text-model-test.c b/widgets/text/e-text-model-test.c deleted file mode 100644 index c364b852c6..0000000000 --- a/widgets/text/e-text-model-test.c +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text-model-test.c - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <gnome.h> -#include <gal/widgets/e-canvas.h> -#include "e-text-model.h" -#include "e-text-model-uri.h" -#include "e-text.h" -#include <gal/util/e-util.h> - -#if 0 -static void -describe_model (ETextModel *model) -{ - gint i, N; - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - N = e_text_model_object_count (model); - - g_print ("text: %s\n", e_text_model_get_text (model)); - g_print ("objs: %d\n", N); - - for (i=0; i<N; ++i) { - gchar *s = e_text_model_strdup_nth_object (model, i); - g_print ("obj%d: %s\n", i, s); - g_free (s); - } -} -#endif - -int -main (int argc, gchar **argv) -{ - GtkWidget *win[2], *canvas[2]; - GnomeCanvasItem *item[2]; - ETextModel *model; - gint i; - - gnome_init ("ETextModelTest", "0.0", argc, argv); - - model = e_text_model_uri_new (); - - e_text_model_set_text (model, "My favorite website is http://www.ximian.com. My next favorite www.assbarn.com."); - - // describe_model (model); - - for (i=0; i<2; ++i) { - win[i] = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - canvas[i] = e_canvas_new (); - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - - item[i] = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas[i])), - e_text_get_type (), - "model", model, - "font", "-adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1", - "anchor", GTK_ANCHOR_NORTH, - "line_wrap", TRUE, - "width", 150.0, - "editable", TRUE, - NULL); - - gtk_container_add (GTK_CONTAINER (win[i]), canvas[i]); - gtk_widget_show_all (win[i]); - } - - gtk_main (); - - return 0; -} diff --git a/widgets/text/e-text-model-uri.c b/widgets/text/e-text-model-uri.c deleted file mode 100644 index 765faa05ca..0000000000 --- a/widgets/text/e-text-model-uri.c +++ /dev/null @@ -1,359 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text-model-uri.c - a text model w/ clickable URIs - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> - -#include "e-text-model-uri.h" - -#include <ctype.h> -#include <sys/types.h> -#include <regex.h> -#include <gtk/gtkmain.h> -#include <libgnome/gnome-url.h> - -static void e_text_model_uri_class_init (ETextModelURIClass *class); -static void e_text_model_uri_init (ETextModelURI *model); -static void e_text_model_uri_destroy (GtkObject *object); - -static void objectify_uris (ETextModelURI *model); - -static void e_text_model_uri_objectify (ETextModel *model); -static gint e_text_model_uri_validate_pos (ETextModel *model, gint pos); -static gint e_text_model_uri_get_obj_count (ETextModel *model); -static const gchar *e_text_model_uri_get_nth_object (ETextModel *model, gint i, gint *len); -static void e_text_model_uri_activate_nth_object (ETextModel *model, gint); - -typedef struct _ObjInfo ObjInfo; -struct _ObjInfo { - gint offset, len; -}; - -static GtkObject *parent_class; - -GtkType -e_text_model_uri_get_type (void) -{ - static GtkType model_uri_type = 0; - - if (!model_uri_type) { - GtkTypeInfo model_uri_info = { - "ETextModelURI", - sizeof (ETextModelURI), - sizeof (ETextModelURIClass), - (GtkClassInitFunc) e_text_model_uri_class_init, - (GtkObjectInitFunc) e_text_model_uri_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_uri_type = gtk_type_unique (e_text_model_get_type (), &model_uri_info); - } - - return model_uri_type; -} - -static void -e_text_model_uri_class_init (ETextModelURIClass *klass) -{ - GtkObjectClass *object_class; - ETextModelClass *model_class; - - object_class = (GtkObjectClass *) klass; - model_class = E_TEXT_MODEL_CLASS (klass); - - parent_class = gtk_type_class (e_text_model_get_type ()); - - object_class->destroy = e_text_model_uri_destroy; - - model_class->object_activated = e_text_model_uri_activate_nth_object; - - model_class->objectify = e_text_model_uri_objectify; - model_class->validate_pos = e_text_model_uri_validate_pos; - model_class->obj_count = e_text_model_uri_get_obj_count; - model_class->get_nth_obj = e_text_model_uri_get_nth_object; - -} - -static void -e_text_model_uri_init (ETextModelURI *model) -{ - -} - -static void -e_text_model_uri_destroy (GtkObject *object) -{ - ETextModelURI *model_uri = E_TEXT_MODEL_URI (object); - GList *iter; - - if (model_uri->objectify_idle) { - gtk_idle_remove (model_uri->objectify_idle); - model_uri->objectify_idle = 0; - } - - for (iter = model_uri->uris; iter != NULL; iter = g_list_next (iter)) - g_free (iter->data); - g_list_free (model_uri->uris); - model_uri->uris = NULL; - - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); - -} - -static const gchar *uri_regex[] = { - "(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp))[-A-Za-z0-9\\.]+(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"]", - "(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp))[-A-Za-z0-9\\.]+[-A-Za-z0-9](:[0-9]*)?", - "mailto:[A-Za-z0-9_]+@[-A-Za-z0-9_]+\\.[-A-Za-z0-9\\.]+[-A-Za-z0-9]", - NULL -}; -static gint regex_count = 0; -static regex_t *regex_compiled = NULL; - -static void -regex_init (void) -{ - gint i; - - if (regex_count != 0) - return; - - while (uri_regex[regex_count]) ++regex_count; - - regex_compiled = g_new0 (regex_t, regex_count); - - for (i=0; i<regex_count; ++i) { - if (regcomp (®ex_compiled[i], uri_regex[i], REG_EXTENDED)) - g_error ("Bad regex?: %s", uri_regex[i]); - } -} - - -static void -objectify_uris (ETextModelURI *model_uri) -{ - static gboolean objectifying = FALSE; - - ETextModel *model = E_TEXT_MODEL (model_uri); - const gchar *txt; - GList *iter, *old_uris; - gint offset, len; - gboolean found_match; - regmatch_t match; - gboolean changed; - - if (objectifying) - return; - - objectifying = TRUE; - - if (regex_count == 0) - regex_init (); - - txt = e_text_model_get_text (model); - len = e_text_model_get_text_length (model); - - old_uris = model_uri->uris; - model_uri->uris = NULL; - - if (txt) { - offset = 0; - found_match = TRUE; - - while (offset < len && found_match) { - - gint i, so=-1, eo=-1; - - found_match = FALSE; - - for (i=0; i<regex_count; ++i) { - - if (regexec (®ex_compiled[i], txt+offset, 1, &match, 0) == 0) { - - /* Take earliest match possible. In case of a tie, take the - largest possible match. */ - if (!found_match - || match.rm_so < so - || (match.rm_so == so && match.rm_eo > eo)) { - so = match.rm_so; - eo = match.rm_eo; - } - found_match = TRUE; - } - } - - if (found_match) { - - ObjInfo *info = g_new0 (ObjInfo, 1); - info->offset = offset + so; - info->len = eo - so; - - model_uri->uris = g_list_append (model_uri->uris, info); - - offset += eo; - } - } - } - - changed = (g_list_length (old_uris) != g_list_length (model_uri->uris)); - - if (!changed) { - /* Check that there is a 1-1 correspondence between object positions. */ - GList *jter; - - for (iter = model_uri->uris; iter != NULL && !changed; iter = g_list_next (iter)) { - ObjInfo *info = (ObjInfo *) iter->data; - found_match = FALSE; - for (jter = old_uris; jter != NULL && !found_match; jter = g_list_next (jter)) { - ObjInfo *jnfo = (ObjInfo *) jter->data; - - if (info->offset == jnfo->offset && info->len == jnfo->len) - found_match = TRUE; - } - changed = !found_match; - } - } - - if (changed) - e_text_model_changed (model); - - /* Free old uris */ - for (iter = old_uris; iter != NULL; iter = g_list_next (iter)) - g_free (iter->data); - g_list_free (old_uris); - - objectifying = FALSE; -} - -static gboolean -objectify_idle_cb (gpointer ptr) -{ - ETextModelURI *model_uri = E_TEXT_MODEL_URI (ptr); - - g_assert (model_uri->objectify_idle); - objectify_uris (model_uri); - model_uri->objectify_idle = 0; - - return FALSE; -} - -static void -e_text_model_uri_objectify (ETextModel *model) -{ - ETextModelURI *model_uri = E_TEXT_MODEL_URI (model); - - if (model_uri->objectify_idle == 0) - model_uri->objectify_idle = gtk_idle_add (objectify_idle_cb, model); - - if (E_TEXT_MODEL_CLASS(parent_class)->objectify) - E_TEXT_MODEL_CLASS(parent_class)->objectify (model); -} - -static void -objectify_idle_flush (ETextModelURI *model_uri) -{ - if (model_uri->objectify_idle) { - gtk_idle_remove (model_uri->objectify_idle); - model_uri->objectify_idle = 0; - objectify_uris (model_uri); - } -} - -static gint -e_text_model_uri_validate_pos (ETextModel *model, gint pos) -{ - gint obj_num; - - /* Cause us to skip over objects */ - - obj_num = e_text_model_get_object_at_offset (model, pos); - if (obj_num != -1) { - gint pos0, pos1, mp; - e_text_model_get_nth_object_bounds (model, obj_num, &pos0, &pos1); - mp = (pos0 + pos1)/2; - if (pos0 < pos && pos < mp) - pos = pos1; - else if (mp <= pos && pos < pos1) - pos = pos0; - } - - - - if (E_TEXT_MODEL_CLASS (parent_class)->validate_pos) - pos = E_TEXT_MODEL_CLASS (parent_class)->validate_pos (model, pos); - - return pos; -} - -static gint -e_text_model_uri_get_obj_count (ETextModel *model) -{ - ETextModelURI *model_uri = E_TEXT_MODEL_URI (model); - - objectify_idle_flush (model_uri); - - return g_list_length (model_uri->uris); -} - -static const gchar * -e_text_model_uri_get_nth_object (ETextModel *model, gint i, gint *len) -{ - ETextModelURI *model_uri = E_TEXT_MODEL_URI (model); - ObjInfo *info; - const gchar *txt; - - objectify_idle_flush (model_uri); - - txt = e_text_model_get_text (model); - - info = (ObjInfo *) g_list_nth_data (model_uri->uris, i); - g_return_val_if_fail (info != NULL, NULL); - - - if (len) - *len = info->len; - return txt + info->offset; -} - -static void -e_text_model_uri_activate_nth_object (ETextModel *model, gint i) -{ - gchar *obj_str; - - objectify_idle_flush (E_TEXT_MODEL_URI (model)); - - obj_str = e_text_model_strdup_nth_object (model, i); - gnome_url_show (obj_str); - g_free (obj_str); -} - -ETextModel * -e_text_model_uri_new (void) -{ - return E_TEXT_MODEL (gtk_type_new (e_text_model_uri_get_type ())); -} - - -/* $Id$ */ diff --git a/widgets/text/e-text-model-uri.h b/widgets/text/e-text-model-uri.h deleted file mode 100644 index bac4e99121..0000000000 --- a/widgets/text/e-text-model-uri.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text-model-uri.h - a text model w/ clickable URIs - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Jon Trowbridge <trow@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef E_TEXT_MODEL_URI_H -#define E_TEXT_MODEL_URI_H - -#include <gal/e-text/e-text-model.h> - -BEGIN_GNOME_DECLS - -#define E_TYPE_TEXT_MODEL_URI (e_text_model_get_type ()) -#define E_TEXT_MODEL_URI(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT_MODEL_URI, ETextModelURI)) -#define E_TEXT_MODEL_URI_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT_MODEL_URI, ETextModelURIClass)) -#define E_IS_TEXT_MODEL_URI(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT_MODEL_URI)) -#define E_IS_TEXT_MODEL_URI_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT_MODEL_URI)) - -typedef struct _ETextModelURI ETextModelURI; -typedef struct _ETextModelURIClass ETextModelURIClass; - -struct _ETextModelURI { - ETextModel item; - GList *uris; - - guint objectify_idle; -}; - -struct _ETextModelURIClass { - ETextModelClass parent_class; -}; - -GtkType e_text_model_uri_get_type (void); -ETextModel *e_text_model_uri_new (void); - -END_GNOME_DECLS - -#endif diff --git a/widgets/text/e-text-model.c b/widgets/text/e-text-model.c deleted file mode 100644 index da8644570b..0000000000 --- a/widgets/text/e-text-model.c +++ /dev/null @@ -1,645 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text-model.c - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#undef PARANOID_DEBUGGING - -#include <config.h> -#include <ctype.h> -#include <string.h> -#include <gtk/gtksignal.h> -#include "e-text-model-repos.h" -#include "e-text-model.h" -#include "gal/util/e-util.h" - -#define CLASS(obj) (E_TEXT_MODEL_CLASS (GTK_OBJECT (obj)->klass)) - -#define MAX_LENGTH (2047) - -enum { - E_TEXT_MODEL_CHANGED, - E_TEXT_MODEL_REPOSITION, - E_TEXT_MODEL_OBJECT_ACTIVATED, - E_TEXT_MODEL_CANCEL_COMPLETION, - E_TEXT_MODEL_LAST_SIGNAL -}; - -static guint e_text_model_signals[E_TEXT_MODEL_LAST_SIGNAL] = { 0 }; - -struct _ETextModelPrivate { - gchar *text; - gint len; -}; - -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 gint e_text_model_real_validate_position (ETextModel *, gint pos); -static const gchar *e_text_model_real_get_text (ETextModel *model); -static gint e_text_model_real_get_text_length (ETextModel *model); -static void e_text_model_real_set_text (ETextModel *model, const gchar *text); -static void e_text_model_real_insert (ETextModel *model, gint postion, const gchar *text); -static void e_text_model_real_insert_length (ETextModel *model, gint postion, const 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, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ETextModelClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_text_model_signals[E_TEXT_MODEL_REPOSITION] = - gtk_signal_new ("reposition", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ETextModelClass, reposition), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, - GTK_TYPE_POINTER, GTK_TYPE_POINTER); - - e_text_model_signals[E_TEXT_MODEL_OBJECT_ACTIVATED] = - gtk_signal_new ("object_activated", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ETextModelClass, object_activated), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, - GTK_TYPE_INT); - - e_text_model_signals[E_TEXT_MODEL_CANCEL_COMPLETION] = - gtk_signal_new ("cancel_completion", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ETextModelClass, cancel_completion), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - E_OBJECT_CLASS_ADD_SIGNALS (object_class, e_text_model_signals, E_TEXT_MODEL_LAST_SIGNAL); - - /* No default signal handlers. */ - klass->changed = NULL; - klass->reposition = NULL; - klass->object_activated = NULL; - - klass->validate_pos = e_text_model_real_validate_position; - - klass->get_text = e_text_model_real_get_text; - klass->get_text_len = e_text_model_real_get_text_length; - 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; - - /* We explicitly don't define default handlers for these. */ - klass->objectify = NULL; - klass->obj_count = NULL; - klass->get_nth_obj = NULL; - - object_class->destroy = e_text_model_destroy; -} - -/* Object initialization function for the text item */ -static void -e_text_model_init (ETextModel *model) -{ - model->priv = g_new0 (struct _ETextModelPrivate, 1); - model->priv->text = g_strdup (""); - model->priv->len = 0; -} - -/* 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); - - g_free (model->priv->text); - - g_free (model->priv); - model->priv = NULL; - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static gint -e_text_model_real_validate_position (ETextModel *model, gint pos) -{ - gint len; - - if (pos < 0) - pos = 0; - else if (pos > ( len = e_text_model_get_text_length (model) )) - pos = len; - - return pos; -} - -static const gchar * -e_text_model_real_get_text (ETextModel *model) -{ - if (model->priv->text) - return model->priv->text; - else - return ""; -} - -static gint -e_text_model_real_get_text_length (ETextModel *model) -{ - if (model->priv->len < 0) - model->priv->len = strlen (e_text_model_get_text (model)); - - return model->priv->len; -} - -static void -e_text_model_real_set_text (ETextModel *model, const gchar *text) -{ - EReposAbsolute repos; - gboolean changed = FALSE; - - if (text == NULL) { - - changed = (model->priv->text != NULL); - - g_free (model->priv->text); - model->priv->text = NULL; - model->priv->len = -1; - - } else if (model->priv->text == NULL || strcmp (model->priv->text, text)) { - - g_free (model->priv->text); - model->priv->text = g_strndup (text, MAX_LENGTH); - model->priv->len = -1; - - changed = TRUE; - } - - if (changed) { - e_text_model_changed (model); - repos.model = model; - repos.pos = -1; - e_text_model_reposition (model, e_repos_absolute, &repos); - } -} - -static void -e_text_model_real_insert (ETextModel *model, gint position, const gchar *text) -{ - EReposInsertShift repos; - gchar *new_text; - gint length; - - if (model->priv->len < 0) - e_text_model_real_get_text_length (model); - length = strlen(text); - - if (length + model->priv->len > MAX_LENGTH) - length = MAX_LENGTH - model->priv->len; - if (length <= 0) - return; - - /* Can't use g_strdup_printf here because on some systems - printf ("%.*s"); is locale dependent. */ - new_text = e_strdup_append_strings (model->priv->text, position, - text, length, - model->priv->text + position, -1, - NULL); - - if (model->priv->text) - g_free (model->priv->text); - - model->priv->text = new_text; - - if (model->priv->len >= 0) - model->priv->len += length; - - e_text_model_changed (model); - - repos.model = model; - repos.pos = position; - repos.len = length; - - e_text_model_reposition (model, e_repos_insert_shift, &repos); -} - -static void -e_text_model_real_insert_length (ETextModel *model, gint position, const gchar *text, gint length) -{ - EReposInsertShift repos; - gchar *new_text; - - if (model->priv->len < 0) - e_text_model_real_get_text_length (model); - - if (length + model->priv->len > MAX_LENGTH) - length = MAX_LENGTH - model->priv->len; - if (length <= 0) - return; - - /* Can't use g_strdup_printf here because on some systems - printf ("%.*s"); is locale dependent. */ - new_text = e_strdup_append_strings (model->priv->text, position, - text, length, - model->priv->text + position, -1, - NULL); - - if (model->priv->text) - g_free (model->priv->text); - model->priv->text = new_text; - - if (model->priv->len >= 0) - model->priv->len += length; - - e_text_model_changed (model); - - repos.model = model; - repos.pos = position; - repos.len = length; - - e_text_model_reposition (model, e_repos_insert_shift, &repos); -} - -static void -e_text_model_real_delete (ETextModel *model, gint position, gint length) -{ - EReposDeleteShift repos; - - memmove (model->priv->text + position, model->priv->text + position + length, strlen (model->priv->text + position + length) + 1); - - if (model->priv->len >= 0) - model->priv->len -= length; - - e_text_model_changed (model); - - repos.model = model; - repos.pos = position; - repos.len = length; - - e_text_model_reposition (model, e_repos_delete_shift, &repos); -} - -void -e_text_model_changed (ETextModel *model) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - /* - Objectify before emitting any signal. - While this method could, in theory, do pretty much anything, it is meant - for scanning objects and converting substrings into embedded objects. - */ - if (CLASS (model)->objectify) - CLASS (model)->objectify (model); - - gtk_signal_emit (GTK_OBJECT (model), - e_text_model_signals[E_TEXT_MODEL_CHANGED]); -} - -void -e_text_model_cancel_completion (ETextModel *model) -{ - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - gtk_signal_emit (GTK_OBJECT (model), e_text_model_signals[E_TEXT_MODEL_CANCEL_COMPLETION]); -} - -void -e_text_model_reposition (ETextModel *model, ETextModelReposFn fn, gpointer repos_data) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - g_return_if_fail (fn != NULL); - - gtk_signal_emit (GTK_OBJECT (model), - e_text_model_signals[E_TEXT_MODEL_REPOSITION], - fn, repos_data); -} - -gint -e_text_model_validate_position (ETextModel *model, gint pos) -{ - g_return_val_if_fail (model != NULL, 0); - g_return_val_if_fail (E_IS_TEXT_MODEL (model), 0); - - if (CLASS (model)->validate_pos) - pos = CLASS (model)->validate_pos (model, pos); - - return pos; -} - -const 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 (CLASS (model)->get_text) - return CLASS (model)->get_text (model); - - return ""; -} - -gint -e_text_model_get_text_length (ETextModel *model) -{ - g_return_val_if_fail (model != NULL, 0); - g_return_val_if_fail (E_IS_TEXT_MODEL (model), 0); - - if (CLASS (model)->get_text_len (model)) { - - gint len = CLASS (model)->get_text_len (model); - -#ifdef PARANOID_DEBUGGING - const gchar *str = e_text_model_get_text (model); - gint len2 = str ? strlen (str) : 0; - if (len != len) - g_error ("\"%s\" length reported as %d, not %d.", str, len, len2); -#endif - - return len; - - } else { - /* Calculate length the old-fashioned way... */ - const gchar *str = e_text_model_get_text (model); - return str ? strlen (str) : 0; - } -} - -void -e_text_model_set_text (ETextModel *model, const gchar *text) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if (CLASS (model)->set_text) - CLASS (model)->set_text (model, text); -} - -void -e_text_model_insert (ETextModel *model, gint position, const gchar *text) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if (text == NULL) - return; - - if (CLASS (model)->insert) - CLASS (model)->insert (model, position, text); -} - -void -e_text_model_insert_length (ETextModel *model, gint position, const gchar *text, gint length) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - g_return_if_fail (length >= 0); - - - if (text == NULL || length == 0) - return; - - if (CLASS (model)->insert_length) - CLASS (model)->insert_length (model, position, text, length); -} - -void -e_text_model_prepend (ETextModel *model, const gchar *text) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if (text == NULL) - return; - - e_text_model_insert (model, 0, text); -} - -void -e_text_model_append (ETextModel *model, const gchar *text) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if (text == NULL) - return; - - e_text_model_insert (model, e_text_model_get_text_length (model), text); -} - -void -e_text_model_delete (ETextModel *model, gint position, gint length) -{ - gint txt_len; - - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - g_return_if_fail (length >= 0); - - txt_len = e_text_model_get_text_length (model); - if (position + length > txt_len) - length = txt_len - position; - - if (length <= 0) - return; - - if (CLASS (model)->delete) - CLASS (model)->delete (model, position, length); -} - -gint -e_text_model_object_count (ETextModel *model) -{ - g_return_val_if_fail (model != NULL, 0); - g_return_val_if_fail (E_IS_TEXT_MODEL (model), 0); - - if (CLASS (model)->obj_count) - return CLASS (model)->obj_count (model); - - return 0; -} - -const gchar * -e_text_model_get_nth_object (ETextModel *model, gint n, gint *len) -{ - g_return_val_if_fail (model != NULL, NULL); - g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL); - - if (n < 0 || n >= e_text_model_object_count (model)) - return NULL; - - if (CLASS (model)->get_nth_obj) - return CLASS (model)->get_nth_obj (model, n, len); - - return NULL; -} - -gchar * -e_text_model_strdup_nth_object (ETextModel *model, gint n) -{ - const gchar *obj; - gint len = 0; - - g_return_val_if_fail (model != NULL, NULL); - g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL); - - obj = e_text_model_get_nth_object (model, n, &len); - - return obj ? g_strndup (obj, n) : NULL; -} - -void -e_text_model_get_nth_object_bounds (ETextModel *model, gint n, gint *start, gint *end) -{ - const gchar *txt = NULL, *obj = NULL; - gint len = 0; - - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - txt = e_text_model_get_text (model); - obj = e_text_model_get_nth_object (model, n, &len); - - g_return_if_fail (obj != NULL); - - if (start) - *start = obj - txt; - if (end) - *end = obj - txt + len; -} - -gint -e_text_model_get_object_at_offset (ETextModel *model, gint offset) -{ - g_return_val_if_fail (model != NULL, -1); - g_return_val_if_fail (E_IS_TEXT_MODEL (model), -1); - - if (offset < 0 || offset >= e_text_model_get_text_length (model)) - return -1; - - /* If an optimized version has been provided, we use it. */ - if (CLASS (model)->obj_at_offset) { - - return CLASS (model)->obj_at_offset (model, offset); - - } else { - /* If not, we fake it.*/ - - gint i, N, pos0, pos1; - - N = e_text_model_object_count (model); - - for (i = 0; i < N; ++i) { - e_text_model_get_nth_object_bounds (model, i, &pos0, &pos1); - if (pos0 <= offset && offset < pos1) - return i; - } - - } - - return -1; -} - -gint -e_text_model_get_object_at_pointer (ETextModel *model, const gchar *s) -{ - g_return_val_if_fail (model != NULL, -1); - g_return_val_if_fail (E_IS_TEXT_MODEL (model), -1); - g_return_val_if_fail (s != NULL, -1); - - return e_text_model_get_object_at_offset (model, s - e_text_model_get_text (model)); -} - -void -e_text_model_activate_nth_object (ETextModel *model, gint n) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - g_return_if_fail (n >= 0); - g_return_if_fail (n < e_text_model_object_count (model)); - - gtk_signal_emit (GTK_OBJECT (model), e_text_model_signals[E_TEXT_MODEL_OBJECT_ACTIVATED], n); -} - -ETextModel * -e_text_model_new (void) -{ - ETextModel *model = gtk_type_new (e_text_model_get_type ()); - return model; -} diff --git a/widgets/text/e-text-model.h b/widgets/text/e-text-model.h deleted file mode 100644 index a3b1caa415..0000000000 --- a/widgets/text/e-text-model.h +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text-model.h - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef E_TEXT_MODEL_H -#define E_TEXT_MODEL_H - -#include <glib.h> -#include <gtk/gtkobject.h> -#include <libgnome/gnome-defs.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 _ETextModelPrivate; - -typedef gint (*ETextModelReposFn) (gint, gpointer); - -struct _ETextModel { - GtkObject item; - - struct _ETextModelPrivate *priv; -}; - -struct _ETextModelClass { - GtkObjectClass parent_class; - - /* Signal */ - void (* changed) (ETextModel *model); - void (* reposition) (ETextModel *model, ETextModelReposFn fn, gpointer repos_fn_data); - void (* object_activated) (ETextModel *model, gint obj_num); - void (* cancel_completion) (ETextModel *model); - - /* Virtual methods */ - - gint (* validate_pos) (ETextModel *model, gint pos); - - const char *(* get_text) (ETextModel *model); - gint (* get_text_len) (ETextModel *model); - void (* set_text) (ETextModel *model, const gchar *text); - void (* insert) (ETextModel *model, gint position, const gchar *text); - void (* insert_length) (ETextModel *model, gint position, const gchar *text, gint length); - void (* delete) (ETextModel *model, gint position, gint length); - - void (* objectify) (ETextModel *model); - gint (* obj_count) (ETextModel *model); - const gchar *(* get_nth_obj) (ETextModel *model, gint n, gint *len); - gint (* obj_at_offset) (ETextModel *model, gint offset); -}; - -GtkType e_text_model_get_type (void); - -ETextModel *e_text_model_new (void); - -void e_text_model_changed (ETextModel *model); -void e_text_model_cancel_completion (ETextModel *model); - -void e_text_model_reposition (ETextModel *model, ETextModelReposFn fn, gpointer repos_data); -gint e_text_model_validate_position (ETextModel *model, gint pos); - - -/* Functions for manipulating the underlying text. */ - -const gchar *e_text_model_get_text (ETextModel *model); -gint e_text_model_get_text_length (ETextModel *model); -void e_text_model_set_text (ETextModel *model, const gchar *text); -void e_text_model_insert (ETextModel *model, gint position, const gchar *text); -void e_text_model_insert_length (ETextModel *model, gint position, const gchar *text, gint length); -void e_text_model_prepend (ETextModel *model, const gchar *text); -void e_text_model_append (ETextModel *model, const gchar *text); -void e_text_model_delete (ETextModel *model, gint position, gint length); - - -/* Functions for accessing embedded objects. */ - -gint e_text_model_object_count (ETextModel *model); -const gchar *e_text_model_get_nth_object (ETextModel *model, gint n, gint *len); -gchar *e_text_model_strdup_nth_object (ETextModel *model, gint n); -void e_text_model_get_nth_object_bounds (ETextModel *model, gint n, gint *start_pos, gint *end_pos); -gint e_text_model_get_object_at_offset (ETextModel *model, gint offset); -gint e_text_model_get_object_at_pointer (ETextModel *model, const gchar *c); -void e_text_model_activate_nth_object (ETextModel *model, gint n); - - - - - - - -END_GNOME_DECLS - -#endif diff --git a/widgets/text/e-text-test.c b/widgets/text/e-text-test.c deleted file mode 100644 index 39572905c8..0000000000 --- a/widgets/text/e-text-test.c +++ /dev/null @@ -1,171 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text-test.c - E-Text item test program - * Copyright 2000: Iain Holmes <ih@csd.abdn.ac.uk> - * - * Authors: - * Iain Holmes <ih@csd.abdn.ac.uk> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include "e-text.h" -#include <gnome.h> -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-unicode.h" - -GnomeCanvasItem *rect; - -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, GnomeCanvasItem *item) -{ - double height; - gnome_canvas_item_set( item, - "width", (double) allocation->width, - NULL ); - gtk_object_get(GTK_OBJECT(item), - "height", &height, - NULL); - height = MAX(height, allocation->height); - gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, allocation->width, height ); - gnome_canvas_item_set( rect, - "x2", (double) allocation->width, - "y2", (double) height, - NULL ); -} - -static void -reflow (GtkWidget *canvas, GnomeCanvasItem *item) -{ - double height; - gtk_object_get(GTK_OBJECT(item), - "height", &height, - NULL); - height = MAX(height, canvas->allocation.height); - gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, canvas->allocation.width, height ); - gnome_canvas_item_set( rect, - "x2", (double) canvas->allocation.width, - "y2", (double) height, - NULL ); -} - -static void -quit_cb (GtkWidget *widget, - gpointer data) -{ - gtk_main_quit (); -} - -static void -change_text_cb (GtkEntry *entry, - EText *text) -{ - gchar *str; - - str = e_utf8_gtk_entry_get_text (entry); - gnome_canvas_item_set (GNOME_CANVAS_ITEM (text), - "text", str, - NULL); -} - -static void -change_font_cb (GtkEntry *entry, - EText *text) -{ - gchar *font; - - font = gtk_entry_get_text (entry); - gnome_canvas_item_set (GNOME_CANVAS_ITEM (text), - "font", font, - NULL); -} - -int -main (int argc, - char **argv) -{ - GtkWidget *window, *canvas, *scroller, *vbox, *text, *font; - GtkWidget *frame; - GnomeCanvasItem *item; - - gnome_init ("ETextTest", "0.0.1", argc, argv); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "EText Test"); - gtk_signal_connect (GTK_OBJECT (window), "destroy", - GTK_SIGNAL_FUNC (quit_cb), NULL); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - canvas = e_canvas_new (); - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - scroller = gtk_scrolled_window_new (NULL, NULL); - vbox = gtk_vbox_new (FALSE, 2); - - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_box_pack_start (GTK_BOX (vbox), scroller, TRUE, TRUE, 2); - gtk_container_add (GTK_CONTAINER (scroller), canvas); - - frame = gtk_frame_new ("Text"); - text = gtk_entry_new (); - gtk_entry_set_text(GTK_ENTRY(text), "Hello World! This is a really long string to test out the ellipsis stuff."); - gtk_container_add (GTK_CONTAINER (frame), text); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); - - frame = gtk_frame_new ("Font"); - font = gtk_entry_new (); - gtk_entry_set_text(GTK_ENTRY(font), "fixed"); - gtk_container_add (GTK_CONTAINER (frame), font); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); - - rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - - item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - e_text_get_type (), - "text", "Hello World! This is a really long string to test out the ellipsis stuff.", - "font", "fixed", - "fill_color", "black", - "anchor", GTK_ANCHOR_NW, - "clip", TRUE, - "use_ellipsis", TRUE, - "editable", TRUE, - "line_wrap", TRUE, - "max_lines", 2, - "width", 150.0, - NULL); - - gtk_signal_connect (GTK_OBJECT (text), "activate", - GTK_SIGNAL_FUNC (change_text_cb), item); - gtk_signal_connect (GTK_OBJECT (font), "activate", - GTK_SIGNAL_FUNC (change_font_cb), item); - - gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", - GTK_SIGNAL_FUNC( allocate_callback ), - item ); - gtk_signal_connect( GTK_OBJECT( canvas ), "reflow", - GTK_SIGNAL_FUNC( reflow ), - item ); - gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0.0, 0.0, 400.0, 400.0); - gtk_widget_show_all (window); - gtk_main (); - - return 0; -} diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c deleted file mode 100644 index 4fc8437732..0000000000 --- a/widgets/text/e-text.c +++ /dev/null @@ -1,4224 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text.c - Text item for evolution. - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Jon Trowbridge <trow@ximian.com> - * - * 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> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> - -#include "e-text.h" - -#include <math.h> -#include <ctype.h> -#include <string.h> -#include <gdk/gdkx.h> /* for BlackPixel */ -#include <gtk/gtkinvisible.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkselection.h> -#include <gtk/gtkwindow.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> - -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-canvas-utils.h" -#include "gal/widgets/e-unicode.h" -#include "gal/util/e-text-event-processor-emacs-like.h" -#include "gal/util/e-util.h" -#include <libart_lgpl/art_affine.h> -#include <libart_lgpl/art_rgb.h> -#include <libart_lgpl/art_rgb_bitmap_affine.h> - -#define BORDER_INDENT 4 - -enum { - E_TEXT_CHANGED, - E_TEXT_ACTIVATE, - E_TEXT_KEYPRESS, - E_TEXT_POPUP, - E_TEXT_LAST_SIGNAL -}; - -static guint e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; - - - -/* This defines a line of text */ -struct line { - const char *text; /* Line's text, it is a pointer into the text->text string */ - int length; /* Line's length IN BYTES */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis */ -}; - -/* Object argument IDs */ -enum { - ARG_0, - ARG_MODEL, - ARG_EVENT_PROCESSOR, - ARG_TEXT, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_FONT_E, - ARG_BOLD, - ARG_STRIKEOUT, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_FILL_CLIP_RECTANGLE, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_LINE_WRAP, - ARG_BREAK_CHARACTERS, - ARG_MAX_LINES, - ARG_WIDTH, - ARG_HEIGHT, - ARG_DRAW_BORDERS, - ARG_ALLOW_NEWLINES, - ARG_DRAW_BACKGROUND, - ARG_DRAW_BUTTON, - ARG_CURSOR_POS -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; -enum _TargetInfo { - TARGET_UTF8_STRING, - TARGET_UTF8, - TARGET_COMPOUND_TEXT, - TARGET_STRING, - TARGET_TEXT -}; - -static void e_text_class_init (ETextClass *class); -static void e_text_init (EText *text); -static void e_text_destroy (GtkObject *object); -static void e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void e_text_reflow (GnomeCanvasItem *item, int flags); -static void e_text_update (GnomeCanvasItem *item, double *affine, - ArtSVP *clip_path, int flags); -static void e_text_realize (GnomeCanvasItem *item); -static void e_text_unrealize (GnomeCanvasItem *item); -static void e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height); -static double e_text_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item); -static void e_text_bounds (GnomeCanvasItem *item, - double *x1, double *y1, double *x2, double *y2); -static void e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf); -static gint e_text_event (GnomeCanvasItem *item, GdkEvent *event); - -static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -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_reposition (ETextModel *model, ETextModelReposFn fn, gpointer repos_data, gpointer data); - -static void _get_tep(EText *text); - -static GtkWidget *e_text_get_invisible(EText *text); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text); - -#if 0 -static ETextSuckFont *e_suck_font (GdkFont *font); -static void e_suck_font_free (ETextSuckFont *suckfont); -#endif - -static void e_text_free_lines(EText *text); - -static gint text_width_with_objects (ETextModel *model, - EFont *font, EFontStyle style, - const gchar *text, gint bytelen); - -static void calc_height (EText *text); -static void calc_line_widths (EText *text); -static void split_into_lines (EText *text); - -static GnomeCanvasItemClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; - - - -/** - * e_text_get_type: - * @void: - * - * Registers the &EText class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EText class. - **/ -GtkType -e_text_get_type (void) -{ - static GtkType text_type = 0; - - if (!text_type) { - GtkTypeInfo text_info = { - "EText", - sizeof (EText), - sizeof (ETextClass), - (GtkClassInitFunc) e_text_class_init, - (GtkObjectInitFunc) e_text_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - text_type = gtk_type_unique (gnome_canvas_item_get_type (), &text_info); - } - - return text_type; -} - -/* Class initialization function for the text item */ -static void -e_text_class_init (ETextClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) klass; - item_class = (GnomeCanvasItemClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_item_get_type ()); - - e_text_signals[E_TEXT_CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ETextClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_text_signals[E_TEXT_ACTIVATE] = - gtk_signal_new ("activate", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ETextClass, activate), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_text_signals[E_TEXT_KEYPRESS] = - gtk_signal_new ("keypress", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ETextClass, keypress), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_UINT, GTK_TYPE_UINT); - - e_text_signals[E_TEXT_POPUP] = - gtk_signal_new ("popup", - GTK_RUN_LAST, - E_OBJECT_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (ETextClass, popup), - gtk_marshal_NONE__POINTER_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_INT); - - E_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::event_processor", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_EVENT_PROCESSOR); - gtk_object_add_arg_type ("EText::text", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); - gtk_object_add_arg_type ("EText::font", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT); - gtk_object_add_arg_type ("EText::fontset", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET); - gtk_object_add_arg_type ("EText::font_gdk", - GTK_TYPE_GDK_FONT, GTK_ARG_WRITABLE, ARG_FONT_GDK); - gtk_object_add_arg_type ("EText::font_e", - GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_FONT_E); - gtk_object_add_arg_type ("EText::bold", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_BOLD); - gtk_object_add_arg_type ("EText::strikeout", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_STRIKEOUT); - gtk_object_add_arg_type ("EText::anchor", - GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); - gtk_object_add_arg_type ("EText::justification", - GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION); - gtk_object_add_arg_type ("EText::clip_width", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_WIDTH); - gtk_object_add_arg_type ("EText::clip_height", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_HEIGHT); - gtk_object_add_arg_type ("EText::clip", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_CLIP); - gtk_object_add_arg_type ("EText::fill_clip_rectangle", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_FILL_CLIP_RECTANGLE); - gtk_object_add_arg_type ("EText::x_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X_OFFSET); - gtk_object_add_arg_type ("EText::y_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y_OFFSET); - gtk_object_add_arg_type ("EText::fill_color", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("EText::fill_color_gdk", - GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK); - gtk_object_add_arg_type ("EText::fill_color_rgba", - GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA); - gtk_object_add_arg_type ("EText::fill_stipple", - GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE); - gtk_object_add_arg_type ("EText::text_width", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_WIDTH); - gtk_object_add_arg_type ("EText::text_height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_HEIGHT); - gtk_object_add_arg_type ("EText::editable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE); - gtk_object_add_arg_type ("EText::use_ellipsis", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS); - gtk_object_add_arg_type ("EText::ellipsis", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); - gtk_object_add_arg_type ("EText::line_wrap", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP); - gtk_object_add_arg_type ("EText::break_characters", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_BREAK_CHARACTERS); - gtk_object_add_arg_type ("EText::max_lines", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); - gtk_object_add_arg_type ("EText::width", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("EText::height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("EText::draw_borders", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BORDERS); - gtk_object_add_arg_type ("EText::allow_newlines", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_ALLOW_NEWLINES); - gtk_object_add_arg_type ("EText::draw_background", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BACKGROUND); - gtk_object_add_arg_type ("EText::draw_button", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BUTTON); - gtk_object_add_arg_type ("EText::cursor_pos", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_CURSOR_POS); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); - - - - klass->changed = NULL; - klass->activate = NULL; - - object_class->destroy = e_text_destroy; - object_class->set_arg = e_text_set_arg; - object_class->get_arg = e_text_get_arg; - - item_class->update = e_text_update; - item_class->realize = e_text_realize; - item_class->unrealize = e_text_unrealize; - item_class->draw = e_text_draw; - item_class->point = e_text_point; - item_class->bounds = e_text_bounds; - item_class->render = e_text_render; - item_class->event = e_text_event; -} - -/* Object initialization function for the text item */ -static void -e_text_init (EText *text) -{ - text->model = e_text_model_new (); - text->text = e_text_model_get_text (text->model); - - text->revert = NULL; - - 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->model_repos_signal_id = - gtk_signal_connect (GTK_OBJECT (text->model), - "reposition", - GTK_SIGNAL_FUNC (e_text_text_model_reposition), - text); - - text->anchor = GTK_ANCHOR_CENTER; - text->justification = GTK_JUSTIFY_LEFT; - text->clip_width = -1.0; - text->clip_height = -1.0; - text->xofs = 0.0; - text->yofs = 0.0; - - text->ellipsis = NULL; - text->use_ellipsis = FALSE; - text->ellipsis_width = 0; - - text->editable = FALSE; - text->editing = FALSE; - text->xofs_edit = 0; - text->yofs_edit = 0; - - text->selection_start = 0; - text->selection_end = 0; - text->select_by_word = FALSE; - - text->timeout_id = 0; - text->timer = NULL; - - text->lastx = 0; - text->lasty = 0; - text->last_state = 0; - - text->scroll_start = 0; - text->show_cursor = TRUE; - text->button_down = FALSE; - - text->tep = NULL; - text->tep_command_id = 0; - - text->has_selection = FALSE; - - text->invisible = NULL; - text->primary_selection = NULL; - text->primary_length = 0; - text->clipboard_selection = NULL; - text->clipboard_length = 0; - - text->pointer_in = FALSE; - text->default_cursor_shown = TRUE; - - text->line_wrap = FALSE; - text->break_characters = NULL; - text->max_lines = -1; - - text->tooltip_timeout = 0; - text->tooltip_count = 0; - text->tooltip_owner = FALSE; - - text->dbl_timeout = 0; - text->tpl_timeout = 0; - - text->draw_background = FALSE; - text->draw_button = FALSE; - - text->bold = FALSE; - text->strikeout = FALSE; - - text->style = E_FONT_PLAIN; - text->allow_newlines = TRUE; - - text->last_type_request = -1; - text->last_time_request = 0; - text->queued_requests = NULL; - - e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(text), e_text_reflow); -} - -/* Destroy handler for the text item */ -static void -e_text_destroy (GtkObject *object) -{ - EText *text; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TEXT (object)); - - text = E_TEXT (object); - - if (text->tooltip_owner) { - e_canvas_hide_tooltip (E_CANVAS(GNOME_CANVAS_ITEM(text)->canvas)); - } - - if (text->model_changed_signal_id) - gtk_signal_disconnect (GTK_OBJECT (text->model), - text->model_changed_signal_id); - - if (text->model_repos_signal_id) - gtk_signal_disconnect (GTK_OBJECT (text->model), - text->model_repos_signal_id); - - if (text->model) - gtk_object_unref(GTK_OBJECT(text->model)); - - if (text->tep_command_id) - gtk_signal_disconnect(GTK_OBJECT(text->tep), - text->tep_command_id); - - if (text->tep) - gtk_object_unref (GTK_OBJECT(text->tep)); - - if (text->invisible) - gtk_object_unref (GTK_OBJECT(text->invisible)); - - g_free (text->lines); - g_free (text->primary_selection); - g_free (text->clipboard_selection); - g_free (text->revert); - - if (text->font) - e_font_unref (text->font); - text->font = NULL; - -#if 0 - if (text->suckfont) - e_suck_font_free (text->suckfont); -#endif - - if (text->stipple) - gdk_bitmap_unref (text->stipple); - - if (text->timeout_id) { - g_source_remove(text->timeout_id); - text->timeout_id = 0; - } - - if (text->timer) { - g_timer_stop(text->timer); - g_timer_destroy(text->timer); - text->timer = NULL; - } - - if ( text->tooltip_timeout ) { - gtk_timeout_remove (text->tooltip_timeout); - text->tooltip_timeout = 0; - } - - if ( text->dbl_timeout ) { - gtk_timeout_remove (text->dbl_timeout); - text->dbl_timeout = 0; - } - - if ( text->tpl_timeout ) { - gtk_timeout_remove (text->tpl_timeout); - text->tpl_timeout = 0; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -e_text_text_model_changed (ETextModel *model, EText *text) -{ - gint model_len = e_text_model_get_text_length (model); - text->text = e_text_model_get_text(model); - e_text_free_lines(text); - - gtk_signal_emit (GTK_OBJECT (text), e_text_signals[E_TEXT_CHANGED]); - - /* Make sure our selection doesn't extend past the bounds of our text. */ - text->selection_start = CLAMP (text->selection_start, 0, model_len); - text->selection_end = CLAMP (text->selection_end, 0, model_len); - - text->needs_split_into_lines = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text)); -} - -static void -e_text_text_model_reposition (ETextModel *model, ETextModelReposFn fn, gpointer repos_data, gpointer user_data) -{ - EText *text = E_TEXT (user_data); - gint model_len = e_text_model_get_text_length (model); - - text->selection_start = fn (text->selection_start, repos_data); - text->selection_end = fn (text->selection_end, repos_data); - - /* Our repos function should make sure we don't overrun the buffer, but it never - hurts to be paranoid. */ - text->selection_start = CLAMP (text->selection_start, 0, model_len); - text->selection_end = CLAMP (text->selection_end, 0, model_len); - - if (text->selection_start > text->selection_end) { - gint tmp = text->selection_start; - text->selection_start = text->selection_end; - text->selection_end = tmp; - } -} - -static void -get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double x, y; - double clip_x, clip_y; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - x = 0; - y = 0; - - clip_x = x; - clip_y = y; - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = (e_font_height (text->font)) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - e_canvas_item_request_parent_reflow(item); - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - if ( text->clip_width >= 0) - clip_x -= text->clip_width / 2; - else - clip_x -= text->width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - if (text->clip_width >= 0) - clip_x -= text->clip_width; - else - clip_x -= text->width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - if ( text->clip_height >= 0 ) - clip_y -= text->clip_height / 2; - else - clip_y -= text->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - if ( text->clip_height >= 0 ) - clip_y -= text->clip_height; - else - clip_y -= text->height; - break; - } - - /* Bounds */ - - if (text->clip) { - /* maybe do bbox intersection here? */ - *px1 = clip_x; - *py1 = clip_y; - if (text->clip_width >= 0) - *px2 = clip_x + text->clip_width; - else - *px2 = clip_x + text->width; - - if ( text->clip_height >= 0 ) - *py2 = clip_y + text->clip_height; - else - *py2 = clip_y + text->height; - } else { - *px1 = x; - *py1 = y; - *px2 = x + text->max_width; - *py2 = y + text->height; - } -} - -static void -get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double wx, wy, clip_width; - - item = GNOME_CANVAS_ITEM (text); - - /* Get canvas pixel coordinates for text position */ - - wx = 0; - wy = 0; - gnome_canvas_item_i2w (item, &wx, &wy); - gnome_canvas_w2c (item->canvas, wx + text->xofs, wy + text->yofs, &text->cx, &text->cy); - - if (text->clip_width < 0) - clip_width = text->max_width; - else - clip_width = text->clip_width; - - /* Get canvas pixel coordinates for clip rectangle position */ - gnome_canvas_w2c (item->canvas, wx, wy, &text->clip_cx, &text->clip_cy); - text->clip_cwidth = clip_width * item->canvas->pixels_per_unit; - if ( text->clip_height >= 0 ) - text->clip_cheight = text->clip_height * item->canvas->pixels_per_unit; - else - text->clip_cheight = text->height * item->canvas->pixels_per_unit; - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - text->cx -= text->max_width / 2; - text->clip_cx -= text->clip_cwidth / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - text->cx -= text->max_width; - text->clip_cx -= text->clip_cwidth; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - text->cy -= text->height / 2; - text->clip_cy -= text->clip_cheight / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - text->cy -= text->height; - text->clip_cy -= text->clip_cheight; - break; - } - - /* Bounds */ - - if (text->clip) { - *px1 = text->clip_cx; - *py1 = text->clip_cy; - *px2 = text->clip_cx + text->clip_cwidth; - *py2 = text->clip_cy + text->clip_cheight; - } else { - *px1 = text->cx; - *py1 = text->cy; - *px2 = text->cx + text->max_width; - *py2 = text->cy + text->height; - } -} - -static void -calc_height (EText *text) -{ - GnomeCanvasItem *item; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = e_font_height (text->font) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - e_canvas_item_request_parent_reflow(item); -} - -static void -calc_ellipsis (EText *text) -{ - if (text->font) - text->ellipsis_width = - e_font_utf8_text_width (text->font, text->style, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? strlen (text->ellipsis) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (EText *text) -{ - struct line *lines; - int i; - gdouble clip_width; - const gchar *p; - - lines = text->lines; - text->max_width = 0; - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - - if (!lines) - return; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - if (text->font) { - lines->width = text_width_with_objects (text->model, - text->font, text->style, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (text->clip && - text->use_ellipsis && - ! text->editing && - lines->width > clip_width && - clip_width >= 0) { - if (text->font) { - lines->ellipsis_length = 0; - for (p = lines->text; - p && *p && g_unichar_validate (g_utf8_get_char (p)) && (p - lines->text) < lines->length; - p = g_utf8_next_char (p)) { - gint text_width = text_width_with_objects (text->model, - text->font, text->style, - lines->text, p - lines->text); - if (clip_width >= text_width + text->ellipsis_width) - lines->ellipsis_length = p - lines->text; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = text_width_with_objects (text->model, - text->font, text->style, - lines->text, lines->ellipsis_length) + - text->ellipsis_width; - } else - lines->ellipsis_length = lines->length; - - if (lines->width > text->max_width) - text->max_width = lines->width; - } - - lines++; - } -} - -static void -e_text_free_lines(EText *text) -{ - if (text->lines) - g_free (text->lines); - - text->lines = NULL; - text->num_lines = 0; -} - -static gint -text_width_with_objects (ETextModel *model, - EFont *font, EFontStyle style, - const gchar *text, gint numbytes) -{ - return text && *text ? e_font_utf8_text_width (font, style, text, numbytes) : 0; -} - -static void -text_draw_with_objects (ETextModel *model, - GdkDrawable *drawable, - EFont *font, EFontStyle style, - GdkGC *gc, - gint x, gint y, - const gchar *text, gint numbytes) -{ - const gchar *c; - - if (text == NULL) - return; - - while (*text && numbytes > 0) { - gint obj_num = -1; - - c = text; - - while (*c - && (obj_num = e_text_model_get_object_at_pointer (model, c)) == -1 - && numbytes > 0) { - ++c; - --numbytes; - } - - e_font_draw_utf8_text (drawable, font, style, gc, x, y, text, c-text); - x += e_font_utf8_text_width (font, style, text, c-text); - - if (obj_num != -1 && numbytes > 0) { - gint len; - gint start_x = x; - - e_text_model_get_nth_object (model, obj_num, &len); - - if (len > numbytes) - len = numbytes; - e_font_draw_utf8_text (drawable, font, style, gc, x, y, c, len); - x += e_font_utf8_text_width (font, style, c, len); - - /* We underline our objects. */ - gdk_draw_line (drawable, gc, start_x, y+1, x, y+1); - - c += len; - numbytes -= len; - } - - text = c; - } -} - -#define IS_BREAKCHAR(text,c) ((text)->break_characters && g_utf8_strchr ((text)->break_characters, (c))) -/* Splits the text of the text item into lines */ -static void -split_into_lines (EText *text) -{ - const char *p, *cp; - struct line *lines; - int len; - int line_num; - const char *laststart; - const char *lastend; - const char *linestart; - double clip_width; - gunichar unival; - - - if (text->text == NULL) - return; - - /* Free old array of lines */ - e_text_free_lines(text); - - /* First, count the number of lines */ - - lastend = text->text; - laststart = text->text; - linestart = text->text; - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - cp = text->text; - - for (p = e_unicode_get_utf8 (cp, &unival); (unival && p); cp = p, p = e_unicode_get_utf8 (p, &unival)) { - if (text->line_wrap - && (g_unichar_isspace (unival) || unival == '\n') - && e_text_model_get_object_at_pointer (text->model, cp) == -1) { /* don't break mid-object */ - if (laststart != lastend - && clip_width < text_width_with_objects (text->model, - text->font, text->style, - linestart, cp - linestart)) { - text->num_lines ++; - - linestart = laststart; - laststart = p; - lastend = cp; - } else if (g_unichar_isspace (unival)) { - laststart = p; - lastend = cp; - } - } else if (text->line_wrap - && IS_BREAKCHAR (text, unival)) { - - if (laststart != lastend - && g_utf8_pointer_to_offset (linestart, cp) != 1 - && clip_width < text_width_with_objects (text->model, - text->font, text->style, - linestart, p - linestart)) { - text->num_lines ++; - - linestart = laststart; - laststart = p; - lastend = p; - } else { - laststart = p; - lastend = p; - } - } - - if (unival == '\n') { - text->num_lines ++; - - lastend = p; - laststart = p; - linestart = p; - } - } - - if ( text->line_wrap - && p - && laststart != lastend - && clip_width < text_width_with_objects (text->model, - text->font, text->style, - linestart, cp - linestart)) { - text->num_lines ++; - } - - text->num_lines++; - - if ( (!text->editing) && text->max_lines != -1 && text->num_lines > text->max_lines ) { - text->num_lines = text->max_lines; - } - - /* Allocate array of lines and calculate split positions */ - - text->lines = lines = g_new0 (struct line, text->num_lines); - len = 0; - line_num = 1; - lastend = text->text; - laststart = text->text; - - cp = text->text; - - for (p = e_unicode_get_utf8 (cp, &unival); p && unival && line_num < text->num_lines; cp = p, p = e_unicode_get_utf8 (p, &unival)) { - gboolean handled = FALSE; - - if (len == 0) - lines->text = cp; - if (text->line_wrap - && (g_unichar_isspace (unival) || unival == '\n') - && e_text_model_get_object_at_pointer (text->model, cp) == -1) { /* don't break mid-object */ - if (clip_width < text_width_with_objects (text->model, - text->font, text->style, - lines->text, cp - lines->text) - && laststart != lastend) { - - lines->length = lastend - lines->text; - - lines++; - line_num++; - len = cp - laststart; - lines->text = laststart; - laststart = p; - lastend = cp; - } else if (g_unichar_isspace (unival)) { - laststart = p; - lastend = cp; - len ++; - } - handled = TRUE; - } else if (text->line_wrap - && IS_BREAKCHAR(text, unival) - && e_text_model_get_object_at_pointer (text->model, cp) == -1) { - if (laststart != lastend - && g_utf8_pointer_to_offset (lines->text, cp) != 1 - && clip_width < text_width_with_objects (text->model, - text->font, text->style, - lines->text, p - lines->text)) { - - lines->length = lastend - lines->text; - - lines++; - line_num++; - len = p - laststart; - lines->text = laststart; - laststart = p; - lastend = p; - } else { - laststart = p; - lastend = p; - len ++; - } - } - if (line_num >= text->num_lines) - break; - if (unival == '\n') { - - lines->length = cp - lines->text; - - lines++; - line_num++; - len = 0; - lastend = p; - laststart = p; - handled = TRUE; - } - if (!handled) - len++; - } - - if ( line_num < text->num_lines && text->line_wrap ) { - if (clip_width < text_width_with_objects (text->model, - text->font, text->style, - lines->text, cp - lines->text) - && laststart != lastend ) { - - lines->length = lastend - lines->text; - - lines++; - line_num++; - len = cp - laststart; - lines->text = laststart; - laststart = p; - lastend = cp; - } - } - - if (len == 0) - lines->text = cp; - lines->length = strlen (lines->text); -} - -/* Convenience function to set the text's GC's foreground color */ -static void -set_text_gc_foreground (EText *text) -{ - if (!text->gc) - return; - - gdk_gc_set_foreground (text->gc, &text->color); -} - -/* Sets the stipple pattern for the text */ -static void -set_stipple (EText *text, GdkBitmap *stipple, int reconfigure) -{ - if (text->stipple && !reconfigure) - gdk_bitmap_unref (text->stipple); - - text->stipple = stipple; - if (stipple && !reconfigure) - gdk_bitmap_ref (stipple); - - if (text->gc) { - if (stipple) { - gdk_gc_set_stipple (text->gc, stipple); - gdk_gc_set_fill (text->gc, GDK_STIPPLED); - } else - gdk_gc_set_fill (text->gc, GDK_SOLID); - } -} - -/* Set_arg handler for the text item */ -static void -e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EText *text; - GdkColor color = { 0, 0, 0, 0, }; - GdkColor *pcolor; - gboolean color_changed; - int have_pixel; - - gboolean needs_update = 0; - gboolean needs_reflow = 0; - - item = GNOME_CANVAS_ITEM (object); - text = E_TEXT (object); - - color_changed = FALSE; - have_pixel = FALSE; - - switch (arg_id) { - case ARG_MODEL: - - if ( text->model_changed_signal_id ) - gtk_signal_disconnect (GTK_OBJECT (text->model), - text->model_changed_signal_id); - - if ( text->model_repos_signal_id ) - gtk_signal_disconnect (GTK_OBJECT (text->model), - text->model_repos_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->model_repos_signal_id = - gtk_signal_connect (GTK_OBJECT (text->model), - "reposition", - GTK_SIGNAL_FUNC (e_text_text_model_reposition), - text); - - e_text_free_lines(text); - - text->text = e_text_model_get_text(text->model); - gtk_signal_emit (GTK_OBJECT (text), e_text_signals[E_TEXT_CHANGED]); - - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_EVENT_PROCESSOR: - if ( text->tep && text->tep_command_id ) - gtk_signal_disconnect(GTK_OBJECT(text->tep), - text->tep_command_id); - if ( text->tep ) { - gtk_object_unref(GTK_OBJECT(text->tep)); - } - text->tep = E_TEXT_EVENT_PROCESSOR(GTK_VALUE_OBJECT (*arg)); - gtk_object_ref(GTK_OBJECT(text->tep)); - text->tep_command_id = - gtk_signal_connect(GTK_OBJECT(text->tep), - "command", - GTK_SIGNAL_FUNC(e_text_command), - text); - if (!text->allow_newlines) - gtk_object_set (GTK_OBJECT (text->tep), - "allow_newlines", FALSE, - NULL); - break; - - case ARG_TEXT: - text->num_lines = 1; - e_text_model_set_text(text->model, GTK_VALUE_STRING (*arg)); - break; - - case ARG_FONT: - if (text->font) - e_font_unref (text->font); - - text->font = e_font_from_gdk_name (GTK_VALUE_STRING (*arg)); - - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else { - text->needs_calc_line_widths = 1; - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case ARG_FONTSET: - if (text->font) - e_font_unref (text->font); - - text->font = e_font_from_gdk_name (GTK_VALUE_STRING (*arg)); - - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else { - text->needs_calc_line_widths = 1; - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case ARG_FONT_GDK: - /* Ref the font in case it was the font that is stored - in the e-font */ - gdk_font_ref (GTK_VALUE_POINTER (*arg)); - if (text->font) - e_font_unref (text->font); - - text->font = e_font_from_gdk_font (GTK_VALUE_POINTER (*arg)); - - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else { - text->needs_calc_line_widths = 1; - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case ARG_FONT_E: - if (text->font) - e_font_unref (text->font); - - text->font = GTK_VALUE_POINTER (*arg); - e_font_ref (text->font); - - calc_ellipsis (text); - if (text->line_wrap) - text->needs_split_into_lines = 1; - else { - text->needs_calc_line_widths = 1; - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case ARG_BOLD: - text->bold = GTK_VALUE_BOOL (*arg); - text->style = text->bold ? E_FONT_BOLD : E_FONT_PLAIN; - - text->needs_redraw = 1; - text->needs_recalc_bounds = 1; - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else { - text->needs_calc_line_widths = 1; - text->needs_calc_height = 1; - } - needs_update = 1; - needs_reflow = 1; - break; - - case ARG_STRIKEOUT: - text->strikeout = GTK_VALUE_BOOL (*arg); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_ANCHOR: - text->anchor = GTK_VALUE_ENUM (*arg); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case ARG_JUSTIFICATION: - text->justification = GTK_VALUE_ENUM (*arg); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_CLIP_WIDTH: - text->clip_width = fabs (GTK_VALUE_DOUBLE (*arg)); - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else { - text->needs_calc_line_widths = 1; - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case ARG_CLIP_HEIGHT: - text->clip_height = fabs (GTK_VALUE_DOUBLE (*arg)); - text->needs_recalc_bounds = 1; - needs_reflow = 1; - break; - - case ARG_CLIP: - text->clip = GTK_VALUE_BOOL (*arg); - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else { - text->needs_calc_line_widths = 1; - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case ARG_FILL_CLIP_RECTANGLE: - text->fill_clip_rectangle = GTK_VALUE_BOOL (*arg); - needs_update = 1; - break; - - case ARG_X_OFFSET: - text->xofs = GTK_VALUE_DOUBLE (*arg); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case ARG_Y_OFFSET: - text->yofs = GTK_VALUE_DOUBLE (*arg); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case ARG_FILL_COLOR: - if (GTK_VALUE_STRING (*arg)) - gdk_color_parse (GTK_VALUE_STRING (*arg), &color); - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case ARG_FILL_COLOR_GDK: - pcolor = GTK_VALUE_BOXED (*arg); - if (pcolor) { - color = *pcolor; - } - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case ARG_FILL_COLOR_RGBA: - text->rgba = GTK_VALUE_UINT (*arg); - color.red = ((text->rgba >> 24) & 0xff) * 0x101; - color.green = ((text->rgba >> 16) & 0xff) * 0x101; - color.blue = ((text->rgba >> 8) & 0xff) * 0x101; - color_changed = TRUE; - break; - - case ARG_FILL_STIPPLE: - set_stipple (text, GTK_VALUE_BOXED (*arg), FALSE); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_EDITABLE: - text->editable = GTK_VALUE_BOOL (*arg); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_USE_ELLIPSIS: - text->use_ellipsis = GTK_VALUE_BOOL (*arg); - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_ELLIPSIS: - if (text->ellipsis) - g_free (text->ellipsis); - - text->ellipsis = g_strdup (GTK_VALUE_STRING (*arg)); - calc_ellipsis (text); - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_LINE_WRAP: - text->line_wrap = GTK_VALUE_BOOL (*arg); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_BREAK_CHARACTERS: - if ( text->break_characters ) { - g_free(text->break_characters); - text->break_characters = NULL; - } - if ( GTK_VALUE_STRING (*arg) ) - text->break_characters = g_strdup( GTK_VALUE_STRING (*arg) ); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_MAX_LINES: - text->max_lines = GTK_VALUE_INT (*arg); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_WIDTH: - text->clip_width = fabs (GTK_VALUE_DOUBLE (*arg)); - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else { - text->needs_calc_line_widths = 1; - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case ARG_DRAW_BORDERS: - if (text->draw_borders != GTK_VALUE_BOOL (*arg)) { - text->draw_borders = GTK_VALUE_BOOL (*arg); - text->needs_calc_height = 1; - text->needs_redraw = 1; - needs_reflow = 1; - needs_update = 1; - } - break; - - case ARG_DRAW_BACKGROUND: - if (text->draw_background != GTK_VALUE_BOOL (*arg)){ - text->draw_background = GTK_VALUE_BOOL (*arg); - text->needs_redraw = 1; - } - break; - - case ARG_DRAW_BUTTON: - if (text->draw_button != GTK_VALUE_BOOL (*arg)){ - text->draw_button = GTK_VALUE_BOOL (*arg); - text->needs_redraw = 1; - } - break; - - case ARG_ALLOW_NEWLINES: - text->allow_newlines = GTK_VALUE_BOOL (*arg); - _get_tep(text); - gtk_object_set (GTK_OBJECT (text->tep), - "allow_newlines", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_CURSOR_POS: { - ETextEventProcessorCommand command; - - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = GTK_VALUE_INT (*arg); - command.time = GDK_CURRENT_TIME; - e_text_command (text->tep, &command, text); - break; - } - - default: - return; - } - - if (color_changed) { - if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(item)) - gdk_color_context_query_color (item->canvas->cc, &color); - - text->color = color; - - if (!item->canvas->aa) - set_text_gc_foreground (text); - - text->needs_redraw = 1; - needs_update = 1; - } - - if ( needs_reflow ) - e_canvas_item_request_reflow (item); - if ( needs_update ) - gnome_canvas_item_request_update (item); -} - -/* Get_arg handler for the text item */ -static void -e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EText *text; - GdkColor *color; - - text = E_TEXT (object); - - switch (arg_id) { - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(text->model); - break; - - case ARG_EVENT_PROCESSOR: - _get_tep(text); - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(text->tep); - break; - - case ARG_TEXT: - GTK_VALUE_STRING (*arg) = g_strdup (text->text); - break; - - case ARG_FONT_E: - GTK_VALUE_BOXED (*arg) = text->font; - break; - - case ARG_BOLD: - GTK_VALUE_BOOL (*arg) = text->bold; - break; - - case ARG_STRIKEOUT: - GTK_VALUE_BOOL (*arg) = text->strikeout; - break; - - case ARG_ANCHOR: - GTK_VALUE_ENUM (*arg) = text->anchor; - break; - - case ARG_JUSTIFICATION: - GTK_VALUE_ENUM (*arg) = text->justification; - break; - - case ARG_CLIP_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->clip_width; - break; - - case ARG_CLIP_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->clip_height; - break; - - case ARG_CLIP: - GTK_VALUE_BOOL (*arg) = text->clip; - break; - - case ARG_FILL_CLIP_RECTANGLE: - GTK_VALUE_BOOL (*arg) = text->fill_clip_rectangle; - break; - - case ARG_X_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->xofs; - break; - - case ARG_Y_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->yofs; - break; - - case ARG_FILL_COLOR_GDK: - color = g_new (GdkColor, 1); - *color = text->color; - GTK_VALUE_BOXED (*arg) = color; - break; - - case ARG_FILL_COLOR_RGBA: - GTK_VALUE_UINT (*arg) = text->rgba; - break; - - case ARG_FILL_STIPPLE: - GTK_VALUE_BOXED (*arg) = text->stipple; - break; - - case ARG_TEXT_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->max_width / text->item.canvas->pixels_per_unit; - break; - - case ARG_TEXT_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->height / text->item.canvas->pixels_per_unit; - break; - - case ARG_EDITABLE: - GTK_VALUE_BOOL (*arg) = text->editable; - break; - - case ARG_USE_ELLIPSIS: - GTK_VALUE_BOOL (*arg) = text->use_ellipsis; - break; - - case ARG_ELLIPSIS: - GTK_VALUE_STRING (*arg) = g_strdup (text->ellipsis); - break; - - case ARG_LINE_WRAP: - GTK_VALUE_BOOL (*arg) = text->line_wrap; - break; - - case ARG_BREAK_CHARACTERS: - GTK_VALUE_STRING (*arg) = g_strdup (text->break_characters); - break; - - case ARG_MAX_LINES: - GTK_VALUE_INT (*arg) = text->max_lines; - break; - - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->clip_width; - break; - - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->clip && text->clip_height != -1 ? text->clip_height : text->height / text->item.canvas->pixels_per_unit; - break; - - case ARG_DRAW_BORDERS: - GTK_VALUE_BOOL (*arg) = text->draw_borders; - break; - - case ARG_DRAW_BACKGROUND: - GTK_VALUE_BOOL (*arg) = text->draw_background; - break; - - case ARG_DRAW_BUTTON: - GTK_VALUE_BOOL (*arg) = text->draw_button; - break; - - case ARG_ALLOW_NEWLINES: - GTK_VALUE_BOOL (*arg) = text->allow_newlines; - break; - - case ARG_CURSOR_POS: - GTK_VALUE_INT (*arg) = text->selection_start; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -/* Update handler for the text item */ -static void -e_text_reflow (GnomeCanvasItem *item, int flags) -{ - EText *text; - - text = E_TEXT (item); - - if (text->needs_split_into_lines) { - split_into_lines (text); - - text->needs_split_into_lines = 0; - text->needs_calc_line_widths = 1; - text->needs_calc_height = 1; - } - - if ( text->needs_calc_line_widths ) { - int x; - int i; - struct line *lines; - gdouble clip_width; - calc_line_widths (text); - text->needs_calc_line_widths = 0; - 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 --; - i--; - x = text_width_with_objects (text->model, - text->font, text->style, - lines->text, - text->selection_end - (lines->text - text->text)); - - if (x < text->xofs_edit) { - text->xofs_edit = x; - } - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - if (2 + x - clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - clip_width; - } - - if (e_font_height (text->font) * i < text->yofs_edit) - text->yofs_edit = e_font_height (text->font) * i; - - if ( text->needs_calc_height ) { - calc_height (text); - gnome_canvas_item_request_update(item); - text->needs_calc_height = 0; - text->needs_recalc_bounds = 1; - } - - if (e_font_height (text->font) * (i + 1) - - (text->clip_height != -1 ? text->clip_height : text->height) > text->yofs_edit) - text->yofs_edit = e_font_height (text->font) * (i + 1) - - (text->clip_height != -1 ? text->clip_height : text->height); - - gnome_canvas_item_request_update (item); - } - if ( text->needs_calc_height ) { - calc_height (text); - gnome_canvas_item_request_update(item); - text->needs_calc_height = 0; - text->needs_recalc_bounds = 1; - } -} - -/* Update handler for the text item */ -static void -e_text_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - EText *text; - double x1, y1, x2, y2; - ArtDRect i_bbox, c_bbox; - int i; - - text = E_TEXT (item); - - if (parent_class->update) - (* parent_class->update) (item, affine, clip_path, flags); - - if ( text->needs_recalc_bounds - || (flags & GNOME_CANVAS_UPDATE_AFFINE)) { - if (!item->canvas->aa) { - set_text_gc_foreground (text); - set_stipple (text, text->stipple, TRUE); - get_bounds (text, &x1, &y1, &x2, &y2); - if ( item->x1 != x1 || - item->x2 != x2 || - item->y1 != y1 || - item->y2 != y2 ) { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - item->x1 = x1; - item->y1 = y1; - item->x2 = x2; - item->y2 = y2; - text->needs_redraw = 1; - item->canvas->need_repick = TRUE; - } - } else { - /* aa rendering */ - for (i = 0; i < 6; i++) - text->affine[i] = affine[i]; - get_bounds_item_relative (text, &i_bbox.x0, &i_bbox.y0, &i_bbox.x1, &i_bbox.y1); - art_drect_affine_transform (&c_bbox, &i_bbox, affine); - } - text->needs_recalc_bounds = 0; - } - if ( text->needs_redraw ) { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - text->needs_redraw = 0; - } -} - -/* Realize handler for the text item */ -static void -e_text_realize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - if (parent_class->realize) - (* parent_class->realize) (item); - - text->gc = gdk_gc_new (item->canvas->layout.bin_window); - gdk_color_context_query_color (item->canvas->cc, &text->color); - gdk_gc_set_foreground (text->gc, &text->color); - - text->i_cursor = gdk_cursor_new (GDK_XTERM); - text->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); - if (text->font == NULL) { - gdk_font_ref (GTK_WIDGET (item->canvas)->style->font); - text->font = e_font_from_gdk_font (GTK_WIDGET (item->canvas)->style->font); - } -} - -/* Unrealize handler for the text item */ -static void -e_text_unrealize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - gdk_gc_unref (text->gc); - text->gc = NULL; - - gdk_cursor_destroy (text->i_cursor); - text->i_cursor = NULL; - gdk_cursor_destroy (text->default_cursor); - text->default_cursor = NULL; - - if (parent_class->unrealize) - (* parent_class->unrealize) (item); -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static double -get_line_xpos_item_relative (EText *text, struct line *line) -{ - double x; - - x = 0; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - break; - } - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) * 0.5; - break; - - default: - if (text->draw_borders) - x += BORDER_INDENT; - - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -#if 0 -/* Calculates the y position of the first line of text. */ -static double -get_line_ypos_item_relative (EText *text) -{ - double y; - - y = 0; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - break; - } - - return y; -} -#endif - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (EText *text, struct line *line) -{ - int x; - - x = text->cx; - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) / 2; - break; - - default: - if (text->draw_borders) - x += BORDER_INDENT; - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - - return x; -} - -static void -_get_tep(EText *text) -{ - if (!text->tep) { - text->tep = e_text_event_processor_emacs_like_new(); - gtk_object_ref (GTK_OBJECT (text->tep)); - gtk_object_sink (GTK_OBJECT (text->tep)); - text->tep_command_id = - gtk_signal_connect(GTK_OBJECT(text->tep), - "command", - GTK_SIGNAL_FUNC(e_text_command), - (gpointer) text); - } -} - -/* Draw handler for the text item */ -static void -e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - EText *text; - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc, *main_gc; - GnomeCanvas *canvas; - GtkWidget *widget; - - text = E_TEXT (item); - canvas = GNOME_CANVAS_ITEM(text)->canvas; - widget = GTK_WIDGET(canvas); - - fg_gc = widget->style->fg_gc[text->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - if (text->draw_background || text->draw_button) { - main_gc = widget->style->text_gc[GTK_STATE_NORMAL]; - } else { - main_gc = text->gc; - } - - if (text->draw_borders || text->draw_background) { - gdouble thisx = item->x1 - x; - gdouble thisy = item->y1 - y; - gdouble thiswidth, thisheight; - GtkWidget *widget = GTK_WIDGET(item->canvas); - - gtk_object_get(GTK_OBJECT(text), - "width", &thiswidth, - "height", &thisheight, - NULL); - - if (text->draw_borders){ - - if (text->editing) { - thisx += 1; - thisy += 1; - thiswidth -= 2; - thisheight -= 2; - } - - gtk_paint_shadow (widget->style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_IN, - NULL, widget, "entry", - thisx, thisy, thiswidth, thisheight); - - if (text->editing) { - thisx -= 1; - thisy -= 1; - thiswidth += 2; - thisheight += 2; - /* - * Chris: I am here "filling in" for the additions - * and substractions done in the previous if (text->editing). - * but you might have other plans for this. Please enlighten - * me as to whether it should be: - * thiswidth + 2 or thiswidth + 1. - */ - gtk_paint_focus (widget->style, drawable, - NULL, widget, "entry", - thisx, thisy, thiswidth - 1, thisheight - 1); - } - } - - if (text->draw_background) { - gtk_paint_flat_box (widget->style, drawable, - GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE, - NULL, widget, "entry_bg", - thisx + widget->style->klass->xthickness, - thisy + widget->style->klass->ythickness, - thiswidth - widget->style->klass->xthickness * 2, - thisheight - widget->style->klass->ythickness * 2); - } - } - if (text->draw_button) { - GtkWidget *widget; - int xoff = item->x1 - x; - int yoff = item->y1 - y; - - widget = GTK_WIDGET (item->canvas); - - xoff -= widget->allocation.x; - yoff -= widget->allocation.y; - - widget = widget->parent; - - while (widget && !GTK_IS_BUTTON(widget)) { - if (!GTK_WIDGET_NO_WINDOW (widget)) { - widget = NULL; - break; - } - widget = widget->parent; - } - if (widget) { - GtkButton *button = GTK_BUTTON (widget); - GtkShadowType shadow_type; - int thisx, thisy, thisheight, thiswidth; - int default_spacing; - GdkRectangle area; - area.x = 0; - area.y = 0; - area.width = width; - area.height = height; - -#define DEFAULT_SPACING 7 -#if 0 - default_spacing = gtk_style_get_prop_experimental (widget->style, - "GtkButton::default_spacing", - DEFAULT_SPACING); -#endif - default_spacing = 7; - - thisx = 0; - thisy = 0; - thiswidth = widget->allocation.width - GTK_CONTAINER (widget)->border_width * 2; - thisheight = widget->allocation.height - GTK_CONTAINER (widget)->border_width * 2; - - if (GTK_WIDGET_HAS_DEFAULT (widget) && - GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL) - { - gtk_paint_box (widget->style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_IN, - &area, widget, "buttondefault", - thisx + xoff, thisy + yoff, thiswidth, thisheight); - } - - if (GTK_WIDGET_CAN_DEFAULT (widget)) { - thisx += widget->style->klass->xthickness; - thisy += widget->style->klass->ythickness; - thiswidth -= 2 * thisx + default_spacing; - thisheight -= 2 * thisy + default_spacing; - thisx += (1 + default_spacing) / 2; - thisy += (1 + default_spacing) / 2; - } - - if (GTK_WIDGET_HAS_FOCUS (widget)) { - thisx += 1; - thisy += 1; - thiswidth -= 2; - thisheight -= 2; - } - - if (GTK_WIDGET_STATE (widget) == GTK_STATE_ACTIVE) - shadow_type = GTK_SHADOW_IN; - else - shadow_type = GTK_SHADOW_OUT; - - if ((button->relief != GTK_RELIEF_NONE) || - ((GTK_WIDGET_STATE(widget) != GTK_STATE_NORMAL) && - (GTK_WIDGET_STATE(widget) != GTK_STATE_INSENSITIVE))) - gtk_paint_box (widget->style, drawable, - GTK_WIDGET_STATE (widget), - shadow_type, &area, widget, "button", - thisx + xoff, thisy + yoff, thiswidth, thisheight); - - if (GTK_WIDGET_HAS_FOCUS (widget)) { - thisx -= 1; - thisy -= 1; - thiswidth += 2; - thisheight += 2; - - gtk_paint_focus (widget->style, widget->window, - &area, widget, "button", - thisx + xoff, thisy + yoff, thiswidth - 1, thisheight - 1); - } - } - } - - - if (!text->text || !text->font) - return; - - lines = text->lines; - if ( !lines ) { - text->needs_split_into_lines = 1; - e_canvas_item_request_reflow (item); - return; - } - - clip_rect = NULL; - if (text->clip) { - rect.x = text->clip_cx - x; - rect.y = text->clip_cy - y; - rect.width = text->clip_cwidth; - rect.height = text->clip_cheight; - - gdk_gc_set_clip_rectangle (main_gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - } - ypos = text->cy + e_font_ascent (text->font); - if (text->draw_borders) - ypos += BORDER_INDENT; - - if (text->editing) - ypos -= text->yofs_edit; - - if (text->stipple) - gnome_canvas_set_stipple_origin (item->canvas, main_gc); - - for (i = 0; i < text->num_lines; i++) { - - xpos = get_line_xpos (text, lines); - if (text->editing) { - xpos -= text->xofs_edit; - start_char = lines->text - text->text; - end_char = start_char + lines->length; - sel_start = text->selection_start; - sel_end = text->selection_end; - if (sel_start > sel_end ) { - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if ( sel_start < start_char ) - sel_start = start_char; - if ( sel_end > end_char ) - sel_end = end_char; - if ( sel_start < sel_end ) { - sel_rect.x = xpos - x + text_width_with_objects (text->model, - text->font, text->style, - lines->text, - sel_start - start_char); - sel_rect.y = ypos - y - e_font_ascent (text->font); - sel_rect.width = text_width_with_objects (text->model, - text->font, text->style, - lines->text + sel_start - start_char, - sel_end - sel_start); - sel_rect.height = e_font_height (text->font); - gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, - drawable, - text->has_selection ? - GTK_STATE_SELECTED : - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - GTK_WIDGET(item->canvas), - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - text_draw_with_objects (text->model, - drawable, - text->font, text->style, - main_gc, - xpos - x, - ypos - y, - lines->text, - sel_start - start_char); - text_draw_with_objects (text->model, - drawable, - text->font, text->style, - fg_gc, - xpos - x + text_width_with_objects (text->model, - text->font, text->style, - lines->text, - sel_start - start_char), - ypos - y, - lines->text + sel_start - start_char, - sel_end - sel_start); - text_draw_with_objects (text->model, - drawable, - text->font, text->style, - main_gc, - xpos - x + text_width_with_objects (text->model, - text->font, text->style, - lines->text, - sel_end - start_char), - ypos - y, - lines->text + sel_end - start_char, - end_char - sel_end); - } else { - text_draw_with_objects (text->model, - drawable, - text->font, text->style, - main_gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - if (text->selection_start == text->selection_end && - text->selection_start >= start_char && - text->selection_start <= end_char && - text->show_cursor) { - gdk_draw_rectangle (drawable, - main_gc, - TRUE, - xpos - x + text_width_with_objects (text->model, - text->font, text->style, - lines->text, - sel_start - start_char), - ypos - y - e_font_ascent (text->font), - 1, - e_font_height (text->font)); - } - } else { - if (text->clip && text->use_ellipsis && lines->ellipsis_length < lines->length) { - text_draw_with_objects (text->model, - drawable, - text->font, text->style, - main_gc, - xpos - x, - ypos - y, - lines->text, - lines->ellipsis_length); - e_font_draw_utf8_text (drawable, - text->font, text->style, - main_gc, - xpos - x + lines->width - text->ellipsis_width, - ypos - y, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? strlen (text->ellipsis) : 3); - } else { - text_draw_with_objects (text->model, - drawable, - text->font, text->style, - main_gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - } - - if (text->strikeout) - gdk_draw_rectangle (drawable, - main_gc, - TRUE, - xpos - x, - ypos - y - e_font_ascent (text->font) / 2, - lines->width, 1); - ypos += e_font_height (text->font); - lines++; - } - - if (text->clip) { - gdk_gc_set_clip_rectangle (main_gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); - } -} - -/* Render handler for the text item */ -static void -e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf) -{ -#if 0 - EText *text; - guint32 fg_color; - double xpos, ypos; - struct line *lines; - int i, j; - double affine[6]; - int dx, dy; - ArtPoint start_i, start_c; - - text = E_TEXT (item); - - if (!text->text || !text->font || !text->suckfont) - return; - - suckfont = text->suckfont; - - fg_color = text->rgba; - - gnome_canvas_buf_ensure_buf (buf); - - lines = text->lines; - if ( !lines ) - return; - - start_i.y = get_line_ypos_item_relative (text); - - art_affine_scale (affine, item->canvas->pixels_per_unit, item->canvas->pixels_per_unit); - for (i = 0; i < 6; i++) - affine[i] = text->affine[i]; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - start_i.x = get_line_xpos_item_relative (text, lines); - art_affine_point (&start_c, &start_i, text->affine); - xpos = start_c.x; - ypos = start_c.y; - - for (j = 0; j < lines->length; j++) { - ETextSuckChar *ch; - - ch = &suckfont->chars[(unsigned char)((lines->text)[j])]; - - affine[4] = xpos; - affine[5] = ypos; - art_rgb_bitmap_affine ( - buf->buf, - buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1, - buf->buf_rowstride, - suckfont->bitmap + (ch->bitmap_offset >> 3), - ch->width, - suckfont->bitmap_height, - suckfont->bitmap_width >> 3, - fg_color, - affine, - ART_FILTER_NEAREST, NULL); - - dx = ch->left_sb + ch->width + ch->right_sb; - xpos += dx * affine[0]; - ypos += dx * affine[1]; - } - } - - dy = text->font->ascent + text->font->descent; - start_i.y += dy; - lines++; - } - - buf->is_bg = 0; -#endif -} - -/* Point handler for the text item */ -static double -e_text_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, GnomeCanvasItem **actual_item) -{ - EText *text; - int i; - struct line *lines; - int x1, y1, x2, y2; - int font_height; - int dx, dy; - double dist, best; - - text = E_TEXT (item); - - *actual_item = item; - - /* The idea is to build bounding rectangles for each of the lines of - * text (clipped by the clipping rectangle, if it is activated) and see - * whether the point is inside any of these. If it is, we are done. - * Otherwise, calculate the distance to the nearest rectangle. - */ - - if (text->font) - font_height = e_font_height (text->font); - else - font_height = 0; - - best = 1.0e36; - - lines = text->lines; - - if ( !lines ) { - text->needs_split_into_lines = 1; - e_canvas_item_request_reflow (item); - return 1; - } - - if (text->fill_clip_rectangle) { - double clip_width; - double clip_height; - - if (text->clip_width < 0) - clip_width = text->max_width; - else - clip_width = text->clip_width; - - /* Get canvas pixel coordinates for clip rectangle position */ - clip_width = clip_width * item->canvas->pixels_per_unit; - if ( text->clip_height >= 0 ) - clip_height = text->clip_height * item->canvas->pixels_per_unit; - else - clip_height = text->height * item->canvas->pixels_per_unit; - - if (cx >= text->clip_cx && - cx <= text->clip_cx + clip_width && - cy >= text->clip_cy && - cy <= text->clip_cy + clip_height) - return 0; - else - return 1; - } - - for (i = 0; i < text->num_lines; i++) { - /* Compute the coordinates of rectangle for the current line, - * clipping if appropriate. - */ - - x1 = get_line_xpos (text, lines); - y1 = text->cy + i * font_height; - x2 = x1 + lines->width; - y2 = y1 + font_height; - - if (text->clip) { - if (x1 < text->clip_cx) - x1 = text->clip_cx; - - if (y1 < text->clip_cy) - y1 = text->clip_cy; - - if ( text->clip_width >= 0 ) { - if (x2 > (text->clip_cx + text->clip_width)) - x2 = text->clip_cx + text->clip_width; - } - - if ( text->clip_height >= 0 ) { - if (y2 > (text->clip_cy + text->clip_height)) - y2 = text->clip_cy + text->clip_height; - } - - if ((x1 >= x2) || (y1 >= y2)) - continue; - } - - /* Calculate distance from point to rectangle */ - - if (cx < x1) - dx = x1 - cx; - else if (cx >= x2) - dx = cx - x2 + 1; - else - dx = 0; - - if (cy < y1) - dy = y1 - cy; - else if (cy >= y2) - dy = cy - y2 + 1; - else - dy = 0; - - if ((dx == 0) && (dy == 0)) - return 0.0; - - dist = sqrt (dx * dx + dy * dy); - if (dist < best) - best = dist; - - /* Next! */ - - lines++; - } - - return best / item->canvas->pixels_per_unit; -} - -/* Bounds handler for the text item */ -static void -e_text_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - EText *text; - double width, height; - - text = E_TEXT (item); - - *x1 = 0; - *y1 = 0; - - if (text->clip) { - width = text->clip_width; - if ( text->clip_height >= 0 ) - height = text->clip_height; - else height = text->height; - } else { - width = text->max_width / item->canvas->pixels_per_unit; - height = text->height / item->canvas->pixels_per_unit; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - *x1 -= width / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - *x1 -= width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - *y1 -= height / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - *y1 -= height; - break; - } - - *x2 = *x1 + width; - *y2 = *y1 + height; -} - -static gboolean -_get_xy_from_position (EText *text, gint position, gint *xp, gint *yp) -{ - if (text->lines && (xp || yp)) { - struct line *lines = NULL; - int x, y; - double xd, yd; - int j; - x = get_line_xpos_item_relative (text, lines); - y = text->yofs; - y -= text->yofs_edit; - for (j = 0, lines = text->lines; j < text->num_lines; lines++, j++) { - if (lines->text > text->text + position) - break; - y += e_font_height (text->font); - } - lines --; - y -= e_font_descent (text->font); - - x += text_width_with_objects (text->model, - text->font, text->style, - lines->text, - position - (lines->text - text->text)); - x -= text->xofs_edit; - - xd = x; yd = y; - gnome_canvas_item_i2w (GNOME_CANVAS_ITEM(text), &xd, &yd); - gnome_canvas_w2c (GNOME_CANVAS_ITEM(text)->canvas, xd, yd, &x, &y); - - if (xp) - *xp = x; - if (yp) - *yp = y; - - return TRUE; - } - - return FALSE; -} - -static gint -_get_position_from_xy (EText *text, gint x, gint y) -{ - int i, j; - int ypos = text->yofs; - int xpos; - double xd, yd; - const char *p; - gunichar unival; - gint font_ht, adjust=0; - struct line *lines; - - xd = x; yd = y; - gnome_canvas_c2w (GNOME_CANVAS_ITEM(text)->canvas, xd, yd, &xd, &yd); - gnome_canvas_item_w2i (GNOME_CANVAS_ITEM(text), &xd, &yd); - x = xd; y = yd; - - y += text->yofs_edit; - font_ht = e_font_height (text->font); - - if (text->draw_borders) - ypos += BORDER_INDENT; - - switch (text->anchor) { - case GTK_ANCHOR_WEST: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_EAST: - y += (text->num_lines * font_ht)/2; - break; - case GTK_ANCHOR_SOUTH: - case GTK_ANCHOR_SOUTH_EAST: - case GTK_ANCHOR_SOUTH_WEST: - y += text->num_lines * font_ht; - default: - /* Do nothing */ - break; - } - - - j = 0; - while (y > ypos) { - ypos += font_ht; - j ++; - } - j--; - if (j >= text->num_lines) - j = text->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - lines = text->lines; - - if ( !lines ) - return 0; - - lines += j; - x += text->xofs_edit; - xpos = get_line_xpos_item_relative (text, lines); - - for (i = 0, p = lines->text; p && i < lines->length; i++, p = e_unicode_get_utf8 (p, &unival)) { - int charwidth; - int step1, step2; - -#if 0 - if (unival == '\1') { - const gchar *obj_str = NULL; /*e_text_model_get_nth_object (text->model, object_num);*/ - charwidth = e_font_utf8_text_width (text->font, text->style, obj_str, strlen (obj_str)); - ++object_num; - - step1 = charwidth; - step2 = 0; - adjust = -1; - - } else { -#endif - charwidth = e_font_utf8_char_width (text->font, text->style, (gchar *) p); - - step1 = charwidth / 2; - step2 = (charwidth + 1) / 2; - adjust = 0; -#if 0 - } -#endif - - xpos += step1; - if (xpos > x) { - break; - } - xpos += step2; - } - - if (!p) return 0; - - return MAX (p - text->text + adjust, 0); -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - EText *text = E_TEXT(data); - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed(text->timer, ¤t_time); - - if (text->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > text->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < text->scroll_start) - scroll = TRUE; - } else { - if (current_time > text->scroll_start + SCROLL_WAIT_TIME || - current_time < text->scroll_start) - scroll = TRUE; - } - if (scroll && text->button_down) { - if (text->lastx - text->clip_cx > text->clip_cwidth && - text->xofs_edit < text->max_width - text->clip_cwidth) { - text->xofs_edit += 4; - if (text->xofs_edit > text->max_width - text->clip_cwidth + 1) - text->xofs_edit = text->max_width - text->clip_cwidth + 1; - redraw = TRUE; - } - if (text->lastx - text->clip_cx < 0 && - text->xofs_edit > 0) { - text->xofs_edit -= 4; - if (text->xofs_edit < 0) - text->xofs_edit = 0; - redraw = TRUE; - } - - if (text->lasty - text->clip_cy > text->clip_cheight && - text->yofs_edit < text->height - text->clip_cheight) { - text->yofs_edit += 4; - if (text->yofs_edit > text->height - text->clip_cheight + 1) - text->yofs_edit = text->height - text->clip_cheight + 1; - redraw = TRUE; - } - if (text->lasty - text->clip_cy < 0 && - text->yofs_edit > 0) { - text->yofs_edit -= 4; - if (text->yofs_edit < 0) - text->yofs_edit = 0; - redraw = TRUE; - } - - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = text->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy(text, text->lastx, text->lasty); - _get_tep(text); - e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!text->show_cursor) - redraw = TRUE; - text->show_cursor = TRUE; - } else { - if (text->show_cursor) - redraw = TRUE; - text->show_cursor = FALSE; - } - if (redraw) { - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - } - return TRUE; -} - -static gboolean -tooltip_event(GtkWidget *tooltip, GdkEvent *event, EText *text) -{ - gint ret_val = FALSE; - if (GTK_OBJECT_DESTROYED (text)) { - return FALSE; - } - switch (event->type) { - case GDK_LEAVE_NOTIFY: - e_canvas_hide_tooltip (E_CANVAS(GNOME_CANVAS_ITEM(text)->canvas)); - break; - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - if (event->type == GDK_BUTTON_RELEASE) { - e_canvas_hide_tooltip (E_CANVAS(GNOME_CANVAS_ITEM(text)->canvas)); - } - /* Forward events to the text item */ - gtk_signal_emit_by_name (GTK_OBJECT (text), "event", event, - &ret_val); - if (!ret_val) - gtk_propagate_event (GTK_WIDGET(GNOME_CANVAS_ITEM(text)->canvas), event); - ret_val = TRUE; - default: - break; - } - return ret_val; -} - -static void -tooltip_destroy(GtkWidget *tooltip, EText *text) -{ - text->tooltip_owner = FALSE; - gtk_object_unref (GTK_OBJECT (text)); -} - -static gboolean -_do_tooltip (gpointer data) -{ - EText *text = E_TEXT (data); - struct line *lines; - GtkWidget *canvas; - int i; - gdouble max_width; - gboolean cut_off; - double i2c[6]; - ArtPoint origin = {0, 0}; - ArtPoint pixel_origin; - int canvas_x, canvas_y; - GnomeCanvasItem *tooltip_text; - double tooltip_width; - double tooltip_height; - double tooltip_x; - double tooltip_y; -#if 0 - double x1, x2, y1, y2; -#endif - GnomeCanvasItem *rect; - GtkWidget *tooltip_window; /* GtkWindow for displaying the tooltip */ - - text->tooltip_count = 0; - - lines = text->lines; - - if (E_CANVAS(GNOME_CANVAS_ITEM(text)->canvas)->tooltip_window || text->editing || (!lines)) { - text->tooltip_timeout = 0; - return FALSE; - } - - cut_off = FALSE; - for ( lines = text->lines, i = 0; i < text->num_lines; lines++, i++ ) { - if (lines->length > lines->ellipsis_length) { - cut_off = TRUE; - break; - } - } - if ( ! cut_off ) { - text->tooltip_timeout = 0; - return FALSE; - } - - gnome_canvas_item_i2c_affine(GNOME_CANVAS_ITEM(text), i2c); - art_affine_point (&pixel_origin, &origin, i2c); - - gdk_window_get_origin (GTK_WIDGET(GNOME_CANVAS_ITEM(text)->canvas)->window, &canvas_x, &canvas_y); - pixel_origin.x += canvas_x; - pixel_origin.y += canvas_y; - pixel_origin.x -= (int) gtk_layout_get_hadjustment(GTK_LAYOUT(GNOME_CANVAS_ITEM(text)->canvas))->value; - pixel_origin.y -= (int) gtk_layout_get_vadjustment(GTK_LAYOUT(GNOME_CANVAS_ITEM(text)->canvas))->value; - - tooltip_window = gtk_window_new (GTK_WINDOW_POPUP); - gtk_container_set_border_width (GTK_CONTAINER (tooltip_window), 1); - - canvas = e_canvas_new (); - - gtk_container_add (GTK_CONTAINER (tooltip_window), canvas); - - /* Get the longest line length */ - max_width = 0.0; - for (lines = text->lines, i = 0; i < text->num_lines; lines++, i++) { - gdouble line_width; - - line_width = text_width_with_objects (text->model, text->font, text->style, lines->text, lines->length); - max_width = MAX (max_width, line_width); - } - - rect = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - gnome_canvas_rect_get_type (), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) max_width + 4, - "y2", (double) text->height + 4, - "fill_color", "light gray", - NULL); - - tooltip_text = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - e_text_get_type (), - "anchor", GTK_ANCHOR_NW, - "bold", text->bold, - "strikeout", text->strikeout, - "font_e", text->font, - "text", text->text, - "editable", FALSE, - "clip_width", text->max_lines != 1 ? text->clip_width : max_width, - "clip_height", text->max_lines != 1 ? -1 : (double)text->height, - "clip", TRUE, - "line_wrap", text->line_wrap, - "justification", text->justification, - NULL); - - - - if (text->draw_borders) - e_canvas_item_move_absolute(tooltip_text, 1 + BORDER_INDENT, 1 + BORDER_INDENT); - else - e_canvas_item_move_absolute(tooltip_text, 1, 1); - - - split_into_lines (E_TEXT(tooltip_text)); - calc_height (E_TEXT(tooltip_text)); - calc_line_widths (E_TEXT(tooltip_text)); - gnome_canvas_item_set (tooltip_text, - "clip_height", (double) E_TEXT(tooltip_text)->height, - "clip_width", (double) E_TEXT(tooltip_text)->max_width, - NULL); - tooltip_width = E_TEXT(tooltip_text)->max_width; - tooltip_height = E_TEXT(tooltip_text)->height; - tooltip_x = 0; - tooltip_y = 0; - switch(E_TEXT(tooltip_text)->justification) { - case GTK_JUSTIFY_CENTER: - tooltip_x = - tooltip_width / 2; - break; - case GTK_JUSTIFY_RIGHT: - tooltip_x = tooltip_width / 2; - break; - case GTK_JUSTIFY_FILL: - case GTK_JUSTIFY_LEFT: - tooltip_x = 0; - break; - } - switch(text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - tooltip_y -= tooltip_height / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - tooltip_y -= tooltip_height; - break; - } - switch(E_TEXT(tooltip_text)->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - tooltip_x -= tooltip_width / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - tooltip_x -= tooltip_width; - break; - } - - gnome_canvas_item_set(rect, - "x2", (double) tooltip_width + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), - "y2", (double) tooltip_height + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), - NULL); - - gtk_widget_set_usize (tooltip_window, - tooltip_width + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), - tooltip_height + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0)); - gnome_canvas_set_scroll_region (GNOME_CANVAS(canvas), 0.0, 0.0, - tooltip_width + (text->draw_borders ? BORDER_INDENT * 2 : 0), - (double)tooltip_height + (text->draw_borders ? BORDER_INDENT * 2 : 0)); - gtk_widget_show (canvas); - gtk_widget_realize (tooltip_window); - gtk_signal_connect (GTK_OBJECT(tooltip_window), "event", - GTK_SIGNAL_FUNC(tooltip_event), text); - gtk_signal_connect (GTK_OBJECT(tooltip_window), "destroy", - GTK_SIGNAL_FUNC(tooltip_destroy), text); - gtk_object_ref (GTK_OBJECT (text)); - - e_canvas_popup_tooltip (E_CANVAS(GNOME_CANVAS_ITEM(text)->canvas), - tooltip_window, - pixel_origin.x - 2 + tooltip_x, - pixel_origin.y - 2 + tooltip_y); - text->tooltip_owner = TRUE; - - text->tooltip_timeout = 0; - return FALSE; -} - -static void -start_editing (EText *text) -{ - if (text->editing) - return; - - g_free (text->revert); - text->revert = g_strdup (text->text); - - text->editing = TRUE; - if (text->pointer_in) { - if (text->default_cursor_shown && (!text->draw_borders)) { - gdk_window_set_cursor (GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - text->select_by_word = FALSE; - text->xofs_edit = 0; - text->yofs_edit = 0; - if (text->timeout_id == 0) - text->timeout_id = g_timeout_add(10, _blink_scroll_timeout, text); - text->timer = g_timer_new(); - g_timer_elapsed(text->timer, &(text->scroll_start)); - g_timer_start(text->timer); -} - -void -e_text_stop_editing (EText *text) -{ - if (!text->editing) - return; - - g_free (text->revert); - text->revert = NULL; - - text->editing = FALSE; - if ( (!text->default_cursor_shown) && (!text->draw_borders) ) { - gdk_window_set_cursor (GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - if (text->timer) { - g_timer_stop(text->timer); - g_timer_destroy(text->timer); - text->timer = NULL; - } -} - -void -e_text_cancel_editing (EText *text) -{ - if (text->revert) - e_text_model_set_text(text->model, text->revert); - e_text_stop_editing (text); -} - -static gboolean -_click (gpointer data) -{ - *(gint *)data = 0; - return FALSE; -} - -static gint -e_text_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EText *text = E_TEXT(item); - ETextEventProcessorEvent e_tep_event; - - gint return_val = 0; - - if (GTK_OBJECT_DESTROYED (item)) - return FALSE; - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (text->editable) { - GdkEventFocus *focus_event; - focus_event = (GdkEventFocus *) event; - if (focus_event->in) { - start_editing (text); - } else { - e_text_stop_editing (text); - if (text->timeout_id) { - g_source_remove(text->timeout_id); - text->timeout_id = 0; - } - } - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text)); - } - return_val = 0; - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (text->editing) { - GdkEventKey key = event->key; - gint ret; - - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - - /* This is probably ugly hack, but we have to handle UTF-8 input somehow */ -#if 0 - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; -#else - e_tep_event.key.string = e_utf8_from_gtk_event_key (GTK_WIDGET (item->canvas), key.keyval, key.string); - if (e_tep_event.key.string != NULL) { - e_tep_event.key.length = strlen (e_tep_event.key.string); - } else { - e_tep_event.key.length = 0; - } -#endif - _get_tep(text); - ret = e_text_event_processor_handle_event (text->tep, &e_tep_event); - - if (event->type == GDK_KEY_PRESS) - gtk_signal_emit (GTK_OBJECT (text), e_text_signals[E_TEXT_KEYPRESS], - e_tep_event.key.keyval, e_tep_event.key.state); - - - if (e_tep_event.key.string) - g_free (e_tep_event.key.string); - - - return ret; - } - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - if (text->tooltip_timeout) { - gtk_timeout_remove (text->tooltip_timeout); - text->tooltip_timeout = 0; - } - e_canvas_hide_tooltip (E_CANVAS(GNOME_CANVAS_ITEM(text)->canvas)); -#if 0 - if ((!text->editing) - && text->editable - && event->type == GDK_BUTTON_RELEASE - && event->button.button == 1) { - GdkEventButton button = event->button; - - e_canvas_item_grab_focus (item, TRUE); - - e_tep_event.type = GDK_BUTTON_RELEASE; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy(text, button.x, button.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - e_tep_event.type = GDK_BUTTON_RELEASE; - } -#else - if ((!text->editing) - && text->editable - && (event->button.button == 1 || - event->button.button == 2)) { - e_canvas_item_grab_focus (item, TRUE); - start_editing (text); - } -#endif - - /* We follow convention and emit popup events on right-clicks. */ - if (event->type == GDK_BUTTON_PRESS && event->button.button == 3) { - gtk_signal_emit (GTK_OBJECT (text), - e_text_signals[E_TEXT_POPUP], - &(event->button), - _get_position_from_xy (text, event->button.x, event->button.y)); - - break; - } - - /* Create our own double and triple click events, - as gnome-canvas doesn't forward them to us */ - if (event->type == GDK_BUTTON_PRESS) { - if (text->dbl_timeout == 0 && - text->tpl_timeout == 0) { - text->dbl_timeout = gtk_timeout_add (200, - _click, - &(text->dbl_timeout)); - } else { - if (text->tpl_timeout == 0) { - e_tep_event.type = GDK_2BUTTON_PRESS; - text->tpl_timeout = gtk_timeout_add (200, _click, &(text->tpl_timeout)); - } else { - e_tep_event.type = GDK_3BUTTON_PRESS; - } - } - } - - if (text->editing) { - GdkEventButton button = event->button; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy(text, button.x, button.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - text->button_down = TRUE; - else - text->button_down = FALSE; - } - text->lastx = button.x; - text->lasty = button.y; - text->last_state = button.state; - } - break; - case GDK_MOTION_NOTIFY: - if (text->editing) { - GdkEventMotion motion = event->motion; - e_tep_event.motion.time = motion.time; - e_tep_event.motion.state = motion.state; - e_tep_event.motion.position = _get_position_from_xy(text, motion.x, motion.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->lastx = motion.x; - text->lasty = motion.y; - text->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: - { -#if 0 - GdkEventCrossing *crossing = (GdkEventCrossing *) event; - double x1, y1, x2, y2; - split_into_lines (text); - calc_height (text); - calc_line_widths (text); - get_bounds (text, &x1, &y1, &x2, &y2); - if (crossing->x >= x1 && - crossing->y >= y1 && - crossing->x <= x2 && - crossing->y <= y2) { -#endif - if ( text->tooltip_count == 0 && text->clip) { - if (!text->tooltip_timeout) - text->tooltip_timeout = gtk_timeout_add (1000, _do_tooltip, text); - } - text->tooltip_count ++; -#if 0 - } -#endif - } - - text->pointer_in = TRUE; - if (text->editing || text->draw_borders) { - if ( text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: - if (text->tooltip_count > 0) - text->tooltip_count --; - if ( text->tooltip_count == 0 && text->clip) { - if ( text->tooltip_timeout ) { - gtk_timeout_remove (text->tooltip_timeout); - text->tooltip_timeout = 0; - } - } - - text->pointer_in = FALSE; - if (text->editing || text->draw_borders) { - if ( ! text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - if (return_val) - return return_val; - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); - else - return 0; -} - -/* fixme: */ - -static int -_get_position(EText *text, ETextEventProcessorCommand *command) -{ - int length, obj_num; - int x, y; - gunichar unival; - char *p = NULL; - gint new_pos = 0; - - switch (command->position) { - - case E_TEP_VALUE: - new_pos = command->value; - break; - - case E_TEP_SELECTION: - new_pos = text->selection_end; - break; - - case E_TEP_START_OF_BUFFER: - new_pos = 0; - break; - - case E_TEP_END_OF_BUFFER: - new_pos = strlen (text->text); - break; - - case E_TEP_START_OF_LINE: - - new_pos = 0; - - if (text->selection_end >= 1) { - - p = g_utf8_find_prev_char (text->text, text->text + text->selection_end); - if (p != text->text) { - p = g_utf8_find_prev_char (text->text, p); - - while (p && p > text->text && !new_pos) { - if (*p == '\n') - new_pos = p - text->text + 1; - p = g_utf8_find_prev_char (text->text, p); - } - } - } - - break; - - case E_TEP_END_OF_LINE: - new_pos = -1; - length = strlen (text->text); - - if (text->selection_end >= length) { - new_pos = length; - } else { - - p = g_utf8_next_char (text->text + text->selection_end); - - while (p && *p && g_unichar_validate (g_utf8_get_char (p))) { - if (*p == '\n') { - new_pos = p - text->text; - p = NULL; - } else - p = g_utf8_next_char (p); - } - } - - if (new_pos == -1) - new_pos = p - text->text; - - break; - - case E_TEP_FORWARD_CHARACTER: - length = strlen (text->text); - - if (text->selection_end >= length) { - new_pos = length; - } else { - p = g_utf8_next_char (text->text + text->selection_end); - new_pos = p - text->text; - } - - break; - - case E_TEP_BACKWARD_CHARACTER: - new_pos = 0; - if (text->selection_end >= 1) { - p = g_utf8_find_prev_char (text->text, text->text + text->selection_end); - - if (p != NULL) - new_pos = p - text->text; - } - - break; - - case E_TEP_FORWARD_WORD: - new_pos = -1; - length = strlen (text->text); - - if (text->selection_end >= length) { - new_pos = length; - } else { - - p = g_utf8_next_char (text->text + text->selection_end); - - while (p && *p && g_unichar_validate (g_utf8_get_char (p))) { - unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) { - new_pos = p - text->text; - p = NULL; - } else - p = g_utf8_next_char (p); - } - } - - if (new_pos == -1) - new_pos = p - text->text; - - break; - - case E_TEP_BACKWARD_WORD: - new_pos = 0; - if (text->selection_end >= 1) { - p = g_utf8_find_prev_char (text->text, text->text + text->selection_end); - if (p != text->text) { - p = g_utf8_find_prev_char (text->text, p); - - while (p && p > text->text && g_unichar_validate (g_utf8_get_char (p))) { - unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) { - new_pos = g_utf8_next_char (p) - text->text; - p = NULL; - } else - p = g_utf8_find_prev_char (text->text, p); - } - } - } - - break; - - case E_TEP_FORWARD_LINE: - if (_get_xy_from_position(text, text->selection_end, &x, &y)) { - y += e_font_height (text->font); - new_pos = _get_position_from_xy(text, x, y); - } - break; - - case E_TEP_BACKWARD_LINE: - if (_get_xy_from_position(text, text->selection_end, &x, &y)) { - y -= e_font_height (text->font); - new_pos = _get_position_from_xy(text, x, y); - } - break; - - case E_TEP_SELECT_WORD: - - /* This is a silly hack to cause double-clicking on an object - to activate that object. - (Normally, double click == select word, which is why this is here.) */ - - obj_num = e_text_model_get_object_at_offset (text->model, text->selection_start); - if (obj_num != -1) { - e_text_model_activate_nth_object (text->model, obj_num); - new_pos = text->selection_start; - break; - } - - - if (text->selection_end < 1) { - new_pos = 0; - break; - } - - p = g_utf8_find_prev_char (text->text, text->text + text->selection_end); - if (p == text->text) { - new_pos = 0; - break; - } - p = g_utf8_find_prev_char (text->text, p); - - while (p && p > text->text && g_unichar_validate (g_utf8_get_char (p))) { - unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) { - p = g_utf8_next_char (p); - break; - } - p = g_utf8_find_prev_char (text->text, p); - } - - if (!p) - text->selection_start = 0; - else - text->selection_start = p - text->text; - - - text->selection_start = e_text_model_validate_position (text->model, text->selection_start); - - length = strlen (text->text); - if (text->selection_end >= length) { - new_pos = length; - break; - } - - p = g_utf8_next_char (text->text + text->selection_end); - - while (p && *p && g_unichar_validate (g_utf8_get_char (p))) { - unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) { - new_pos = p - text->text; - p = NULL; - } else - p = g_utf8_next_char (p); - } - - if (p) - new_pos = p - text->text; - - return new_pos; - - case E_TEP_SELECT_ALL: - text->selection_start = 0; - new_pos = strlen (text->text); - break; - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - new_pos = text->selection_end; - break; - - default: - new_pos = text->selection_end; - break; - } - - new_pos = e_text_model_validate_position (text->model, new_pos); - - return new_pos; -} - -static void -_delete_selection(EText *text) -{ - if ( text->selection_start < text->selection_end ) { - e_text_model_delete(text->model, text->selection_start, text->selection_end - text->selection_start); -#if 0 - text->selection_end = text->selection_start; -#endif - } else { - e_text_model_delete(text->model, text->selection_end, text->selection_start - text->selection_end); -#if 0 - text->selection_start = text->selection_end; -#endif - } -} - -static void -_insert(EText *text, char *string, int value) -{ - if (value > 0) { - if (!text->allow_newlines) { - char *i; - for (i = string; *i; i++) { - if (*i == '\n') { - char *new_string = g_malloc (strlen (string) + 1); - char *j = new_string; - for (i = string; *i; i++) { - if (*i != '\n') - *(j++) = *i; - } - *j = 0; - e_text_model_insert_length(text->model, text->selection_start, new_string, j - new_string); - g_free (new_string); - return; - } - } - } - e_text_model_insert_length(text->model, text->selection_start, string, value); - -#if 0 - text->selection_start += value; - text->selection_end = text->selection_start; -#endif - } -} - -static void -e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - EText *text = E_TEXT(data); - int sel_start, sel_end; - gboolean scroll = TRUE; - - switch (command->action) { - case E_TEP_MOVE: - text->selection_start = _get_position(text, command); - text->selection_end = text->selection_start; - if (text->timer) { - g_timer_reset(text->timer); - } - - break; - case E_TEP_SELECT: - text->selection_start = e_text_model_validate_position (text->model, text->selection_start); /* paranoia */ - text->selection_end = _get_position(text, command); - - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - - sel_start = e_text_model_validate_position (text->model, sel_start); - - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, GDK_SELECTION_PRIMARY, - (guchar *) text->text + sel_start, sel_end - sel_start); - } else if (text->timer) { - g_timer_reset(text->timer); - } - - break; - case E_TEP_DELETE: - if (text->selection_end == text->selection_start) { - text->selection_end = _get_position(text, command); - } - _delete_selection(text); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - - case E_TEP_INSERT: - if (text->selection_end != text->selection_start) { - _delete_selection(text); - } - _insert(text, command->string, command->value); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_COPY: - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, clipboard_atom, - (guchar *) text->text + sel_start, sel_end - sel_start); - } - if (text->timer) { - g_timer_reset(text->timer); - } - scroll = FALSE; - break; - case E_TEP_PASTE: - e_text_get_selection (text, clipboard_atom, command->time); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_GET_SELECTION: - e_text_get_selection (text, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - gtk_signal_emit (GTK_OBJECT (text), e_text_signals[E_TEXT_ACTIVATE]); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SET_SELECT_BY_WORD: - text->select_by_word = command->value; - break; - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text->i_cursor, - command->time); - scroll = FALSE; - break; - case E_TEP_UNGRAB: - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - scroll = FALSE; - break; - case E_TEP_NOP: - scroll = FALSE; - break; - } - - if (scroll && !text->button_down) { - int x; - int i; - struct line *lines = text->lines; - gdouble clip_width; - 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 --; - i --; - x = text_width_with_objects (text->model, - text->font, text->style, - lines->text, - text->selection_end - (lines->text - text->text)); - - - if (x < text->xofs_edit) { - text->xofs_edit = x; - } - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - if (2 + x - clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - clip_width; - } - - if (e_font_height (text->font) * i < text->yofs_edit) - text->yofs_edit = e_font_height (text->font) * i; - - if (e_font_height (text->font) * (i + 1) - (text->clip_height != -1 ? text->clip_height : text->height) > text->yofs_edit) - text->yofs_edit = e_font_height (text->font) * (i + 1) - (text->clip_height != -1 ? text->clip_height : text->height); - } - - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -} - -static void -_invisible_destroy (GtkInvisible *invisible, - EText *text) -{ - text->invisible = NULL; -} - -static GtkWidget * -e_text_get_invisible(EText *text) -{ - GtkWidget *invisible; - if (text->invisible) { - invisible = text->invisible; - } else { - static const GtkTargetEntry targets[] = { - { "UTF8_STRING", 0, TARGET_UTF8_STRING }, - { "UTF-8", 0, TARGET_UTF8 }, - { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, - { "STRING", 0, TARGET_STRING }, - { "TEXT", 0, TARGET_TEXT } - }; - static const gint n_targets = sizeof(targets) / sizeof(targets[0]); - - invisible = gtk_invisible_new(); - text->invisible = invisible; - - gtk_selection_add_targets (invisible, - GDK_SELECTION_PRIMARY, - targets, n_targets); - gtk_selection_add_targets (invisible, - clipboard_atom, - targets, n_targets); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - text); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - text); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (text->primary_selection); - text->primary_selection = NULL; - text->primary_length = 0; - - text->has_selection = FALSE; - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - - } else if (event->selection == clipboard_atom) { - g_free (text->clipboard_selection); - text->clipboard_selection = NULL; - text->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text) -{ - char *selection_string; - int selection_length; - if (selection_data->selection == GDK_SELECTION_PRIMARY) { - selection_string = text->primary_selection; - selection_length = text->primary_length; - } else /* CLIPBOARD */ { - selection_string = text->clipboard_selection; - selection_length = text->clipboard_length; - } - - if (selection_string != NULL) { - if (info == TARGET_UTF8_STRING) { - gtk_selection_data_set (selection_data, - gdk_atom_intern ("UTF8_STRING", FALSE), 8, - (const guchar *) selection_string, - selection_length); - } else if (info == TARGET_UTF8) { - gtk_selection_data_set (selection_data, - gdk_atom_intern ("UTF-8", FALSE), 8, - (const guchar *) selection_string, - selection_length); - } else if (info == TARGET_STRING || info == TARGET_TEXT || info == TARGET_COMPOUND_TEXT) { - gchar *localized_string; - - localized_string = e_utf8_to_gtk_string (GTK_WIDGET (GNOME_CANVAS_ITEM(text)->canvas), - selection_string); - - if (info == TARGET_STRING) { - gtk_selection_data_set (selection_data, - GDK_SELECTION_TYPE_STRING, 8, - (const guchar *) localized_string, - strlen (localized_string)); - } else { - guchar *text; - GdkAtom encoding; - gint format; - gint new_length; - - gdk_string_to_compound_text (localized_string, - &encoding, &format, - &text, &new_length); - - gtk_selection_data_set (selection_data, - encoding, format, - text, new_length); - gdk_free_compound_text (text); - } - g_free (localized_string); - } - } -} - -typedef struct { - guint32 time; - GdkAtom selection; -} SelectionAndTime; - -static const char *formats[] = {"UTF8_STRING", "UTF-8", "STRING"}; -#define E_STRING_ATOM 2 -static const int format_count = sizeof (formats) / sizeof (formats[0]); -static GdkAtom atoms[sizeof (formats) / sizeof (formats[0])]; -static int initialized = FALSE; - -static inline void -init_atoms (void) -{ - int type; - if (!initialized) { - for (type = 0; type < format_count; type++) - atoms[type] = gdk_atom_intern (formats[type], FALSE); - initialized = TRUE; - } -} - -static void -e_text_request_paste (EText *text) -{ - GdkAtom format_atom; - GtkWidget *invisible; - int type = text->last_type_request; - - init_atoms (); - - format_atom = GDK_NONE; - - while (format_atom == GDK_NONE) { - type ++; - - if (type >= format_count) { - if (text->queued_requests) { - guint32 *new_time = text->queued_requests->data; - text->queued_requests = g_list_remove_link (text->queued_requests, text->queued_requests); - text->last_time_request = *new_time; - g_free (new_time); - - type = -1; - } else { - text->last_type_request = -1; - text->last_time_request = 0; - return; - } - } - - format_atom = atoms [type]; - } - - /* And request the format target for the required selection */ - invisible = e_text_get_invisible(text); - gtk_selection_convert(invisible, - text->last_selection_request, - format_atom, - text->last_time_request); - - text->last_type_request = type; - return; -} - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text) -{ - init_atoms (); - if (selection_data->length < 0) { - e_text_request_paste (text); - return; - } else if (selection_data->type == atoms[E_STRING_ATOM]) { - ETextEventProcessorCommand command; - char *string; - - string = e_utf8_from_gtk_string_sized (GTK_WIDGET (GNOME_CANVAS_ITEM(text)->canvas), - selection_data->data, - selection_data->length); - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = string; - command.value = strlen (string); - command.time = time; - e_text_command(text->tep, &command, text); - g_free (string); - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_text_command(text->tep, &command, text); - } - text->last_type_request = -1; - if (text->queued_requests) { - SelectionAndTime *new_request = text->queued_requests->data; - text->queued_requests = g_list_remove_link (text->queued_requests, text->queued_requests); - text->last_time_request = new_request->time; - text->last_selection_request = new_request->selection; - g_free (new_request); - e_text_request_paste (text); - } -} - - - -static void -e_text_get_selection(EText *text, GdkAtom selection, guint32 time) -{ - if (text->last_type_request == -1) { - text->last_time_request = time; - text->last_selection_request = selection; - e_text_request_paste (text); - } else { - SelectionAndTime *new_request = g_new (SelectionAndTime, 1); - new_request->time = time; - new_request->selection = selection; - /* FIXME: Queue the selection request type as well. */ - text->queued_requests = g_list_append (text->queued_requests, new_request); - } -} - -static void -e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_text_get_invisible(text); - - if (selection == GDK_SELECTION_PRIMARY ) { - g_free (text->primary_selection); - text->primary_selection = g_strndup(data, length); - text->primary_length = length; - } else if (selection == clipboard_atom) { - g_free (text->clipboard_selection); - text->clipboard_selection = g_strndup(data, length); - text->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - text->has_selection = successful; -} - -#if 0 -static void -e_text_real_copy_clipboard (EText *text) -{ - guint32 time; - gint selection_start_pos; - gint selection_end_pos; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = gtk_text_get_event_time (text); - selection_start_pos = MIN (text->selection_start, text->selection_end); - selection_end_pos = MAX (text->selection_start, text->selection_end); - - if (selection_start_pos != selection_end_pos) - { - if (gtk_selection_owner_set (GTK_WIDGET (text->canvas), - clipboard_atom, - time)) - text->clipboard_text = ""; - } -} - -static void -e_text_real_paste_clipboard (EText *text) -{ - guint32 time; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = e_text_get_event_time (text); - if (text->editable) - gtk_selection_convert (GTK_WIDGET(text->widget), - clipboard_atom, - gdk_atom_intern ("COMPOUND_TEXT", FALSE), time); -} -#endif - - -#if 0 -/* Routines for sucking fonts from the X server */ - -static ETextSuckFont * -e_suck_font (GdkFont *font) -{ - ETextSuckFont *suckfont; - int i; - int x, y; - char text[1]; - int lbearing, rbearing, ch_width, ascent, descent; - GdkPixmap *pixmap; - GdkColor black, white; - GdkImage *image; - GdkGC *gc; - guchar *line; - int width, height; - int black_pixel, pixel; - - if (!font) - return NULL; - - suckfont = g_new (ETextSuckFont, 1); - - height = font->ascent + font->descent; - x = 0; - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_text_extents (font, text, 1, - &lbearing, &rbearing, &ch_width, &ascent, &descent); - suckfont->chars[i].left_sb = lbearing; - suckfont->chars[i].right_sb = ch_width - rbearing; - suckfont->chars[i].width = rbearing - lbearing; - suckfont->chars[i].ascent = ascent; - suckfont->chars[i].descent = descent; - suckfont->chars[i].bitmap_offset = x; - x += (ch_width + 31) & -32; - } - - width = x; - - suckfont->bitmap_width = width; - suckfont->bitmap_height = height; - suckfont->ascent = font->ascent; - - pixmap = gdk_pixmap_new (NULL, suckfont->bitmap_width, - suckfont->bitmap_height, 1); - gc = gdk_gc_new (pixmap); - gdk_gc_set_font (gc, font); - - black_pixel = BlackPixel (gdk_display, DefaultScreen (gdk_display)); - black.pixel = black_pixel; - white.pixel = WhitePixel (gdk_display, DefaultScreen (gdk_display)); - gdk_gc_set_foreground (gc, &white); - gdk_draw_rectangle (pixmap, gc, 1, 0, 0, width, height); - - gdk_gc_set_foreground (gc, &black); - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_draw_text (pixmap, font, gc, - suckfont->chars[i].bitmap_offset - suckfont->chars[i].left_sb, - font->ascent, - text, 1); - } - - /* The handling of the image leaves me with distinct unease. But this - * is more or less copied out of gimp/app/text_tool.c, so it _ought_ to - * work. -RLL - */ - - image = gdk_image_get (pixmap, 0, 0, width, height); - suckfont->bitmap = g_malloc0 ((width >> 3) * height); - - line = suckfont->bitmap; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - pixel = gdk_image_get_pixel (image, x, y); - if (pixel == black_pixel) - line[x >> 3] |= 128 >> (x & 7); - } - line += width >> 3; - } - - gdk_image_destroy (image); - - /* free the pixmap */ - gdk_pixmap_unref (pixmap); - - /* free the gc */ - gdk_gc_destroy (gc); - - return suckfont; -} - -static void -e_suck_font_free (ETextSuckFont *suckfont) -{ - g_free (suckfont->bitmap); - g_free (suckfont); -} -#endif diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h deleted file mode 100644 index a5deedad3b..0000000000 --- a/widgets/text/e-text.h +++ /dev/null @@ -1,272 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text.h - Text item for evolution. - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Jon Trowbridge <trow@ximian.com> - * - * 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> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef E_TEXT_H -#define E_TEXT_H - -#include <gtk/gtkobject.h> -#include <gtk/gtkpacker.h> - -#include <gal/widgets/e-font.h> -#include <gal/util/e-text-event-processor.h> -#include <gal/e-text/e-text-model.h> -#include <gal/widgets/e-canvas.h> - -BEGIN_GNOME_DECLS - - -/* Text item for the canvas. Text items are positioned by an anchor point and an anchor direction. - * - * A clipping rectangle may be specified for the text. The rectangle is anchored at the text's anchor - * point, and is specified by clipping width and height parameters. If the clipping rectangle is - * enabled, it will clip the text. - * - * In addition, x and y offset values may be specified. These specify an offset from the anchor - * position. If used in conjunction with the clipping rectangle, these could be used to implement - * simple scrolling of the text within the clipping rectangle. - * - * The following object arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - * text string RW The string of the text label - * font string W X logical font descriptor - * fontset string W X logical fontset descriptor - * font_gdk GdkFont* RW Pointer to a GdkFont - * bold boolean RW Bold? - * anchor GtkAnchorType RW Anchor side for the text - * justification GtkJustification RW Justification for multiline text - * fill_color string W X color specification for text - * fill_color_gdk GdkColor* RW Pointer to an allocated GdkColor - * fill_stipple GdkBitmap* RW Stipple pattern for filling the text - * clip_width double RW Width of clip rectangle - * clip_height double RW Height of clip rectangle - * clip boolean RW Use clipping rectangle? - * fill_clip_rect boolean RW Whether the text item represents itself as being the size of the clipping rectangle. - * x_offset double RW Horizontal offset distance from anchor position - * y_offset double RW Vertical offset distance from anchor position - * text_width double R Used to query the width of the rendered text - * text_height double R Used to query the rendered height of the text - * width double RW A synonym for clip_width - * height double R A synonym for text_height - * - * These are currently ignored in the AA version: - * editable boolean RW Can this item be edited - * use_ellipsis boolean RW Whether to use ellipsises if text gets cut off. Meaningless if clip == false. - * ellipsis string RW The characters to use as ellipsis. NULL = "...". - * line_wrap boolean RW Line wrap when not editing. - * break_characters string RW List of characters to optionally break on. - * max_lines int RW Number of lines possible when doing line wrap. - * draw_borders boolean RW Whether to draw borders. - * draw_background boolean RW Whether to draw the background. - * draw_button boolean RW This makes EText handle being the child of a button properly and highlighting as it should. - */ - -#define E_TYPE_TEXT (e_text_get_type ()) -#define E_TEXT(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT, EText)) -#define E_TEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT, ETextClass)) -#define E_IS_TEXT(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT)) -#define E_IS_TEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT)) - - -typedef struct _EText EText; -typedef struct _ETextClass ETextClass; - -#if 0 -typedef struct _ETextSuckFont ETextSuckFont; -typedef struct _ETextSuckChar ETextSuckChar; - -struct _ETextSuckChar { - int left_sb; - int right_sb; - int width; - int ascent; - int descent; - int bitmap_offset; /* in pixels */ -}; - -struct _ETextSuckFont { - guchar *bitmap; - gint bitmap_width; - gint bitmap_height; - gint ascent; - ETextSuckChar chars[256]; -}; -#endif - -struct _EText { - GnomeCanvasItem item; - - ETextModel *model; - gint model_changed_signal_id; - gint model_repos_signal_id; - - const gchar *text; /* Text to display --- from the ETextModel */ - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - - gchar *revert; /* Text to revert to */ - -#if 0 - GdkFont *font; /* Font for text */ -#else - EFont *font; -#endif - GtkAnchorType anchor; /* Anchor side for text */ - GtkJustification justification; /* Justification for text */ - - double clip_width; /* Width of optional clip rectangle */ - double clip_height; /* Height of optional clip rectangle */ - - double xofs, yofs; /* Text offset distance from anchor position */ - - GdkColor color; /* Fill color */ - GdkBitmap *stipple; /* Stipple for text */ - GdkGC *gc; /* GC for drawing text */ - - int cx, cy; /* Top-left canvas coordinates for text */ - int clip_cx, clip_cy; /* Top-left canvas coordinates for clip rectangle */ - int clip_cwidth, clip_cheight; /* Size of clip rectangle in pixels */ - int max_width; /* Maximum width of text lines */ - int width; /* Rendered text width in pixels */ - int height; /* Rendered text height in pixels */ - - /* Antialiased specific stuff follows */ -#if 0 - ETextSuckFont *suckfont; /* Sucked font */ -#endif - guint32 rgba; /* RGBA color for text */ - double affine[6]; /* The item -> canvas affine */ - - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - double ellipsis_width; /* The width of the ellipsis. */ - - int xofs_edit; /* Offset because of editing */ - int yofs_edit; /* Offset because of editing */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection IN BYTES */ - int selection_end; /* End of selection IN BYTES */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - gint timeout_id; /* Current timeout id for scrolling */ - GTimer *timer; /* Timer for blinking cursor and scrolling */ - - gint lastx, lasty; /* Last x and y motion events */ - gint last_state; /* Last state */ - gulong scroll_start; /* Starting time for scroll (microseconds) */ - - gint show_cursor; /* Is cursor currently shown */ - gboolean button_down; /* Is mouse button 1 down */ - - ETextEventProcessor *tep; /* Text Event Processor */ - gint tep_command_id; - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length*/ - - guint clip : 1; /* Use clip rectangle? */ - guint fill_clip_rectangle : 1; /* Fill the clipping rectangle. */ - - guint pointer_in : 1; /* Is the pointer currently over us? */ - guint default_cursor_shown : 1; /* Is the default cursor currently shown? */ - guint draw_borders : 1; /* Draw borders? */ - guint draw_background : 1; /* Draw background? */ - guint draw_button : 1; /* Draw button? */ - - guint line_wrap : 1; /* Do line wrap */ - - guint needs_redraw : 1; /* Needs redraw */ - guint needs_recalc_bounds : 1; /* Need recalc_bounds */ - guint needs_calc_height : 1; /* Need calc_height */ - guint needs_calc_line_widths : 1; /* Needs calc_line_widths */ - guint needs_split_into_lines : 1; /* Needs split_into_lines */ - - guint bold : 1; - guint strikeout : 1; - - guint tooltip_owner : 1; - guint allow_newlines : 1; - - guint use_ellipsis : 1; /* Whether to use the ellipsis. */ - - guint editable : 1; /* Item is editable */ - guint editing : 1; /* Item is currently being edited */ - - EFontStyle style; - - gchar *break_characters; /* Characters to optionally break after */ - - gint max_lines; /* Max number of lines (-1 = infinite) */ - - GdkCursor *default_cursor; /* Default cursor (arrow) */ - GdkCursor *i_cursor; /* I beam cursor */ - - gint tooltip_timeout; /* Timeout for the tooltip */ - gint tooltip_count; /* GDK_ENTER_NOTIFY count. */ - - gint dbl_timeout; /* Double click timeout */ - gint tpl_timeout; /* Triple click timeout */ - - gint last_type_request; /* Last selection type requested. */ - guint32 last_time_request; /* The time of the last selection request. */ - guint32 last_selection_request; /* The time of the last selection request. */ - GList *queued_requests; /* Queued selection requests. */ -}; - -struct _ETextClass { - GnomeCanvasItemClass parent_class; - - void (* changed) (EText *text); - void (* activate) (EText *text); - void (* keypress) (EText *text, guint keyval, guint state); - void (* popup) (EText *text, GdkEventButton *ev, gint pos); -}; - - -/* Standard Gtk function */ -GtkType e_text_get_type (void); -void e_text_cancel_editing (EText *text); -void e_text_stop_editing (EText *text); - -END_GNOME_DECLS - -#endif |