2 * complete-sheet.c: Auto completes values from a sheet.
5 * Miguel de Icaza (miguel@gnu.org)
7 * This is a pretty simple implementation, should be helpful
8 * to find performance hot-spots (if you bump SEARCH_STEPS to gnm_sheet_get_max_rows (sheet)/2)
10 * (C) 2000-2001 Ximian, Inc.
12 #include <gnumeric-config.h>
14 #include <complete-sheet.h>
15 #include <gnumeric-conf.h>
20 #include <parse-util.h>
22 #include <gsf/gsf-impl-utils.h>
25 #define SEARCH_STEPS 50
27 #define PARENT_TYPE GNM_COMPLETE_TYPE
29 static GObjectClass
*parent_class
;
33 search_strategy_reset_search (GnmCompleteSheet
*cs
)
35 cs
->current
.col
= cs
->entry
.col
;
36 cs
->current
.row
= cs
->entry
.row
;
41 * Very simple search strategy: up until blank.
44 search_strategy_next (GnmCompleteSheet
*cs
)
47 if (cs
->current
.row
< 0)
50 cs
->cell
= sheet_cell_get (cs
->sheet
, cs
->current
.col
, cs
->current
.row
);
51 return cs
->cell
!= NULL
;
56 complete_sheet_finalize (GObject
*object
)
58 GnmCompleteSheet
*cs
= GNM_COMPLETE_SHEET (object
);
59 g_free (cs
->current_text
);
60 parent_class
->finalize (object
);
64 text_matches (GnmCompleteSheet
const *cs
)
67 GnmComplete
const *complete
= &cs
->parent
;
69 if (cs
->cell
->value
== NULL
||
70 !VALUE_IS_STRING (cs
->cell
->value
) ||
71 gnm_cell_has_expr (cs
->cell
))
74 text
= value_peek_string (cs
->cell
->value
);
75 if (strncmp (text
, complete
->text
, strlen (complete
->text
)) != 0)
78 (*complete
->notify
)(text
, complete
->notify_closure
);
83 complete_sheet_search_iteration (GnmComplete
*complete
)
85 GnmCompleteSheet
*cs
= GNM_COMPLETE_SHEET (complete
);
88 if ((int)strlen (complete
->text
) <
89 gnm_conf_get_core_gui_editing_autocomplete_min_chars ())
92 if (strncmp (cs
->current_text
, complete
->text
, strlen (cs
->current_text
)) != 0)
93 search_strategy_reset_search (cs
);
95 for (i
= 0; i
< SEARCH_STEPS
; i
++) {
96 if (!search_strategy_next (cs
))
99 if (text_matches (cs
))
107 complete_sheet_class_init (GObjectClass
*object_class
)
109 GnmCompleteClass
*auto_complete_class
= (GnmCompleteClass
*) object_class
;
111 parent_class
= g_type_class_peek (PARENT_TYPE
);
112 object_class
->finalize
= complete_sheet_finalize
;
113 auto_complete_class
->search_iteration
= complete_sheet_search_iteration
;
117 * gnm_complete_sheet_new:
121 * @notify: (scope async): #GnmCompleteMatchNotifyFn
122 * @notify_closure: user data
124 * Returns: (transfer full): the new #GnmComplete.
127 gnm_complete_sheet_new (Sheet
*sheet
, int col
, int row
, GnmCompleteMatchNotifyFn notify
, void *notify_closure
)
130 * Somehow every time I pronounce this, I feel like something is not quite right.
132 GnmCompleteSheet
*cs
;
134 cs
= g_object_new (GNM_COMPLETE_SHEET_TYPE
, NULL
);
135 gnm_complete_construct (GNM_COMPLETE (cs
), notify
, notify_closure
);
140 cs
->current_text
= g_strdup ("");
141 search_strategy_reset_search (cs
);
143 return GNM_COMPLETE (cs
);
146 GSF_CLASS (GnmCompleteSheet
, gnm_complete_sheet
,
147 complete_sheet_class_init
, NULL
, PARENT_TYPE
)