1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * complete-sheet.c: Auto completes values from a sheet.
6 * Miguel de Icaza (miguel@gnu.org)
8 * This is a pretty simple implementation, should be helpful
9 * to find performance hot-spots (if you bump SEARCH_STEPS to gnm_sheet_get_max_rows (sheet)/2)
11 * (C) 2000-2001 Ximian, Inc.
13 #include <gnumeric-config.h>
15 #include "complete-sheet.h"
16 #include "gnumeric-conf.h"
21 #include "parse-util.h"
23 #include <gsf/gsf-impl-utils.h>
26 #define SEARCH_STEPS 50
28 #define PARENT_TYPE GNM_COMPLETE_TYPE
30 static GObjectClass
*parent_class
;
34 search_strategy_reset_search (GnmCompleteSheet
*cs
)
36 cs
->current
.col
= cs
->entry
.col
;
37 cs
->current
.row
= cs
->entry
.row
;
42 * Very simple search strategy: up until blank.
45 search_strategy_next (GnmCompleteSheet
*cs
)
48 if (cs
->current
.row
< 0)
51 cs
->cell
= sheet_cell_get (cs
->sheet
, cs
->current
.col
, cs
->current
.row
);
52 return cs
->cell
!= NULL
;
57 complete_sheet_finalize (GObject
*object
)
59 GnmCompleteSheet
*cs
= GNM_COMPLETE_SHEET (object
);
60 g_free (cs
->current_text
);
61 parent_class
->finalize (object
);
65 text_matches (GnmCompleteSheet
const *cs
)
68 GnmComplete
const *complete
= &cs
->parent
;
70 if (cs
->cell
->value
== NULL
||
71 !VALUE_IS_STRING (cs
->cell
->value
) ||
72 gnm_cell_has_expr (cs
->cell
))
75 text
= value_peek_string (cs
->cell
->value
);
76 if (strncmp (text
, complete
->text
, strlen (complete
->text
)) != 0)
79 (*complete
->notify
)(text
, complete
->notify_closure
);
84 complete_sheet_search_iteration (GnmComplete
*complete
)
86 GnmCompleteSheet
*cs
= GNM_COMPLETE_SHEET (complete
);
89 if ((int)strlen (complete
->text
) <
90 gnm_conf_get_core_gui_editing_autocomplete_min_chars ())
93 if (strncmp (cs
->current_text
, complete
->text
, strlen (cs
->current_text
)) != 0)
94 search_strategy_reset_search (cs
);
96 for (i
= 0; i
< SEARCH_STEPS
; i
++) {
97 if (!search_strategy_next (cs
))
100 if (text_matches (cs
))
108 complete_sheet_class_init (GObjectClass
*object_class
)
110 GnmCompleteClass
*auto_complete_class
= (GnmCompleteClass
*) object_class
;
112 parent_class
= g_type_class_peek (PARENT_TYPE
);
113 object_class
->finalize
= complete_sheet_finalize
;
114 auto_complete_class
->search_iteration
= complete_sheet_search_iteration
;
118 * gnm_complete_sheet_new:
122 * @notify: (scope async): #GnmCompleteMatchNotifyFn
123 * @notify_closure: user data
125 * Returns: (transfer full): the new #GnmComplete.
128 gnm_complete_sheet_new (Sheet
*sheet
, int col
, int row
, GnmCompleteMatchNotifyFn notify
, void *notify_closure
)
131 * Somehow every time I pronounce this, I feel like something is not quite right.
133 GnmCompleteSheet
*cs
;
135 cs
= g_object_new (GNM_COMPLETE_SHEET_TYPE
, NULL
);
136 gnm_complete_construct (GNM_COMPLETE (cs
), notify
, notify_closure
);
141 cs
->current_text
= g_strdup ("");
142 search_strategy_reset_search (cs
);
144 return GNM_COMPLETE (cs
);
147 GSF_CLASS (GnmCompleteSheet
, gnm_complete_sheet
,
148 complete_sheet_class_init
, NULL
, PARENT_TYPE
)