Move plugin init code
[gnumeric.git] / src / search.h
blobfb6ce327a2e2cde522603f5823afc1da2c64fec0
1 #ifndef _GNM_SEARCH_H_
2 # define _GNM_SEARCH_H_
4 #include <gnumeric.h>
5 #include <position.h>
6 #include <numbers.h>
7 #include <goffice/goffice.h>
9 G_BEGIN_DECLS
11 char *gnm_search_normalize (const char *txt);
13 #define GNM_SEARCH_REPLACE_TYPE (gnm_search_replace_get_type ())
14 #define GNM_SEARCH_REPLACE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNM_SEARCH_REPLACE_TYPE, GnmSearchReplace))
15 #define GNM_IS_SEARCH_REPLACE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_SEARCH_REPLACE_TYPE))
17 typedef enum {
18 GNM_SRE_FAIL = 0,
19 GNM_SRE_SKIP,
20 GNM_SRE_QUERY,
21 GNM_SRE_ERROR,
22 GNM_SRE_STRING
23 } GnmSearchReplaceError;
25 typedef enum {
26 GNM_SRS_WORKBOOK = 0,
27 GNM_SRS_SHEET,
28 GNM_SRS_RANGE
29 } GnmSearchReplaceScope;
30 GType gnm_search_replace_scope_get_type (void);
31 #define GNM_SEARCH_REPLACE_SCOPE_TYPE (gnm_search_replace_scope_get_type ())
33 typedef enum {
34 GNM_SRQ_FAIL,
35 GNM_SRQ_QUERY,
36 GNM_SRQ_QUERY_COMMENT
37 } GnmSearchReplaceQuery;
39 typedef enum {
40 GNM_SRL_CONTENTS,
41 GNM_SRL_VALUE,
42 GNM_SRL_COMMENT
43 } GnmSearchReplaceLocus;
45 typedef int (*GnmSearchReplaceQueryFunc) (GnmSearchReplaceQuery q, GnmSearchReplace *sr, ...);
47 struct _GnmSearchReplace {
48 GOSearchReplace base;
50 GnmSearchReplaceScope scope;
51 char *range_text;
54 * This is the default sheet for the range and used also to locate
55 * a workbook.
57 Sheet *sheet;
59 gboolean query; /* Ask before each change. */
61 gboolean is_number; /* Search for specific number. */
62 gnm_float low_number, high_number; /* protected. */
64 /* The following identify what kinds of cells are the target. */
65 gboolean search_strings;
66 gboolean search_other_values;
67 gboolean search_expressions;
68 gboolean search_expression_results;
69 gboolean search_comments;
70 gboolean search_scripts;
71 gboolean invert;
73 GnmSearchReplaceError error_behaviour;
74 gboolean replace_keep_strings;
77 * If true: A1,B1,...,A2,B2,...
78 * If false: A1,A2,...,B1,B2,...
80 gboolean by_row;
83 * Query and info function.
85 * GNM_SRQ_FAIL (..., GnmCell *cell, char const *old, char const *new)
86 * Inform the user that an error occurred in GNM_SRE_FAIL mode.
88 * GNM_SRQ_QUERY (..., GnmCell *cell, char const *old, char const *new)
89 * Ask user whether to change. GTK_RESPONSE_(YES|NO|CANCEL)
91 * GNM_SRQ_QUERY_COMMENT (..., Sheet *sheet, CellPos *cp,
92 * char const *old, char const *new)
93 * Ask user whether to change. GTK_RESPONSE_(YES|NO|CANCEL)
95 GnmSearchReplaceQueryFunc query_func;
96 void *user_data;
99 GType gnm_search_replace_get_type (void);
101 char *gnm_search_replace_verify (GnmSearchReplace *sr, gboolean repl);
103 GPtrArray *gnm_search_collect_cells (GnmSearchReplace *sr);
104 void gnm_search_collect_cells_free (GPtrArray *cells);
106 typedef struct {
107 GnmEvalPos ep;
108 GnmSearchReplaceLocus locus;
109 } GnmSearchFilterResult;
110 GPtrArray *gnm_search_filter_matching (GnmSearchReplace *sr, GPtrArray const *cells);
111 void gnm_search_filter_matching_free (GPtrArray *matches);
113 typedef struct {
114 GnmComment *comment;
115 char const *old_text;
116 char *new_text; /* Caller must free if replacing and found. */
117 } GnmSearchReplaceCommentResult;
118 gboolean gnm_search_replace_comment (GnmSearchReplace *sr,
119 GnmEvalPos const *ep,
120 gboolean repl,
121 GnmSearchReplaceCommentResult *res);
123 typedef struct {
124 GnmCell *cell;
125 char *old_text; /* Caller must free. */
126 char *new_text; /* Caller must free if replacing and found. */
127 } GnmSearchReplaceCellResult;
128 gboolean gnm_search_replace_cell (GnmSearchReplace *sr,
129 GnmEvalPos const *ep,
130 gboolean repl,
131 GnmSearchReplaceCellResult *res);
133 void gnm_search_replace_query_fail (GnmSearchReplace *sr,
134 const GnmSearchReplaceCellResult *res);
136 int gnm_search_replace_query_cell (GnmSearchReplace *sr,
137 const GnmSearchReplaceCellResult *res);
139 int gnm_search_replace_query_comment (GnmSearchReplace *sr,
140 const GnmEvalPos *ep,
141 const GnmSearchReplaceCommentResult *res);
143 G_END_DECLS
145 #endif /* _GNM_SEARCH_H_ */