Commit 6fead70d authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

new routine.

2001-08-14  Jody Goldberg <jgoldberg@home.com>

	* src/expr.c (expr_to_graph_vector) : new routine.

2001-08-14  Jody Goldberg <jgoldberg@home.com>

	* src/item-edit.c (item_edit_draw_text) : ignore leading newlines.
	(recalc_spans) : handle embedded newlines.

	* src/workbook-control-gui.c (wb_edit_key_pressed) : delete, and
	  move this logic from here.
	(workbook_setup_edit_area) : don't hook up wb_edit_key_pressed.
	  Use a GnumericExprEntry instead.

	* src/widgets/gnumeric-expr-entry.c (gnumeric_expr_entry_key_press_event) :
	  Move the magic embedded newline and Abs/Rel handling here.
	(gnumeric_expr_entry_new) : Take a wbcg.
parent 7e27ef51
2001-08-14 Jody Goldberg <jgoldberg@home.com>
* src/expr.c (expr_to_graph_vector) : new routine.
2001-08-14 Jody Goldberg <jgoldberg@home.com>
* src/item-edit.c (item_edit_draw_text) : ignore leading newlines.
(recalc_spans) : handle embedded newlines.
* src/workbook-control-gui.c (wb_edit_key_pressed) : delete, and
move this logic from here.
(workbook_setup_edit_area) : don't hook up wb_edit_key_pressed.
Use a GnumericExprEntry instead.
* src/widgets/gnumeric-expr-entry.c (gnumeric_expr_entry_key_press_event) :
Move the magic embedded newline and Abs/Rel handling here.
(gnumeric_expr_entry_new) : Take a wbcg.
2001-08-13 Morten Welinder <terra@diku.dk>
* src/mathfunc.c (gnumeric_sub_epsilon): New function. Dual of
......
--------------------------------------------------------------------------
Gnumeric 0.70
Jody :
* Basic support for M-Enter to add embedded newlines.
Morten:
* Make CEIL more as users expect (based on Jody's idea).
......
2001-08-14 Jody Goldberg <jgoldberg@home.com>
* src/expr.c (expr_to_graph_vector) : new routine.
2001-08-14 Jody Goldberg <jgoldberg@home.com>
* src/item-edit.c (item_edit_draw_text) : ignore leading newlines.
(recalc_spans) : handle embedded newlines.
* src/workbook-control-gui.c (wb_edit_key_pressed) : delete, and
move this logic from here.
(workbook_setup_edit_area) : don't hook up wb_edit_key_pressed.
Use a GnumericExprEntry instead.
* src/widgets/gnumeric-expr-entry.c (gnumeric_expr_entry_key_press_event) :
Move the magic embedded newline and Abs/Rel handling here.
(gnumeric_expr_entry_new) : Take a wbcg.
2001-08-13 Morten Welinder <terra@diku.dk>
* src/mathfunc.c (gnumeric_sub_epsilon): New function. Dual of
......
2001-08-14 Jody Goldberg <jgoldberg@home.com>
* src/expr.c (expr_to_graph_vector) : new routine.
2001-08-14 Jody Goldberg <jgoldberg@home.com>
* src/item-edit.c (item_edit_draw_text) : ignore leading newlines.
(recalc_spans) : handle embedded newlines.
* src/workbook-control-gui.c (wb_edit_key_pressed) : delete, and
move this logic from here.
(workbook_setup_edit_area) : don't hook up wb_edit_key_pressed.
Use a GnumericExprEntry instead.
* src/widgets/gnumeric-expr-entry.c (gnumeric_expr_entry_key_press_event) :
Move the magic embedded newline and Abs/Rel handling here.
(gnumeric_expr_entry_new) : Take a wbcg.
2001-08-13 Morten Welinder <terra@diku.dk>
* src/mathfunc.c (gnumeric_sub_epsilon): New function. Dual of
......
2001-08-14 Jody Goldberg <jgoldberg@home.com>
* src/expr.c (expr_to_graph_vector) : new routine.
2001-08-14 Jody Goldberg <jgoldberg@home.com>
* src/item-edit.c (item_edit_draw_text) : ignore leading newlines.
(recalc_spans) : handle embedded newlines.
* src/workbook-control-gui.c (wb_edit_key_pressed) : delete, and
move this logic from here.
(workbook_setup_edit_area) : don't hook up wb_edit_key_pressed.
Use a GnumericExprEntry instead.
* src/widgets/gnumeric-expr-entry.c (gnumeric_expr_entry_key_press_event) :
Move the magic embedded newline and Abs/Rel handling here.
(gnumeric_expr_entry_new) : Take a wbcg.
2001-08-13 Morten Welinder <terra@diku.dk>
* src/mathfunc.c (gnumeric_sub_epsilon): New function. Dual of
......
......@@ -189,11 +189,11 @@ static void
cb_dialog_set_focus (GtkWidget *window, GtkWidget *focus_widget,
ConsolidateState *state)
{
if (GNUMERIC_IS_EXPR_ENTRY (focus_widget)) {
if (IS_GNUMERIC_EXPR_ENTRY (focus_widget)) {
GnumericExprEntryFlags flags;
wbcg_set_entry (state->wbcg,
GNUMERIC_EXPR_ENTRY (focus_widget));
GNUMERIC_EXPR_ENTRY (focus_widget));
flags = GNUM_EE_SHEET_OPTIONAL;
gnumeric_expr_entry_set_flags (state->gui.destination, flags, flags);
......@@ -349,9 +349,9 @@ setup_widgets (ConsolidateState *state, GladeXML *glade_gui)
state->gui.function = GTK_OPTION_MENU (glade_xml_get_widget (glade_gui, "function"));
state->gui.put = GTK_OPTION_MENU (glade_xml_get_widget (glade_gui, "put"));
state->gui.destination = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
state->gui.destination = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
state->gui.source = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
state->gui.source = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
state->gui.add = GTK_BUTTON (glade_xml_get_widget (glade_gui, "add"));
state->gui.areas = GTK_CLIST (glade_xml_get_widget (glade_gui, "areas"));
state->gui.clear = GTK_BUTTON (glade_xml_get_widget (glade_gui, "clear"));
......
......@@ -564,7 +564,7 @@ static void
cb_name_guru_set_focus (GtkWidget *window, GtkWidget *focus_widget,
NameGuruState *state)
{
if (GNUMERIC_IS_EXPR_ENTRY (focus_widget)) {
if (IS_GNUMERIC_EXPR_ENTRY (focus_widget)) {
wbcg_set_entry (state->wbcg,
GNUMERIC_EXPR_ENTRY (focus_widget));
gnumeric_expr_entry_set_absolute (state->expr_text);
......@@ -588,7 +588,7 @@ name_guru_init (NameGuruState *state, WorkbookControlGUI *wbcg)
state->dialog = glade_xml_get_widget (state->gui, "NameGuru");
table2 = GTK_TABLE (glade_xml_get_widget (state->gui, "table2"));
state->name = GTK_ENTRY (glade_xml_get_widget (state->gui, "name"));
state->expr_text = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
state->expr_text = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
gtk_table_attach (table2, GTK_WIDGET (state->expr_text),
1, 2, 1, 2,
GTK_EXPAND | GTK_FILL, 0,
......
......@@ -425,7 +425,7 @@ formula_guru_arg_new (char * const name,
0, 1, row, row+1,
GTK_EXPAND|GTK_FILL, 0, 0, 0);
as->entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
as->entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
gnumeric_expr_entry_set_flags (
as->entry, GNUM_EE_SHEET_OPTIONAL, GNUM_EE_SHEET_OPTIONAL);
gtk_table_attach (GTK_TABLE (state->arg_table),
......@@ -594,7 +594,7 @@ formula_guru_init (FormulaGuruState *state, ExprTree const *expr, Cell const *ce
state->cancel_button= formula_guru_init_button (state, "cancel_button");
state->rolled_box = glade_xml_get_widget (state->gui, "rolled_box");
state->rolled_label = glade_xml_get_widget (state->gui, "rolled_label");
state->rolled_entry = gnumeric_expr_entry_new ();
state->rolled_entry = gnumeric_expr_entry_new (state->wbcg);
gnumeric_expr_entry_set_flags (
GNUMERIC_EXPR_ENTRY (state->rolled_entry),
GNUM_EE_SHEET_OPTIONAL, GNUM_EE_SHEET_OPTIONAL);
......
......@@ -425,7 +425,7 @@ formula_guru_arg_new (char * const name,
0, 1, row, row+1,
GTK_EXPAND|GTK_FILL, 0, 0, 0);
as->entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
as->entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
gnumeric_expr_entry_set_flags (
as->entry, GNUM_EE_SHEET_OPTIONAL, GNUM_EE_SHEET_OPTIONAL);
gtk_table_attach (GTK_TABLE (state->arg_table),
......@@ -594,7 +594,7 @@ formula_guru_init (FormulaGuruState *state, ExprTree const *expr, Cell const *ce
state->cancel_button= formula_guru_init_button (state, "cancel_button");
state->rolled_box = glade_xml_get_widget (state->gui, "rolled_box");
state->rolled_label = glade_xml_get_widget (state->gui, "rolled_label");
state->rolled_entry = gnumeric_expr_entry_new ();
state->rolled_entry = gnumeric_expr_entry_new (state->wbcg);
gnumeric_expr_entry_set_flags (
GNUMERIC_EXPR_ENTRY (state->rolled_entry),
GNUM_EE_SHEET_OPTIONAL, GNUM_EE_SHEET_OPTIONAL);
......
......@@ -1043,7 +1043,7 @@ do_setup_page_info (PrinterSetupState *state)
GtkCombo *comments_combo;
GtkWidget *order;
state->area_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
state->area_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
gnumeric_expr_entry_set_scg (state->area_entry,
wb_control_gui_cur_sheet (state->wbcg));
gnumeric_expr_entry_set_flags (state->area_entry,
......@@ -1053,7 +1053,7 @@ do_setup_page_info (PrinterSetupState *state)
TRUE, TRUE, 0);
gtk_widget_show (GTK_WIDGET (state->area_entry));
state->top_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
state->top_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
gnumeric_expr_entry_set_scg (state->top_entry,
wb_control_gui_cur_sheet (state->wbcg));
gnumeric_expr_entry_set_flags (
......@@ -1066,7 +1066,7 @@ do_setup_page_info (PrinterSetupState *state)
GTK_EXPAND|GTK_FILL, 0, 0, 0);
gtk_widget_show (GTK_WIDGET (state->top_entry));
state->left_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
state->left_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
gnumeric_expr_entry_set_scg (state->left_entry,
wb_control_gui_cur_sheet (state->wbcg));
gnumeric_expr_entry_set_flags (
......@@ -1294,7 +1294,7 @@ static void
do_print_set_focus_cb (GtkWidget *window, GtkWidget *focus_widget,
PrinterSetupState *state)
{
if (GNUMERIC_IS_EXPR_ENTRY (focus_widget))
if (IS_GNUMERIC_EXPR_ENTRY (focus_widget))
wbcg_set_entry (state->wbcg,
GNUMERIC_EXPR_ENTRY (focus_widget));
else
......
......@@ -144,7 +144,7 @@ dialog_destroy (GtkWidget *widget, DialogState *dd)
static void
set_focus (GtkWidget *widget, GtkWidget *focus_widget, DialogState *dd)
{
if (GNUMERIC_IS_EXPR_ENTRY (focus_widget))
if (IS_GNUMERIC_EXPR_ENTRY (focus_widget))
wbcg_set_entry (dd->wbcg,
GNUMERIC_EXPR_ENTRY (focus_widget));
else
......@@ -201,7 +201,7 @@ dialog_search_replace (WorkbookControlGUI *wbcg,
gtk_window_set_policy (GTK_WINDOW (dialog), FALSE, TRUE, FALSE);
dd->rangetext = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
dd->rangetext = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (wbcg));
gnumeric_expr_entry_set_flags (
GNUMERIC_EXPR_ENTRY (dd->rangetext),
GNUM_EE_SHEET_OPTIONAL, GNUM_EE_SHEET_OPTIONAL);
......
......@@ -76,7 +76,7 @@ static void
cb_dialog_set_focus (GtkWidget *window, GtkWidget *focus_widget,
ValidateState *state)
{
if (GNUMERIC_IS_EXPR_ENTRY (focus_widget)) {
if (IS_GNUMERIC_EXPR_ENTRY (focus_widget)) {
GnumericExprEntryFlags flags;
wbcg_set_entry (state->wbcg,
......@@ -204,8 +204,8 @@ setup_widgets (ValidateState *state, GladeXML *gui)
state->set_operator = GTK_OPTION_MENU (glade_xml_get_widget (gui, "set_operator"));
state->set_bound1_name = GTK_LABEL (glade_xml_get_widget (gui, "set_bound1_name"));
state->set_bound2_name = GTK_LABEL (glade_xml_get_widget (gui, "set_bound2_name"));
state->set_bound1_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
state->set_bound2_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
state->set_bound1_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
state->set_bound2_entry = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new (state->wbcg));
state->set_apply_shared = GTK_CHECK_BUTTON (glade_xml_get_widget (gui, "set_apply_shared"));
state->set_ignore_blank = GTK_CHECK_BUTTON (glade_xml_get_widget (gui, "set_ignore_blank"));
state->set_in_dropdown = GTK_CHECK_BUTTON (glade_xml_get_widget (gui, "set_in_dropdown"));
......
......@@ -1709,3 +1709,50 @@ expr_tree_boundingbox (ExprTree const *expr, Range *bound)
g_assert_not_reached ();
}
}
#ifdef ENABLE_BONOBO
#include "graph-vector.h"
GraphVector *
expr_to_graph_vector (ExprTree const *expr)
{
g_return_val_if_fail (expr != NULL, FALSE);
if (expr->any.oper == OPER_CONSTANT &&
expr->constant.value->type == VALUE_CELLRANGE) {
CellRef const * const a = &expr->constant.value->v_range.cell.a;
CellRef const * const b = &expr->constant.value->v_range.cell.b;
Range r;
g_return_val_if_fail (!a->col_relative &&
!a->row_relative &&
a->sheet != NULL, NULL);
g_return_val_if_fail (!b->col_relative &&
!b->row_relative &&
b->sheet != NULL, NULL);
g_return_val_if_fail (a->sheet == b->sheet, NULL);
range_normalize (range_init (&r, a->col, a->row, b->col, b->row));
return graph_vector_new (a->sheet, &r, NULL);
} else if (expr->any.oper == OPER_VAR) {
CellRef const *src = &expr->var.ref;
Range r;
g_return_val_if_fail (!src->col_relative &&
!src->row_relative &&
src->sheet != NULL, NULL);
r.start.col = r.end.col = src->col;
r.start.row = r.end.row = src->row;
return graph_vector_new (src->sheet, &r, NULL);
}
return NULL;
}
#else
GraphVector *
expr_to_graph_vector (ExprTree const *expr)
{
return NULL;
}
#endif
......@@ -211,4 +211,6 @@ FunctionDefinition *expr_tree_get_func_def (ExprTree const *expr);
ExprTree const * expr_tree_first_func (ExprTree const *expr);
void expr_tree_boundingbox (ExprTree const *expr, Range *bound);
GraphVector *expr_to_graph_vector (ExprTree const *expr);
#endif /* GNUMERIC_EXPR_H */
/* vim: set sw=8: */
/*
* item-edit.c : Edit facilities for worksheets.
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
* Jody Goldberg (jgoldberg@home.org)
* (C) 1999-2001 Miguel de Icaza & Jody Goldberg
*
* This module provides:
* * Integration of an in-sheet text editor (GtkEntry) with the Workbook
......@@ -11,8 +10,6 @@
*
* * Feedback on expressions in the spreadsheet (referenced cells or
* ranges are highlighted on the spreadsheet).
*
* (C) 1999, 2000 Miguel de Icaza
*/
#include <config.h>
......@@ -179,6 +176,13 @@ item_edit_draw_text (ItemEdit *item_edit, GdkDrawable *drawable, GtkStyle *style
GdkGC *gc = style->black_gc;
/* skip leading newlines */
if (*text == '\n') {
text++;
text_length--;
cursor_pos--;
}
/* If this segment contains the cursor draw it */
if (0 <= cursor_pos && cursor_pos <= text_length) {
if (cursor_pos > 0) {
......@@ -291,44 +295,64 @@ static void
recalc_spans (GnomeCanvasItem *item)
{
ItemEdit *item_edit = ITEM_EDIT (item);
Sheet *sheet = ((SheetControl *) item_edit->scg)->sheet;
GnumericCanvas *gcanvas = GNUMERIC_CANVAS (item->canvas);
int const visible_bottom = gcanvas->first_offset.row +
GTK_WIDGET (gcanvas)->allocation.height;
int item_bottom = item->y1 + item_edit->font_height;
Sheet *sheet = sc_sheet (SHEET_CONTROL (item_edit->scg));
GdkFont *font = item_edit->font;
GSList *text_offsets = NULL;
Range const *merged;
ColRowInfo const *cri;
char const *start = wbcg_edit_get_display_text (item_edit->scg->wbcg);
char const *text = start;
int col_span, row_span, tmp;
GSList *text_offsets = NULL;
Range const *merged;
/* Adjust the spans */
GnumericCanvas *gcanvas = GNUMERIC_CANVAS (item->canvas);
int cur_line = 1;
int cur_col = item_edit->pos.col, max_col = cur_col;
ColRowInfo const * cri = sheet_col_get_info (sheet, cur_col);
int max_col = item_edit->pos.col;
int left_in_col, cur_col, ignore_rows = 0;
reset :
cur_col = item_edit->pos.col;
cri = sheet_col_get_info (sheet, cur_col);
g_return_if_fail (cri != NULL);
/* Start after the grid line and the left margin */
int left_in_col = cri->size_pixels - cri->margin_a - 1;
int ignore_rows = 0;
left_in_col = cri->size_pixels - cri->margin_a - 1;
/* the entire string */
while (*text) {
int pos_size = gdk_text_width (font, text++, 1);
int pos_size;
if (*text == '\n') {
text_offsets = g_slist_prepend (text_offsets,
GINT_TO_POINTER (text - start));
text++;
cur_line++;
item_bottom += item_edit->font_height;
if (item_bottom > visible_bottom)
ignore_rows++;
goto reset;
}
pos_size = gdk_text_width (font, text++, 1);
/* Be wary of large fonts and small columns */
while (left_in_col < pos_size) {
do {
++cur_col;
if (cur_col > gcanvas->last_full.col || cur_col >= SHEET_MAX_COLS) {
int height = GTK_WIDGET (gcanvas)->allocation.height;
/* Be wary of large fonts and small columns */
int offset = text - start - 1;
if (offset < 0)
offset = 0;
if (offset < 1)
offset = 1;
cur_line++;
cur_col = item_edit->pos.col;
text_offsets = g_slist_prepend (text_offsets,
GINT_TO_POINTER(offset));
if (item->y1 + cur_line * item_edit->font_height >
(gcanvas->first_offset.row + height))
GINT_TO_POINTER (offset));
cur_line++;
item_bottom += item_edit->font_height;
if (item_bottom > visible_bottom)
ignore_rows++;
} else if (max_col < cur_col)
max_col = cur_col;
......
......@@ -8,12 +8,20 @@
#include <config.h>
#include "gnumeric-expr-entry.h"
#include "workbook-edit.h"
#include "workbook-control-gui-priv.h"
#include "sheet-control-gui.h"
#include "sheet-merge.h"
#include "parse-util.h"
#include "gnumeric-util.h"
#include "ranges.h"
#include "value.h"
#include "sheet.h"
#include "commands.h"
#include <gal/util/e-util.h>
#include <gtk/gtkentry.h>
#include <ctype.h>
static GtkObjectClass *gnumeric_expr_entry_parent_class;
......@@ -26,6 +34,7 @@ typedef struct {
struct _GnumericExprEntry {
GtkEntry entry;
WorkbookControlGUI *wbcg;
SheetControlGUI *scg;
GnumericExprEntryFlags flags;
int freeze_count;
......@@ -35,9 +44,12 @@ struct _GnumericExprEntry {
Rangesel rangesel;
};
static char * make_rangesel_text (GnumericExprEntry *expr_entry);
typedef struct _GnumericExprEntryClass {
GtkEntryClass parent_class;
} GnumericExprEntryClass;
static void update_rangesel_text (GnumericExprEntry *expr_entry, char *text);
static char *make_rangesel_text (GnumericExprEntry *expr_entry);
static void update_rangesel_text (GnumericExprEntry *expr_entry, char *text);
static void
gnumeric_expr_entry_finalize (GtkObject *object)
......@@ -51,37 +63,162 @@ gnumeric_expr_entry_finalize (GtkObject *object)
GTK_OBJECT_CLASS (gnumeric_expr_entry_parent_class)->finalize (object);
}
static gint
gnumeric_expr_entry_key_press_event (GtkWidget *widget, GdkEventKey *event)
{
GnumericExprEntry *gee = GNUMERIC_EXPR_ENTRY (widget);
WorkbookControlGUI *wbcg = gee->wbcg;
GtkEntry *entry = &gee->entry;
int state = gnumeric_filter_modifiers (event->state);
switch (event->keyval) {
case GDK_Up: case GDK_KP_Up:
case GDK_Down: case GDK_KP_Down:
/* Ignore these keys */
return TRUE;
case GDK_F4: {
/* FIXME FIXME FIXME
* 1) Make sure that a cursor move after an F4
* does not insert.
* 2) Handle calls for a range rather than a single cell.
*/
int end_pos = GTK_EDITABLE (entry)->current_pos;
int start_pos;
int row_status_pos, col_status_pos;
gboolean abs_row = FALSE, abs_col = FALSE;
/* Only applies while editing */
if (!wb_control_gui_is_editing (wbcg))
return TRUE; /* Ignore this character */
/* Only apply do this for formulas */
if (NULL == gnumeric_char_start_expr_p (entry->text_mb))
return TRUE;
/* Find the end of the current range starting from the current
* position. Don't bother validating. The goal is the find
* the end. We'll validate on the way back.
*/
if (entry->text[end_pos] == '$')
++end_pos;
while (isalpha (entry->text[end_pos]))
++end_pos;
if (entry->text[end_pos] == '$')
++end_pos;
while (isdigit ((unsigned char)entry->text[end_pos]))
++end_pos;
/* Try to find the begining of the current range
* starting from the end we just found
*/
start_pos = end_pos - 1;
while (start_pos >= 0 && isdigit ((unsigned char)entry->text[start_pos]))
--start_pos;
if (start_pos == end_pos)
return TRUE;
row_status_pos = start_pos + 1;
if ((abs_row = (entry->text[start_pos] == '$')))
--start_pos;
while (start_pos >= 0 && isalpha (entry->text[start_pos]))
--start_pos;
if (start_pos == end_pos)
return TRUE;
col_status_pos = start_pos + 1;
if ((abs_col = (entry->text[start_pos] == '$')))
--start_pos;
/* Toggle the relative vs absolute flags */
if (abs_col) {
--end_pos;
--row_status_pos;
gtk_editable_delete_text (GTK_EDITABLE (entry),
col_status_pos-1, col_status_pos);
} else {
++end_pos;
++row_status_pos;
gtk_editable_insert_text (GTK_EDITABLE (entry), "$", 1,
&col_status_pos);
}
if (!abs_col) {
if (abs_row) {
--end_pos;
gtk_editable_delete_text (GTK_EDITABLE (entry),
row_status_pos-1, row_status_pos);
} else {
++end_pos;
gtk_editable_insert_text (GTK_EDITABLE (entry), "$", 1,
&row_status_pos);
}
}
/* Do not select the current range, and do not change the position. */
gtk_entry_set_position (entry, end_pos);
return TRUE;
}
case GDK_Escape:
wbcg_edit_finish (wbcg, FALSE);
return TRUE;
case GDK_KP_Enter:
case GDK_Return:
if (!wb_control_gui_is_editing (wbcg))
break;
/* Is this the right way to append a newline ?? */
if (state == GDK_MOD1_MASK) {
gtk_entry_append_text (entry, "\n");
return TRUE;
}
if (state == GDK_CONTROL_MASK ||
state == (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) {
EvalPos pos;
gboolean const is_array = (state & GDK_SHIFT_MASK);
char const *text = gtk_entry_get_text (
GTK_ENTRY (wbcg_get_entry (wbcg)));
Sheet *sheet = wbcg->editing_sheet;
/* Be careful to use the editing sheet */
cmd_area_set_text (WORKBOOK_CONTROL (wbcg),
eval_pos_init (&pos, sheet, &sheet->edit_pos),
text, is_array);
/* Finish editing but do NOT store the results
* If the assignment was successful it will
* have taken care of that.
*/
wbcg_edit_finish (wbcg, FALSE);
return TRUE;
}
default:
break;
}
return GTK_WIDGET_CLASS (gnumeric_expr_entry_parent_class)->key_press_event (widget, event);
}
static void
gnumeric_expr_entry_class_init (GtkObjectClass *object_class)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (object_class);
gnumeric_expr_entry_parent_class
= gtk_type_class (gtk_entry_get_type());
object_class->finalize = gnumeric_expr_entry_finalize;
object_class->finalize = gnumeric_expr_entry_finalize;
widget_class->key_press_event = gnumeric_expr_entry_key_press_event;
}
GtkType
gnumeric_expr_entry_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"GnumericExprEntry",
sizeof (GnumericExprEntry),
sizeof (GnumericExprEntryClass),
(GtkClassInitFunc) gnumeric_expr_entry_class_init,
(GtkObjectInitFunc) NULL,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gtk_entry_get_type (), &info);
}
return type;
}
E_MAKE_TYPE (gnumeric_expr_entry, "GnumericExprEntry", GnumericExprEntry,
gnumeric_expr_entry_class_init, NULL,
GTK_TYPE_ENTRY);
/**
* gnumeric_expr_entry_new:
......@@ -94,13 +231,14 @@ gnumeric_expr_entry_get_type (void)
* Return value: a new #GnumericExprEntry.
**/
GtkWidget *
gnumeric_expr_entry_new ()
gnumeric_expr_entry_new (WorkbookControlGUI *wbcg)
{
GnumericExprEntry *expr_entry;
expr_entry = gtk_type_new (gnumeric_expr_entry_get_type ());
expr_entry->flags |= GNUM_EE_SINGLE_RANGE;
expr_entry->wbcg = wbcg;
return GTK_WIDGET (expr_entry);
}
......@@ -109,7 +247,7 @@ void
gnumeric_expr_entry_freeze (GnumericExprEntry *expr_entry)
{
g_return_if_fail (expr_entry != NULL);
g_return_if_fail (GNUMERIC_IS_EXPR_ENTRY (expr_entry));
g_return_if_fail (IS_GNUMERIC_EXPR_ENTRY (expr_entry));
expr_entry->freeze_count++;
}
......@@ -118,7 +256,7 @@ void
gnumeric_expr_entry_thaw (GnumericExprEntry *expr_entry)
{
g_return_if_fail (expr_entry != NULL);
g_return_if_fail (GNUMERIC_IS_EXPR_ENTRY (expr_entry));
g_return_if_fail (IS_GNUMERIC_EXPR_ENTRY (expr_entry));
if (expr_entry->freeze_count > 0)
if ((--expr_entry->freeze_count) == 0) {
......@@ -176,7 +314,7 @@ gnumeric_expr_entry_set_flags (GnumericExprEntry *expr_entry,
GnumericExprEntryFlags flags,
GnumericExprEntryFlags mask)
{
g_return_if_fail (GNUMERIC_IS_EXPR_ENTRY (expr_entry));
g_return_if_fail (IS_GNUMERIC_EXPR_ENTRY (expr_entry));
expr_entry->flags = (expr_entry->flags & ~mask) | (flags & mask);
}
......@@ -194,7 +332,7 @@ void
gnumeric_expr_entry_set_scg (GnumericExprEntry *expr_entry,
SheetControlGUI *scg)
{
g_return_if_fail (GNUMERIC_IS_EXPR_ENTRY (expr_entry));
g_return_if_fail (IS_GNUMERIC_EXPR_ENTRY (expr_entry));
g_return_if_fail (scg == NULL ||IS_SHEET_CONTROL_GUI (scg));
if ((expr_entry->flags & GNUM_EE_SINGLE_RANGE) ||
......@@ -233,7 +371,7 @@ void
gnumeric_expr_entry_set_rangesel_from_text (GnumericExprEntry *expr_entry,
char *text)
{
g_return_if_fail (GNUMERIC_IS_EXPR_ENTRY (expr_entry));
g_return_if_fail (IS_GNUMERIC_EXPR_ENTRY (expr_entry));
g_return_if_fail (text != NULL);
/* We have nowhere to store the text while frozen. */
g_return_if_fail (expr_entry->freeze_count == 0);
......@@ -350,7 +488,7 @@ gnumeric_expr_entry_set_rangesel_from_range (GnumericExprEntry *expr_entry,
Rangesel *rs;
gboolean needs_change = FALSE;
g_return_val_if_fail (GNUMERIC_IS_EXPR_ENTRY (expr_entry), FALSE);
g_return_val_if_fail (IS_GNUMERIC_EXPR_ENTRY (expr_entry), FALSE);
g_return_val_if_fail (IS_SHEET (sheet), FALSE);
g_return_val_if_fail (pos >= 0, FALSE);
......@@ -395,7 +533,7 @@ void
gnumeric_expr_entry_get_rangesel (GnumericExprEntry *expr_entry,
Range *r, Sheet **sheet)
{
g_return_if_fail (GNUMERIC_IS_EXPR_ENTRY (expr_entry));
g_return_if_fail (IS_GNUMERIC_EXPR_ENTRY (expr_entry));
g_return_if_fail (r != NULL);