53 static QofLogModule log_module = GNC_MOD_REGISTER;
57 static void gnc_table_init (Table *
table);
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);
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)
125 gnc_table_free_data (
table);
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)
156 gnc_table_clear_current_cursor_changes (Table *
table)
165 gnc_table_save_current_cursor (Table *
table, CursorBuffer *buffer)
167 if (!
table || !buffer)
170 gnc_table_layout_save_cursor (
table->layout,
table->current_cursor, buffer);
174 gnc_table_restore_current_cursor (Table *
table,
175 CursorBuffer *buffer)
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,
196 VirtualLocation *virt_loc)
201 return gnc_table_get_cell_location (
table, cell_name,
202 table->current_cursor_loc.vcell_loc,
208 VirtualCellLocation vcell_loc)
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,
221 VirtualLocation virt_loc)
223 return (virt_loc.vcell_loc.virt_row == 0);
233 vcell_loc.virt_row, vcell_loc.virt_col);
239 VirtualCellLocation vcell_loc = { 0, 0 };
245 table_get_model_entry (Table *
table, VirtualLocation virt_loc,
246 gboolean translate, gboolean *conditionally_changed,
const char *cell_name)
248 TableGetEntryHandler entry_handler = gnc_table_model_get_entry_handler (
249 table->model, cell_name);
253 const char *entry = entry_handler (virt_loc, translate, conditionally_changed,
254 table->model->handler_user_data);
263 table_get_entry (Table *
table, VirtualLocation virt_loc,
264 gboolean *conditionally_changed)
266 const char *cell_name = gnc_table_get_cell_name (
table, virt_loc);
268 return table_get_model_entry (
table, virt_loc, FALSE, conditionally_changed,
273 gnc_table_get_entry (Table *
table, VirtualLocation virt_loc)
275 BasicCell *cell = gnc_table_get_cell (
table, virt_loc);
277 if (!cell || !cell->cell_name)
280 if (virt_cell_loc_equal (
table->current_cursor_loc.vcell_loc,
283 CellIOFlags io_flags = gnc_table_get_io_flags (
table, virt_loc);
285 if (io_flags & XACC_CELL_ALLOW_INPUT)
289 return table_get_model_entry (
table, virt_loc, TRUE, NULL, cell->cell_name);
293 gnc_table_get_model_entry (Table *
table,
const char *cell_name)
295 return table_get_model_entry (
table,
table->current_cursor_loc, TRUE, NULL,
300 gnc_table_get_tooltip (Table *
table, VirtualLocation virt_loc)
302 TableGetTooltipHandler tooltip_handler;
305 cell = gnc_table_get_cell (
table, virt_loc);
306 if (!cell || !cell->cell_name)
310 gnc_table_model_get_tooltip_handler (
table->model, cell->cell_name);
312 if (!tooltip_handler)
315 return tooltip_handler (virt_loc,
table->model->handler_user_data);
319 gnc_table_get_io_flags (Table *
table, VirtualLocation virt_loc)
321 TableGetCellIOFlagsHandler io_flags_handler;
322 const char *cell_name;
326 return XACC_CELL_ALLOW_NONE;
328 cell_name = gnc_table_get_cell_name (
table, virt_loc);
331 gnc_table_model_get_io_flags_handler (
table->model, cell_name);
332 if (!io_flags_handler)
333 return XACC_CELL_ALLOW_NONE;
335 flags = io_flags_handler (virt_loc,
table->model->handler_user_data);
337 if (gnc_table_model_read_only (
table->model))
338 flags &= XACC_CELL_ALLOW_SHADOW;
344 gnc_table_get_label (Table *
table, VirtualLocation virt_loc)
346 TableGetLabelHandler label_handler;
347 const char *cell_name;
353 cell_name = gnc_table_get_cell_name (
table, virt_loc);
355 label_handler = gnc_table_model_get_label_handler (
table->model, cell_name);
359 label = label_handler (virt_loc,
table->model->handler_user_data);
367 gnc_table_get_color (Table *
table, VirtualLocation virt_loc,
370 TableGetCellColorHandler color_handler;
371 const char *handler_name;
377 return COLOR_UNDEFINED;
379 handler_name = gnc_table_get_cell_name (
table, virt_loc);
382 gnc_table_model_get_cell_color_handler (
table->model, handler_name);
385 return COLOR_UNDEFINED;
387 return color_handler (virt_loc, hatching,
388 table->model->handler_user_data);
392 gnc_table_get_borders (Table *
table, VirtualLocation virt_loc,
395 TableGetCellBorderHandler cell_border_handler;
396 const char *cell_name;
401 cell_name = gnc_table_get_cell_name (
table, virt_loc);
403 cell_border_handler =
404 gnc_table_model_get_cell_border_handler (
table->model, cell_name);
405 if (!cell_border_handler)
408 cell_border_handler (virt_loc, borders,
table->model->handler_user_data);
412 gnc_table_get_align (Table *
table, VirtualLocation virt_loc)
416 cell = gnc_table_get_cell (
table, virt_loc);
418 return CELL_ALIGN_RIGHT;
420 return cell->alignment;
424 gnc_table_is_popup (Table *
table, VirtualLocation virt_loc)
428 cell = gnc_table_get_cell (
table, virt_loc);
432 return cell->is_popup;
436 gnc_table_get_help (Table *
table)
438 TableGetHelpHandler help_handler;
439 VirtualLocation virt_loc;
440 const char * cell_name;
445 virt_loc =
table->current_cursor_loc;
447 cell_name = gnc_table_get_cell_name (
table, virt_loc);
449 help_handler = gnc_table_model_get_help_handler (
table->model, cell_name);
453 return help_handler (virt_loc,
table->model->handler_user_data);
457 gnc_table_get_cell (Table *
table, VirtualLocation virt_loc)
469 virt_loc.phys_row_offset,
470 virt_loc.phys_col_offset);
474 gnc_table_get_cell_name (Table *
table, VirtualLocation virt_loc)
478 cell = gnc_table_get_cell (
table, virt_loc);
482 return cell->cell_name;
486 gnc_table_get_cell_type_name (Table *
table, VirtualLocation virt_loc)
490 cell = gnc_table_get_cell (
table, virt_loc);
494 return cell->cell_type_name;
499 gnc_table_get_cell_location (Table *
table,
500 const char *cell_name,
501 VirtualCellLocation vcell_loc,
502 VirtualLocation *virt_loc)
506 int cell_row, cell_col;
515 cellblock = vcell->cellblock;
517 for (cell_row = 0; cell_row < cellblock->num_rows; cell_row++)
518 for (cell_col = 0; cell_col < cellblock->num_cols; cell_col++)
526 if (gnc_basic_cell_has_name (cell, cell_name))
528 if (virt_loc != NULL)
530 virt_loc->vcell_loc = vcell_loc;
532 virt_loc->phys_row_offset = cell_row;
533 virt_loc->phys_col_offset = cell_col;
544 gnc_table_save_cells (Table *
table, gpointer save_data)
546 TableSaveHandler save_handler;
550 g_return_if_fail (
table);
553 if (gnc_table_model_read_only (
table->model))
558 save_handler = gnc_table_model_get_pre_save_handler (
table->model);
560 save_handler (save_data,
table->model->handler_user_data);
562 cells = gnc_table_layout_get_cells (
table->layout);
563 for (node = cells; node; node = node->next)
565 BasicCell * cell = node->data;
566 TableSaveCellHandler save_cell_handler;
570 if (!gnc_table_layout_get_cell_changed (
table->layout,
571 cell->cell_name, TRUE))
574 save_cell_handler = gnc_table_model_get_save_handler (
table->model,
576 if (save_cell_handler)
577 save_cell_handler (cell, save_data,
table->model->handler_user_data);
580 save_handler = gnc_table_model_get_post_save_handler (
table->model);
582 save_handler (save_data,
table->model->handler_user_data);
592 if ((virt_rows < table->num_virt_rows) ||
593 (virt_cols < table->num_virt_cols))
595 gnc_virtual_location_init (&
table->current_cursor_loc);
596 table->current_cursor = NULL;
599 gnc_table_resize (
table, virt_rows, virt_cols);
603 gnc_table_free_data (Table *
table)
612 gnc_virtual_location_init (VirtualLocation *vloc)
617 vloc->phys_row_offset = -1;
618 vloc->phys_col_offset = -1;
619 vloc->vcell_loc.virt_row = -1;
620 vloc->vcell_loc.virt_col = -1;
624 gnc_virtual_cell_construct (gpointer _vcell, gpointer user_data)
627 Table *
table = user_data;
629 vcell->cellblock = NULL;
631 if (
table &&
table->model->cell_data_allocator)
640 gnc_virtual_cell_destroy (gpointer _vcell, gpointer user_data)
643 Table *
table = user_data;
652 gnc_table_resize (Table *
table,
int new_virt_rows,
int new_virt_cols)
658 table->num_virt_rows = new_virt_rows;
659 table->num_virt_cols = new_virt_cols;
665 gconstpointer vcell_data,
667 gboolean start_primary_color,
668 VirtualCellLocation vcell_loc)
672 if ((
table == NULL) || (cursor == NULL))
675 if ((vcell_loc.virt_row >=
table->num_virt_rows) ||
676 (vcell_loc.virt_col >=
table->num_virt_cols))
677 gnc_table_resize (
table,
678 MAX (
table->num_virt_rows, vcell_loc.virt_row + 1),
679 MAX (
table->num_virt_cols, vcell_loc.virt_col + 1));
686 vcell->cellblock = cursor;
689 if (
table->model->cell_data_copy)
694 vcell->
visible = visible ? 1 : 0;
700 VirtualCellLocation vcell_loc,
701 gconstpointer vcell_data)
712 if (
table->model->cell_data_copy)
720 VirtualCellLocation vcell_loc,
732 vcell->
visible = visible ? 1 : 0;
737 VirtualCellLocation vcell_loc,
749 vcell->cellblock = cursor;
753 gnc_table_move_cursor_internal (Table *
table,
754 VirtualLocation new_virt_loc,
755 gboolean do_move_gui)
757 int cell_row, cell_col;
758 VirtualLocation virt_loc;
762 ENTER(
"new_virt=(%d %d) do_move_gui=%d\n",
763 new_virt_loc.vcell_loc.virt_row,
764 new_virt_loc.vcell_loc.virt_col, do_move_gui);
769 if (
table->control->move_cursor &&
table->control->allow_move)
771 table->control->move_cursor (&new_virt_loc,
table->control->user_data);
782 gnc_virtual_location_init (&
table->current_cursor_loc);
784 curs =
table->current_cursor;
785 table->current_cursor = NULL;
788 if ((new_virt_loc.vcell_loc.virt_row < 0) ||
789 (new_virt_loc.vcell_loc.virt_col < 0))
793 if (do_move_gui && curs)
795 for (cell_row = 0; cell_row < curs->num_rows; cell_row++)
796 for (cell_col = 0; cell_col < curs->num_cols; cell_col++)
803 cell->changed = FALSE;
804 cell->conditionally_changed = FALSE;
807 cell->gui_move (cell);
812 LEAVE(
"out of bounds\n");
816 if (!gnc_table_virtual_loc_valid (
table, new_virt_loc, TRUE))
818 PWARN(
"bad table location");
826 curs = vcell->cellblock;
827 table->current_cursor = curs;
830 table->current_cursor_loc = new_virt_loc;
832 virt_loc.vcell_loc = new_virt_loc.vcell_loc;
835 for (cell_row = 0; cell_row < curs->num_rows; cell_row++)
836 for (cell_col = 0; cell_col < curs->num_cols; cell_col++)
839 CellIOFlags io_flags;
841 virt_loc.phys_row_offset = cell_row;
842 virt_loc.phys_col_offset = cell_col;
851 if (do_move_gui && cell->gui_move)
852 cell->gui_move (cell);
856 io_flags = gnc_table_get_io_flags (
table, virt_loc);
857 if (io_flags & XACC_CELL_ALLOW_SHADOW)
860 gboolean conditionally_changed = FALSE;
862 entry = table_get_entry (
table, virt_loc,
863 &conditionally_changed);
865 gnc_basic_cell_set_value (cell, entry);
867 cell->changed = FALSE;
868 cell->conditionally_changed = conditionally_changed;
881 gnc_table_move_cursor_internal (
table, new_virt_loc, FALSE);
890 gnc_table_move_cursor_internal (
table, new_virt_loc, TRUE);
899 gboolean do_move = FALSE;
900 gboolean moved_cursor = FALSE;
902 if (!
table)
return FALSE;
912 if (!virt_cell_loc_equal (virt_loc.vcell_loc,
913 table->current_cursor_loc.vcell_loc))
921 else if (!virt_loc_equal (virt_loc,
table->current_cursor_loc))
923 table->current_cursor_loc = virt_loc;
935 if (!
table)
return NULL;
949 gnc_table_realize_gui (Table *
table)
955 if (!
table->ui_data)
return;
957 cells = gnc_table_layout_get_cells (
table->layout);
959 for (node = cells; node; node = node->next)
961 BasicCell *cell = node->data;
963 if (cell->gui_realize)
964 cell->gui_realize (cell,
table->ui_data);
969 gnc_table_wrap_verify_cursor_position (Table *
table, VirtualLocation virt_loc)
971 VirtualLocation save_loc;
972 gboolean moved_cursor;
976 ENTER(
"(%d %d)", virt_loc.vcell_loc.virt_row, virt_loc.vcell_loc.virt_col);
978 save_loc =
table->current_cursor_loc;
1003 gnc_table_virtual_loc_valid(Table *
table,
1004 VirtualLocation virt_loc,
1005 gboolean exact_pointer)
1008 CellIOFlags io_flags;
1010 if (!
table)
return FALSE;
1013 if (virt_loc.vcell_loc.virt_row == 0)
1026 if ((0 > virt_loc.phys_row_offset) || (0 > virt_loc.phys_col_offset))
1030 if (vcell->cellblock == NULL)
return FALSE;
1033 if (gnc_table_model_read_only (
table->model))
return TRUE;
1035 io_flags = gnc_table_get_io_flags (
table, virt_loc);
1038 if (io_flags & XACC_CELL_ALLOW_ENTER)
return TRUE;
1041 if (0 == (XACC_CELL_ALLOW_INPUT & io_flags))
return FALSE;
1045 if (!exact_pointer && ((XACC_CELL_ALLOW_EXACT_ONLY & io_flags) != 0))
1053 gnc_table_enter_update (Table *
table,
1054 VirtualLocation virt_loc,
1055 int *cursor_position,
1056 int *start_selection,
1059 gboolean can_edit = TRUE;
1060 CellEnterFunc enter;
1065 CellIOFlags io_flags;
1070 cb =
table->current_cursor;
1072 cell_row = virt_loc.phys_row_offset;
1073 cell_col = virt_loc.phys_col_offset;
1075 ENTER(
"enter %d %d (relrow=%d relcol=%d)",
1076 virt_loc.vcell_loc.virt_row,
1077 virt_loc.vcell_loc.virt_col,
1078 cell_row, cell_col);
1088 io_flags = gnc_table_get_io_flags (
table, virt_loc);
1089 if (io_flags == XACC_CELL_ALLOW_READ_ONLY)
1091 if (
table->gui_handlers.redraw_help)
1093 LEAVE(
"read only cell");
1097 enter = cell->enter_cell;
1103 DEBUG(
"gnc_table_enter_update(): %d %d has enter handler\n",
1104 cell_row, cell_col);
1106 old_value = g_strdup (cell->value);
1108 can_edit = enter (cell, cursor_position, start_selection, end_selection);
1110 if (g_strcmp0 (old_value, cell->value) != 0)
1112 if (gnc_table_model_read_only (
table->model))
1114 PWARN (
"enter update changed read-only table");
1117 cell->changed = TRUE;
1123 if (
table->gui_handlers.redraw_help)
1126 LEAVE(
"return %d\n", can_edit);
1131 gnc_table_leave_update (Table *
table, VirtualLocation virt_loc)
1133 CellLeaveFunc leave;
1142 cb =
table->current_cursor;
1144 cell_row = virt_loc.phys_row_offset;
1145 cell_col = virt_loc.phys_col_offset;
1147 ENTER(
"proposed (%d %d) rel(%d %d)\n",
1148 virt_loc.vcell_loc.virt_row,
1149 virt_loc.vcell_loc.virt_col,
1150 cell_row, cell_col);
1160 leave = cell->leave_cell;
1166 old_value = g_strdup (cell->value);
1170 if (g_strcmp0 (old_value, cell->value) != 0)
1172 if (gnc_table_model_read_only (
table->model))
1174 PWARN (
"leave update changed read-only table");
1177 cell->changed = TRUE;
1186 gnc_table_confirm_change (Table *
table, VirtualLocation virt_loc)
1188 TableConfirmHandler confirm_handler;
1189 const char *cell_name;
1194 cell_name = gnc_table_get_cell_name (
table, virt_loc);
1196 confirm_handler = gnc_table_model_get_confirm_handler (
table->model,
1198 if (!confirm_handler)
1201 return confirm_handler (virt_loc,
table->model->handler_user_data);
1207 gnc_table_modify_update (Table *
table,
1208 VirtualLocation virt_loc,
1213 int *cursor_position,
1214 int *start_selection,
1216 gboolean *cancelled)
1218 gboolean changed = FALSE;
1219 CellModifyVerifyFunc mv;
1226 g_return_val_if_fail (
table, NULL);
1227 g_return_val_if_fail (
table->model, NULL);
1229 if (gnc_table_model_read_only (
table->model))
1231 PWARN (
"change to read-only table");
1235 cb =
table->current_cursor;
1237 cell_row = virt_loc.phys_row_offset;
1238 cell_col = virt_loc.phys_col_offset;
1242 if (!gnc_table_confirm_change (
table, virt_loc))
1247 LEAVE(
"change cancelled");
1262 mv = cell->modify_verify;
1264 old_value = g_strdup (cell->value);
1268 mv (cell, change, change_len, newval, newval_len,
1269 cursor_position, start_selection, end_selection);
1273 gnc_basic_cell_set_value (cell, newval);
1276 if (g_strcmp0 (old_value, cell->value) != 0)
1279 cell->changed = TRUE;
1284 if (
table->gui_handlers.redraw_help)
1287 LEAVE (
"change %d %d (relrow=%d relcol=%d) val=%s\n",
1288 virt_loc.vcell_loc.virt_row,
1289 virt_loc.vcell_loc.virt_col,
1291 cell->value ? cell->value :
"(null)");
1300 gnc_table_direct_update (Table *
table,
1301 VirtualLocation virt_loc,
1303 int *cursor_position,
1304 int *start_selection,
1315 g_return_val_if_fail (
table, FALSE);
1316 g_return_val_if_fail (
table->model, FALSE);
1318 if (gnc_table_model_read_only (
table->model))
1320 PWARN (
"input to read-only table");
1324 cb =
table->current_cursor;
1326 cell_row = virt_loc.phys_row_offset;
1327 cell_col = virt_loc.phys_col_offset;
1335 gboolean changed = cell->changed;
1336 old_value = g_strdup (cell->value);
1338 CellDirectUpdateFunc du = cell->direct_update;
1341 du =
table->gui_handlers.default_direct_update;
1345 LEAVE(
"no direct update");
1349 result = du (cell, cursor_position, start_selection, end_selection, gui_data);
1351 if (g_strcmp0 (old_value, cell->value) != 0)
1353 if (!gnc_table_confirm_change (
table, virt_loc))
1355 gnc_basic_cell_set_value (cell, old_value);
1362 cell->changed = TRUE;
1363 *newval_ptr = cell->value;
1371 if (
table->gui_handlers.redraw_help)
1378 static gboolean gnc_table_find_valid_cell_horiz (Table *
table,
1379 VirtualLocation *virt_loc,
1380 gboolean exact_cell);
1383 gnc_table_find_valid_row_vert (Table *
table, VirtualLocation *virt_loc)
1385 VirtualLocation vloc;
1393 if (virt_loc == NULL)
1398 if (vloc.vcell_loc.virt_row < 1)
1399 vloc.vcell_loc.virt_row = 1;
1400 if (vloc.vcell_loc.virt_row >=
table->num_virt_rows)
1401 vloc.vcell_loc.virt_row =
table->num_virt_rows - 1;
1403 top = vloc.vcell_loc.virt_row;
1404 bottom = vloc.vcell_loc.virt_row + 1;
1406 while (top >= 1 || bottom < table->num_virt_rows)
1408 vloc.vcell_loc.virt_row = top;
1410 if (vcell && vcell->cellblock && vcell->
visible)
1412 vloc.phys_row_offset = 0;
1413 vloc.phys_col_offset = 0;
1415 if (gnc_table_find_valid_cell_horiz (
table, &vloc, FALSE))
1419 vloc.vcell_loc.virt_row = bottom;
1421 if (vcell && vcell->cellblock && vcell->
visible)
1423 vloc.phys_row_offset = 0;
1424 vloc.phys_col_offset = 0;
1426 if (gnc_table_find_valid_cell_horiz (
table, &vloc, FALSE))
1434 if (!vcell || !vcell->cellblock || !vcell->
visible)
1437 if (vloc.phys_row_offset < 0)
1438 vloc.phys_row_offset = 0;
1439 if (vloc.phys_row_offset >= vcell->cellblock->num_rows)
1440 vloc.phys_row_offset = vcell->cellblock->num_rows - 1;
1442 virt_loc->vcell_loc = vloc.vcell_loc;
1448 gnc_table_find_valid_cell_horiz (Table *
table,
1449 VirtualLocation *virt_loc,
1450 gboolean exact_cell)
1452 VirtualLocation vloc;
1460 if (virt_loc == NULL)
1466 if (gnc_table_virtual_loc_valid (
table, *virt_loc, exact_cell))
1474 if (vcell->cellblock == NULL)
1477 if (vloc.phys_col_offset < 0)
1478 vloc.phys_col_offset = 0;
1479 if (vloc.phys_col_offset >= vcell->cellblock->num_cols)
1480 vloc.phys_col_offset = vcell->cellblock->num_cols - 1;
1482 left = vloc.phys_col_offset - 1;
1483 right = vloc.phys_col_offset + 1;
1485 while (left >= 0 || right < vcell->cellblock->num_cols)
1487 vloc.phys_col_offset = right;
1488 if (gnc_table_virtual_loc_valid(
table, vloc, FALSE))
1494 vloc.phys_col_offset = left;
1495 if (gnc_table_virtual_loc_valid(
table, vloc, FALSE))
1510 gboolean exact_pointer)
1512 if (!gnc_table_find_valid_row_vert (
table, virt_loc))
1515 return gnc_table_find_valid_cell_horiz (
table, virt_loc, exact_pointer);
1520 VirtualCellLocation vcell_loc,
1523 g_return_if_fail (
table != NULL);
1524 g_return_if_fail (
table->gui_handlers.cursor_refresh != NULL);
1526 table->gui_handlers.cursor_refresh (
table, vcell_loc, do_scroll);
1530 gnc_table_move_tab (Table *
table,
1531 VirtualLocation *virt_loc,
1532 gboolean move_right)
1535 VirtualLocation vloc;
1538 if ((
table == NULL) || (virt_loc == NULL))
1544 if ((vcell == NULL) || (vcell->cellblock == NULL) || !vcell->
visible)
1549 CellIOFlags io_flags;
1553 vloc.phys_col_offset++;
1555 if (vloc.phys_col_offset >= vcell->cellblock->num_cols)
1560 vloc.phys_col_offset = 0;
1565 vloc.phys_col_offset--;
1567 if (vloc.phys_col_offset < 0)
1572 vloc.phys_col_offset = vcell->cellblock->num_cols - 1;
1577 if ((vcell == NULL) || (vcell->cellblock == NULL) || !vcell->
visible)
1581 vloc.phys_row_offset,
1582 vloc.phys_col_offset);
1586 io_flags = gnc_table_get_io_flags (
table, vloc);
1588 if (!(io_flags & XACC_CELL_ALLOW_INPUT))
1591 if (io_flags & XACC_CELL_ALLOW_EXACT_ONLY)
1598 gboolean changed = !virt_loc_equal (vloc, *virt_loc);
1608 VirtualLocation *virt_loc,
1609 int phys_row_offset)
1611 VirtualLocation vloc;
1613 gint last_visible_row;
1615 if ((
table == NULL) || (virt_loc == NULL))
1619 last_visible_row = vloc.vcell_loc.virt_row;
1622 if ((vcell == NULL) || (vcell->cellblock == NULL))
1625 while (phys_row_offset != 0)
1628 if (phys_row_offset < 0)
1633 if (vloc.phys_row_offset > 0)
1635 vloc.phys_row_offset--;
1640 if (vloc.vcell_loc.virt_row == 1)
1645 vloc.vcell_loc.virt_row--;
1649 while (vcell && vcell->cellblock && !vcell->
visible);
1651 if (!vcell || !vcell->cellblock)
1654 last_visible_row = vloc.vcell_loc.virt_row;
1655 vloc.phys_row_offset = vcell->cellblock->num_rows - 1;
1663 if (vloc.phys_row_offset < (vcell->cellblock->num_rows - 1))
1665 vloc.phys_row_offset++;
1670 if (vloc.vcell_loc.virt_row == (
table->num_virt_rows - 1))
1675 vloc.vcell_loc.virt_row++;
1679 while (vcell && vcell->cellblock && !vcell->
visible);
1681 if (!vcell || !vcell->cellblock)
1684 last_visible_row = vloc.vcell_loc.virt_row;
1685 vloc.phys_row_offset = 0;
1689 vloc.vcell_loc.virt_row = last_visible_row;
1692 gboolean changed = !virt_loc_equal (vloc, *virt_loc);
1701 gnc_table_traverse_update(Table *
table,
1702 VirtualLocation virt_loc,
1703 gncTableTraversalDir dir,
1704 VirtualLocation *dest_loc)
1706 gboolean abort_move;
1708 if ((
table == NULL) || (dest_loc == NULL))
1711 ENTER(
"proposed (%d %d) -> (%d %d)\n",
1712 virt_loc.vcell_loc.virt_row, virt_loc.vcell_loc.virt_row,
1713 dest_loc->vcell_loc.virt_row, dest_loc->vcell_loc.virt_col);
1719 PERR(
"destination (%d, %d) out of bounds (%d, %d)\n",
1720 dest_loc->vcell_loc.virt_row, dest_loc->vcell_loc.virt_col,
1729 if (!gnc_table_virtual_loc_valid (
table, virt_loc, TRUE))
1731 PINFO(
"source (%d, %d) out of bounds (%d, %d)\n",
1732 virt_loc.vcell_loc.virt_row, virt_loc.vcell_loc.virt_col,
1735 dir = GNC_TABLE_TRAVERSE_POINTER;
1741 case GNC_TABLE_TRAVERSE_RIGHT:
1742 case GNC_TABLE_TRAVERSE_LEFT:
1743 gnc_table_find_valid_cell_horiz(
table, dest_loc, FALSE);
1747 case GNC_TABLE_TRAVERSE_UP:
1748 case GNC_TABLE_TRAVERSE_DOWN:
1750 VirtualLocation new_loc = *dest_loc;
1753 gboolean second_traversal = FALSE;
1760 increment = (dir == GNC_TABLE_TRAVERSE_DOWN) ? 1 : -1;
1762 while (!gnc_table_virtual_loc_valid(
table, new_loc, FALSE))
1764 if (virt_loc_equal (new_loc, virt_loc))
1766 new_loc = *dest_loc;
1767 gnc_table_find_valid_cell_horiz(
table, &new_loc, FALSE);
1782 if (!second_traversal)
1783 second_traversal = TRUE;
1786 second_traversal = FALSE;
1790 new_loc = *dest_loc;
1791 new_loc.phys_col_offset = new_loc.phys_col_offset + col_offset;
1795 *dest_loc = new_loc;
1798 if (!gnc_table_virtual_loc_valid(
table, *dest_loc, FALSE))
1806 case GNC_TABLE_TRAVERSE_POINTER:
1807 if (!gnc_table_find_valid_cell_horiz(
table, dest_loc, TRUE))
1816 g_return_val_if_fail (FALSE, TRUE);
1821 if (
table->control->traverse)
1822 abort_move =
table->control->traverse (dest_loc, dir,
1823 table->control->user_data);
1827 LEAVE(
"dest_row = %d, dest_col = %d\n",
1828 dest_loc->vcell_loc.virt_row, dest_loc->vcell_loc.virt_col);
gpointer vcell_data
Array of physical cells.
GTable * g_table_new(guint entry_size, g_table_entry_constructor constructor, g_table_entry_destroyer destroyer, gpointer user_data)
Create a new table with the given entry constructor and destroyer.
#define PINFO(format, args...)
Print an informational note.
gpointer gnc_table_get_vcell_data(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell data associated with a cursor located at the given virtual coords...
void gnc_table_set_virt_cell_visible(Table *table, VirtualCellLocation vcell_loc, gboolean visible)
Set the visibility flag for a particular location.
gpointer g_table_index(GTable *gtable, int row, int col)
Return the element at the given row and column.
holds information about each virtual cell.
#define DEBUG(format, args...)
Print a debugging message.
void gnc_table_move_cursor_gui(Table *table, VirtualLocation new_virt_loc)
will move the cursor and its GUI to the indicated location.
gboolean gnc_table_find_close_valid_cell(Table *table, VirtualLocation *virt_loc, gboolean exact_pointer)
Find a close valid cell.
void gnc_cellblock_clear_changes(CellBlock *cursor)
Sets all cells in the cellblock to not changed.
void gnc_table_set_size(Table *table, int virt_rows, int virt_cols)
The gnc_table_set_size() method will resize the table to the indicated dimensions.
VirtualCell * gnc_table_get_header_cell(Table *table)
Return the virtual cell of the header.
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
void gnc_table_set_virt_cell_data(Table *table, VirtualCellLocation vcell_loc, gconstpointer vcell_data)
Set the virtual cell data for a particular location.
#define PWARN(format, args...)
Log a warning.
VirtualCell * gnc_table_get_virtual_cell(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell associated with a particular virtual location.
void gnc_table_set_default_gui_handlers(TableGUIHandlers *gui_handlers)
Implementation.
gboolean gnc_table_verify_cursor_position(Table *table, VirtualLocation virt_loc)
checks the location of the cursor with respect to a virtual location position, and if the resulting v...
unsigned int start_primary_color
visible in the GUI
void gnc_table_set_vcell(Table *table, CellBlock *cursor, gconstpointer vcell_data, gboolean visible, gboolean start_primary_color, VirtualCellLocation vcell_loc)
Indicate what handler should be used for a given virtual block.
gboolean gnc_table_move_vertical_position(Table *table, VirtualLocation *virt_loc, int phys_row_offset)
Moves away from virtual location virt_loc by phys_row_offset physical rows.
All type declarations for the whole Gnucash engine.
unsigned int visible
Used by higher-level code.
void g_table_destroy(GTable *gtable)
Free the table and all associated table elements.
void gnc_table_refresh_cursor_gui(Table *table, VirtualCellLocation vcell_loc, gboolean do_scroll)
Refresh the cursor in the given location.
void gnc_table_refresh_current_cursor_gui(Table *table, gboolean do_scroll)
Refresh the current cursor gui.
void gnc_table_set_virt_cell_cursor(Table *table, VirtualCellLocation vcell_loc, CellBlock *cursor)
Set the cellblock handler for a virtual cell.
gboolean gnc_table_virtual_cell_out_of_bounds(Table *table, VirtualCellLocation vcell_loc)
checks the given location and returns true if it is out of bounds of the table.
Declarations for the Table object.
#define LEAVE(format, args...)
Print a function exit debugging message.
void g_table_resize(GTable *gtable, int rows, int cols)
Resize the table, allocating and deallocating extra table members if needed.
Declarations for the CellBlock object.
void gnc_table_move_cursor(Table *table, VirtualLocation new_virt_loc)
will move the cursor (but not the cursor GUI) to the indicated location.
int gnc_cellblock_changed(CellBlock *cursor, gboolean include_conditional)
Return number of changed cells.
BasicCell * gnc_cellblock_get_cell(CellBlock *cellblock, int row, int col)
Retrieve the Cell at the specified coordinates.