1 #ifndef _GNM_SHEET_FILTER_H_
2 # define _GNM_SHEET_FILTER_H_
3 
4 #include <gnumeric.h>
5 #include <goffice/goffice.h>
6 
7 G_BEGIN_DECLS
8 
9 typedef enum {
10 	GNM_FILTER_UNUSED	= -1,
11 
12 	GNM_FILTER_OP_EQUAL	= 0,	/* exact match, no regecxp */
13 	GNM_FILTER_OP_GT,
14 	GNM_FILTER_OP_LT,
15 	GNM_FILTER_OP_GTE,
16 	GNM_FILTER_OP_LTE,
17 	GNM_FILTER_OP_NOT_EQUAL,	/* exact match, no regecxp */
18 
19 	GNM_FILTER_OP_BLANKS		= 0x20,
20 	GNM_FILTER_OP_NON_BLANKS	= 0x21,
21 
22 	GNM_FILTER_OP_TOP_N		= 0x30,
23 	GNM_FILTER_OP_BOTTOM_N		= 0x31,
24 	GNM_FILTER_OP_TOP_N_PERCENT	= 0x32,
25 	GNM_FILTER_OP_BOTTOM_N_PERCENT	= 0x33,
26 	/* Next two added in 1.11.6 */
27 	GNM_FILTER_OP_TOP_N_PERCENT_N	= 0x34,
28 	GNM_FILTER_OP_BOTTOM_N_PERCENT_N	= 0x35,
29 	GNM_FILTER_OP_BOTTOM_MASK	= 0x01,
30 	GNM_FILTER_OP_REL_N_MASK	= 0x04,
31 	GNM_FILTER_OP_PERCENT_MASK	= 0x06,
32 
33 	/* Added in 1.7.7 */
34 	GNM_FILTER_OP_GT_AVERAGE	= 0x40,
35 	GNM_FILTER_OP_LT_AVERAGE	= 0x41,
36 	GNM_FILTER_OP_WITHIN_STDDEV	= 0x50,
37 	GNM_FILTER_OP_OUTSIDE_STDDEV	= 0x51,
38 
39 	GNM_FILTER_OP_MATCH		= 0x60,	/* regexp */
40 	GNM_FILTER_OP_NO_MATCH		= 0x61,	/* regexp */
41 
42 	GNM_FILTER_OP_TYPE_OP		= 0x00,
43 	GNM_FILTER_OP_TYPE_BLANKS	= 0x20,
44 	GNM_FILTER_OP_TYPE_BUCKETS	= 0x30,
45 	GNM_FILTER_OP_TYPE_AVERAGE	= 0x40,
46 	GNM_FILTER_OP_TYPE_STDDEV	= 0x50,
47 	GNM_FILTER_OP_TYPE_MATCH	= 0x60,
48 	GNM_FILTER_OP_TYPE_MASK		= 0x70
49 } GnmFilterOp;
50 
51 struct _GnmFilterCondition {
52 	GnmFilterOp  op[2];
53 	GnmValue    *value[2];
54 	gboolean is_and;
55 	double	 count;
56 };
57 
58 struct _GnmFilter {
59 	int ref_count;
60 	Sheet *sheet;
61 	GnmRange  r;
62 
63 	GPtrArray *fields;
64 	gboolean   is_active;
65 };
66 
67 GType               gnm_filter_condition_get_type   (void);
68 GnmFilterCondition *gnm_filter_condition_dup        (GnmFilterCondition const *src);
69 void                gnm_filter_condition_free       (GnmFilterCondition *cond);
70 GnmFilterCondition *gnm_filter_condition_new_single (GnmFilterOp op, GnmValue *v);
71 GnmFilterCondition *gnm_filter_condition_new_double (GnmFilterOp op0, GnmValue *v0,
72 						     gboolean join_with_and,
73 						     GnmFilterOp op1, GnmValue *v1);
74 GnmFilterCondition *gnm_filter_condition_new_bucket (gboolean top,
75 						     gboolean absolute,
76 						     gboolean rel_range,
77 						     double n);
78 
79 GType                     gnm_filter_get_type       (void);
80 GnmFilter		 *gnm_filter_new	    (Sheet *sheet,
81 						     GnmRange const *r,
82 						     gboolean attach);
83 GnmFilter		 *gnm_filter_dup	    (GnmFilter const *src,
84 						     Sheet *sheet);
85 GnmFilter *               gnm_filter_ref            (GnmFilter *filter);
86 void			  gnm_filter_unref	    (GnmFilter *filter);
87 void			  gnm_filter_remove	    (GnmFilter *filter);
88 void			  gnm_filter_attach	    (GnmFilter *filter, Sheet *sheet);
89 GnmFilterCondition const *gnm_filter_get_condition  (GnmFilter const *filter, unsigned i);
90 void			  gnm_filter_set_condition  (GnmFilter *filter, unsigned i,
91 						     GnmFilterCondition *cond,
92 						     gboolean apply);
93 void                      gnm_filter_reapply        (GnmFilter *filter);
94 
95 GnmFilter *gnm_sheet_filter_at_pos  (Sheet const *sheet, GnmCellPos const *pos);
96 GnmFilter *gnm_sheet_filter_intersect_rows  (Sheet const *sheet,
97 					     int from, int to);
98 GnmRange  *gnm_sheet_filter_can_be_extended (Sheet const *sheet,
99 					     GnmFilter const *f,
100 					     GnmRange const *r);
101 void gnm_sheet_filter_insdel_colrow (Sheet *sheet,
102 				     gboolean is_cols, gboolean is_insert,
103 				     int start, int count,
104 				     GOUndo **pundo);
105 
106 G_END_DECLS
107 
108 #endif /* _GNM_SHEET_FILTER_H_ */
109