Commit 0fb55e5d authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

All callers changed. renamed from scenario_free_all. (scenarios_dup) :


2006-12-02  Jody Goldberg <jody@gnome.org>

	All callers changed.
	* scenarios.c (scenarios_free) : renamed from scenario_free_all.
	(scenarios_dup) : renamed from scenario_copy_all.
	(scenarios_insert_rows) : renamed from scenario_insert_rows.
	(scenarios_insert_cols) : renamed from scenario_insert_cols.
	(scenarios_delete_rows) : renamed from scenario_delete_rows.
	(scenarios_delete_cols) : renamed from scenario_delete_cols.
	(scenarios_move_range) : renamed from scenario_move_range.

2006-12-02  Jody Goldberg <jody@gnome.org>

	* src/expr.c (gnm_expr_top_relocate) : don't init rinfo::from_inside
	  for INVALIDATE_SHEET case, it's unnecesasry and the inputs are
	  undefined.

	* src/gnumeric-canvas.h : Remove scaling from GNUMERIC_CANVAS_FACTOR_X
	  that was breaking text display in RTL.  We need a gtk patch for that
	  to work.

2006-12-02  Jody Goldberg <jody@gnome.org>

	* src/sheet.c (sheet_dup_filters) : new.
	(sheet_dup) : called from here.
	* src/sheet-filter.c (gnm_filter_condition_dup) : new.
	(gnm_filter_dup) : new.
	(filter_field_apply) : take target_sheet to allow filtering a
	  different sheet using the src data.
	(gnm_filter_get_condition) : replace 'apply' boolean with
	  'target_sheet'.
	(gnm_filter_combo_foo_view_new) : move this internal and use
	  gnm_cell_combo_foo_view_new.
	(gnm_filter_add_field) : use offset to replace the effect of
	  SO_ANCHOR_PERCENTAGE_FROM_COLROW_END.

	* src/validation.c (gnm_validation_combo_foo_view_new) : move this
	  internal and use gnm_cell_combo_foo_view_new.

	* src/sheet-view.c (sv_update) : Use wb_view_selection_desc instead of
	  putting a subset of the logic here.

	* src/gnumeric-canvas.c (gnm_canvas_key_mode_sheet) : Add a hook to
	  popdown validate from list, or autofilter combos.

	* src/sheet-object.h : remove SO_ANCHOR_PERCENTAGE_FROM_COLROW_END.
	* src/sheet-object.c (sheet_object_draw_cairo) : ditto.
	* component/gnumeric.c (go_gnm_component_print) : ditto.
	* src/sheet-object-cell-comment.c (cell_comment_set_cell) : use offset
	  to replace the effect of SO_ANCHOR_PERCENTAGE_FROM_COLROW_END.
	* src/sheet-control-gui.c (calc_obj_place) : FROM_COLROW_END is gone.
	(cell_offset_calc_pixel) : ditto.

	* src/ranges.c (range_init_cellpos) : take only 1 cellpos and use for
	  both ends.  All callers changed.

2006-12-02  Jody Goldberg <jody@gnome.org>

	* gnumeric.xsd : Make schema validate by
	    - adding Attributes.
	    - Add Autofilters.
	    - Add Input Messages

	* src/xml-io.c (xml_init) : Make the sax importer the default.
	(xml_read_colrow_info) : update the max_outline_level.
	* src/xml-sax-read.c (xml_sax_colrow) : ditto. [#380015]
	(gnm_xml_file_open) : init State::filter
	(content_ns) : add schema namespace.
	(xml_sax_filter_end) : new.
	(xml_sax_filter_start) : new.
	(xml_sax_filter_condition) : new.
	(xml_sax_filter_operator) : new.
	(xml_sax_input_msg) : sync with logic in the DOM importer and do
	  not generate an input msg if both title and msg are missing.

2006-12-02  Jody Goldberg <jody@gnome.org>

	* Makefile.am (libwidgets_la_SOURCES) : add
	    gnm-cell-combo-foo-view.[ch]

	* gnm-cell-combo-foo-view.h : new.
	* gnm-cell-combo-foo-view.c : new.
	  Implementation pulled from validation-combo and generalized to share
	  between validation and autofilter.  It adds
	    - autoscroll of the list
	    - more keybindings in the list
	    - RTL support for dropdown placement.
	(gnm_cell_combo_foo_view_new) : create the specified GType (which need
	  to imlement SheetObjectView and GnmCellComboFooView interfaces).
	(gnm_cell_combo_foo_view_popdown) : new routine to allow an external
	  entity to force the combo to populate and open. (eg the alt-down in
	  a cell)
	(gnm_cell_combo_foo_view_popdown): set the
	  cursor in addition to selecting the desired row so that arrows move
	  from the selected item rather than the 1st.

	* gnm-validation-combo-foo-view.h : all we need to expose now is the GType
	* gnm-filter-combo-foo-view.h : ditto.
	* gnm-validation-combo-foo-view.c : split out the content into the new
	  gnm-cell-combo-foo-view.[ch] and implement GnmCComboFooViewIface
	(validation_view_set_bounds) : handle RTL placement of combo.
	* gnm-filter-combo-foo-view.c : ditto.
	(filter_view_set_bounds) : handle RTL placement of combo.

2006-11-25  Jody Goldberg <jody@gnome.org>

	* gnm-validation-combo-foo-view.c (gnm_validation_combo_foo_view_new) :
	  rename from gnm_validation_combo_new_foo_view_new.
	(gnm_validation_combo_foo_view_popdown) : new public interface split
	  out of cb_cell_button_pressed.
parent 1617df3e
......@@ -340,9 +340,6 @@ go_gnm_component_print (GOComponent *component, GnomePrintContext *gpc,
case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
x = cell_width * anchor->offset[0];
break;
case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
x = cell_width * (1. - anchor->offset[0]);
break;
case SO_ANCHOR_PTS_FROM_COLROW_START:
x = anchor->offset[0];
break;
......@@ -358,9 +355,6 @@ go_gnm_component_print (GOComponent *component, GnomePrintContext *gpc,
case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
y = cell_height * anchor->offset[1];
break;
case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
y = cell_height * (1 - anchor->offset[1]);
break;
case SO_ANCHOR_PTS_FROM_COLROW_START:
y = anchor->offset[1];
break;
......@@ -382,9 +376,6 @@ go_gnm_component_print (GOComponent *component, GnomePrintContext *gpc,
case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
width -= cell_width * (1. - anchor->offset[2]);
break;
case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
width -= cell_width * anchor->offset[2];
break;
case SO_ANCHOR_PTS_FROM_COLROW_START:
width -= cell_width - anchor->offset[2];
break;
......@@ -402,9 +393,6 @@ go_gnm_component_print (GOComponent *component, GnomePrintContext *gpc,
case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
height -= cell_height * (1 - anchor->offset[3]);
break;
case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
height -= cell_height * anchor->offset[3];
break;
case SO_ANCHOR_PTS_FROM_COLROW_START:
height -= cell_height - anchor->offset[3];
break;
......@@ -441,7 +429,7 @@ static GtkActionEntry const actions[] = {
/* File */
{ "FileSaveEmbed", GTK_STOCK_SAVE, NULL,
NULL, N_("Save the embedded workbook"),
G_CALLBACK (cb_gognm_save) },
G_CALLBACK (cb_gognm_save) }
};
static void
......
......@@ -70,6 +70,14 @@
<sect2 id="sect-data-modify-filter">
<title>Filtering Data</title>
ALT+DOWN ARROW: Display the AutoFilter list for the current column
DOWN ARROW: Select the next item in the AutoFilter list
UP ARROW: Select the previous item in the AutoFilter list
ALT+UP ARROW: Close the AutoFilter list for the current column
HOME: Select the first item (All) in the AutoFilter list
END: Select the last item in the AutoFilter list
ENTER: Filter the list by using the selected item in the AutoFilter list
<para>
With data filters you can select a subset of rows in the
worksheet that meet the given criteria. You can, for example,
......
......@@ -3675,7 +3675,11 @@ excel_read_COLINFO (BiffQuery *q, ExcelReadSheet *esheet)
if (lastcol >= SHEET_MAX_COLS)
lastcol = SHEET_MAX_COLS - 1;
for (i = firstcol; i <= lastcol; i++) {
sheet_col_set_size_pts (esheet->sheet, i, width, customWidth && !bestFit);
/* Kludge : we should really use
* hard_size == customWidth && !bestFit
* but these flags are undocumented and gnumeric < 1.75 && OOo
* export them as 0. So we are reduced to using */
sheet_col_set_size_pts (esheet->sheet, i, width, !bestFit);
if (outline_level > 0 || collapsed)
colrow_set_outline (sheet_col_fetch (esheet->sheet, i),
outline_level, collapsed);
......@@ -5224,7 +5228,7 @@ excel_read_AUTOFILTER (BiffQuery *q, ExcelReadSheet *esheet)
}
gnm_filter_set_condition (filter,
GSF_LE_GET_GUINT16 (q->data), cond, FALSE);
GSF_LE_GET_GUINT16 (q->data), cond, NULL);
}
void
......
......@@ -4217,8 +4217,7 @@ excel_write_selections (BiffPut *bp, ExcelWriteSheet *esheet, SheetView *sv)
pos = sv->edit_pos;
if (pos.col < sv->unfrozen_top_left.col)
pos.col = sv->unfrozen_top_left.col;
tmp = g_slist_prepend (NULL,
range_init_cellpos (&r, &pos, &pos));
tmp = g_slist_prepend (NULL, range_init_cellpos (&r, &pos));
excel_write_SELECTION (bp, tmp, &pos, 1);
g_slist_free (tmp);
}
......@@ -4226,15 +4225,13 @@ excel_write_selections (BiffPut *bp, ExcelWriteSheet *esheet, SheetView *sv)
pos = sv->edit_pos;
if (pos.row < sv->unfrozen_top_left.row)
pos.row = sv->unfrozen_top_left.row;
tmp = g_slist_prepend (NULL,
range_init_cellpos (&r, &pos, &pos));
tmp = g_slist_prepend (NULL, range_init_cellpos (&r, &pos));
excel_write_SELECTION (bp, tmp, &pos, 2);
g_slist_free (tmp);
}
if (sv->unfrozen_top_left.col > 0 && sv->unfrozen_top_left.row > 0) {
pos = sv->edit_pos; /* apparently no bounds check needed */
tmp = g_slist_prepend (NULL,
range_init_cellpos (&r, &pos, &pos));
tmp = g_slist_prepend (NULL, range_init_cellpos (&r, &pos));
excel_write_SELECTION (bp, tmp, &pos, 0);
g_slist_free (tmp);
}
......
......@@ -1111,11 +1111,18 @@ excel_parse_formula1 (MSContainer const *container,
case FORMULA_PTG_STR: {
char *str;
int len = GSF_LE_GET_GUINT8 (cur);
int byte_len, char_len = GSF_LE_GET_GUINT8 (cur);
if (len <= len_left) {
str = excel_get_text (container->importer, cur+1, len, &len);
ptg_length = 1 + len;
if (char_len <= len_left) {
str = excel_get_text (container->importer, cur+1, char_len, &byte_len);
ptg_length = 1 + byte_len;
/* data validation has a non-standard form of expression
*/
#if 0
if (str != NULL && ) {
int res_char_len = g_utf8_strlen (str, byte_len);
}
#endif
} else {
str = NULL;
......
......@@ -1053,6 +1053,17 @@ xlsx_cell_val_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
}
}
static void
xlsx_validation_expr (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
{
XLSXReadState *state = (XLSXReadState *)xin->user_state;
GnmParsePos pp;
parse_pos_init_sheet (&pp, state->sheet);
g_warning ("validation fmla%d : %s", xin->node->user_data.v_int,
xin->content->str);
}
static void
xlsx_cell_expr_start (GsfXMLIn *xin, xmlChar const **attrs)
{
......@@ -1803,6 +1814,11 @@ GSF_XML_IN_NODE_FULL (START, SHEET, XL_NS_SS, "worksheet", GSF_XML_NO_CONTENT, F
GSF_XML_IN_NODE (CELL, VALUE, XL_NS_SS, "v", GSF_XML_CONTENT, NULL, &xlsx_cell_val_end),
GSF_XML_IN_NODE (CELL, FMLA, XL_NS_SS, "f", GSF_XML_CONTENT, &xlsx_cell_expr_start, &xlsx_cell_expr_end),
GSF_XML_IN_NODE (SHEET, VALIDATIONS, XL_NS_SS, "dataValidations", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (VALIDATIONS, VALIDATION, XL_NS_SS, "dataValidation", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE_FULL (VALIDATION, VAL_FORMULA1, XL_NS_SS, "formula1", GSF_XML_CONTENT, FALSE, FALSE, NULL, &xlsx_validation_expr, 0),
GSF_XML_IN_NODE_FULL (VALIDATION, VAL_FORMULA2, XL_NS_SS, "formula2", GSF_XML_CONTENT, FALSE, FALSE, NULL, &xlsx_validation_expr, 1),
GSF_XML_IN_NODE (SHEET, MERGES, XL_NS_SS, "mergeCells", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (MERGES, MERGE, XL_NS_SS, "mergeCell", GSF_XML_NO_CONTENT, &xlsx_CT_MergeCell, NULL),
......
......@@ -117,11 +117,14 @@ src/tools/solver/reports-write.c
src/tools/solver/solver.c
src/tools/tabulate.c
src/widgets/gnm-dao.c
src/widgets/gnm-format-sel.c
src/widgets/gnm-cell-combo-foo-view.c
src/widgets/gnm-filter-combo-foo-view.c
src/widgets/gnm-validation-combo-foo-view.c
src/widgets/gnumeric-cell-renderer-expr-entry.c
src/widgets/gnumeric-cell-renderer-text.c
src/widgets/gnumeric-cell-renderer-toggle.c
src/widgets/gnumeric-expr-entry.c
src/widgets/gnm-filter-combo.c
src/widgets/widget-font-selector.c
src/application.c
src/cell.c
......
......@@ -233,11 +233,14 @@ src/tools/solver/reports-write.c
src/tools/solver/solver.c
src/tools/tabulate.c
src/widgets/gnm-dao.c
src/widgets/gnm-format-sel.c
src/widgets/gnm-cell-combo-foo-view.c
src/widgets/gnm-filter-combo-foo-view.c
src/widgets/gnm-validation-combo-foo-view.c
src/widgets/gnumeric-cell-renderer-expr-entry.c
src/widgets/gnumeric-cell-renderer-text.c
src/widgets/gnumeric-cell-renderer-toggle.c
src/widgets/gnumeric-expr-entry.c
src/widgets/gnm-filter-combo.c
src/widgets/widget-font-selector.c
src/application.c
src/cell.c
......
......@@ -901,7 +901,7 @@ cmd_set_text_redo (GnmCommand *cmd, WorkbookControl *wbc)
}
}
range_init_cellpos (&r, &me->pos.eval, &me->pos.eval);
range_init_cellpos (&r, &me->pos.eval);
if (texpr || !VALUE_IS_STRING (cell->value))
colrow_autofit (me->cmd.sheet, &r, TRUE, TRUE,
TRUE, FALSE,
......@@ -5243,7 +5243,7 @@ cmd_merge_data_redo (GnmCommand *cmd, WorkbookControl *wbc)
colrow_set_states (new_sheet, TRUE, target_range.start.col, state_col);
colrow_set_states (new_sheet, FALSE, target_range.start.row, state_row);
sheet_object_clone_sheet (source_sheet, new_sheet, &target_range);
sheet_objects_dup (source_sheet, new_sheet, &target_range);
clipboard_paste_region (merge_contents,
paste_target_init (&pt, new_sheet, &target_range, PASTE_ALL_TYPES),
GO_CMD_CONTEXT (wbc));
......@@ -6391,7 +6391,7 @@ cmd_goal_seek (WorkbookControl *wbc, GnmCell *cell, GnmValue *ov, GnmValue *nv)
me->cmd.sheet = cell->base.sheet;
me->cmd.size = 1;
range_init_cellpos (&range, &cell->pos, &cell->pos);
range_init_cellpos (&range, &cell->pos);
me->cmd.cmd_descriptor = g_strdup_printf
(_("Goal Seek (%s)"), undo_range_name (cell->base.sheet, &range));
......
......@@ -158,7 +158,7 @@ cb_autofilter_ok (G_GNUC_UNUSED GtkWidget *button,
}
if (cond != NULL) {
gnm_filter_set_condition (state->filter, state->field,
cond, TRUE);
cond, state->filter->sheet);
sheet_update (state->filter->sheet);
}
......
......@@ -2756,8 +2756,9 @@ gnm_expr_top_relocate (GnmExprTop const *texpr,
rinfo_tmp.details = rinfo;
rinfo_tmp.check_rels = !ignore_rel;
rinfo_tmp.from_inside = (rinfo->origin_sheet == rinfo->pos.sheet) &&
range_contains (&rinfo->origin, rinfo->pos.eval.col, rinfo->pos.eval.row);
if (rinfo->reloc_type != GNM_EXPR_RELOCATE_INVALIDATE_SHEET)
rinfo_tmp.from_inside = (rinfo->origin_sheet == rinfo->pos.sheet) &&
range_contains (&rinfo->origin, rinfo->pos.eval.col, rinfo->pos.eval.row);
return gnm_expr_top_new (gnm_expr_relocate (texpr->expr, &rinfo_tmp));
}
......
......@@ -33,6 +33,9 @@
#include "commands.h"
#include "cmd-edit.h"
#include "clipboard.h"
#include "sheet-filter-combo.h"
#include "widgets/gnm-cell-combo-foo-view.h"
#include <gsf/gsf-impl-utils.h>
#include <gdk/gdkkeysyms.h>
#include <goffice/utils/go-glib-extras.h>
......@@ -216,6 +219,27 @@ gnm_canvas_key_mode_sheet (GnmCanvas *gcanvas, GdkEventKey *event,
case GDK_KP_Down:
case GDK_Down:
if ((event->state == GDK_MOD1_MASK)) {
SheetObject *so;
if (NULL == (so = sv_wbv (sv)->validation_combo)) {
GnmRange r;
GSList *objs = sheet_objects_get (sheet,
range_init_cellpos (&r, &sv->edit_pos),
GNM_FILTER_COMBO_TYPE);
if (objs != NULL) {
so = objs->data,
g_slist_free (objs);
}
}
if (NULL != so) {
SheetObjectView *sov = sheet_object_get_view (so,
(SheetObjectViewContainer *)gcanvas->pane);
gnm_cell_combo_foo_view_popdown (sov);
break;
}
}
if (event->state & SCROLL_LOCK_MASK)
scg_set_top_row (scg, gcanvas->first.row + 1);
else if (transition_keys && jump_to_bounds) {
......
......@@ -8,8 +8,8 @@
#define GNM_CANVAS(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GNM_CANVAS_TYPE, GnmCanvas))
#define IS_GNM_CANVAS(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GNM_CANVAS_TYPE))
#define GNUMERIC_CANVAS_FACTOR_X 1000000*256
#define GNUMERIC_CANVAS_FACTOR_Y 6000000*16
#define GNUMERIC_CANVAS_FACTOR_X 1000000
#define GNUMERIC_CANVAS_FACTOR_Y 6000000
typedef struct {
int col, row;
......
......@@ -65,10 +65,10 @@ range_init_value (GnmRange *range, GnmValue const *v)
}
GnmRange *
range_init_cellpos (GnmRange *r, GnmCellPos const *start, GnmCellPos const *end)
range_init_cellpos (GnmRange *r, GnmCellPos const *pos)
{
r->start = *start;
r->end = *end;
r->start = *pos;
r->end = *pos;
return r;
}
......
......@@ -55,8 +55,7 @@
GnmRange *range_init_full_sheet (GnmRange *r);
GnmRange *range_init_rangeref (GnmRange *r, GnmRangeRef const *rr);
GnmRange *range_init_value (GnmRange *r, GnmValue const *v);
GnmRange *range_init_cellpos (GnmRange *r, GnmCellPos const *start,
GnmCellPos const *end);
GnmRange *range_init_cellpos (GnmRange *r, GnmCellPos const *pos);
GnmRange *range_init_cellpos_size (GnmRange *r, GnmCellPos const *start,
int cols, int rows);
GnmRange *range_init (GnmRange *r, int start_col, int start_row,
......
......@@ -1519,7 +1519,7 @@ scg_finalize (GObject *object)
for (ptr = sheet->sheet_objects; ptr != NULL ; ptr = ptr->next )
SCG_FOREACH_PANE (scg, pane,
sheet_object_view_destroy (
sheet_object_get_view (ptr->data, (gpointer)pane));
sheet_object_get_view (ptr->data, (SheetObjectViewContainer *)pane));
);
g_ptr_array_free (scg->col_group.buttons, TRUE);
......@@ -2006,8 +2006,6 @@ calc_obj_place (GnmCanvas *gcanvas, int canvas_coord, gboolean is_col,
/* TODO : handle other anchor types */
*offset = ((float) (canvas_coord - origin))/ ((float) cri->size_pixels);
if (anchor_type == SO_ANCHOR_PERCENTAGE_FROM_COLROW_END)
*offset = 1. - *offset;
return colrow;
}
......@@ -2393,8 +2391,6 @@ cell_offset_calc_pixel (Sheet const *sheet, int i, gboolean is_col,
{
ColRowInfo const *cri = sheet_colrow_get_info (sheet, i, is_col);
/* TODO : handle other anchor types */
if (anchor_type == SO_ANCHOR_PERCENTAGE_FROM_COLROW_END)
return (1. - offset) * cri->size_pixels;
return offset * cri->size_pixels;
}
......
......@@ -36,6 +36,7 @@
#include "gutils.h"
#include "sheet-object.h"
#include "gnm-filter-combo-foo-view.h"
#include "gnm-cell-combo-foo-view.h"
#include <gsf/gsf-impl-utils.h>
#include <glib/gi18n-lib.h>
......@@ -72,6 +73,24 @@ gnm_filter_condition_new_bucket (gboolean top, gboolean absolute, unsigned n)
return res;
}
GnmFilterCondition *
gnm_filter_condition_dup (GnmFilterCondition const *src)
{
GnmFilterCondition *dst;
if (src == NULL)
return NULL;
dst = g_new0 (GnmFilterCondition, 1);
dst->op[0] = src->op[0];
dst->op[1] = src->op[1];
dst->is_and = src->is_and;
dst->count = src->count;
dst->value[0] = value_dup (src->value[0]);
dst->value[1] = value_dup (src->value[1]);
return dst;
}
void
gnm_filter_condition_unref (GnmFilterCondition *cond)
{
......@@ -88,6 +107,7 @@ typedef struct {
GnmFilterCondition const *cond;
GnmValue *val[2];
GORegexp regexp[2];
Sheet *target_sheet; /* not necessarilly the src */
} FilterExpr;
static void
......@@ -200,7 +220,7 @@ cb_filter_expr (GnmCellIter const *iter, FilterExpr const *fexpr)
}
nope:
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
colrow_set_visibility (fexpr->target_sheet, FALSE, FALSE,
iter->pp.eval.row, iter->pp.eval.row);
return NULL;
}
......@@ -208,19 +228,19 @@ cb_filter_expr (GnmCellIter const *iter, FilterExpr const *fexpr)
/*****************************************************************************/
static GnmValue *
cb_filter_non_blanks (GnmCellIter const *iter, G_GNUC_UNUSED gpointer user)
cb_filter_non_blanks (GnmCellIter const *iter, Sheet *target_sheet)
{
if (gnm_cell_is_blank (iter->cell))
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
colrow_set_visibility (target_sheet, FALSE, FALSE,
iter->pp.eval.row, iter->pp.eval.row);
return NULL;
}
static GnmValue *
cb_filter_blanks (GnmCellIter const *iter, G_GNUC_UNUSED gpointer user)
cb_filter_blanks (GnmCellIter const *iter, Sheet *target_sheet)
{
if (!gnm_cell_is_blank (iter->cell))
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
colrow_set_visibility (target_sheet, FALSE, FALSE,
iter->pp.eval.row, iter->pp.eval.row);
return NULL;
}
......@@ -232,6 +252,7 @@ typedef struct {
unsigned elements;
gboolean find_max;
GnmValue const **vals;
Sheet *target_sheet;
} FilterItems;
static GnmValue *
......@@ -270,7 +291,7 @@ cb_hide_unwanted_items (GnmCellIter const *iter, FilterItems const *data)
if (data->vals[i] == v)
return NULL;
}
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
colrow_set_visibility (data->target_sheet, FALSE, FALSE,
iter->pp.eval.row, iter->pp.eval.row);
return NULL;
}
......@@ -278,8 +299,9 @@ cb_hide_unwanted_items (GnmCellIter const *iter, FilterItems const *data)
/*****************************************************************************/
typedef struct {
gboolean initialized, find_max;
gnm_float low, high;
gboolean initialized, find_max;
gnm_float low, high;
Sheet *target_sheet;
} FilterPercentage;
static GnmValue *
......@@ -315,14 +337,14 @@ cb_hide_unwanted_percentage (GnmCellIter const *iter,
return NULL;
}
}
colrow_set_visibility (iter->pp.sheet, FALSE, FALSE,
colrow_set_visibility (data->target_sheet, FALSE, FALSE,
iter->pp.eval.row, iter->pp.eval.row);
return NULL;
}
/*****************************************************************************/
static void
filter_field_apply (GnmFilterCombo *fcombo)
filter_field_apply (GnmFilterCombo *fcombo, Sheet *target_sheet)
{
GnmFilter const *filter = fcombo->filter;
GnmFilterCondition const *cond = fcombo->cond;
......@@ -330,11 +352,11 @@ filter_field_apply (GnmFilterCombo *fcombo)
int const start_row = filter->r.start.row + 1;
int const end_row = filter->r.end.row;
if (start_row > end_row)
if (start_row > end_row ||
cond == NULL ||
cond->op[0] == GNM_FILTER_UNUSED)
return;
if (cond == NULL || cond->op[0] == GNM_FILTER_UNUSED)
return;
if (0x10 >= (cond->op[0] & GNM_FILTER_OP_TYPE_MASK)) {
FilterExpr data;
data.cond = cond;
......@@ -354,12 +376,12 @@ filter_field_apply (GnmFilterCombo *fcombo)
sheet_foreach_cell_in_range (filter->sheet,
CELL_ITER_IGNORE_HIDDEN,
col, start_row, col, end_row,
cb_filter_blanks, NULL);
cb_filter_blanks, target_sheet);
else if (cond->op[0] == GNM_FILTER_OP_NON_BLANKS)
sheet_foreach_cell_in_range (filter->sheet,
CELL_ITER_IGNORE_HIDDEN,
col, start_row, col, end_row,
cb_filter_non_blanks, NULL);
cb_filter_non_blanks, target_sheet);
else if (0x30 == (cond->op[0] & GNM_FILTER_OP_TYPE_MASK)) {
if (cond->op[0] & 0x2) { /* relative */
FilterPercentage data;
......@@ -374,6 +396,7 @@ filter_field_apply (GnmFilterCombo *fcombo)
offset = (data.high - data.low) * cond->count / 100.;
data.high -= offset;
data.low += offset;
data.target_sheet = target_sheet;
sheet_foreach_cell_in_range (filter->sheet,
CELL_ITER_IGNORE_HIDDEN,
col, start_row, col, end_row,
......@@ -388,6 +411,7 @@ filter_field_apply (GnmFilterCombo *fcombo)
CELL_ITER_IGNORE_HIDDEN | CELL_ITER_IGNORE_BLANK,
col, start_row, col, end_row,
(CellIterFunc) cb_filter_find_items, &data);
data.target_sheet = target_sheet;
sheet_foreach_cell_in_range (filter->sheet,
CELL_ITER_IGNORE_HIDDEN,
col, start_row, col, end_row,
......@@ -429,7 +453,12 @@ gnm_filter_combo_init (SheetObject *so)
/* keep the arrows from wandering with their cells */
so->flags &= ~SHEET_OBJECT_MOVE_WITH_CELLS;
}
static SheetObjectView *
gnm_filter_combo_foo_view_new (SheetObject *so, SheetObjectViewContainer *container)
{
return gnm_cell_combo_foo_view_new (so,
gnm_filter_combo_foo_view_get_type (), container);
}
static void
gnm_filter_combo_class_init (GObjectClass *gobject_class)
{
......@@ -439,7 +468,7 @@ gnm_filter_combo_class_init (GObjectClass *gobject_class)
gobject_class->finalize = gnm_filter_combo_finalize;
/* SheetObject class method overrides */
so_class->new_view = gnm_filter_combo_foo_view_new;
so_class->new_view = gnm_filter_combo_foo_view_new;
so_class->read_xml_dom = NULL;
so_class->write_xml_sax = NULL;
so_class->print = NULL;
......@@ -464,13 +493,7 @@ static void
gnm_filter_add_field (GnmFilter *filter, int i)
{
/* pretend to fill the cell, then clip the X start later */
static SheetObjectAnchorType const anchor_types [4] = {
SO_ANCHOR_PERCENTAGE_FROM_COLROW_START,
SO_ANCHOR_PERCENTAGE_FROM_COLROW_START,
SO_ANCHOR_PERCENTAGE_FROM_COLROW_END,
SO_ANCHOR_PERCENTAGE_FROM_COLROW_END
};
static float const offsets [4] = { .0, .0, 0., 0. };
static float const a_offsets [4] = { .0, .0, 1., 1. };
int n;
GnmRange tmp;
SheetObjectAnchor anchor;
......@@ -479,8 +502,8 @@ gnm_filter_add_field (GnmFilter *filter, int i)
fcombo->filter = filter;
tmp.start.row = tmp.end.row = filter->r.start.row;
tmp.start.col = tmp.end.col = filter->r.start.col + i;
sheet_object_anchor_init (&anchor, &tmp, offsets, anchor_types,
GOD_ANCHOR_DIR_DOWN_RIGHT);
sheet_object_anchor_init (&anchor, &tmp, a_offsets, NULL,
GOD_ANCHOR_DIR_DOWN_RIGHT);
sheet_object_set_anchor (SHEET_OBJECT (fcombo), &anchor);
sheet_object_set_sheet (SHEET_OBJECT (fcombo), filter->sheet);
......@@ -497,7 +520,7 @@ gnm_filter_add_field (GnmFilter *filter, int i)
* @sheet :
* @r :
*
* Init a filter
* Init a filter and add it to @sheet
**/
GnmFilter *
gnm_filter_new (Sheet *sheet, GnmRange const *r)
......@@ -524,6 +547,42 @@ gnm_filter_new (Sheet *sheet, GnmRange const *r)
return filter;
}
/**
* gnm_filter_dup :
* @src : #GnmFilter
* @sheet : #Sheet
*
* Duplicate @src into @sheet
**/
GnmFilter *
gnm_filter_dup (GnmFilter const *src, Sheet *sheet)
{
int i;
GnmFilter *dst;
g_return_val_if_fail (src != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
dst = g_new0 (GnmFilter, 1);
dst->sheet = sheet;
dst->is_active = src->is_active;
dst->r = src->r;
dst->fields = g_ptr_array_new ();
for (i = 0 ; i < range_width (&dst->r); i++) {
gnm_filter_add_field (dst, i);
gnm_filter_set_condition (dst, i,
gnm_filter_condition_dup (
gnm_filter_get_condition (src, i)),
NULL);
}
sheet->filters = g_slist_prepend (sheet->filters, dst);
sheet->priv->filters_changed = TRUE;
return dst;
}
void
gnm_filter_free (GnmFilter *filter)
{
......@@ -583,13 +642,16 @@ gnm_filter_get_condition (GnmFilter const *filter, unsigned i)
* @filter :
* @i :
* @cond :
* @apply :
* @target_sheet : #Sheet
*
* Change the @i-th condition of @filter to @cond.
* If @target_sheet is non-NULL @filter is used to set the visibility
* of it's rows (using the data from @filter->sheet).
**/
void
gnm_filter_set_condition (GnmFilter *filter, unsigned i,
GnmFilterCondition *cond,
gboolean apply)
Sheet *target_sheet)
{
GnmFilterCombo *fcombo;
gboolean set_infilter = FALSE;
......@@ -608,7 +670,7 @@ gnm_filter_set_condition (GnmFilter *filter, unsigned i,
fcombo->cond = cond;
g_signal_emit (G_OBJECT (fcombo), signals [COND_CHANGED], 0);
if (apply) {
if (target_sheet != NULL) {
/* if there was an existing cond then we need to do
* 1) unfilter everything
* 2) reapply all the filters
......@@ -619,11 +681,12 @@ gnm_filter_set_condition (GnmFilter *filter, unsigned i,
colrow_set_visibility (filter->sheet, FALSE, TRUE,
filter->r.start.row + 1, filter->r.end.row);
for (i = 0 ; i < filter->fields->len ; i++)
filter_field_apply (g_ptr_array_index (filter->fields, i));
filter_field_apply (g_ptr_array_index (filter->fields, i),
target_sheet);
} else
/* When adding a new cond all we need to do is
* apply that filter */
filter_field_apply (fcombo);
filter_field_apply (fcombo, target_sheet);
}
/* set the activity flag and potentially activate the
......
......@@ -20,7 +20,14 @@ typedef enum {
GNM_FILTER_OP_BOTTOM_N = 0x31,
GNM_FILTER_OP_TOP_N_PERCENT = 0x32,
GNM_FILTER_OP_BOTTOM_N_PERCENT = 0x33,
GNM_FILTER_OP_TYPE_MASK = 0x30
/* Added in 1.7.5 */
GNM_FILTER_OP_GT_AVERAGE = 0x40,
GNM_FILTER_OP_LT_AVERAGE = 0x41,
GNM_FILTER_OP_WITHIN_STDDEV = 0x50,
GNM_FILTER_OP_OUTSIDE_STDDEV = 0x51,
GNM_FILTER_OP_TYPE_MASK = 0x70
} GnmFilterOp;
struct _GnmFilterCondition {
......@@ -45,15 +52,18 @@ GnmFilterCondition *gnm_filter_condition_new_double (GnmFilterOp op1, GnmValue *
GnmFilterCondition *gnm_filter_condition_new_bucket (gboolean top,
gboolean absolute,
unsigned n);
GnmFilterCondition *gnm_filter_condition_dup (GnmFilterCondition const *src);
void gnm_filter_condition_unref (GnmFilterCondition *cond);
GnmFilter *gnm_filter_new (Sheet *sheet, GnmRange const *r);
GnmFilter *gnm_filter_dup (GnmFilter const *src,
Sheet *sheet);
void gnm_filter_free (GnmFilter *filter);
void gnm_filter_remove (GnmFilter *filter);
GnmFilterCondition const *gnm_filter_get_condition (GnmFilter const *filter, unsigned i);
void gnm_filter_set_condition (GnmFilter *filter, unsigned i,
GnmFilterCondition *cond,
gboolean apply);
Sheet *target_sheet);
gboolean gnm_filter_overlaps_range (GnmFilter const *filter, GnmRange const *r);
gboolean gnm_filter_overlaps_range (GnmFilter const *filter, GnmRange const *r);
......
......@@ -389,20 +389,15 @@ void
cell_comment_set_cell (GnmComment *cc, GnmCellPos const *pos)
{
/* top right */
static SheetObjectAnchorType const anchor_types [4] = {
SO_ANCHOR_PERCENTAGE_FROM_COLROW_END,
SO_ANCHOR_PERCENTAGE_FROM_COLROW_START,
SO_ANCHOR_PERCENTAGE_FROM_COLROW_END,
SO_ANCHOR_PERCENTAGE_FROM_COLROW_START
};
static float const a_offsets [4] = { 1., 0., 1., 0. };
SheetObjectAnchor anchor;
GnmRange r;
g_return_if_fail (IS_CELL_COMMENT (cc));
r.start = r.end = *pos;
sheet_object_anchor_init (&anchor, &r, NULL,
anchor_types, GOD_ANCHOR_DIR_DOWN_RIGHT);
sheet_object_anchor_init (&anchor, &r, a_offsets,
NULL, GOD_ANCHOR_DIR_DOWN_RIGHT);
sheet_object_set_anchor (SHEET_OBJECT (cc), &anchor);
}
......
......@@ -126,7 +126,7 @@ typedef struct {
#define IS_SHEET_OBJECT_VIEW(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SHEET_OBJECT_VIEW_TYPE))
#define SHEET_OBJECT_VIEW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SHEET_OBJECT_VIEW_TYPE, SheetObjectViewIface))
#define IS_SHEET_OBJECT_VIEW_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SHEET_OBJECT_VIEW_TYPE))
#define SHEET_OBJECT_VIEW_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), SHEET_OBJECT_VIEW_TYPE, SheetObjectViewIface))