Commit 123f215d authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

finish. And use the new cmd_create_data_table.

    2007-10-27  Jody Goldberg <jody@gnome.org>

    	* dialog-data-table.c (dialog_data_table) : finish.  And use the new
    	  cmd_create_data_table.

    2007-10-27  Jody Goldberg <jody@gnome.org>

    	* gnumeric-expr-entry.c : Move from
    	  ABS_COL/ABS_ROW -> FORCE_ABS/FORCE_REL
    	  All callers changed.

    2007-10-27  Jody Goldberg <jody@gnome.org>

    	* src/commands.c (cmd_create_data_table) : New.  Wrapper to set_area
    	  that creates a data table with undo capabilities.

    	* src/func-builtin.c (gnumeric_table) : clear the val point in a cell
    	  before destroying it because the value was a temporary and has
    	  already been released.  Cache and restore the x_iter value to avoid
    	  leaving the last calculated value in the cell after evaluating for
    	  TABLE(,ADDR)

    	* src/parser.y : convert from distinct gboolean flags to using a
    	  simple bit mask.  Switch from distinct ABS_COL/ABS_ROW to ABS and
    	  REL.  There was no need to split COL vs ROW, but there was a need
    	  [Data->Table] to force relative (XL requires rel refs).

svn path=/trunk/; revision=16026
parent 4ddf5372
2007-10-27 Jody Goldberg <jody@gnome.org>
* src/commands.c (cmd_create_data_table) : New. Wrapper to set_area
that creates a data table with undo capabilities.
* src/func-builtin.c (gnumeric_table) : clear the val point in a cell
before destroying it because the value was a temporary and has
already been released. Cache and restore the x_iter value to avoid
leaving the last calculated value in the cell after evaluating for
TABLE(,ADDR)
* src/parser.y : convert from distinct gboolean flags to using a
simple bit mask. Switch from distinct ABS_COL/ABS_ROW to ABS and
REL. There was no need to split COL vs ROW, but there was a need
[Data->Table] to force relative (XL requires rel refs).
2007-10-27 Morten Welinder <terra@gnome.org>
* src/xml-sax-read.c (xml_sax_read_obj): Survive a missing
......
......@@ -7,6 +7,7 @@ Jody:
* Improve ODF (and .sxc) import.
* Improve ODF chart data import (ick).
* Add Snap-to-grid context menu command for objects.
* Fix Data -> Table and enable the UI.
Morten:
* Improve test suite.
......
......@@ -194,13 +194,19 @@ static GSF_CLASS (type, func, \
/******************************************************************/
static guint
max_descriptor_width (void)
{
return gnm_app_prefs->max_descriptor_width;
}
static char *
make_undo_text (char const *src, int max_len, gboolean *truncated)
make_undo_text (char const *src, gboolean *truncated)
{
char *dst = g_strdup (src);
char *p;
int len;
int max_len = max_descriptor_width ();
*truncated = FALSE;
for (len = 0, p = dst;
*p;
......@@ -337,13 +343,6 @@ select_selection (Sheet *sheet, GSList *selection, WorkbookControl *wbc)
sv_make_cell_visible (sv, r0->start.col, r0->start.row, FALSE);
}
static guint
max_descriptor_width (void)
{
return gnm_app_prefs->max_descriptor_width;
}
/**
* get_menu_label : Utility routine to get the descriptor associated
* with a list of commands.
......@@ -996,9 +995,7 @@ cmd_set_text (WorkbookControl *wbc,
r.start = r.end = *pos;
me->old_contents = clipboard_copy_range (sheet, &r);
text = make_undo_text (corrected_text,
max_descriptor_width (),
&truncated);
text = make_undo_text (corrected_text, &truncated);
me->cmd.sheet = sheet;
me->cmd.size = 1;
......@@ -1201,9 +1198,7 @@ cmd_area_set_text (WorkbookControl *wbc, SheetView *sv,
} else
parse_pos_init_editpos (&me->pp, sv);
text = make_undo_text (new_text,
max_descriptor_width (),
&truncated);
text = make_undo_text (new_text, &truncated);
me->cmd.sheet = me->pp.sheet;
me->cmd.size = 1;
......@@ -1217,6 +1212,25 @@ cmd_area_set_text (WorkbookControl *wbc, SheetView *sv,
return command_push_undo (wbc, G_OBJECT (me));
}
gboolean
cmd_create_data_table (WorkbookControl *wbc, Sheet *sheet, GnmRange const *r,
char const *col_input, char const *row_input)
{
CmdAreaSetText *me = g_object_new (CMD_AREA_SET_TEXT_TYPE, NULL);
parse_pos_init (&me->pp, NULL, sheet, r->start.col, r->start.row);
me->text = g_strdup_printf ("=TABLE(%s,%s)", row_input, col_input);
me->selection = g_slist_prepend (NULL, range_dup (r));
me->old_contents = NULL;
me->as_array = TRUE;
me->cmd.sheet = sheet;
me->cmd.size = 1;
me->cmd.cmd_descriptor =
g_strdup_printf (_("Creating a Data Table in %s"),
range_as_string (r));
return command_push_undo (wbc, G_OBJECT (me));
}
/******************************************************************/
#define CMD_INS_DEL_COLROW_TYPE (cmd_ins_del_colrow_get_type ())
......
......@@ -17,6 +17,9 @@ gboolean cmd_set_text (WorkbookControl *wbc, Sheet *sheet,
gboolean cmd_area_set_text (WorkbookControl *wbc, SheetView *sv,
char const *text, gboolean as_array);
gboolean cmd_create_data_table (WorkbookControl *wbc,
Sheet *sheet, GnmRange const *r,
char const *col_input, char const *row_input);
gboolean cmd_insert_cols (WorkbookControl *wbc, Sheet *sheet,
int start_col, int count);
......
2007-10-27 Jody Goldberg <jody@gnome.org>
* dialog-data-table.c (dialog_data_table) : finish. And use the new
cmd_create_data_table.
2007-10-21 Morten Welinder <terra@gnome.org>
* Release 1.7.13
......
......@@ -1720,8 +1720,6 @@ static void
fmt_dialog_init_validation_expr_entry (FormatState *state, ExprEntry *entry,
char const *name, int i)
{
GnmExprEntryFlags flags = GNM_EE_ABS_ROW | GNM_EE_ABS_COL | GNM_EE_SHEET_OPTIONAL;
entry->name = GTK_LABEL (glade_xml_get_widget (state->gui, name));
entry->entry = gnm_expr_entry_new (state->wbcg, TRUE);
gtk_table_attach (state->validation.criteria_table,
......@@ -1734,7 +1732,8 @@ fmt_dialog_init_validation_expr_entry (FormatState *state, ExprEntry *entry,
g_signal_connect (G_OBJECT (entry->entry),
"changed",
G_CALLBACK (cb_validation_changed), state);
gnm_expr_entry_set_flags (entry->entry, flags, flags | GNM_EE_SINGLE_RANGE);
gnm_expr_entry_set_flags (entry->entry, GNM_EE_FORCE_ABS_REF | GNM_EE_SHEET_OPTIONAL, GNM_EE_MASK);
}
static void
......
......@@ -3,7 +3,7 @@
/*
* dialog-data-table.c: Create a Data Table
*
* Copyright (C) 2006 Jody Goldberg (jody@gnome.org)
* Copyright (C) 2006-2007 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
......@@ -34,6 +34,7 @@
#include <gui-util.h>
#include <parse-util.h>
#include <commands.h>
#include <ranges.h>
#include <widgets/gnumeric-expr-entry.h>
#include <gtk/gtktable.h>
#include <glib/gi18n.h>
......@@ -46,6 +47,8 @@ typedef struct {
GnmExprEntry *row_entry, *col_entry;
WBCGtk *wbcg;
Sheet *sheet;
GnmRange input_range;
} GnmDialogDataTable;
static void
......@@ -64,7 +67,8 @@ init_entry (GnmDialogDataTable *state, char const *name)
g_return_val_if_fail (w != NULL, NULL);
gnm_expr_entry_set_flags (GNM_EXPR_ENTRY (w),
GNM_EE_SINGLE_RANGE, GNM_EE_SINGLE_RANGE);
GNM_EE_SINGLE_RANGE | GNM_EE_SHEET_OPTIONAL | GNM_EE_FORCE_REL_REF,
GNM_EE_MASK);
g_object_set (G_OBJECT (w),
"scg", wbcg_cur_scg (state->wbcg),
"with-icon", TRUE,
......@@ -77,9 +81,11 @@ cb_data_table_response (GtkWidget *dialog, gint response_id, GnmDialogDataTable
{
if (response_id == GTK_RESPONSE_HELP)
return;
if (response_id == GTK_RESPONSE_OK) {
}
if (response_id == GTK_RESPONSE_OK)
cmd_create_data_table (WORKBOOK_CONTROL (state->wbcg),
state->sheet, &state->input_range,
gnm_expr_entry_get_text (state->col_entry),
gnm_expr_entry_get_text (state->row_entry));
gtk_object_destroy (GTK_OBJECT (dialog));
}
......@@ -88,7 +94,6 @@ data_table_init (GnmDialogDataTable *state, WBCGtk *wbcg)
{
GtkTable *table;
state->wbcg = wbcg;
state->gui = gnm_glade_xml_new (GO_CMD_CONTEXT (wbcg),
"data-table.glade", NULL, NULL);
if (state->gui == NULL)
......@@ -125,6 +130,10 @@ void
dialog_data_table (WBCGtk *wbcg)
{
GnmDialogDataTable *state;
GnmRange const *r;
GnmRange input_range;
SheetView *sv;
Sheet *sheet;
g_return_if_fail (wbcg != NULL);
......@@ -132,7 +141,29 @@ dialog_data_table (WBCGtk *wbcg)
gnumeric_dialog_raise_if_exists (wbcg, DIALOG_DATA_TABLE_KEY))
return;
sv = wb_control_cur_sheet_view (WORKBOOK_CONTROL (wbcg));
r = selection_first_range (sv, GO_CMD_CONTEXT (wbcg), _("Create Data Table"));
if (NULL == r)
return;
if (range_width (r) <= 1 || range_height (r) <= 1) {
GError *msg = g_error_new (go_error_invalid(), 0,
_("The selection must have more than 1 column and row to create a Data Table."));
go_cmd_context_error (GO_CMD_CONTEXT (wbcg), msg);
g_error_free (msg);
return;
}
input_range = *r;
input_range.start.col++;
input_range.start.row++;
sheet = sv_sheet (sv);
if (sheet_range_splits_region (sheet, &input_range, NULL,
GO_CMD_CONTEXT (wbcg), _("Data Table")))
return;
state = g_new0 (GnmDialogDataTable, 1);
state->wbcg = wbcg;
state->sheet = sheet;
state->input_range = input_range;
if (data_table_init (state, wbcg)) {
go_gtk_notice_dialog (wbcg_toplevel (wbcg), GTK_MESSAGE_ERROR,
_("Could not create the Data Table definition dialog."));
......
......@@ -544,8 +544,7 @@ dialog_init (GoalSeekState *state)
table = GTK_TABLE (glade_xml_get_widget (state->gui, "goal-table"));
state->set_cell_entry = gnm_expr_entry_new (state->wbcg, TRUE);
gnm_expr_entry_set_flags (state->set_cell_entry,
GNM_EE_SINGLE_RANGE | GNM_EE_SHEET_OPTIONAL |
GNM_EE_ABS_ROW | GNM_EE_ABS_COL,
GNM_EE_SINGLE_RANGE | GNM_EE_SHEET_OPTIONAL | GNM_EE_FORCE_ABS_REF,
GNM_EE_MASK);
gtk_table_attach (table, GTK_WIDGET (state->set_cell_entry),
2, 3, 1, 2,
......@@ -558,8 +557,7 @@ dialog_init (GoalSeekState *state)
state->change_cell_entry = gnm_expr_entry_new (state->wbcg, TRUE);
gnm_expr_entry_set_flags (state->change_cell_entry,
GNM_EE_SINGLE_RANGE | GNM_EE_SHEET_OPTIONAL |
GNM_EE_ABS_ROW | GNM_EE_ABS_COL,
GNM_EE_SINGLE_RANGE | GNM_EE_SHEET_OPTIONAL | GNM_EE_FORCE_ABS_REF,
GNM_EE_MASK);
gtk_table_attach (table, GTK_WIDGET (state->change_cell_entry),
2, 3, 3, 4,
......
......@@ -1341,7 +1341,7 @@ do_setup_page_info (PrinterSetupState *state)
state->top_entry = gnm_expr_entry_new (state->wbcg, TRUE);
gnm_expr_entry_set_flags (state->top_entry,
GNM_EE_SINGLE_RANGE | GNM_EE_FULL_ROW | GNM_EE_SHEET_OPTIONAL,
GNM_EE_SINGLE_RANGE | GNM_EE_FULL_ROW | GNM_EE_ABS_ROW | GNM_EE_SHEET_OPTIONAL);
GNM_EE_MASK);
gtk_table_attach (GTK_TABLE (repeat_table),
GTK_WIDGET (state->top_entry),
1, 2, 0, 1,
......@@ -1351,7 +1351,7 @@ do_setup_page_info (PrinterSetupState *state)
state->left_entry = gnm_expr_entry_new (state->wbcg, TRUE);
gnm_expr_entry_set_flags (state->left_entry,
GNM_EE_SINGLE_RANGE | GNM_EE_FULL_COL | GNM_EE_SHEET_OPTIONAL,
GNM_EE_SINGLE_RANGE | GNM_EE_FULL_COL | GNM_EE_ABS_COL | GNM_EE_SHEET_OPTIONAL);
GNM_EE_MASK);
gtk_table_attach (GTK_TABLE (repeat_table),
GTK_WIDGET (state->left_entry),
1, 2, 1, 2,
......
......@@ -73,7 +73,7 @@ init_entry (GnmDialogSOList *state, char const *name,
"with-icon", TRUE,
NULL);
gnm_expr_entry_set_flags (gee,
GNM_EE_ABS_ROW | GNM_EE_ABS_COL | GNM_EE_SHEET_OPTIONAL | GNM_EE_SINGLE_RANGE,
GNM_EE_FORCE_ABS_REF | GNM_EE_SHEET_OPTIONAL | GNM_EE_SINGLE_RANGE,
GNM_EE_MASK);
gnm_expr_entry_load_from_dep (gee, dep);
return gee;
......
......@@ -213,7 +213,9 @@ gnumeric_table (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
gnm_cell_eval (x_iter);
in[0]->value = value_dup (x_iter->value);
dependent_queue_recalc (&in[0]->base);
}
} else
val[0] = value_dup (x_iter->value);
for (y = ei->pos->array->rows ; y-- > 0 ; ) {
y_iter = sheet_cell_get (ei->pos->sheet,
ei->pos->eval.col-1, y + ei->pos->eval.row);
......@@ -221,6 +223,7 @@ gnumeric_table (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
continue;
gnm_cell_eval (y_iter);
if (NULL != in[1]) {
/* not a leak, val[] holds the original */
in[1]->value = value_dup (y_iter->value);
dependent_queue_recalc (&in[1]->base);
if (NULL != in[0]) {
......@@ -236,14 +239,18 @@ gnumeric_table (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
}
if (NULL != in[0])
value_release (in[0]->value);
else {
value_release (x_iter->value);
x_iter->value = val[0];
val[0] = NULL;
}
}
if (NULL != in[2])
value_release (in[2]->value);
for (x = 0 ; x < 3 ; x++)
if (in[x]) {
if (val[x])
in[x]->value = val[x];
else
/* always assign, we still point at a released value */
if (NULL == (in[x]->value = val[x]))
sheet_cell_remove (ei->pos->sheet, in[x], FALSE, FALSE);
dependent_queue_recalc (&in[x]->base);
}
......
......@@ -79,8 +79,8 @@ void parse_error_free (GnmParseError *pe);
typedef enum {
GNM_EXPR_PARSE_DEFAULT = 0, /* default is Excel */
GNM_EXPR_PARSE_FORCE_ABSOLUTE_COL_REFERENCES = 1 << 0,
GNM_EXPR_PARSE_FORCE_ABSOLUTE_ROW_REFERENCES = 1 << 1,
GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES = 1 << 0,
GNM_EXPR_PARSE_FORCE_RELATIVE_REFERENCES = 1 << 0,
GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES = 1 << 2,
GNM_EXPR_PARSE_PERMIT_MULTIPLE_EXPRESSIONS = 1 << 3,
GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS = 1 << 4,
......
......@@ -204,13 +204,7 @@ typedef struct {
/* if arg_sep conflicts with array_col_sep or array_row_sep */
int in_array_sep_is; /* token id */
/* flags */
gboolean force_absolute_col_references;
gboolean force_absolute_row_references;
gboolean force_explicit_sheet_references;
gboolean unknown_names_are_strings;
gboolean unknown_names_are_invalid;
GnmExprParseFlags flags;
GnmConventions const *convs;
/* dynamic state */
......@@ -446,13 +440,13 @@ parser_simple_val_or_name (GnmExpr *str_expr)
if (v == NULL) {
GnmNamedExpr *nexpr = expr_name_lookup (state->pos, str);
if (nexpr == NULL) {
if (state->unknown_names_are_invalid) {
if (state->flags & GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_INVALID) {
report_err (state, g_error_new (1, PERR_UNKNOWN_NAME,
_("Name '%s' does not exist"),
str),
state->ptr, 0);
res = NULL;
} else if (state->unknown_names_are_strings) {
} else if (state->flags & GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS) {
res = gnm_expr_new_constant (value_new_string (str));
} else {
GnmParsePos pp = *state->pos;
......@@ -1078,7 +1072,7 @@ yylex (void)
if (start != (end = state->convs->input.range_ref (&ref, start, state->pos, state->convs))) {
state->ptr = end;
if (state->force_absolute_col_references) {
if (state->flags & GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES) {
if (ref.a.col_relative) {
ref.a.col += state->pos->eval.col;
ref.a.col_relative = FALSE;
......@@ -1087,8 +1081,6 @@ yylex (void)
ref.b.col += state->pos->eval.col;
ref.b.col_relative = FALSE;
}
}
if (state->force_absolute_row_references) {
if (ref.a.row_relative) {
ref.a.row += state->pos->eval.row;
ref.a.row_relative = FALSE;
......@@ -1097,9 +1089,26 @@ yylex (void)
ref.b.row += state->pos->eval.row;
ref.b.row_relative = FALSE;
}
} else if (state->flags & GNM_EXPR_PARSE_FORCE_RELATIVE_REFERENCES) {
if (!ref.a.col_relative) {
ref.a.col -= state->pos->eval.col;
ref.a.col_relative = TRUE;
}
if (!ref.b.col_relative) {
ref.b.col -= state->pos->eval.col;
ref.b.col_relative = TRUE;
}
if (!ref.a.row_relative) {
ref.a.row -= state->pos->eval.row;
ref.a.row_relative = TRUE;
}
if (!ref.b.row_relative) {
ref.b.row -= state->pos->eval.row;
ref.b.row_relative = TRUE;
}
}
if (ref.a.sheet == NULL && state->force_explicit_sheet_references) {
if (ref.a.sheet == NULL && (state->flags & GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES)) {
ref.a.sheet = state->pos->sheet;
if (ref.a.sheet == NULL) {
report_err (state, g_error_new (1, PERR_SHEET_IS_REQUIRED,
......@@ -1352,11 +1361,7 @@ gnm_expr_parse_str (char const *str, GnmParsePos const *pp,
pstate.start = pstate.ptr = str;
pstate.pos = pp;
pstate.force_absolute_col_references = flags & GNM_EXPR_PARSE_FORCE_ABSOLUTE_COL_REFERENCES;
pstate.force_absolute_row_references = flags & GNM_EXPR_PARSE_FORCE_ABSOLUTE_ROW_REFERENCES;
pstate.force_explicit_sheet_references = flags & GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
pstate.unknown_names_are_strings = flags & GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS;
pstate.unknown_names_are_invalid = flags & GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_INVALID;
pstate.flags = flags;
pstate.convs =
(NULL != convs) ? convs : ((NULL != pp->sheet) ? pp->sheet->convs : gnm_conventions_default);
......
......@@ -965,7 +965,7 @@ sheet_widget_adjustment_user_config (SheetObject *so, SheetControl *sc)
state->expression = gnm_expr_entry_new (wbcg, TRUE);
gnm_expr_entry_set_flags (state->expression,
GNM_EE_ABS_ROW | GNM_EE_ABS_COL | GNM_EE_SHEET_OPTIONAL | GNM_EE_SINGLE_RANGE,
GNM_EE_FORCE_ABS_REF | GNM_EE_SHEET_OPTIONAL | GNM_EE_SINGLE_RANGE,
GNM_EE_MASK);
gnm_expr_entry_load_from_dep (state->expression, &swa->dep);
go_atk_setup_label (glade_xml_get_widget (state->gui, "label_linkto"),
......@@ -1603,7 +1603,7 @@ sheet_widget_checkbox_user_config (SheetObject *so, SheetControl *sc)
state->expression = gnm_expr_entry_new (wbcg, TRUE);
gnm_expr_entry_set_flags (state->expression,
GNM_EE_ABS_ROW | GNM_EE_ABS_COL | GNM_EE_SHEET_OPTIONAL | GNM_EE_SINGLE_RANGE,
GNM_EE_FORCE_ABS_REF | GNM_EE_SHEET_OPTIONAL | GNM_EE_SINGLE_RANGE,
GNM_EE_MASK);
gnm_expr_entry_load_from_dep (state->expression, &swc->dep);
go_atk_setup_label (glade_xml_get_widget (state->gui, "label_linkto"),
......
......@@ -4151,8 +4151,7 @@ wbcg_data_allocator_editor (GogDataAllocator *dalloc,
gnm_expr_entry_load_from_text (editor->entry, txt);
g_free (txt);
}
gnm_expr_entry_set_flags (editor->entry,
GNM_EE_ABS_COL|GNM_EE_ABS_ROW, GNM_EE_MASK);
gnm_expr_entry_set_flags (editor->entry, GNM_EE_FORCE_ABS_REF, GNM_EE_MASK);
editor->entry_update_handler = g_signal_connect (G_OBJECT (editor->entry),
"update",
......
2007-10-27 Jody Goldberg <jody@gnome.org>
* gnumeric-expr-entry.c : Move from
ABS_COL/ABS_ROW -> FORCE_ABS/FORCE_REL
All callers changed.
2007-10-21 Morten Welinder <terra@gnome.org>
* Release 1.7.13
......
......@@ -36,10 +36,10 @@
#include <string.h>
typedef struct {
int text_start;
int text_end;
GnmRangeRef ref;
gboolean is_valid;
int text_start;
int text_end;
gboolean is_valid;
} Rangesel;
struct _GnmExprEntry {
......@@ -50,7 +50,7 @@ struct _GnmExprEntry {
SheetControlGUI *scg; /* the source of the edit */
Sheet *sheet; /* from scg */
GnmParsePos pp; /* from scg->sv */
WBCGtk *wbcg; /* from scg */
WBCGtk *wbcg; /* from scg */
Rangesel rangesel;
GnmExprEntryFlags flags;
......@@ -119,6 +119,18 @@ split_char_p (unsigned char const *c)
}
}
static inline void
gee_force_abs_rel (GnmExprEntry *gee)
{
Rangesel *rs = &gee->rangesel;
if ((gee->flags & GNM_EE_FORCE_ABS_REF))
rs->ref.a.col_relative = rs->ref.b.col_relative =
rs->ref.a.row_relative = rs->ref.b.row_relative = FALSE;
else if ((gee->flags & GNM_EE_FORCE_REL_REF))
rs->ref.a.col_relative = rs->ref.b.col_relative =
rs->ref.a.row_relative = rs->ref.b.row_relative = TRUE;
}
static void
gee_rangesel_reset (GnmExprEntry *gee)
{
......@@ -127,10 +139,9 @@ gee_rangesel_reset (GnmExprEntry *gee)
rs->text_start = 0;
rs->text_end = 0;
memset (&rs->ref, 0, sizeof (GnmRange));
/* restore the default based on the flags */
rs->ref.a.col_relative = rs->ref.b.col_relative = (gee->flags & GNM_EE_ABS_COL) != 0;
rs->ref.a.row_relative = rs->ref.b.row_relative = (gee->flags & GNM_EE_ABS_ROW) != 0;
if (gee->flags & GNM_EE_FORCE_REL_REF)
rs->ref.a.col_relative = rs->ref.b.col_relative =
rs->ref.a.row_relative = rs->ref.b.row_relative = TRUE;
gee->rangesel.is_valid = FALSE;
}
......@@ -427,8 +438,6 @@ cb_gee_key_press_event (GtkEntry *entry,
* displayed in entry.
*/
Rangesel *rs = &gee->rangesel;
gboolean abs_cols = (gee->flags & GNM_EE_ABS_COL);
gboolean abs_rows = (gee->flags & GNM_EE_ABS_ROW);
gboolean c, r;
/* FIXME: since the range can't have changed we should just be able to */
......@@ -442,22 +451,15 @@ cb_gee_key_press_event (GtkEntry *entry,
if (!rs->is_valid || rs->text_start >= rs->text_end)
return TRUE;
if ((GNM_EE_FORCE_ABS_REF | GNM_EE_FORCE_REL_REF) & gee->flags)
return TRUE;
c = rs->ref.a.col_relative;
r = rs->ref.a.row_relative;
if (abs_rows) {
if (abs_cols)
return TRUE;
gnm_cellref_set_row_ar (&rs->ref.a, &gee->pp, !c);
gnm_cellref_set_col_ar (&rs->ref.b, &gee->pp, !c);
} else if (abs_cols) {
gnm_cellref_set_row_ar (&rs->ref.a, &gee->pp, !r);
gnm_cellref_set_row_ar (&rs->ref.b, &gee->pp, !r);
} else {
gnm_cellref_set_col_ar (&rs->ref.a, &gee->pp, !c);
gnm_cellref_set_col_ar (&rs->ref.b, &gee->pp, !c);
gnm_cellref_set_row_ar (&rs->ref.a, &gee->pp, c^r);
gnm_cellref_set_row_ar (&rs->ref.b, &gee->pp, c^r);
}
gnm_cellref_set_col_ar (&rs->ref.a, &gee->pp, !c);
gnm_cellref_set_col_ar (&rs->ref.b, &gee->pp, !c);
gnm_cellref_set_row_ar (&rs->ref.a, &gee->pp, c^r);
gnm_cellref_set_row_ar (&rs->ref.b, &gee->pp, c^r);
gee_rangesel_update_text (gee);
......@@ -812,9 +814,8 @@ gnm_expr_entry_find_range (GnmExprEntry *gee)
text = gtk_entry_get_text (gee->entry);
rs->ref.a.col_relative = rs->ref.b.col_relative = (gee->flags & GNM_EE_ABS_COL) == 0;
rs->ref.a.row_relative = rs->ref.b.row_relative = (gee->flags & GNM_EE_ABS_ROW) == 0;
rs->ref.a.sheet = rs->ref.b.sheet = NULL;
gee_force_abs_rel (gee);
rs->is_valid = FALSE;
if (text == NULL)
return;
......@@ -1102,16 +1103,10 @@ gnm_expr_entry_set_flags (GnmExprEntry *gee,
GnmExprEntryFlags flags,
GnmExprEntryFlags mask)
{
Rangesel *rs;
g_return_if_fail (IS_GNM_EXPR_ENTRY (gee));
gee->flags = (gee->flags & ~mask) | (flags & mask);
rs = &gee->rangesel;
if (mask & GNM_EE_ABS_COL)
rs->ref.a.col_relative = rs->ref.b.col_relative = (gee->flags & GNM_EE_ABS_COL) != 0;
if (mask & GNM_EE_ABS_ROW)
rs->ref.a.row_relative = rs->ref.b.row_relative = (gee->flags & GNM_EE_ABS_ROW) != 0;
gee_force_abs_rel (gee);
}
/**
......@@ -1321,24 +1316,6 @@ gnm_expr_entry_get_rangesel (GnmExprEntry const *gee,
return rs->is_valid;
}
/**
* gnm_expr_entry_set_absolute
* @gee: a #GnmExprEntry
*
* Select absolute reference mode for rows and columns. Do not change
* displayed text. This is a convenience function which wraps
* gnm_expr_entry_set_flags.
**/
void
gnm_expr_entry_set_absolute (GnmExprEntry *gee)
{
GnmExprEntryFlags flags;
flags = GNM_EE_ABS_ROW | GNM_EE_ABS_COL;
gnm_expr_entry_set_flags (gee, flags, flags);
}
/**
* gnm_expr_entry_can_rangesel
* @gee: a #GnmExprEntry
......@@ -1413,10 +1390,10 @@ gnm_expr_entry_parse (GnmExprEntry *gee, GnmParsePos const *pp,
if (text == NULL || text[0] == '\0')
return NULL;
if (gee->flags & GNM_EE_ABS_COL)
flags |= GNM_EXPR_PARSE_FORCE_ABSOLUTE_COL_REFERENCES;
if (gee->flags & GNM_EE_ABS_ROW)
flags |= GNM_EXPR_PARSE_FORCE_ABSOLUTE_ROW_REFERENCES;
if ((gee->flags & GNM_EE_FORCE_ABS_REF))
flags |= GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES;
else if ((gee->flags & GNM_EE_FORCE_REL_REF))
flags |= GNM_EXPR_PARSE_FORCE_RELATIVE_REFERENCES;
if (!(gee->flags & GNM_EE_SHEET_OPTIONAL))
flags |= GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
......
......@@ -13,8 +13,8 @@ typedef struct _GnmExprEntry GnmExprEntry;
typedef enum {
GNM_EE_SINGLE_RANGE = 1 << 0,
GNM_EE_ABS_COL = 1 << 1,
GNM_EE_ABS_ROW = 1 << 2,
GNM_EE_FORCE_ABS_REF = 1 << 1, /* takes precedence over FORCE_REL_REF */
GNM_EE_FORCE_REL_REF = 1 << 2,
GNM_EE_FULL_COL = 1 << 3,
GNM_EE_FULL_ROW = 1 << 4,
GNM_EE_SHEET_OPTIONAL = 1 << 5,
......@@ -30,7 +30,6 @@ GtkWidget *gnm_expr_entry_new_glade (void);
/* Widget specific methods */
void gnm_expr_entry_freeze (GnmExprEntry *gee);
void gnm_expr_entry_thaw (GnmExprEntry *gee);
void gnm_expr_entry_set_absolute (GnmExprEntry *gee);
void gnm_expr_entry_set_flags (GnmExprEntry *gee,
GnmExprEntryFlags flags,
GnmExprEntryFlags mask);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment