Commit 739a6dc7 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

We need to manually trigger a changed event after setting the position

2000-06-19  Jody Goldberg <jgoldberg@home.com>

	* dialog-function-wizard.c (formula_guru_set_expr) : We need to
	  manually trigger a changed event after setting the position becuase
	  pre-gtk-1.4 setting the text reset the cursor position to 0.
	(cb_formula_guru_entry_event) : new function.
	(cb_formula_guru_rolled_entry_event) : new function.


2000-06-19  Jody Goldberg <jgoldberg@home.com>

	* src/eval.c (invalidate_refs) : const.
	(do_deps_destroy) : const.

	* src/cell.c (cell_set_expr_internal) : Be careful about unrefing.

	* src/item-edit.c (entry_event) : Rather than catching 'event' and
	  checking for the type of event we want.  Catch the events directly.
	  That way the events can take place BEFORE we look for our position.
parent 51a85c5f
2000-06-19 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (invalidate_refs) : const.
(do_deps_destroy) : const.
* src/cell.c (cell_set_expr_internal) : Be careful about unrefing.
* src/item-edit.c (entry_event) : Rather than catching 'event' and
checking for the type of event we want. Catch the events directly.
That way the events can take place BEFORE we look for our position.
* src/workbook-edit.c (entry_changed) : The characters starting
expressions are not alphabetic. Don't bother testing them too.
(workbook_start_editing_at_cursor) : Do not start autocompletetion
......
2000-06-19 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (invalidate_refs) : const.
(do_deps_destroy) : const.
* src/cell.c (cell_set_expr_internal) : Be careful about unrefing.
* src/item-edit.c (entry_event) : Rather than catching 'event' and
checking for the type of event we want. Catch the events directly.
That way the events can take place BEFORE we look for our position.
* src/workbook-edit.c (entry_changed) : The characters starting
expressions are not alphabetic. Don't bother testing them too.
(workbook_start_editing_at_cursor) : Do not start autocompletetion
......
2000-06-19 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (invalidate_refs) : const.
(do_deps_destroy) : const.
* src/cell.c (cell_set_expr_internal) : Be careful about unrefing.
* src/item-edit.c (entry_event) : Rather than catching 'event' and
checking for the type of event we want. Catch the events directly.
That way the events can take place BEFORE we look for our position.
* src/workbook-edit.c (entry_changed) : The characters starting
expressions are not alphabetic. Don't bother testing them too.
(workbook_start_editing_at_cursor) : Do not start autocompletetion
......
2000-06-19 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (invalidate_refs) : const.
(do_deps_destroy) : const.
* src/cell.c (cell_set_expr_internal) : Be careful about unrefing.
* src/item-edit.c (entry_event) : Rather than catching 'event' and
checking for the type of event we want. Catch the events directly.
That way the events can take place BEFORE we look for our position.
* src/workbook-edit.c (entry_changed) : The characters starting
expressions are not alphabetic. Don't bother testing them too.
(workbook_start_editing_at_cursor) : Do not start autocompletetion
......
2000-06-19 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (invalidate_refs) : const.
(do_deps_destroy) : const.
* src/cell.c (cell_set_expr_internal) : Be careful about unrefing.
* src/item-edit.c (entry_event) : Rather than catching 'event' and
checking for the type of event we want. Catch the events directly.
That way the events can take place BEFORE we look for our position.
* src/workbook-edit.c (entry_changed) : The characters starting
expressions are not alphabetic. Don't bother testing them too.
(workbook_start_editing_at_cursor) : Do not start autocompletetion
......
2000-06-19 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (invalidate_refs) : const.
(do_deps_destroy) : const.
* src/cell.c (cell_set_expr_internal) : Be careful about unrefing.
* src/item-edit.c (entry_event) : Rather than catching 'event' and
checking for the type of event we want. Catch the events directly.
That way the events can take place BEFORE we look for our position.
* src/workbook-edit.c (entry_changed) : The characters starting
expressions are not alphabetic. Don't bother testing them too.
(workbook_start_editing_at_cursor) : Do not start autocompletetion
......
2000-06-19 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (invalidate_refs) : const.
(do_deps_destroy) : const.
* src/cell.c (cell_set_expr_internal) : Be careful about unrefing.
* src/item-edit.c (entry_event) : Rather than catching 'event' and
checking for the type of event we want. Catch the events directly.
That way the events can take place BEFORE we look for our position.
* src/workbook-edit.c (entry_changed) : The characters starting
expressions are not alphabetic. Don't bother testing them too.
(workbook_start_editing_at_cursor) : Do not start autocompletetion
......
......@@ -476,13 +476,15 @@ cell_set_expr_internal (Cell *cell, ExprTree *expr, char const *optional_format)
{
StyleFormat * fmt;
/* Repeat after me. Ref before unref. */
expr_tree_ref (expr);
fmt = (optional_format != NULL) ? style_format_new (optional_format) : NULL;
cell_dirty (cell);
cell_cleanout (cell);
if (cell->u.expression)
expr_tree_unref (cell->u.expression);
cell->u.expression = expr;
cell->cell_flags |= CELL_HAS_EXPRESSION;
cell->format = fmt;
......
......@@ -162,7 +162,7 @@ dependency_single_destroy (gpointer key, gpointer value, gpointer closure)
}
typedef struct {
ExprRewriteInfo *rwinfo;
ExprRewriteInfo const *rwinfo;
GSList *cell_list;
} destroy_closure_t;
......@@ -212,7 +212,7 @@ cb_single_hash_to_list (gpointer key, gpointer value, gpointer closure)
}
static void
invalidate_refs (Cell *cell, ExprRewriteInfo *rwinfo)
invalidate_refs (Cell *cell, const ExprRewriteInfo *rwinfo)
{
ExprTree *newtree;
......@@ -238,8 +238,13 @@ invalidate_refs (Cell *cell, ExprRewriteInfo *rwinfo)
cell_set_expr_unsafe (cell, newtree, NULL);
}
/*
* do_deps_destroy :
* Invalidate references of all kinds to the target region described by
* @rwinfo.
*/
static void
do_deps_destroy (Sheet *sheet, ExprRewriteInfo *rwinfo)
do_deps_destroy (Sheet *sheet, const ExprRewriteInfo *rwinfo)
{
DependencyData *deps;
destroy_closure_t c;
......
2000-06-19 Jody Goldberg <jgoldberg@home.com>
* dialog-function-wizard.c (formula_guru_set_expr) : We need to
manually trigger a changed event after setting the position becuase
pre-gtk-1.4 setting the text reset the cursor position to 0.
(cb_formula_guru_entry_event) : new function.
(cb_formula_guru_rolled_entry_event) : new function.
2000-06-19 Jon K Hellan <hellan@acm.org>
* dialog-function-wizard.c (cb_formula_guru_entry_focus_in): Make
......
......@@ -88,8 +88,9 @@ static void formula_guru_arg_new (char * const name, char const type,
FormulaGuruState *state);
static void
formula_guru_set_expr (FormulaGuruState *state, int index)
formula_guru_set_expr (FormulaGuruState *state, int index, gboolean set_text)
{
GtkEntry *entry;
GString *str;
int pos = 0, i;
......@@ -120,8 +121,20 @@ formula_guru_set_expr (FormulaGuruState *state, int index)
}
}
g_string_append_c (str, ')'); /* FIXME use suffix string */
gtk_entry_set_text (workbook_get_entry (state->wb), str->str);
gtk_entry_set_position (workbook_get_entry (state->wb), pos);
entry = workbook_get_entry (state->wb);
if (set_text)
gtk_entry_set_text (entry, str->str);
/*
* ICK!
* This is necessary until Gtk-1.4.
* Setting the text resets the cursor position to 0 then triggers the
* changed event. The changed handler is what handles creating the
* magic cursor to mark the range being edited
*/
gtk_entry_set_position (entry, pos);
gtk_editable_changed (GTK_EDITABLE (entry));
g_string_free (str, TRUE);
}
......@@ -134,6 +147,23 @@ cb_formula_guru_rolled_entry_changed (GtkEditable *editable,
gtk_entry_get_text (GTK_ENTRY (state->rolled_entry)));
}
static gboolean
cb_formula_guru_entry_event (GtkWidget *w, GdkEvent *ev, ArgumentState *as)
{
g_return_val_if_fail (as != NULL, TRUE);
/* FIXME : this is lazy. Have a special routine */
formula_guru_set_expr (as->state, as->index, FALSE);
return TRUE;
}
static gboolean
cb_formula_guru_rolled_entry_event (GtkWidget *w, GdkEvent *ev,
FormulaGuruState *state)
{
return cb_formula_guru_entry_event (w, ev, state->cur_arg);
}
static void
cb_formula_guru_entry_changed (GtkEditable *editable, ArgumentState *as)
{
......@@ -151,7 +181,7 @@ cb_formula_guru_entry_changed (GtkEditable *editable, ArgumentState *as)
}
}
formula_guru_set_expr (as->state, as->index);
formula_guru_set_expr (as->state, as->index, TRUE);
}
static void
......@@ -169,9 +199,6 @@ formula_guru_set_rolled_state (FormulaGuruState *state, gboolean is_rolled)
gtk_label_set_text (GTK_LABEL (state->rolled_label),
state->cur_arg->name);
gtk_signal_connect (GTK_OBJECT (new_entry), "changed",
GTK_SIGNAL_FUNC (cb_formula_guru_rolled_entry_changed),
state);
gnumeric_editable_enters (GTK_WINDOW (state->dialog),
GTK_EDITABLE (new_entry));
......@@ -218,10 +245,13 @@ cb_formula_guru_entry_focus_in (GtkWidget *ignored0, GdkEventFocus *ignored1, Ar
gtk_container_remove (GTK_CONTAINER (state->arg_table),
GTK_WIDGET (tmp->name_label));
gtk_widget_destroy (GTK_WIDGET (tmp->name_label));
gtk_container_remove (GTK_CONTAINER (state->arg_table),
GTK_WIDGET (tmp->entry));
gtk_widget_destroy (GTK_WIDGET (tmp->entry));
gtk_container_remove (GTK_CONTAINER (state->arg_table),
GTK_WIDGET (tmp->type_label));
gtk_widget_destroy (GTK_WIDGET (tmp->type_label));
formula_guru_arg_delete (state, i);
}
......@@ -265,7 +295,7 @@ cb_formula_guru_entry_focus_in (GtkWidget *ignored0, GdkEventFocus *ignored1, Ar
state->cur_arg = as;
workbook_set_entry (state->wb, as->entry);
formula_guru_set_expr (state, as->index);
formula_guru_set_expr (state, as->index, TRUE);
return FALSE;
}
......@@ -409,6 +439,10 @@ formula_guru_arg_new (char * const name,
GTK_SIGNAL_FUNC (cb_formula_guru_entry_focus_in), as);
gtk_signal_connect (GTK_OBJECT (as->entry), "changed",
GTK_SIGNAL_FUNC (cb_formula_guru_entry_changed), as);
gtk_signal_connect_after (GTK_OBJECT (as->entry), "key-press-event",
GTK_SIGNAL_FUNC (cb_formula_guru_entry_event), as);
gtk_signal_connect_after (GTK_OBJECT (as->entry), "button-press-event",
GTK_SIGNAL_FUNC (cb_formula_guru_entry_event), as);
g_ptr_array_add (state->args, as);
if (row == 0)
......@@ -564,6 +598,13 @@ formula_guru_init (FormulaGuruState *state, ExprTree const *expr, Cell const *ce
formula_guru_init_args (state);
gtk_signal_connect (GTK_OBJECT (state->rolled_entry), "changed",
GTK_SIGNAL_FUNC (cb_formula_guru_rolled_entry_changed), state);
gtk_signal_connect_after (GTK_OBJECT (state->rolled_entry), "key-press-event",
GTK_SIGNAL_FUNC (cb_formula_guru_rolled_entry_event), state);
gtk_signal_connect_after (GTK_OBJECT (state->rolled_entry), "button-press-event",
GTK_SIGNAL_FUNC (cb_formula_guru_rolled_entry_event), state);
/* If there were arguments initialize the fields */
if (expr != NULL) {
GList *l;
......@@ -607,7 +648,7 @@ formula_guru_init (FormulaGuruState *state, ExprTree const *expr, Cell const *ce
GTK_WINDOW (state->wb->toplevel));
workbook_edit_attach_guru (state->wb, state->dialog);
formula_guru_set_expr (state, 0);
formula_guru_set_expr (state, 0, TRUE);
formula_guru_set_rolled_state (state, FALSE);
return FALSE;
......@@ -667,5 +708,5 @@ dialog_formula_guru (Workbook *wb)
/* Ok everything is hooked up. Let-er rip */
state->valid = TRUE;
gtk_widget_show (state->dialog);
formula_guru_set_expr (state, 0);
formula_guru_set_expr (state, 0, TRUE);
}
......@@ -88,8 +88,9 @@ static void formula_guru_arg_new (char * const name, char const type,
FormulaGuruState *state);
static void
formula_guru_set_expr (FormulaGuruState *state, int index)
formula_guru_set_expr (FormulaGuruState *state, int index, gboolean set_text)
{
GtkEntry *entry;
GString *str;
int pos = 0, i;
......@@ -120,8 +121,20 @@ formula_guru_set_expr (FormulaGuruState *state, int index)
}
}
g_string_append_c (str, ')'); /* FIXME use suffix string */
gtk_entry_set_text (workbook_get_entry (state->wb), str->str);
gtk_entry_set_position (workbook_get_entry (state->wb), pos);
entry = workbook_get_entry (state->wb);
if (set_text)
gtk_entry_set_text (entry, str->str);
/*
* ICK!
* This is necessary until Gtk-1.4.
* Setting the text resets the cursor position to 0 then triggers the
* changed event. The changed handler is what handles creating the
* magic cursor to mark the range being edited
*/
gtk_entry_set_position (entry, pos);
gtk_editable_changed (GTK_EDITABLE (entry));
g_string_free (str, TRUE);
}
......@@ -134,6 +147,23 @@ cb_formula_guru_rolled_entry_changed (GtkEditable *editable,
gtk_entry_get_text (GTK_ENTRY (state->rolled_entry)));
}
static gboolean
cb_formula_guru_entry_event (GtkWidget *w, GdkEvent *ev, ArgumentState *as)
{
g_return_val_if_fail (as != NULL, TRUE);
/* FIXME : this is lazy. Have a special routine */
formula_guru_set_expr (as->state, as->index, FALSE);
return TRUE;
}
static gboolean
cb_formula_guru_rolled_entry_event (GtkWidget *w, GdkEvent *ev,
FormulaGuruState *state)
{
return cb_formula_guru_entry_event (w, ev, state->cur_arg);
}
static void
cb_formula_guru_entry_changed (GtkEditable *editable, ArgumentState *as)
{
......@@ -151,7 +181,7 @@ cb_formula_guru_entry_changed (GtkEditable *editable, ArgumentState *as)
}
}
formula_guru_set_expr (as->state, as->index);
formula_guru_set_expr (as->state, as->index, TRUE);
}
static void
......@@ -169,9 +199,6 @@ formula_guru_set_rolled_state (FormulaGuruState *state, gboolean is_rolled)
gtk_label_set_text (GTK_LABEL (state->rolled_label),
state->cur_arg->name);
gtk_signal_connect (GTK_OBJECT (new_entry), "changed",
GTK_SIGNAL_FUNC (cb_formula_guru_rolled_entry_changed),
state);
gnumeric_editable_enters (GTK_WINDOW (state->dialog),
GTK_EDITABLE (new_entry));
......@@ -218,10 +245,13 @@ cb_formula_guru_entry_focus_in (GtkWidget *ignored0, GdkEventFocus *ignored1, Ar
gtk_container_remove (GTK_CONTAINER (state->arg_table),
GTK_WIDGET (tmp->name_label));
gtk_widget_destroy (GTK_WIDGET (tmp->name_label));
gtk_container_remove (GTK_CONTAINER (state->arg_table),
GTK_WIDGET (tmp->entry));
gtk_widget_destroy (GTK_WIDGET (tmp->entry));
gtk_container_remove (GTK_CONTAINER (state->arg_table),
GTK_WIDGET (tmp->type_label));
gtk_widget_destroy (GTK_WIDGET (tmp->type_label));
formula_guru_arg_delete (state, i);
}
......@@ -265,7 +295,7 @@ cb_formula_guru_entry_focus_in (GtkWidget *ignored0, GdkEventFocus *ignored1, Ar
state->cur_arg = as;
workbook_set_entry (state->wb, as->entry);
formula_guru_set_expr (state, as->index);
formula_guru_set_expr (state, as->index, TRUE);
return FALSE;
}
......@@ -409,6 +439,10 @@ formula_guru_arg_new (char * const name,
GTK_SIGNAL_FUNC (cb_formula_guru_entry_focus_in), as);
gtk_signal_connect (GTK_OBJECT (as->entry), "changed",
GTK_SIGNAL_FUNC (cb_formula_guru_entry_changed), as);
gtk_signal_connect_after (GTK_OBJECT (as->entry), "key-press-event",
GTK_SIGNAL_FUNC (cb_formula_guru_entry_event), as);
gtk_signal_connect_after (GTK_OBJECT (as->entry), "button-press-event",
GTK_SIGNAL_FUNC (cb_formula_guru_entry_event), as);
g_ptr_array_add (state->args, as);
if (row == 0)
......@@ -564,6 +598,13 @@ formula_guru_init (FormulaGuruState *state, ExprTree const *expr, Cell const *ce
formula_guru_init_args (state);
gtk_signal_connect (GTK_OBJECT (state->rolled_entry), "changed",
GTK_SIGNAL_FUNC (cb_formula_guru_rolled_entry_changed), state);
gtk_signal_connect_after (GTK_OBJECT (state->rolled_entry), "key-press-event",
GTK_SIGNAL_FUNC (cb_formula_guru_rolled_entry_event), state);
gtk_signal_connect_after (GTK_OBJECT (state->rolled_entry), "button-press-event",
GTK_SIGNAL_FUNC (cb_formula_guru_rolled_entry_event), state);
/* If there were arguments initialize the fields */
if (expr != NULL) {
GList *l;
......@@ -607,7 +648,7 @@ formula_guru_init (FormulaGuruState *state, ExprTree const *expr, Cell const *ce
GTK_WINDOW (state->wb->toplevel));
workbook_edit_attach_guru (state->wb, state->dialog);
formula_guru_set_expr (state, 0);
formula_guru_set_expr (state, 0, TRUE);
formula_guru_set_rolled_state (state, FALSE);
return FALSE;
......@@ -667,5 +708,5 @@ dialog_formula_guru (Workbook *wb)
/* Ok everything is hooked up. Let-er rip */
state->valid = TRUE;
gtk_widget_show (state->dialog);
formula_guru_set_expr (state, 0);
formula_guru_set_expr (state, 0, TRUE);
}
......@@ -162,7 +162,7 @@ dependency_single_destroy (gpointer key, gpointer value, gpointer closure)
}
typedef struct {
ExprRewriteInfo *rwinfo;
ExprRewriteInfo const *rwinfo;
GSList *cell_list;
} destroy_closure_t;
......@@ -212,7 +212,7 @@ cb_single_hash_to_list (gpointer key, gpointer value, gpointer closure)
}
static void
invalidate_refs (Cell *cell, ExprRewriteInfo *rwinfo)
invalidate_refs (Cell *cell, const ExprRewriteInfo *rwinfo)
{
ExprTree *newtree;
......@@ -238,8 +238,13 @@ invalidate_refs (Cell *cell, ExprRewriteInfo *rwinfo)
cell_set_expr_unsafe (cell, newtree, NULL);
}
/*
* do_deps_destroy :
* Invalidate references of all kinds to the target region described by
* @rwinfo.
*/
static void
do_deps_destroy (Sheet *sheet, ExprRewriteInfo *rwinfo)
do_deps_destroy (Sheet *sheet, const ExprRewriteInfo *rwinfo)
{
DependencyData *deps;
destroy_closure_t c;
......
......@@ -72,7 +72,6 @@ setup_range_from_value (Range *range, Value *v)
* Currently it will not handle ranges like R[-1]C1, nor named ranges,
* nor will it detect whether something is part of an expression or a
* string .
*
*/
static gboolean
point_is_inside_range (ItemEdit *item_edit, const char *text, Range *range)
......@@ -227,12 +226,9 @@ item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
(int)(item->x2-item->x1),
(int)(item->y2-item->y1));
/*
* Make a number of tests for auto-completion
*/
/* Make a number of tests for auto-completion */
text = workbook_edit_get_display_text (item_edit->sheet_view->sheet->workbook);
for (ptr = item_edit->text_offsets; ptr != NULL; ptr = ptr->next){
int const text_end = GPOINTER_TO_INT (ptr->data);
......@@ -463,7 +459,8 @@ item_edit_destroy (GtkObject *o)
entry_destroy_feedback_range (item_edit);
gtk_signal_disconnect (GTK_OBJECT (entry), item_edit->signal_changed);
gtk_signal_disconnect (GTK_OBJECT (entry), item_edit->signal_event);
gtk_signal_disconnect (GTK_OBJECT (entry), item_edit->signal_key_press);
gtk_signal_disconnect (GTK_OBJECT (entry), item_edit->signal_button_press);
if (GTK_OBJECT_CLASS (item_edit_parent_class)->destroy)
(*GTK_OBJECT_CLASS (item_edit_parent_class)->destroy)(o);
......@@ -472,16 +469,8 @@ item_edit_destroy (GtkObject *o)
static int
entry_event (GtkEntry *entry, GdkEvent *event, GnomeCanvasItem *item)
{
switch (event->type) {
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE:
case GDK_BUTTON_PRESS:
gnome_canvas_item_request_update (item);
default:
break;
}
return FALSE;
entry_changed (entry, item);
return TRUE;
}
static void
......@@ -508,8 +497,11 @@ item_edit_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
item_edit->signal_changed = gtk_signal_connect (
GTK_OBJECT (entry), "changed",
GTK_SIGNAL_FUNC (entry_changed), item_edit);
item_edit->signal_event = gtk_signal_connect_after (
GTK_OBJECT (entry), "event",
item_edit->signal_key_press = gtk_signal_connect_after (
GTK_OBJECT (entry), "key-press-event",
GTK_SIGNAL_FUNC (entry_event), item_edit);
item_edit->signal_button_press = gtk_signal_connect_after (
GTK_OBJECT (entry), "button-press-event",
GTK_SIGNAL_FUNC (entry_event), item_edit);
scan_for_range (item_edit, "");
......
......@@ -12,8 +12,9 @@ typedef struct {
GnomeCanvasItem canvas_item;
guint signal_changed; /* ::changed signal in the GtkEntry */
guint signal_event; /* ::event signal in the GtkEntry */
guint signal_key_press; /* ::key-press-event signal in the GtkWidget */
guint signal_button_press; /* ::button-press-event signal in the GtkWidget */
ItemGrid *item_grid;
SheetView *sheet_view;
GtkEntry *entry; /* Utility pointer to the workbook entry */
......
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