4
4
* filter.c: support for filters
6
* Copyright (C) 2002-2005 Jody Goldberg (jody@gnome.org)
6
* Copyright (C) 2002-2006 Jody Goldberg (jody@gnome.org)
8
8
* This program is free software; you can redistribute it and/or
9
9
* modify it under the terms of version 2 of the GNU General Public
288
288
} UniqueCollection;
290
290
static GnmValue *
291
cb_collect_unique (Sheet *sheet, int col, int row, GnmCell *cell,
292
UniqueCollection *uc)
291
cb_collect_unique (GnmCellIter const *iter, UniqueCollection *uc)
294
if (cell_is_blank (cell))
293
if (cell_is_blank (iter->cell))
295
294
uc->has_blank = TRUE;
297
GOFormat const *format = cell_get_format (cell);
298
GnmValue const *v = cell->value;
296
GOFormat const *format = cell_get_format (iter->cell);
297
GnmValue const *v = iter->cell->value;
299
298
char *str = format_value (format, v, NULL, -1, uc->date_conv);
300
g_hash_table_replace (uc->hash, str, cell);
299
g_hash_table_replace (uc->hash, str, iter->cell);
749
748
static GnmValue *
750
cb_filter_expr (Sheet *sheet, int col, int row, GnmCell *cell,
751
FilterExpr const *fexpr)
749
cb_filter_expr (GnmCellIter const *iter, FilterExpr const *fexpr)
751
if (iter->cell != NULL) {
756
754
for (ui = 0; ui < G_N_ELEMENTS (fexpr->cond->op); ui++) {
762
760
res = filter_expr_eval (fexpr->cond->op[ui],
764
762
fexpr->regexp + ui,
766
764
if (fexpr->cond->is_and && !res)
767
765
goto nope; /* AND(...,FALSE,...) */
768
766
if (res && !fexpr->cond->is_and)
777
colrow_set_visibility (sheet, FALSE, FALSE, row, row);
775
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
776
iter->pp.eval.row, iter->pp.eval.row);
781
780
/*****************************************************************************/
783
782
static GnmValue *
784
cb_filter_non_blanks (Sheet *sheet, int col, int row, GnmCell *cell, gpointer data)
783
cb_filter_non_blanks (GnmCellIter const *iter, G_GNUC_UNUSED gpointer user)
786
if (cell_is_blank (cell))
787
colrow_set_visibility (sheet, FALSE, FALSE, row, row);
785
if (cell_is_blank (iter->cell))
786
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
787
iter->pp.eval.row, iter->pp.eval.row);
791
791
static GnmValue *
792
cb_filter_blanks (Sheet *sheet, int col, int row, GnmCell *cell, gpointer data)
792
cb_filter_blanks (GnmCellIter const *iter, G_GNUC_UNUSED gpointer user)
794
if (!cell_is_blank (cell))
795
colrow_set_visibility (sheet, FALSE, FALSE, row, row);
794
if (!cell_is_blank (iter->cell))
795
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
796
iter->pp.eval.row, iter->pp.eval.row);
808
809
static GnmValue *
809
cb_filter_find_items (Sheet *sheet, int col, int row, GnmCell *cell,
810
cb_filter_find_items (GnmCellIter const *iter, FilterItems *data)
812
GnmValue const *v = cell->value;
812
GnmValue const *v = iter->cell->value;
813
813
if (data->elements >= data->count) {
814
814
unsigned j, i = data->elements;
815
815
GnmValDiff const cond = data->find_max ? IS_GREATER : IS_LESS;
834
834
static GnmValue *
835
cb_hide_unwanted_items (Sheet *sheet, int col, int row, GnmCell *cell,
836
FilterItems const *data)
835
cb_hide_unwanted_items (GnmCellIter const *iter, FilterItems const *data)
837
if (iter->cell != NULL) {
839
838
int i = data->elements;
840
GnmValue const *v = cell->value;
839
GnmValue const *v = iter->cell->value;
843
842
if (data->vals[i] == v)
846
colrow_set_visibility (sheet, FALSE, FALSE, row, row);
845
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
846
iter->pp.eval.row, iter->pp.eval.row);
855
855
} FilterPercentage;
857
857
static GnmValue *
858
cb_filter_find_percentage (Sheet *sheet, int col, int row, GnmCell *cell,
859
FilterPercentage *data)
858
cb_filter_find_percentage (GnmCellIter const *iter, FilterPercentage *data)
861
if (VALUE_IS_NUMBER (cell->value)) {
862
gnm_float const v = value_get_as_float (cell->value);
860
if (VALUE_IS_NUMBER (iter->cell->value)) {
861
gnm_float const v = value_get_as_float (iter->cell->value);
864
863
if (data->initialized) {
865
864
if (data->low > v)
877
876
static GnmValue *
878
cb_hide_unwanted_percentage (Sheet *sheet, int col, int row, GnmCell *cell,
877
cb_hide_unwanted_percentage (GnmCellIter const *iter,
879
878
FilterPercentage const *data)
881
if (cell != NULL && VALUE_IS_NUMBER (cell->value)) {
882
gnm_float const v = value_get_as_float (cell->value);
880
if (iter->cell != NULL && VALUE_IS_NUMBER (iter->cell->value)) {
881
gnm_float const v = value_get_as_float (iter->cell->value);
883
882
if (data->find_max) {
884
883
if (v >= data->high)
891
colrow_set_visibility (sheet, FALSE, FALSE, row, row);
890
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
891
iter->pp.eval.row, iter->pp.eval.row);
894
894
/*****************************************************************************/
1002
1002
tmp.start.row = tmp.end.row = filter->r.start.row;
1003
1003
tmp.start.col = tmp.end.col = filter->r.start.col + i;
1004
1004
sheet_object_anchor_init (&anchor, &tmp, offsets, anchor_types,
1005
GOD_ANCHOR_DIR_DOWN_RIGHT);
1006
1006
sheet_object_set_anchor (&field->parent, &anchor);
1007
1007
sheet_object_set_sheet (&field->parent, filter->sheet);