Update Spanish translation
[gnumeric.git] / src / complete.c
blob60edeebf9b963587cfc96e790156a7727ff88d66
1 /*
2 * complete.c: Our auto completion engine. This is an abstract class
3 * that must be derived to implement its actual functionality.
5 * Author:
6 * Miguel de Icaza (miguel@gnu.org)
8 * Theory of operation:
10 * Derived types of GnmComplete provide the search function.
12 * The search function should not take too long to run, and try to
13 * search on each step information on its data repository. When the
14 * data repository information has been extenuated or if a match has
15 * been found, then the method should return FALSE and invoke the
16 * notification function that was provided to GnmComplete.
19 * (C) 2000-2001 Ximain Inc.
21 #include <gnumeric-config.h>
22 #include <gnumeric.h>
23 #include <complete.h>
25 #include <gsf/gsf-impl-utils.h>
26 #include <stdlib.h>
28 #define PARENT_TYPE (G_TYPE_OBJECT)
29 #define ACC(o) (GNM_COMPLETE_CLASS (G_OBJECT_GET_CLASS (o)))
31 /**
32 * gnm_complete_construct:
33 * @complete: #GnmComplete
34 * @notify: (scope async): #GnmCompleteMatchNotifyFn
35 * @notify_closure: user data
36 **/
37 void
38 gnm_complete_construct (GnmComplete *complete,
39 GnmCompleteMatchNotifyFn notify,
40 void *notify_closure)
42 complete->notify = notify;
43 complete->notify_closure = notify_closure;
46 static void
47 complete_finalize (GObject *object)
49 GObjectClass *parent;
50 GnmComplete *complete = GNM_COMPLETE (object);
52 if (complete->idle_tag) {
53 g_source_remove (complete->idle_tag);
54 complete->idle_tag = 0;
57 g_free (complete->text);
58 complete->text = NULL;
60 parent = g_type_class_peek (PARENT_TYPE);
61 parent->finalize (object);
64 static gint
65 complete_idle (gpointer data)
67 GnmComplete *complete = data;
69 g_return_val_if_fail (complete->idle_tag != 0, FALSE);
71 if (ACC(complete)->search_iteration (complete))
72 return TRUE;
74 complete->idle_tag = 0;
76 return FALSE;
79 void
80 gnm_complete_start (GnmComplete *complete, char const *text)
82 g_return_if_fail (complete != NULL);
83 g_return_if_fail (GNM_IS_COMPLETE (complete));
84 g_return_if_fail (text != NULL);
86 if (complete->text != text) {
87 g_free (complete->text);
88 complete->text = g_strdup (text);
91 if (complete->idle_tag == 0)
92 complete->idle_tag = g_idle_add (complete_idle, complete);
94 if (ACC(complete)->start_over)
95 ACC(complete)->start_over (complete);
98 static gboolean
99 default_search_iteration (G_GNUC_UNUSED GnmComplete *complete)
101 return FALSE;
104 static void
105 complete_class_init (GObjectClass *object_class)
107 GnmCompleteClass *complete_class = (GnmCompleteClass *) object_class;
109 object_class->finalize = complete_finalize;
110 complete_class->search_iteration = default_search_iteration;
113 GSF_CLASS (GnmComplete, gnm_complete,
114 complete_class_init, NULL, PARENT_TYPE)