1 #ifndef _GNM_SEARCH_H_ 2 # define _GNM_SEARCH_H_ 3 4 #include <gnumeric.h> 5 #include <position.h> 6 #include <numbers.h> 7 #include <goffice/goffice.h> 8 9 G_BEGIN_DECLS 10 11 char *gnm_search_normalize (const char *txt); 12 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)) 16 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; 24 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 ()) 32 33 typedef enum { 34 GNM_SRQ_FAIL, 35 GNM_SRQ_QUERY, 36 GNM_SRQ_QUERY_COMMENT 37 } GnmSearchReplaceQuery; 38 39 typedef enum { 40 GNM_SRL_CONTENTS, 41 GNM_SRL_VALUE, 42 GNM_SRL_COMMENT 43 } GnmSearchReplaceLocus; 44 45 typedef int (*GnmSearchReplaceQueryFunc) (GnmSearchReplaceQuery q, GnmSearchReplace *sr, ...); 46 47 struct _GnmSearchReplace { 48 GOSearchReplace base; 49 50 GnmSearchReplaceScope scope; 51 char *range_text; 52 53 /* 54 * This is the default sheet for the range and used also to locate 55 * a workbook. 56 */ 57 Sheet *sheet; 58 59 gboolean query; /* Ask before each change. */ 60 61 gboolean is_number; /* Search for specific number. */ 62 gnm_float low_number, high_number; /* protected. */ 63 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; 72 73 GnmSearchReplaceError error_behaviour; 74 gboolean replace_keep_strings; 75 76 /* 77 * If true: A1,B1,...,A2,B2,... 78 * If false: A1,A2,...,B1,B2,... 79 */ 80 gboolean by_row; 81 82 /* 83 * Query and info function. 84 * 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. 87 * 88 * GNM_SRQ_QUERY (..., GnmCell *cell, char const *old, char const *new) 89 * Ask user whether to change. GTK_RESPONSE_(YES|NO|CANCEL) 90 * 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) 94 */ 95 GnmSearchReplaceQueryFunc query_func; 96 void *user_data; 97 }; 98 99 GType gnm_search_replace_get_type (void); 100 101 char *gnm_search_replace_verify (GnmSearchReplace *sr, gboolean repl); 102 103 GPtrArray *gnm_search_collect_cells (GnmSearchReplace *sr); 104 void gnm_search_collect_cells_free (GPtrArray *cells); 105 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); 112 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); 122 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); 132 133 void gnm_search_replace_query_fail (GnmSearchReplace *sr, 134 const GnmSearchReplaceCellResult *res); 135 136 int gnm_search_replace_query_cell (GnmSearchReplace *sr, 137 const GnmSearchReplaceCellResult *res); 138 139 int gnm_search_replace_query_comment (GnmSearchReplace *sr, 140 const GnmEvalPos *ep, 141 const GnmSearchReplaceCommentResult *res); 142 143 G_END_DECLS 144 145 #endif /* _GNM_SEARCH_H_ */ 146