58 static void gnc_table_free_data (
Table *
table);
59 static void gnc_virtual_cell_construct (gpointer vcell, gpointer user_data);
60 static void gnc_virtual_cell_destroy (gpointer vcell, gpointer user_data);
61 static void gnc_table_resize (
Table *
table,
int virt_rows,
int virt_cols);
70 memset (&default_gui_handlers, 0,
sizeof (default_gui_handlers));
72 default_gui_handlers = *gui_handlers;
80 g_return_val_if_fail (layout != NULL, NULL);
81 g_return_val_if_fail (model != NULL, NULL);
82 g_return_val_if_fail (control != NULL, NULL);
84 table = g_new0 (
Table, 1);
86 table->layout = layout;
88 table->control = control;
90 table->gui_handlers = default_gui_handlers;
92 gnc_table_init (table);
94 table->virt_cells = g_table_new (
sizeof (
VirtualCell),
95 gnc_virtual_cell_construct,
96 gnc_virtual_cell_destroy, table);
102 gnc_table_init (
Table * table)
104 table->num_virt_rows = -1;
105 table->num_virt_cols = -1;
107 table->current_cursor = NULL;
109 gnc_virtual_location_init (&table->current_cursor_loc);
113 table->virt_cells = NULL;
114 table->ui_data = NULL;
118 gnc_table_destroy (
Table * table)
121 if (table->gui_handlers.destroy)
122 table->gui_handlers.destroy (table);
125 gnc_table_free_data (table);
128 g_table_destroy (table->virt_cells);
130 gnc_table_layout_destroy (table->layout);
131 table->layout = NULL;
133 gnc_table_control_destroy (table->control);
134 table->control = NULL;
136 gnc_table_model_destroy (table->model);
140 gnc_table_init (table);
146 gnc_table_current_cursor_changed (
Table *table,
147 gboolean include_conditional)
152 return gnc_cellblock_changed (table->current_cursor, include_conditional);
156 gnc_table_clear_current_cursor_changes (
Table *table)
161 gnc_cellblock_clear_changes (table->current_cursor);
167 if (!table || !buffer)
170 gnc_table_layout_save_cursor (table->layout, table->current_cursor, buffer);
174 gnc_table_restore_current_cursor (
Table *table,
177 if (!table || !buffer)
180 gnc_table_layout_restore_cursor (table->layout,
181 table->current_cursor, buffer);
185 gnc_table_get_current_cell_name (
Table *table)
190 return gnc_table_get_cell_name (table, table->current_cursor_loc);
194 gnc_table_get_current_cell_location (
Table *table,
195 const char *cell_name,
201 return gnc_table_get_cell_location (table, cell_name,
202 table->current_cursor_loc.vcell_loc,
207 gnc_table_virtual_cell_out_of_bounds (
Table *table,
213 return ((vcell_loc.virt_row < 0) ||
214 (vcell_loc.virt_row >= table->num_virt_rows) ||
215 (vcell_loc.virt_col < 0) ||
216 (vcell_loc.virt_col >= table->num_virt_cols));
220 gnc_table_virtual_location_in_header (
Table *table,
223 return (virt_loc.vcell_loc.virt_row == 0);
232 return g_table_index (table->virt_cells,
233 vcell_loc.virt_row, vcell_loc.virt_col);
237 gnc_table_get_header_cell (
Table *table)
241 return gnc_table_get_virtual_cell (table, vcell_loc);
246 gboolean *conditionally_changed)
248 TableGetEntryHandler entry_handler;
249 const char *cell_name;
252 cell_name = gnc_table_get_cell_name (table, virt_loc);
254 entry_handler = gnc_table_model_get_entry_handler (table->model, cell_name);
255 if (!entry_handler)
return "";
257 entry = entry_handler (virt_loc, FALSE,
258 conditionally_changed,
259 table->model->handler_user_data);
269 TableGetEntryHandler entry_handler;
273 cell = gnc_table_get_cell (table, virt_loc);
274 if (!cell || !cell->cell_name)
277 if (virt_cell_loc_equal (table->current_cursor_loc.vcell_loc,
280 CellIOFlags io_flags;
282 io_flags = gnc_table_get_io_flags (table, virt_loc);
284 if (io_flags & XACC_CELL_ALLOW_INPUT)
288 entry_handler = gnc_table_model_get_entry_handler (table->model,
290 if (!entry_handler)
return "";
292 entry = entry_handler (virt_loc, TRUE, NULL,
293 table->model->handler_user_data);
303 TableGetCellIOFlagsHandler io_flags_handler;
304 const char *cell_name;
307 if (!table || !table->model)
308 return XACC_CELL_ALLOW_NONE;
310 cell_name = gnc_table_get_cell_name (table, virt_loc);
312 io_flags_handler = gnc_table_model_get_io_flags_handler (table->model,
314 if (!io_flags_handler)
315 return XACC_CELL_ALLOW_NONE;
317 flags = io_flags_handler (virt_loc, table->model->handler_user_data);
319 if (gnc_table_model_read_only (table->model))
320 flags &= XACC_CELL_ALLOW_SHADOW;
328 TableGetLabelHandler label_handler;
329 const char *cell_name;
332 if (!table || !table->model)
335 cell_name = gnc_table_get_cell_name (table, virt_loc);
337 label_handler = gnc_table_model_get_label_handler (table->model, cell_name);
341 label = label_handler (virt_loc, table->model->handler_user_data);
352 TableGetFGColorHandler fg_color_handler;
353 const char *handler_name =
"gtkrc";
355 if (!table || !table->model)
359 handler_name = gnc_table_get_cell_name (table, virt_loc);
361 fg_color_handler = gnc_table_model_get_fg_color_handler (table->model,
363 if (!fg_color_handler)
366 return fg_color_handler (virt_loc, table->model->handler_user_data);
372 return gnc_table_get_fg_color_internal (table, virt_loc, FALSE);
378 return gnc_table_get_fg_color_internal (table, virt_loc, TRUE);
386 TableGetBGColorHandler bg_color_handler;
387 const char *handler_name =
"gtkrc";
392 if (!table || !table->model)
396 handler_name = gnc_table_get_cell_name (table, virt_loc);
398 bg_color_handler = gnc_table_model_get_bg_color_handler (table->model,
400 if (!bg_color_handler)
403 return bg_color_handler (virt_loc, hatching,
404 table->model->handler_user_data);
411 return gnc_table_get_bg_color_internal (table, virt_loc, hatching, FALSE);
418 return gnc_table_get_bg_color_internal (table, virt_loc, hatching, TRUE);
425 TableGetCellBorderHandler cell_border_handler;
426 const char *cell_name;
428 if (!table || !table->model)
431 cell_name = gnc_table_get_cell_name (table, virt_loc);
433 cell_border_handler = gnc_table_model_get_cell_border_handler (table->model,
435 if (!cell_border_handler)
438 cell_border_handler (virt_loc, borders, table->model->handler_user_data);
446 cell = gnc_table_get_cell (table, virt_loc);
448 return CELL_ALIGN_RIGHT;
450 return cell->alignment;
458 cell = gnc_table_get_cell (table, virt_loc);
462 return cell->is_popup;
466 gnc_table_get_help (
Table *table)
468 TableGetHelpHandler help_handler;
470 const char * cell_name;
475 virt_loc = table->current_cursor_loc;
477 cell_name = gnc_table_get_cell_name (table, virt_loc);
479 help_handler = gnc_table_model_get_help_handler (table->model, cell_name);
483 return help_handler (virt_loc, table->model->handler_user_data);
494 vcell = gnc_table_get_virtual_cell (table, virt_loc.vcell_loc);
498 return gnc_cellblock_get_cell (vcell->cellblock,
499 virt_loc.phys_row_offset,
500 virt_loc.phys_col_offset);
508 cell = gnc_table_get_cell (table, virt_loc);
512 return cell->cell_name;
520 cell = gnc_table_get_cell (table, virt_loc);
524 return cell->cell_type_name;
529 gnc_table_get_cell_location (
Table *table,
530 const char *cell_name,
536 int cell_row, cell_col;
541 vcell = gnc_table_get_virtual_cell (table, vcell_loc);
545 cellblock = vcell->cellblock;
547 for (cell_row = 0; cell_row < cellblock->num_rows; cell_row++)
548 for (cell_col = 0; cell_col < cellblock->num_cols; cell_col++)
552 cell = gnc_cellblock_get_cell (cellblock, cell_row, cell_col);
556 if (gnc_basic_cell_has_name (cell, cell_name))
558 if (virt_loc != NULL)
560 virt_loc->vcell_loc = vcell_loc;
562 virt_loc->phys_row_offset = cell_row;
563 virt_loc->phys_col_offset = cell_col;
574 gnc_table_save_cells (
Table *table, gpointer save_data)
576 TableSaveHandler save_handler;
580 g_return_if_fail (table);
583 if (gnc_table_model_read_only (table->model))
588 save_handler = gnc_table_model_get_pre_save_handler (table->model);
590 save_handler (save_data, table->model->handler_user_data);
592 cells = gnc_table_layout_get_cells (table->layout);
593 for (node = cells; node; node = node->next)
596 TableSaveCellHandler save_cell_handler;
600 if (!gnc_table_layout_get_cell_changed (table->layout,
601 cell->cell_name, TRUE))
604 save_cell_handler = gnc_table_model_get_save_handler (table->model,
606 if (save_cell_handler)
607 save_cell_handler (cell, save_data, table->model->handler_user_data);
610 save_handler = gnc_table_model_get_post_save_handler (table->model);
612 save_handler (save_data, table->model->handler_user_data);
616 gnc_table_set_size (
Table * table,
int virt_rows,
int virt_cols)
622 if ((virt_rows < table->num_virt_rows) ||
623 (virt_cols < table->num_virt_cols))
625 gnc_virtual_location_init (&table->current_cursor_loc);
626 table->current_cursor = NULL;
629 gnc_table_resize (table, virt_rows, virt_cols);
633 gnc_table_free_data (
Table * table)
638 g_table_resize (table->virt_cells, 0, 0);
647 vloc->phys_row_offset = -1;
648 vloc->phys_col_offset = -1;
649 vloc->vcell_loc.virt_row = -1;
650 vloc->vcell_loc.virt_col = -1;
654 gnc_virtual_cell_construct (gpointer _vcell, gpointer user_data)
657 Table *table = user_data;
659 vcell->cellblock = NULL;
661 if (table && table->model->cell_data_allocator)
662 vcell->vcell_data = table->model->cell_data_allocator ();
664 vcell->vcell_data = NULL;
670 gnc_virtual_cell_destroy (gpointer _vcell, gpointer user_data)
673 Table *table = user_data;
675 if (vcell->vcell_data && table && table->model->cell_data_deallocator)
676 table->model->cell_data_deallocator (vcell->vcell_data);
678 vcell->vcell_data = NULL;
682 gnc_table_resize (
Table * table,
int new_virt_rows,
int new_virt_cols)
686 g_table_resize (table->virt_cells, new_virt_rows, new_virt_cols);
688 table->num_virt_rows = new_virt_rows;
689 table->num_virt_cols = new_virt_cols;
693 gnc_table_set_vcell (
Table *table,
695 gconstpointer vcell_data,
697 gboolean start_primary_color,
702 if ((table == NULL) || (cursor == NULL))
705 if ((vcell_loc.virt_row >= table->num_virt_rows) ||
706 (vcell_loc.virt_col >= table->num_virt_cols))
707 gnc_table_resize (table,
708 MAX (table->num_virt_rows, vcell_loc.virt_row + 1),
709 MAX (table->num_virt_cols, vcell_loc.virt_col + 1));
711 vcell = gnc_table_get_virtual_cell (table, vcell_loc);
716 vcell->cellblock = cursor;
719 if (table->model->cell_data_copy)
720 table->model->cell_data_copy (vcell->vcell_data, vcell_data);
722 vcell->vcell_data = (gpointer) vcell_data;
724 vcell->visible = visible ? 1 : 0;
725 vcell->start_primary_color = start_primary_color ? 1 : 0;
729 gnc_table_set_virt_cell_data (
Table *table,
731 gconstpointer vcell_data)
738 vcell = gnc_table_get_virtual_cell (table, vcell_loc);
742 if (table->model->cell_data_copy)
743 table->model->cell_data_copy (vcell->vcell_data, vcell_data);
745 vcell->vcell_data = (gpointer) vcell_data;
749 gnc_table_set_virt_cell_visible (
Table *table,
758 vcell = gnc_table_get_virtual_cell (table, vcell_loc);
762 vcell->visible = visible ? 1 : 0;
766 gnc_table_set_virt_cell_cursor (
Table *table,
775 vcell = gnc_table_get_virtual_cell (table, vcell_loc);
779 vcell->cellblock = cursor;
783 gnc_table_move_cursor_internal (
Table *table,
785 gboolean do_move_gui)
787 int cell_row, cell_col;
792 ENTER(
"new_virt=(%d %d) do_move_gui=%d\n",
793 new_virt_loc.vcell_loc.virt_row,
794 new_virt_loc.vcell_loc.virt_col, do_move_gui);
799 if (table->control->move_cursor && table->control->allow_move)
801 table->control->move_cursor (&new_virt_loc, table->control->user_data);
808 gnc_table_refresh_current_cursor_gui (table, FALSE);
812 gnc_virtual_location_init (&table->current_cursor_loc);
814 curs = table->current_cursor;
815 table->current_cursor = NULL;
818 if ((new_virt_loc.vcell_loc.virt_row < 0) ||
819 (new_virt_loc.vcell_loc.virt_col < 0))
823 if (do_move_gui && curs)
825 for (cell_row = 0; cell_row < curs->num_rows; cell_row++)
826 for (cell_col = 0; cell_col < curs->num_cols; cell_col++)
830 cell = gnc_cellblock_get_cell (curs, cell_row, cell_col);
833 cell->changed = FALSE;
834 cell->conditionally_changed = FALSE;
837 cell->gui_move (cell);
842 LEAVE(
"out of bounds\n");
846 if (!gnc_table_virtual_loc_valid (table, new_virt_loc, TRUE))
848 PWARN(
"bad table location");
855 vcell = gnc_table_get_virtual_cell (table, new_virt_loc.vcell_loc);
856 curs = vcell->cellblock;
857 table->current_cursor = curs;
860 table->current_cursor_loc = new_virt_loc;
862 virt_loc.vcell_loc = new_virt_loc.vcell_loc;
865 for (cell_row = 0; cell_row < curs->num_rows; cell_row++)
866 for (cell_col = 0; cell_col < curs->num_cols; cell_col++)
869 CellIOFlags io_flags;
871 virt_loc.phys_row_offset = cell_row;
872 virt_loc.phys_col_offset = cell_col;
874 cell = gnc_cellblock_get_cell(curs, cell_row, cell_col);
881 if (do_move_gui && cell->gui_move)
882 cell->gui_move (cell);
886 io_flags = gnc_table_get_io_flags (table, virt_loc);
887 if (io_flags & XACC_CELL_ALLOW_SHADOW)
890 gboolean conditionally_changed = FALSE;
892 entry = gnc_table_get_entry_internal (table, virt_loc,
893 &conditionally_changed);
895 gnc_basic_cell_set_value (cell, entry);
897 cell->changed = FALSE;
898 cell->conditionally_changed = conditionally_changed;
911 gnc_table_move_cursor_internal (table, new_virt_loc, FALSE);
920 gnc_table_move_cursor_internal (table, new_virt_loc, TRUE);
929 gboolean do_move = FALSE;
930 gboolean moved_cursor = FALSE;
932 if (!table)
return FALSE;
939 if (gnc_table_virtual_cell_out_of_bounds (table, virt_loc.vcell_loc))
942 if (!virt_cell_loc_equal (virt_loc.vcell_loc,
943 table->current_cursor_loc.vcell_loc))
948 gnc_table_move_cursor_gui (table, virt_loc);
951 else if (!virt_loc_equal (virt_loc, table->current_cursor_loc))
953 table->current_cursor_loc = virt_loc;
965 if (!table)
return NULL;
967 vcell = gnc_table_get_virtual_cell (table, vcell_loc);
971 return vcell->vcell_data;
979 gnc_table_realize_gui (
Table * table)
985 if (!table->ui_data)
return;
987 cells = gnc_table_layout_get_cells (table->layout);
989 for (node = cells; node; node = node->next)
993 if (cell->gui_realize)
994 cell->gui_realize (cell, table->ui_data);
1002 gboolean moved_cursor;
1006 ENTER(
"(%d %d)", virt_loc.vcell_loc.virt_row, virt_loc.vcell_loc.virt_col);
1008 save_loc = table->current_cursor_loc;
1011 moved_cursor = gnc_table_verify_cursor_position (table, virt_loc);
1016 gnc_table_refresh_current_cursor_gui (table, TRUE);
1017 gnc_table_refresh_cursor_gui (table, save_loc.vcell_loc, FALSE);
1024 gnc_table_refresh_current_cursor_gui (
Table * table, gboolean do_scroll)
1028 gnc_table_refresh_cursor_gui (table, table->current_cursor_loc.vcell_loc,
1033 gnc_table_virtual_loc_valid(
Table *table,
1035 gboolean exact_pointer)
1038 CellIOFlags io_flags;
1040 if (!table)
return FALSE;
1043 if (virt_loc.vcell_loc.virt_row == 0)
1046 vcell = gnc_table_get_virtual_cell(table, virt_loc.vcell_loc);
1050 if (!vcell->visible)
1056 if ((0 > virt_loc.phys_row_offset) || (0 > virt_loc.phys_col_offset))
1060 if (vcell->cellblock == NULL)
return FALSE;
1063 if (gnc_table_model_read_only (table->model))
return TRUE;
1065 io_flags = gnc_table_get_io_flags (table, virt_loc);
1068 if (io_flags & XACC_CELL_ALLOW_ENTER)
return TRUE;
1071 if (0 == (XACC_CELL_ALLOW_INPUT & io_flags))
return FALSE;
1075 if (!exact_pointer && ((XACC_CELL_ALLOW_EXACT_ONLY & io_flags) != 0))
1083 gnc_table_enter_update (
Table *table,
1085 int *cursor_position,
1086 int *start_selection,
1089 gboolean can_edit = TRUE;
1090 CellEnterFunc enter;
1095 CellIOFlags io_flags;
1100 cb = table->current_cursor;
1102 cell_row = virt_loc.phys_row_offset;
1103 cell_col = virt_loc.phys_col_offset;
1105 ENTER(
"enter %d %d (relrow=%d relcol=%d)",
1106 virt_loc.vcell_loc.virt_row,
1107 virt_loc.vcell_loc.virt_col,
1108 cell_row, cell_col);
1111 cell = gnc_cellblock_get_cell (cb, cell_row, cell_col);
1118 io_flags = gnc_table_get_io_flags (table, virt_loc);
1119 if (io_flags == XACC_CELL_ALLOW_READ_ONLY)
1121 LEAVE(
"read only cell");
1125 enter = cell->enter_cell;
1131 DEBUG(
"gnc_table_enter_update(): %d %d has enter handler\n",
1132 cell_row, cell_col);
1134 old_value = g_strdup (cell->value);
1136 can_edit = enter (cell, cursor_position, start_selection, end_selection);
1138 if (g_strcmp0 (old_value, cell->value) != 0)
1140 if (gnc_table_model_read_only (table->model))
1142 PWARN (
"enter update changed read-only table");
1145 cell->changed = TRUE;
1151 if (table->gui_handlers.redraw_help)
1152 table->gui_handlers.redraw_help (table);
1154 LEAVE(
"return %d\n", can_edit);
1161 CellLeaveFunc leave;
1170 cb = table->current_cursor;
1172 cell_row = virt_loc.phys_row_offset;
1173 cell_col = virt_loc.phys_col_offset;
1175 ENTER(
"proposed (%d %d) rel(%d %d)\n",
1176 virt_loc.vcell_loc.virt_row,
1177 virt_loc.vcell_loc.virt_col,
1178 cell_row, cell_col);
1181 cell = gnc_cellblock_get_cell (cb, cell_row, cell_col);
1188 leave = cell->leave_cell;
1194 old_value = g_strdup (cell->value);
1198 if (g_strcmp0 (old_value, cell->value) != 0)
1200 if (gnc_table_model_read_only (table->model))
1202 PWARN (
"leave update changed read-only table");
1205 cell->changed = TRUE;
1216 TableConfirmHandler confirm_handler;
1217 const char *cell_name;
1219 if (!table || !table->model)
1222 cell_name = gnc_table_get_cell_name (table, virt_loc);
1224 confirm_handler = gnc_table_model_get_confirm_handler (table->model,
1226 if (!confirm_handler)
1229 return confirm_handler (virt_loc, table->model->handler_user_data);
1235 gnc_table_modify_update (
Table *table,
1241 int *cursor_position,
1242 int *start_selection,
1244 gboolean *cancelled)
1246 gboolean changed = FALSE;
1247 CellModifyVerifyFunc mv;
1254 g_return_val_if_fail (table, NULL);
1255 g_return_val_if_fail (table->model, NULL);
1257 if (gnc_table_model_read_only (table->model))
1259 PWARN (
"change to read-only table");
1263 cb = table->current_cursor;
1265 cell_row = virt_loc.phys_row_offset;
1266 cell_col = virt_loc.phys_col_offset;
1270 if (!gnc_table_confirm_change (table, virt_loc))
1275 LEAVE(
"change cancelled");
1283 cell = gnc_cellblock_get_cell (cb, cell_row, cell_col);
1290 mv = cell->modify_verify;
1292 old_value = g_strdup (cell->value);
1296 mv (cell, change, change_len, newval, newval_len,
1297 cursor_position, start_selection, end_selection);
1301 gnc_basic_cell_set_value (cell, newval);
1304 if (g_strcmp0 (old_value, cell->value) != 0)
1307 cell->changed = TRUE;
1312 if (table->gui_handlers.redraw_help)
1313 table->gui_handlers.redraw_help (table);
1315 LEAVE (
"change %d %d (relrow=%d relcol=%d) val=%s\n",
1316 virt_loc.vcell_loc.virt_row,
1317 virt_loc.vcell_loc.virt_col,
1319 cell->value ? cell->value :
"(null)");
1328 gnc_table_direct_update (
Table *table,
1331 int *cursor_position,
1332 int *start_selection,
1343 g_return_val_if_fail (table, FALSE);
1344 g_return_val_if_fail (table->model, FALSE);
1346 if (gnc_table_model_read_only (table->model))
1348 PWARN (
"input to read-only table");
1352 cb = table->current_cursor;
1354 cell_row = virt_loc.phys_row_offset;
1355 cell_col = virt_loc.phys_col_offset;
1357 cell = gnc_cellblock_get_cell (cb, cell_row, cell_col);
1363 if (cell->direct_update == NULL)
1365 LEAVE(
"no direct update");
1369 old_value = g_strdup (cell->value);
1371 result = cell->direct_update (cell, cursor_position, start_selection,
1372 end_selection, gui_data);
1374 if (g_strcmp0 (old_value, cell->value) != 0)
1376 if (!gnc_table_confirm_change (table, virt_loc))
1378 gnc_basic_cell_set_value (cell, old_value);
1384 cell->changed = TRUE;
1385 *newval_ptr = cell->value;
1393 if (table->gui_handlers.redraw_help)
1394 table->gui_handlers.redraw_help (table);
1400 static gboolean gnc_table_find_valid_cell_horiz (
Table *table,
1402 gboolean exact_cell);
1415 if (virt_loc == NULL)
1420 if (vloc.vcell_loc.virt_row < 1)
1421 vloc.vcell_loc.virt_row = 1;
1422 if (vloc.vcell_loc.virt_row >= table->num_virt_rows)
1423 vloc.vcell_loc.virt_row = table->num_virt_rows - 1;
1425 top = vloc.vcell_loc.virt_row;
1426 bottom = vloc.vcell_loc.virt_row + 1;
1428 while (top >= 1 || bottom < table->num_virt_rows)
1430 vloc.vcell_loc.virt_row = top;
1431 vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1432 if (vcell && vcell->cellblock && vcell->visible)
1434 vloc.phys_row_offset = 0;
1435 vloc.phys_col_offset = 0;
1437 if (gnc_table_find_valid_cell_horiz (table, &vloc, FALSE))
1441 vloc.vcell_loc.virt_row = bottom;
1442 vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1443 if (vcell && vcell->cellblock && vcell->visible)
1445 vloc.phys_row_offset = 0;
1446 vloc.phys_col_offset = 0;
1448 if (gnc_table_find_valid_cell_horiz (table, &vloc, FALSE))
1456 if (!vcell || !vcell->cellblock || !vcell->visible)
1459 if (vloc.phys_row_offset < 0)
1460 vloc.phys_row_offset = 0;
1461 if (vloc.phys_row_offset >= vcell->cellblock->num_rows)
1462 vloc.phys_row_offset = vcell->cellblock->num_rows - 1;
1464 virt_loc->vcell_loc = vloc.vcell_loc;
1470 gnc_table_find_valid_cell_horiz (
Table *table,
1472 gboolean exact_cell)
1482 if (virt_loc == NULL)
1485 if (gnc_table_virtual_cell_out_of_bounds (table, virt_loc->vcell_loc))
1488 if (gnc_table_virtual_loc_valid (table, *virt_loc, exact_cell))
1493 vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1496 if (vcell->cellblock == NULL)
1499 if (vloc.phys_col_offset < 0)
1500 vloc.phys_col_offset = 0;
1501 if (vloc.phys_col_offset >= vcell->cellblock->num_cols)
1502 vloc.phys_col_offset = vcell->cellblock->num_cols - 1;
1504 left = vloc.phys_col_offset - 1;
1505 right = vloc.phys_col_offset + 1;
1507 while (left >= 0 || right < vcell->cellblock->num_cols)
1509 vloc.phys_col_offset = right;
1510 if (gnc_table_virtual_loc_valid(table, vloc, FALSE))
1516 vloc.phys_col_offset = left;
1517 if (gnc_table_virtual_loc_valid(table, vloc, FALSE))
1532 gboolean exact_pointer)
1534 if (!gnc_table_find_valid_row_vert (table, virt_loc))
1537 return gnc_table_find_valid_cell_horiz (table, virt_loc, exact_pointer);
1541 gnc_table_refresh_cursor_gui (
Table * table,
1545 g_return_if_fail (table != NULL);
1546 g_return_if_fail (table->gui_handlers.cursor_refresh != NULL);
1548 table->gui_handlers.cursor_refresh (table, vcell_loc, do_scroll);
1552 gnc_table_move_tab (
Table *table,
1554 gboolean move_right)
1560 if ((table == NULL) || (virt_loc == NULL))
1565 vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1566 if ((vcell == NULL) || (vcell->cellblock == NULL) || !vcell->visible)
1571 CellIOFlags io_flags;
1575 vloc.phys_col_offset++;
1577 if (vloc.phys_col_offset >= vcell->cellblock->num_cols)
1582 vloc.phys_col_offset = 0;
1587 vloc.phys_col_offset--;
1589 if (vloc.phys_col_offset < 0)
1594 vloc.phys_col_offset = vcell->cellblock->num_cols - 1;
1598 vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1599 if ((vcell == NULL) || (vcell->cellblock == NULL) || !vcell->visible)
1602 cell = gnc_cellblock_get_cell (vcell->cellblock,
1603 vloc.phys_row_offset,
1604 vloc.phys_col_offset);
1608 io_flags = gnc_table_get_io_flags (table, vloc);
1610 if (!(io_flags & XACC_CELL_ALLOW_INPUT))
1613 if (io_flags & XACC_CELL_ALLOW_EXACT_ONLY)
1620 gboolean changed = !virt_loc_equal (vloc, *virt_loc);
1631 int phys_row_offset)
1635 gint last_visible_row;
1637 if ((table == NULL) || (virt_loc == NULL))
1641 last_visible_row = vloc.vcell_loc.virt_row;
1643 vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1644 if ((vcell == NULL) || (vcell->cellblock == NULL))
1647 while (phys_row_offset != 0)
1650 if (phys_row_offset < 0)
1655 if (vloc.phys_row_offset > 0)
1657 vloc.phys_row_offset--;
1662 if (vloc.vcell_loc.virt_row == 1)
1667 vloc.vcell_loc.virt_row--;
1669 vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1671 while (vcell && vcell->cellblock && !vcell->visible);
1673 if (!vcell || !vcell->cellblock)
1676 last_visible_row = vloc.vcell_loc.virt_row;
1677 vloc.phys_row_offset = vcell->cellblock->num_rows - 1;
1685 if (vloc.phys_row_offset < (vcell->cellblock->num_rows - 1))
1687 vloc.phys_row_offset++;
1692 if (vloc.vcell_loc.virt_row == (table->num_virt_rows - 1))
1697 vloc.vcell_loc.virt_row++;
1699 vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1701 while (vcell && vcell->cellblock && !vcell->visible);
1703 if (!vcell || !vcell->cellblock)
1706 last_visible_row = vloc.vcell_loc.virt_row;
1707 vloc.phys_row_offset = 0;
1711 vloc.vcell_loc.virt_row = last_visible_row;
1714 gboolean changed = !virt_loc_equal (vloc, *virt_loc);
1723 gnc_table_traverse_update(
Table *table,
1725 gncTableTraversalDir dir,
1728 gboolean abort_move;
1730 if ((table == NULL) || (dest_loc == NULL))
1733 ENTER(
"proposed (%d %d) -> (%d %d)\n",
1734 virt_loc.vcell_loc.virt_row, virt_loc.vcell_loc.virt_row,
1735 dest_loc->vcell_loc.virt_row, dest_loc->vcell_loc.virt_col);
1739 if (gnc_table_virtual_cell_out_of_bounds (table, dest_loc->vcell_loc))
1741 PERR(
"destination (%d, %d) out of bounds (%d, %d)\n",
1742 dest_loc->vcell_loc.virt_row, dest_loc->vcell_loc.virt_col,
1743 table->num_virt_rows, table->num_virt_cols);
1751 if (!gnc_table_virtual_loc_valid (table, virt_loc, TRUE))
1753 PINFO(
"source (%d, %d) out of bounds (%d, %d)\n",
1754 virt_loc.vcell_loc.virt_row, virt_loc.vcell_loc.virt_col,
1755 table->num_virt_rows, table->num_virt_cols);
1757 dir = GNC_TABLE_TRAVERSE_POINTER;
1763 case GNC_TABLE_TRAVERSE_RIGHT:
1764 case GNC_TABLE_TRAVERSE_LEFT:
1765 gnc_table_find_valid_cell_horiz(table, dest_loc, FALSE);
1769 case GNC_TABLE_TRAVERSE_UP:
1770 case GNC_TABLE_TRAVERSE_DOWN:
1775 gboolean second_traversal = FALSE;
1782 increment = (dir == GNC_TABLE_TRAVERSE_DOWN) ? 1 : -1;
1784 while (!gnc_table_virtual_loc_valid(table, new_loc, FALSE))
1786 if (virt_loc_equal (new_loc, virt_loc))
1788 new_loc = *dest_loc;
1789 gnc_table_find_valid_cell_horiz(table, &new_loc, FALSE);
1804 if (!second_traversal)
1805 second_traversal = TRUE;
1808 second_traversal = FALSE;
1812 new_loc = *dest_loc;
1813 new_loc.phys_col_offset = new_loc.phys_col_offset + col_offset;
1817 *dest_loc = new_loc;
1820 if (!gnc_table_virtual_loc_valid(table, *dest_loc, FALSE))
1828 case GNC_TABLE_TRAVERSE_POINTER:
1829 if (!gnc_table_find_valid_cell_horiz(table, dest_loc, TRUE))
1838 g_return_val_if_fail (FALSE, TRUE);
1843 if (table->control->traverse)
1844 abort_move = table->control->traverse (dest_loc, dir,
1845 table->control->user_data);
1849 LEAVE(
"dest_row = %d, dest_col = %d\n",
1850 dest_loc->vcell_loc.virt_row, dest_loc->vcell_loc.virt_col);
#define PINFO(format, args...)
#define DEBUG(format, args...)
gboolean gnc_table_move_vertical_position(Table *table, VirtualLocation *virt_loc, int phys_row_offset)
void gnc_table_set_default_gui_handlers(TableGUIHandlers *gui_handlers)
#define PERR(format, args...)
#define ENTER(format, args...)
#define PWARN(format, args...)
All type declarations for the whole Gnucash engine.
Declarations for the Table object.
#define LEAVE(format, args...)
Declarations for the CellBlock object.
const gchar * QofLogModule