static void gnc_item_edit_popup_toggled (GtkToggleButton *button, gpointer data) { GncItemEdit *item_edit = GNC_ITEM_EDIT (data); gboolean show_popup; show_popup = gtk_toggle_button_get_active (button); if (show_popup) { Table *table; VirtualLocation virt_loc; table = item_edit->sheet->table; virt_loc = table->current_cursor_loc; if (!gnc_table_confirm_change (table, virt_loc)) { g_signal_handlers_block_matched (button, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data); gtk_toggle_button_set_active (button, FALSE); g_signal_handlers_unblock_matched (button, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data); return; } } item_edit->show_popup = show_popup; if (!item_edit->show_popup) gnc_item_edit_hide_popup (item_edit); gnc_item_edit_configure (item_edit); }
gboolean gnc_table_direct_update (Table *table, VirtualLocation virt_loc, char **newval_ptr, int *cursor_position, int *start_selection, int *end_selection, gpointer gui_data) { gboolean result; BasicCell *cell; CellBlock *cb; int cell_row; int cell_col; char * old_value; g_return_val_if_fail (table, FALSE); g_return_val_if_fail (table->model, FALSE); if (gnc_table_model_read_only (table->model)) { PWARN ("input to read-only table"); return FALSE; } cb = table->current_cursor; cell_row = virt_loc.phys_row_offset; cell_col = virt_loc.phys_col_offset; cell = gnc_cellblock_get_cell (cb, cell_row, cell_col); if (!cell) return FALSE; ENTER (""); if (cell->direct_update == NULL) { LEAVE("no direct update"); return FALSE; } old_value = g_strdup (cell->value); result = cell->direct_update (cell, cursor_position, start_selection, end_selection, gui_data); if (g_strcmp0 (old_value, cell->value) != 0) { if (!gnc_table_confirm_change (table, virt_loc)) { gnc_basic_cell_set_value (cell, old_value); *newval_ptr = NULL; result = TRUE; } else { cell->changed = TRUE; *newval_ptr = cell->value; } } else *newval_ptr = NULL; g_free (old_value); if (table->gui_handlers.redraw_help) table->gui_handlers.redraw_help (table); LEAVE(""); return result; }
/* Returned result should not be touched by the caller. * NULL return value means the edit was rejected. */ const char * gnc_table_modify_update (Table *table, VirtualLocation virt_loc, const char *change, int change_len, const char *newval, int newval_len, int *cursor_position, int *start_selection, int *end_selection, gboolean *cancelled) { gboolean changed = FALSE; CellModifyVerifyFunc mv; BasicCell *cell; CellBlock *cb; int cell_row; int cell_col; char * old_value; g_return_val_if_fail (table, NULL); g_return_val_if_fail (table->model, NULL); if (gnc_table_model_read_only (table->model)) { PWARN ("change to read-only table"); return NULL; } cb = table->current_cursor; cell_row = virt_loc.phys_row_offset; cell_col = virt_loc.phys_col_offset; ENTER (""); if (!gnc_table_confirm_change (table, virt_loc)) { if (cancelled) *cancelled = TRUE; LEAVE("change cancelled"); return NULL; } if (cancelled) *cancelled = FALSE; /* OK, if there is a callback for this cell, call it */ cell = gnc_cellblock_get_cell (cb, cell_row, cell_col); if (!cell) { LEAVE("no cell"); return NULL; } mv = cell->modify_verify; old_value = g_strdup (cell->value); if (mv) { mv (cell, change, change_len, newval, newval_len, cursor_position, start_selection, end_selection); } else { gnc_basic_cell_set_value (cell, newval); } if (g_strcmp0 (old_value, cell->value) != 0) { changed = TRUE; cell->changed = TRUE; } g_free (old_value); if (table->gui_handlers.redraw_help) table->gui_handlers.redraw_help (table); LEAVE ("change %d %d (relrow=%d relcol=%d) val=%s\n", virt_loc.vcell_loc.virt_row, virt_loc.vcell_loc.virt_col, cell_row, cell_col, cell->value ? cell->value : "(null)"); if (changed) return cell->value; else return NULL; }