~ubuntu-branches/ubuntu/feisty/gnumeric/feisty-security

« back to all changes in this revision

Viewing changes to src/sheet-filter.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2006-11-14 14:02:03 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061114140203-iv3j2aii3vch6isl
Tags: 1.7.2-1ubuntu1
* Merge with debian experimental:
  - debian/control, debian/*-gtk-*, debian/rules,
    debian/shlibs.local: Xubuntu changes for
    gtk/gnome multibuild.
  - run intltool-update in po*
  - Build Depend on intltool

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
/*
4
4
 * filter.c: support for filters
5
5
 *
6
 
 * Copyright (C) 2002-2005 Jody Goldberg (jody@gnome.org)
 
6
 * Copyright (C) 2002-2006 Jody Goldberg (jody@gnome.org)
7
7
 *
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
47
47
#include <gdk/gdkevents.h>
48
48
#include <gdk/gdkkeysyms.h>
49
49
#include <gsf/gsf-impl-utils.h>
50
 
#include <glib/gi18n.h>
 
50
#include <glib/gi18n-lib.h>
51
51
#include <string.h>
52
52
#include <stdlib.h>
53
53
 
288
288
} UniqueCollection;
289
289
 
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)
293
292
{
294
 
        if (cell_is_blank (cell))
 
293
        if (cell_is_blank (iter->cell))
295
294
                uc->has_blank = TRUE;
296
295
        else {
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);
301
300
        }
302
301
 
303
302
        return NULL;
747
746
}
748
747
 
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)
752
750
{
753
 
        if (cell != NULL) {
 
751
        if (iter->cell != NULL) {
754
752
                unsigned int ui;
755
753
 
756
754
                for (ui = 0; ui < G_N_ELEMENTS (fexpr->cond->op); ui++) {
762
760
                        res = filter_expr_eval (fexpr->cond->op[ui],
763
761
                                                fexpr->val[ui],
764
762
                                                fexpr->regexp + ui,
765
 
                                                cell);
 
763
                                                iter->cell);
766
764
                        if (fexpr->cond->is_and && !res)
767
765
                                goto nope;   /* AND(...,FALSE,...) */
768
766
                        if (res && !fexpr->cond->is_and)
774
772
        }
775
773
 
776
774
 nope:
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);
778
777
        return NULL;
779
778
}
780
779
 
781
780
/*****************************************************************************/
782
781
 
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)
785
784
{
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);
788
788
        return NULL;
789
789
}
790
790
 
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)
793
793
{
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);
796
797
        return NULL;
797
798
}
798
799
 
806
807
} FilterItems;
807
808
 
808
809
static GnmValue *
809
 
cb_filter_find_items (Sheet *sheet, int col, int row, GnmCell *cell,
810
 
                      FilterItems *data)
 
810
cb_filter_find_items (GnmCellIter const *iter, FilterItems *data)
811
811
{
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;
832
832
}
833
833
 
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
836
{
838
 
        if (cell != NULL) {
 
837
        if (iter->cell != NULL) {
839
838
                int i = data->elements;
840
 
                GnmValue const *v = cell->value;
 
839
                GnmValue const *v = iter->cell->value;
841
840
 
842
841
                while (i-- > 0)
843
842
                        if (data->vals[i] == v)
844
843
                                return NULL;
845
844
        }
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);
847
847
        return NULL;
848
848
}
849
849
 
855
855
} FilterPercentage;
856
856
 
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)
860
859
{
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);
863
862
 
864
863
                if (data->initialized) {
865
864
                        if (data->low > v)
875
874
}
876
875
 
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)
880
879
{
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)
885
884
                                return NULL;
888
887
                                return NULL;
889
888
                }
890
889
        }
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);
892
892
        return NULL;
893
893
}
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
 
                                  SO_DIR_DOWN_RIGHT);
 
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);
1008
1008