diff options
author | Chris Toshok <toshok@ximian.com> | 2003-02-10 10:21:47 +0800 |
---|---|---|
committer | Chris Toshok <toshok@src.gnome.org> | 2003-02-10 10:21:47 +0800 |
commit | 18d96c5ff3a43c4ca830a08a1f0a76a2a002895e (patch) | |
tree | 545ad68d32baf1c78a2a43c9b2b9aad7535f9674 /widgets | |
parent | 23c65aa0bf31030485e5131c7e796f11bfe462d6 (diff) | |
download | gsoc2013-evolution-18d96c5ff3a43c4ca830a08a1f0a76a2a002895e.tar gsoc2013-evolution-18d96c5ff3a43c4ca830a08a1f0a76a2a002895e.tar.gz gsoc2013-evolution-18d96c5ff3a43c4ca830a08a1f0a76a2a002895e.tar.bz2 gsoc2013-evolution-18d96c5ff3a43c4ca830a08a1f0a76a2a002895e.tar.lz gsoc2013-evolution-18d96c5ff3a43c4ca830a08a1f0a76a2a002895e.tar.xz gsoc2013-evolution-18d96c5ff3a43c4ca830a08a1f0a76a2a002895e.tar.zst gsoc2013-evolution-18d96c5ff3a43c4ca830a08a1f0a76a2a002895e.zip |
ignore test-completion.
2003-02-09 Chris Toshok <toshok@ximian.com>
* tests/.cvsignore: ignore test-completion.
* tests/test-completion.c: new program, completion test.
* tests/Makefile.am (noinst_PROGRAMS): add test-completion.
* gal/e-text/Makefile.am: remove e-completion-test from the build
here, moving it to ../../tests.
* gal/e-text/e-completion.c (e_completion_class_init): we've
removed the restart, cancel, clear, and lost signals. Also, we've
renamed some so it's easier to tell from the name which it is
(virtual func or signal.)
(e_completion_dispose): remove call to clear_search_stack, as we
don't do auto-refinement anymore.
(e_completion_clear): gone.
(e_completion_push_search): gone.
(e_completion_pop_search): gone.
(e_completion_clear_search_stack): gone.
(e_completion_refine_search): gone.
(e_completion_unrefine_search): gone.
(e_completion_begin_search): substantially clear this up, since we
don't have the refinement stuff anymore. Also, the call to
request_completion is a virtual function call, not a signal.
(e_completion_match_count): always return matches->len here, never
match_count, which is gone (with the refinement stuff)
(e_completion_foreach_match): remove the hit_count stuff.
(e_completion_restart): gone.
(e_completion_lost_match): gone.
(e_completion_end_search): remove the sorting stuff from here (and
the call to restart.) the etable sorting stuff will have to take
up the slack, but for now there's no reason to restart the search
here.
* gal/e-text/e-completion.h (struct _ECompletionClass): straighten
out what's a virtual function and what's a signal, instead of
using signals for both. Also, remove the auto_refine stuff, as
it's not used.
* gal/e-text/e-completion-view.c (e_completion_view_size_request):
make the damn drop down window bigger (100 pixels, or the
requisition height, whichever is bigger.)
(e_completion_view_disconnect): remove handling for signals that
are gone.
(restart_completion_cb): gone.
(cancel_completion_cb): gone.
(clear_completion_cb): gone.
(lost_completion_cb): gone.
(e_completion_view_construct): track new names of ECompletion
signals.
* gal/e-text/e-completion-view.h (struct _ECompletionView): remove
restart_signal_id, cancel_signal_id, clear_signal_id, and
lost_signal_id.
* gal/e-text/e-entry.c (get_borders): new function, ala gtkentry.
(canvas_size_request): use get_borders instead of computing it
here.
(e_entry_init): remove duplicate assignment of
emulate_label_resize.
(e_entry_show_popup): remove some ifdef'ed crap.
(e_entry_start_completion): don't cancel the completion before
starting again. This keeps the popup from disappearing.
* gal/e-text/e-completion-match.c (e_completion_match_construct):
no more hit_count.
* gal/e-text/e-completion-match.h (struct _ECompletionMatch):
remove hit_count.
* gal/e-text/e-completion-callbacks.[ch]: new class so we can use
callbacks instead of subclassing.
svn path=/trunk/; revision=19859
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/text/e-completion-callbacks.c | 96 | ||||
-rw-r--r-- | widgets/text/e-completion-callbacks.h | 68 | ||||
-rw-r--r-- | widgets/text/e-completion-match.c | 1 | ||||
-rw-r--r-- | widgets/text/e-completion-match.h | 1 | ||||
-rw-r--r-- | widgets/text/e-completion-test.c | 220 | ||||
-rw-r--r-- | widgets/text/e-completion-view.c | 94 | ||||
-rw-r--r-- | widgets/text/e-completion-view.h | 4 | ||||
-rw-r--r-- | widgets/text/e-completion.c | 363 | ||||
-rw-r--r-- | widgets/text/e-completion.h | 21 | ||||
-rw-r--r-- | widgets/text/e-entry.c | 78 | ||||
-rw-r--r-- | widgets/text/e-text.c | 6 |
11 files changed, 239 insertions, 713 deletions
diff --git a/widgets/text/e-completion-callbacks.c b/widgets/text/e-completion-callbacks.c new file mode 100644 index 0000000000..935ba7fb43 --- /dev/null +++ b/widgets/text/e-completion-callbacks.c @@ -0,0 +1,96 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-completion-callbacks.c - A callback based ECompletion. + * Copyright 2003 + * + * Authors: + * Chris Toshok <toshok@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 "gal/util/e-util.h" +#include "e-completion-callbacks.h" + +static void e_completion_callbacks_class_init (ECompletionCallbacksClass *klass); +static void e_completion_callbacks_init (ECompletionCallbacks *complete); + +static void callbacks_request_completion (ECompletion *comp, const gchar *search_text, gint pos, gint limit); +static void callbacks_end_completion (ECompletion *comp); + +#define PARENT_TYPE E_COMPLETION_TYPE +static ECompletionClass *parent_class; + + + +E_MAKE_TYPE (e_completion_callbacks, + "ECompletionCallbacks", + ECompletionCallbacks, + e_completion_callbacks_class_init, + e_completion_callbacks_init, + PARENT_TYPE) + +static void +e_completion_callbacks_class_init (ECompletionCallbacksClass *klass) +{ + ECompletionClass *comp_class = (ECompletionClass *) klass; + + parent_class = g_type_class_ref (PARENT_TYPE); + + comp_class->request_completion = callbacks_request_completion; + comp_class->end_completion = callbacks_end_completion; +} + +static void +e_completion_callbacks_init (ECompletionCallbacks *complete) +{ +} + +static void +callbacks_request_completion (ECompletion *comp, const gchar *search_text, gint pos, gint limit) +{ + ECompletionCallbacks *cc = E_COMPLETION_CALLBACKS (comp); + + cc->request_completion (cc, search_text, pos, limit, cc->data); +} + +static void +callbacks_end_completion (ECompletion *comp) +{ + ECompletionCallbacks *cc = E_COMPLETION_CALLBACKS (comp); + + cc->end_completion (cc, cc->data); +} + +ECompletion* +e_completion_callbacks_new (ECompletionCallbacksRequestCompletionFn request_completion, + ECompletionCallbacksEndCompletionFn end_completion, + gpointer data) +{ + ECompletionCallbacks *cc; + + g_return_val_if_fail (request_completion != NULL, NULL); + g_return_val_if_fail (end_completion != NULL, NULL); + + cc = gtk_type_new (E_COMPLETION_CALLBACKS_TYPE); + + cc->request_completion = request_completion; + cc->end_completion = end_completion; + cc->data = data; +} diff --git a/widgets/text/e-completion-callbacks.h b/widgets/text/e-completion-callbacks.h new file mode 100644 index 0000000000..57df9cd3e5 --- /dev/null +++ b/widgets/text/e-completion-callbacks.h @@ -0,0 +1,68 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-completion-callback.h - A callback based completion object. + * Copyright 2003, Ximian, Inc. + * + * Authors: + * Chris Toshok <toshok@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_CALLBACKS_H +#define E_COMPLETION_CALLBACKS_H + +#include <gtk/gtkobject.h> +#include "e-completion.h" + +G_BEGIN_DECLS + +#define E_COMPLETION_CALLBACKS_TYPE (e_completion_callbacks_get_type ()) +#define E_COMPLETION_CALLBACKS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), E_COMPLETION_CALLBACKS_TYPE, ECompletionCallbacks)) +#define E_COMPLETION_CALLBACKS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), E_COMPLETION_CALLBACKS_TYPE, ECompletionCallbacksClass)) +#define E_IS_COMPLETION_CALLBACKS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), E_COMPLETION_CALLBACKS_TYPE)) +#define E_IS_COMPLETION_CALLBACKS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), E_COMPLETION_CALLBACKS_TYPE)) + +typedef struct _ECompletionCallbacks ECompletionCallbacks; +typedef struct _ECompletionCallbacksClass ECompletionCallbacksClass; +struct _ECompletionCallbacksPrivate; + +typedef void (*ECompletionCallbacksRequestCompletionFn) (ECompletionCallbacks *comp, const gchar *search_text, gint pos, gint limit, gpointer data); +typedef void (*ECompletionCallbacksEndCompletionFn) (ECompletionCallbacks *comp, gpointer data); + +struct _ECompletionCallbacks { + ECompletion parent; + + ECompletionCallbacksRequestCompletionFn request_completion; + ECompletionCallbacksEndCompletionFn end_completion; + + gpointer data; +}; + +struct _ECompletionCallbacksClass { + ECompletionClass parent_class; +}; + +GtkType e_completion_callbacks_get_type (void); + +ECompletion* e_completion_callbacks_new (ECompletionCallbacksRequestCompletionFn request_completion, + ECompletionCallbacksEndCompletionFn end_completion, + gpointer data); + +G_END_DECLS + + +#endif /* E_COMPLETION_CALLBACKS_H */ + diff --git a/widgets/text/e-completion-match.c b/widgets/text/e-completion-match.c index 0da197d1fe..d13ba15973 100644 --- a/widgets/text/e-completion-match.c +++ b/widgets/text/e-completion-match.c @@ -50,7 +50,6 @@ e_completion_match_construct (ECompletionMatch *match) match->sort_minor = 0; match->user_data = NULL; match->ref = 1; - match->hit_count = 0; match->destroy = NULL; } diff --git a/widgets/text/e-completion-match.h b/widgets/text/e-completion-match.h index f2773ee094..162373add4 100644 --- a/widgets/text/e-completion-match.h +++ b/widgets/text/e-completion-match.h @@ -40,7 +40,6 @@ struct _ECompletionMatch { gpointer user_data; gint ref; - gint hit_count; void (*destroy) (ECompletionMatch *); }; diff --git a/widgets/text/e-completion-test.c b/widgets/text/e-completion-test.c deleted file mode 100644 index dfefe23e1b..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 (); - g_signal_connect (complete, - "request_completion", - G_CALLBACK (request_dict_search), - NULL); - g_signal_connect (complete, - "end_completion", - G_CALLBACK (end_dict_search), - NULL); - g_signal_connect (complete, - "cancel_completion", - G_CALLBACK (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); - - g_signal_connect (entry, - "popup", - G_CALLBACK (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 index 774e73cd17..f9728de60c 100644 --- a/widgets/text/e-completion-view.c +++ b/widgets/text/e-completion-view.c @@ -161,6 +161,8 @@ e_completion_view_size_request (GtkWidget *widget, GtkRequisition *requisition) requisition->width += child_requisition.width; requisition->height += child_requisition.height; } + + requisition->height = MAX (100, requisition->height); } static void @@ -319,24 +321,12 @@ e_completion_view_disconnect (ECompletionView *cv) g_signal_handler_disconnect (cv->completion, cv->begin_signal_id); if (cv->comp_signal_id) g_signal_handler_disconnect (cv->completion, cv->comp_signal_id); - if (cv->restart_signal_id) - g_signal_handler_disconnect (cv->completion, cv->restart_signal_id); - if (cv->cancel_signal_id) - g_signal_handler_disconnect (cv->completion, cv->cancel_signal_id); if (cv->end_signal_id) g_signal_handler_disconnect (cv->completion, cv->end_signal_id); - if (cv->clear_signal_id) - g_signal_handler_disconnect (cv->completion, cv->clear_signal_id); - if (cv->lost_signal_id) - g_signal_handler_disconnect (cv->completion, cv->lost_signal_id); cv->begin_signal_id = 0; cv->comp_signal_id = 0; - cv->restart_signal_id = 0; - cv->cancel_signal_id = 0; cv->end_signal_id = 0; - cv->clear_signal_id = 0; - cv->lost_signal_id = 0; } static ETable * @@ -594,28 +584,6 @@ begin_completion_cb (ECompletion *completion, const gchar *txt, gint pos, gint l } 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_table_model_pre_change (cv->model); - 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); - - g_signal_emit (cv, e_completion_view_signals[E_COMPLETION_VIEW_UNBROWSE] ,0); -} - -static void completion_cb (ECompletion *completion, ECompletionMatch *match, gpointer user_data) { ECompletionView *cv = E_COMPLETION_VIEW (user_data); @@ -648,42 +616,10 @@ end_completion_cb (ECompletion *completion, gpointer user_data) g_signal_emit (cv, e_completion_view_signals[E_COMPLETION_VIEW_FULL], 0); } -static void -clear_completion_cb (ECompletion *completion, gpointer user_data) -{ - ECompletionView *cv = E_COMPLETION_VIEW (user_data); - - e_table_model_pre_change (cv->model); - 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) */ - e_table_model_pre_change (cv->model); - g_ptr_array_remove_index (c, i); - e_table_model_row_deleted (cv->model, i); - - e_completion_match_unref (match); -} - /*** Table Callbacks ***/ +/* XXX toshok - we need to add sorting to this etable, through the use + of undisplayed fields of all the sort keys we want to use */ static char *simple_spec = "<ETableSpecification no-headers=\"true\" draw-grid=\"false\" cursor-mode=\"line\" alternating-row-colors=\"false\" gettext-domain=\"" E_I18N_DOMAIN "\">" " <ETableColumn model_col=\"0\" _title=\"Node\" expansion=\"1.0\" " @@ -756,33 +692,17 @@ e_completion_view_construct (ECompletionView *cv, ECompletion *completion) g_object_ref (completion); cv->begin_signal_id = g_signal_connect (completion, - "begin_completion", + "completion_started", G_CALLBACK (begin_completion_cb), cv); cv->comp_signal_id = g_signal_connect (completion, - "completion", + "completion_found", G_CALLBACK (completion_cb), cv); - cv->restart_signal_id = g_signal_connect (completion, - "restart_completion", - G_CALLBACK (restart_completion_cb), - cv); - cv->cancel_signal_id = g_signal_connect (completion, - "cancel_completion", - G_CALLBACK (cancel_completion_cb), - cv); cv->end_signal_id = g_signal_connect (completion, - "end_completion", + "completion_finished", G_CALLBACK (end_completion_cb), cv); - cv->clear_signal_id = g_signal_connect (completion, - "clear_completion", - G_CALLBACK (clear_completion_cb), - cv); - cv->lost_signal_id = g_signal_connect (completion, - "lost_completion", - G_CALLBACK (lost_completion_cb), - cv); cv->model = e_table_simple_new (table_col_count, table_row_count, diff --git a/widgets/text/e-completion-view.h b/widgets/text/e-completion-view.h index 9aa3860ebd..25b2eff645 100644 --- a/widgets/text/e-completion-view.h +++ b/widgets/text/e-completion-view.h @@ -51,11 +51,7 @@ struct _ECompletionView { 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; diff --git a/widgets/text/e-completion.c b/widgets/text/e-completion.c index cddd6ed4f4..b243d4db35 100644 --- a/widgets/text/e-completion.c +++ b/widgets/text/e-completion.c @@ -31,47 +31,32 @@ #include "gal/util/e-marshal.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 + COMPLETION_STARTED, + COMPLETION_FOUND, + COMPLETION_CANCELED, + COMPLETION_FINISHED, + LAST_SIGNAL }; -static guint e_completion_signals[E_COMPLETION_LAST_SIGNAL] = { 0 }; +static guint e_completion_signals[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_dispose (GObject *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); #define PARENT_TYPE GTK_TYPE_OBJECT static GtkObjectClass *parent_class; @@ -92,80 +77,34 @@ e_completion_class_init (ECompletionClass *klass) parent_class = g_type_class_ref (PARENT_TYPE); - e_completion_signals[E_COMPLETION_REQUEST_COMPLETION] = - g_signal_new ("request_completion", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECompletionClass, request_completion), - NULL, NULL, - e_marshal_NONE__POINTER_INT_INT, - G_TYPE_NONE, 3, - G_TYPE_POINTER, G_TYPE_INT, G_TYPE_INT); - - e_completion_signals[E_COMPLETION_BEGIN_COMPLETION] = - g_signal_new ("begin_completion", + e_completion_signals[COMPLETION_STARTED] = + g_signal_new ("completion_started", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECompletionClass, begin_completion), + G_STRUCT_OFFSET (ECompletionClass, completion_started), NULL, NULL, e_marshal_NONE__POINTER_INT_INT, G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_INT); - e_completion_signals[E_COMPLETION_COMPLETION] = - g_signal_new ("completion", + e_completion_signals[COMPLETION_FOUND] = + g_signal_new ("completion_found", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECompletionClass, completion), + G_STRUCT_OFFSET (ECompletionClass, completion_found), NULL, NULL, e_marshal_NONE__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - e_completion_signals[E_COMPLETION_RESTART_COMPLETION] = - g_signal_new ("restart_completion", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECompletionClass, restart_completion), - NULL, NULL, - e_marshal_NONE__NONE, - G_TYPE_NONE, 0); - - e_completion_signals[E_COMPLETION_CANCEL_COMPLETION] = - g_signal_new ("cancel_completion", + e_completion_signals[COMPLETION_FINISHED] = + g_signal_new ("completion_finished", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECompletionClass, cancel_completion), + G_STRUCT_OFFSET (ECompletionClass, completion_finished), NULL, NULL, e_marshal_NONE__NONE, G_TYPE_NONE, 0); - - e_completion_signals[E_COMPLETION_END_COMPLETION] = - g_signal_new ("end_completion", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECompletionClass, end_completion), - NULL, NULL, - e_marshal_NONE__NONE, - G_TYPE_NONE, 0); - - e_completion_signals[E_COMPLETION_CLEAR_COMPLETION] = - g_signal_new ("clear_completion", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECompletionClass, clear_completion), - NULL, NULL, - e_marshal_NONE__NONE, - G_TYPE_NONE, 0); - - e_completion_signals[E_COMPLETION_LOST_COMPLETION] = - g_signal_new ("lost_completion", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECompletionClass, lost_completion), - NULL, NULL, - e_marshal_NONE__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); object_class->dispose = e_completion_dispose; } @@ -187,7 +126,6 @@ e_completion_dispose (GObject *object) 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; @@ -241,149 +179,9 @@ e_completion_clear_matches (ECompletion *complete) } 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; - g_signal_emit (complete, e_completion_signals[E_COMPLETION_CLEAR_COMPLETION], 0); -} - -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); - - g_signal_emit (comp, e_completion_signals[E_COMPLETION_BEGIN_COMPLETION], 0, 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; - g_signal_emit (comp, e_completion_signals[E_COMPLETION_COMPLETION], 0, match); - ++comp->priv->match_count; - } - } - - ++comp->priv->refinement_count; - - g_signal_emit (comp, e_completion_signals[E_COMPLETION_END_COMPLETION], 0); - - 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); - - g_signal_emit (comp, e_completion_signals[E_COMPLETION_BEGIN_COMPLETION], 0, - 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; - g_signal_emit (comp, e_completion_signals[E_COMPLETION_COMPLETION], 0, match); - ++comp->priv->match_count; - } - } - - g_signal_emit (comp, e_completion_signals[E_COMPLETION_END_COMPLETION], 0); - - 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)); @@ -391,35 +189,6 @@ e_completion_begin_search (ECompletion *complete, const gchar *text, gint pos, g klass = E_COMPLETION_CLASS (GTK_OBJECT_GET_CLASS (complete)); - 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); @@ -430,25 +199,10 @@ e_completion_begin_search (ECompletion *complete, const gchar *text, gint pos, g e_completion_clear_matches (complete); complete->priv->limit = limit > 0 ? limit : G_MAXINT; - complete->priv->refinement_count = 0; - - g_signal_emit (complete, e_completion_signals[E_COMPLETION_BEGIN_COMPLETION], 0, text, pos, limit); - g_signal_emit (complete, e_completion_signals[E_COMPLETION_REQUEST_COMPLETION], 0, 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; - - g_signal_emit (complete, e_completion_signals[E_COMPLETION_CANCEL_COMPLETION], 0); - complete->priv->searching = FALSE; + g_signal_emit (complete, e_completion_signals[COMPLETION_STARTED], 0, text, pos, limit); + if (klass->request_completion) + klass->request_completion (complete, text, pos, limit); } gboolean @@ -460,15 +214,6 @@ e_completion_searching (ECompletion *complete) 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) { @@ -493,7 +238,7 @@ 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; + return complete->priv->matches->len; } void @@ -511,9 +256,7 @@ e_completion_foreach_match (ECompletion *complete, ECompletionMatchFn fn, gpoint 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); - } + fn (match, closure); } } @@ -554,25 +297,6 @@ e_completion_sort (ECompletion *complete) 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; - - g_signal_emit (complete, e_completion_signals[E_COMPLETION_RESTART_COMPLETION], 0); - - m = complete->priv->matches; - for (i = count = 0; - i < m->len && count < complete->priv->limit; - i++, count++) { - g_signal_emit (complete, - e_completion_signals[E_COMPLETION_COMPLETION], 0, - g_ptr_array_index (m, i)); - } -} - void e_completion_found_match (ECompletion *complete, ECompletionMatch *match) { @@ -594,47 +318,22 @@ e_completion_found_match (ECompletion *complete, ECompletionMatch *match) e_completion_add_match (complete, match); - g_signal_emit (complete, e_completion_signals[E_COMPLETION_COMPLETION], 0, 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); - - g_signal_emit (complete, e_completion_signals[E_COMPLETION_LOST_COMPLETION], 0, match); - - e_completion_match_unref (match); + g_signal_emit (complete, e_completion_signals[COMPLETION_FOUND], 0, match); } void -e_completion_end_search (ECompletion *complete) +e_completion_end_search (ECompletion *comp) { - 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); + g_return_if_fail (comp != NULL); + g_return_if_fail (E_IS_COMPLETION (comp)); + g_return_if_fail (comp->priv->searching); - g_signal_emit (complete, e_completion_signals[E_COMPLETION_END_COMPLETION], 0); + if (E_COMPLETION_CLASS (GTK_OBJECT_GET_CLASS (comp))->end_completion) { + E_COMPLETION_CLASS (GTK_OBJECT_GET_CLASS (comp))->end_completion (comp); + } + g_signal_emit (comp, e_completion_signals[COMPLETION_FINISHED], 0); - complete->priv->searching = FALSE; - complete->priv->done_search = TRUE; + comp->priv->searching = FALSE; + comp->priv->done_search = TRUE; } diff --git a/widgets/text/e-completion.h b/widgets/text/e-completion.h index f8d38e45a7..74976e579c 100644 --- a/widgets/text/e-completion.h +++ b/widgets/text/e-completion.h @@ -52,29 +52,20 @@ 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 (*end_completion) (ECompletion *comp); - void (*begin_completion) (ECompletion *comp, const gchar *search_text, gint pos, gint limit); - void (*restart_completion) (ECompletion *comp); + /* Signals */ + void (*completion_started) (ECompletion *comp, const gchar *search_text, gint pos, gint limit); - void (*completion) (ECompletion *comp, ECompletionMatch *match); - void (*lost_completion) (ECompletion *comp, ECompletionMatch *match); + void (*completion_found) (ECompletion *comp, ECompletionMatch *match); - void (*cancel_completion) (ECompletion *comp); - void (*end_completion) (ECompletion *comp); - void (*clear_completion) (ECompletion *comp); + void (*completion_finished) (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); @@ -91,8 +82,6 @@ ECompletion *e_completion_new (void); 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); G_END_DECLS diff --git a/widgets/text/e-entry.c b/widgets/text/e-entry.c index a297f1d26a..130b66f02d 100644 --- a/widgets/text/e-entry.c +++ b/widgets/text/e-entry.c @@ -42,15 +42,8 @@ #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 INNER_BORDER 2 #define d(x) @@ -166,6 +159,30 @@ canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, } static void +get_borders (EEntry *entry, + gint *xborder, + gint *yborder) +{ + GtkWidget *widget = GTK_WIDGET (entry); + gint focus_width; + gboolean interior_focus; + + gtk_widget_style_get (widget, + "interior-focus", &interior_focus, + "focus-line-width", &focus_width, + NULL); + + *xborder = widget->style->xthickness; + *yborder = widget->style->ythickness; + + if (!interior_focus) + { + *xborder += focus_width; + *yborder += focus_width; + } +} + +static void canvas_size_request (GtkWidget *widget, GtkRequisition *requisition, EEntry *entry) { @@ -177,10 +194,8 @@ canvas_size_request (GtkWidget *widget, GtkRequisition *requisition, g_return_if_fail (GNOME_IS_CANVAS (widget)); g_return_if_fail (requisition != NULL); - if (entry->priv->draw_borders) { - xthick = 2 * widget->style->xthickness; - ythick = 2 * widget->style->ythickness; + get_borders (entry, &xthick, &ythick); } else { xthick = ythick = 0; } @@ -190,7 +205,7 @@ canvas_size_request (GtkWidget *widget, GtkRequisition *requisition, g_object_get (entry->item, "text_width", &width, NULL); - requisition->width = 2 + xthick + width; + requisition->width = 2 + 2 * xthick + width; } else { requisition->width = 2 + MIN_ENTRY_WIDTH + xthick; } @@ -207,7 +222,7 @@ canvas_size_request (GtkWidget *widget, GtkRequisition *requisition, requisition->height = (2 + PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)) + - ythick); + 2 * ythick); pango_font_metrics_unref (metrics); } @@ -287,8 +302,6 @@ e_entry_init (GtkObject *object) entry->priv->emulate_label_resize = FALSE; - entry->priv->emulate_label_resize = FALSE; - entry->canvas = GNOME_CANVAS (e_canvas_new ()); g_signal_connect (entry->canvas, @@ -500,43 +513,12 @@ e_entry_show_popup (EEntry *entry, gboolean visible) 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); @@ -584,8 +566,6 @@ 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; diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c index a28b6f2649..26b1534817 100644 --- a/widgets/text/e-text.c +++ b/widgets/text/e-text.c @@ -62,7 +62,7 @@ #define PARENT_TYPE (gnome_canvas_item_get_type()) -#define BORDER_INDENT 4 +#define BORDER_INDENT 3 #define d(x) enum { @@ -1223,8 +1223,8 @@ show_pango_rectangle (EText *text, PangoRectangle rect) } if (clip_height >= 0) { - if (2 + y2 - clip_height > new_yofs_edit) - new_yofs_edit = 2 + y2 - clip_height; + if (y2 - clip_height > new_yofs_edit) + new_yofs_edit = y2 - clip_height; } else { new_yofs_edit = 0; } |