static void
cb_dialog_goto_go_clicked (G_GNUC_UNUSED GtkWidget *button,
			   GotoState *state)
{
	GnmEvalPos ep;
	GnmRangeRef range;
	gint cols = gtk_spin_button_get_value_as_int (state->spin_cols);
	gint rows = gtk_spin_button_get_value_as_int (state->spin_rows);
	GnmValue *val = dialog_goto_get_val (state);
	Sheet *sheet = wb_control_cur_sheet (WORKBOOK_CONTROL (state->wbcg));

	if (val == NULL)
		return;
	
	val->v_range.cell.b.row = val->v_range.cell.a.row + (rows - 1);
	val->v_range.cell.b.col = val->v_range.cell.a.col + (cols - 1);
	eval_pos_init_sheet (&ep, sheet);
	gnm_cellref_make_abs (&range.a, &val->v_range.cell.a, &ep);
	gnm_cellref_make_abs (&range.b, &val->v_range.cell.b, &ep);
	value_release (val);

	wb_control_jump (WORKBOOK_CONTROL (state->wbcg), sheet, &range);
#if 0
	gnome_entry_append_history (state->goto_text, TRUE, text);
#endif
	return;
}
Beispiel #2
0
/*
 * This is called when something is entered in the location entry.
 * We either go there (if the text refers to a cell by address or
 * name), or we try to define a name for the selection.
 */
gboolean
wb_control_parse_and_jump (WorkbookControl *wbc, char const *text)
{
	Sheet *sheet = wb_control_cur_sheet (wbc);
	GnmParsePos pp;
	GnmEvalPos ep;
	GnmValue *target;
	GnmRangeRef range;
	SheetView *sv;

	if (text == NULL || *text == '\0')
		return FALSE;

	sv = wb_control_cur_sheet_view (wbc);
	parse_pos_init_editpos (&pp, sv);
	target = value_new_cellrange_parsepos_str (&pp, text,
						   GNM_EXPR_PARSE_DEFAULT);
	if (target == NULL) {
		/* Not an address; is it a name? */
		GnmParsePos pp;
		GnmNamedExpr *nexpr = expr_name_lookup (
			parse_pos_init_sheet (&pp, sheet), text);

		/* If no name, or just a placeholder exists create a name */
		if (nexpr == NULL || expr_name_is_placeholder (nexpr)) {
			wb_create_name (wbc, text, &pp);
			return FALSE;
		} else {
			target = gnm_expr_top_get_range (nexpr->texpr);
			if (target == NULL) {
				go_cmd_context_error_invalid (GO_CMD_CONTEXT (wbc),
					_("Address"), text);
				return FALSE;
			}
		}
	}

	eval_pos_init_editpos (&ep, sv);
	gnm_cellref_make_abs (&range.a, &target->v_range.cell.a, &ep);
	gnm_cellref_make_abs (&range.b, &target->v_range.cell.b, &ep);
	value_release (target);

	return wb_control_jump (wbc, sheet, &range);
}