ssdiff: move comparison engine into its own file.
[gnumeric.git] / src / complete.c
blob6e840f9a5c536e9aea26d20374b6b92993189b0d
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * complete.c: Our auto completion engine. This is an abstract class
4 * that must be derived to implement its actual functionality.
6 * Author:
7 * Miguel de Icaza (miguel@gnu.org)
9 * Theory of operation:
11 * Derived types of GnmComplete provide the search function.
13 * The search function should not take too long to run, and try to
14 * search on each step information on its data repository. When the
15 * data repository information has been extenuated or if a match has
16 * been found, then the method should return FALSE and invoke the
17 * notification function that was provided to GnmComplete.
20 * (C) 2000-2001 Ximain Inc.
22 #include <gnumeric-config.h>
23 #include "gnumeric.h"
24 #include "complete.h"
26 #include <gsf/gsf-impl-utils.h>
27 #include <gtk/gtk.h>
28 #include <stdlib.h>
30 #define PARENT_TYPE (G_TYPE_OBJECT)
31 #define ACC(o) (GNM_COMPLETE_CLASS (G_OBJECT_GET_CLASS (o)))
33 /**
34 * gnm_complete_construct:
35 * @complete: #GnmComplete
36 * @notify: (scope async): #GnmCompleteMatchNotifyFn
37 * @notify_closure: user data
38 **/
39 void
40 gnm_complete_construct (GnmComplete *complete,
41 GnmCompleteMatchNotifyFn notify,
42 void *notify_closure)
44 complete->notify = notify;
45 complete->notify_closure = notify_closure;
48 static void
49 complete_finalize (GObject *object)
51 GObjectClass *parent;
52 GnmComplete *complete = GNM_COMPLETE (object);
54 if (complete->idle_tag) {
55 g_source_remove (complete->idle_tag);
56 complete->idle_tag = 0;
59 g_free (complete->text);
60 complete->text = NULL;
62 parent = g_type_class_peek (PARENT_TYPE);
63 parent->finalize (object);
66 static gint
67 complete_idle (gpointer data)
69 GnmComplete *complete = data;
71 g_return_val_if_fail (complete->idle_tag != 0, FALSE);
73 if (ACC(complete)->search_iteration (complete))
74 return TRUE;
76 complete->idle_tag = 0;
78 return FALSE;
81 void
82 gnm_complete_start (GnmComplete *complete, char const *text)
84 g_return_if_fail (complete != NULL);
85 g_return_if_fail (GNM_IS_COMPLETE (complete));
86 g_return_if_fail (text != NULL);
88 if (complete->text != text) {
89 g_free (complete->text);
90 complete->text = g_strdup (text);
93 if (complete->idle_tag == 0)
94 complete->idle_tag = g_idle_add (complete_idle, complete);
96 if (ACC(complete)->start_over)
97 ACC(complete)->start_over (complete);
100 static gboolean
101 default_search_iteration (G_GNUC_UNUSED GnmComplete *complete)
103 return FALSE;
106 static void
107 complete_class_init (GObjectClass *object_class)
109 GnmCompleteClass *complete_class = (GnmCompleteClass *) object_class;
111 object_class->finalize = complete_finalize;
112 complete_class->search_iteration = default_search_iteration;
115 GSF_CLASS (GnmComplete, gnm_complete,
116 complete_class_init, NULL, PARENT_TYPE)