GnuCash  5.6-150-g038405b370+
Files | Data Structures | Macros | Typedefs | Enumerations | Functions

The "Table" is a displayed matrix. More...

Files

file  gtable.h
 This is the API for GTables, a datatype for 2-dimensional tables with automatic resizing and memory management.
 
file  table-allgui.h
 Declarations for the Table object.
 
file  table-control.h
 
file  table-layout.h
 
file  table-model.h
 

Data Structures

struct  VirtualCell
 holds information about each virtual cell. More...
 
struct  TableGUIHandlers
 
struct  Table
 
struct  TableControl
 
struct  PhysicalCellBorders
 
struct  TableModel
 

Macros

#define CURSOR_HEADER   "cursor-header"
 Standard Cursor Names.
 

Typedefs

typedef void(* g_table_entry_constructor) (gpointer entry, gpointer user_data)
 
typedef void(* g_table_entry_destroyer) (gpointer entry, gpointer user_data)
 
typedef void(* TableCursorRefreshCB) (Table *table, VirtualCellLocation vcell_loc, gboolean do_scroll)
 
typedef void(* TableRedrawHelpCB) (Table *table)
 
typedef void(* TableDestroyCB) (Table *table)
 
typedef void(* TableMoveFunc) (VirtualLocation *new_virt_loc, gpointer user_data)
 
typedef gboolean(* TableTraverseFunc) (VirtualLocation *new_virt_loc, gncTableTraversalDir dir, gpointer user_data)
 
typedef const char *(* TableGetEntryHandler) (VirtualLocation virt_loc, gboolean translate, gboolean *conditionally_changed, gpointer user_data)
 
typedef const char *(* TableGetLabelHandler) (VirtualLocation virt_loc, gpointer user_data)
 
typedef char *(* TableGetHelpHandler) (VirtualLocation virt_loc, gpointer user_data)
 
typedef char *(* TableGetTooltipHandler) (VirtualLocation virt_loc, gpointer user_data)
 
typedef CellIOFlags(* TableGetCellIOFlagsHandler) (VirtualLocation virt_loc, gpointer user_data)
 
typedef guint32(* TableGetCellColorHandler) (VirtualLocation virt_loc, gboolean *hatching, gpointer user_data)
 
typedef void(* TableGetCellBorderHandler) (VirtualLocation virt_loc, PhysicalCellBorders *borders, gpointer user_data)
 
typedef gboolean(* TableConfirmHandler) (VirtualLocation virt_loc, gpointer user_data)
 
typedef void(* TableSaveCellHandler) (BasicCell *cell, gpointer save_data, gpointer user_data)
 
typedef void(* TableSaveHandler) (gpointer save_data, gpointer user_data)
 
typedef gpointer(* VirtCellDataAllocator) (void)
 
typedef void(* VirtCellDataDeallocator) (gpointer cell_data)
 
typedef void(* VirtCellDataCopy) (gpointer to, gconstpointer from)
 

Enumerations

enum  RegisterColor {
  COLOR_UNDEFINED = 0, COLOR_HEADER, COLOR_PRIMARY, COLOR_PRIMARY_ACTIVE,
  COLOR_SECONDARY, COLOR_SECONDARY_ACTIVE, COLOR_SPLIT, COLOR_SPLIT_ACTIVE,
  COLOR_NEGATIVE = 16
}
 Color definitions used for table elements.
 
enum  gncTableTraversalDir {
  GNC_TABLE_TRAVERSE_POINTER, GNC_TABLE_TRAVERSE_LEFT, GNC_TABLE_TRAVERSE_RIGHT, GNC_TABLE_TRAVERSE_UP,
  GNC_TABLE_TRAVERSE_DOWN
}
 
enum  CellIOFlags {
  XACC_CELL_ALLOW_NONE = 0, XACC_CELL_ALLOW_INPUT = 1 << 0, XACC_CELL_ALLOW_SHADOW = 1 << 1, XACC_CELL_ALLOW_ALL = XACC_CELL_ALLOW_INPUT | XACC_CELL_ALLOW_SHADOW,
  XACC_CELL_ALLOW_EXACT_ONLY = 1 << 2, XACC_CELL_ALLOW_ENTER = 1 << 3, XACC_CELL_ALLOW_READ_ONLY = XACC_CELL_ALLOW_SHADOW | XACC_CELL_ALLOW_ENTER
}
 
enum  PhysicalCellBorderLineStyle {
  CELL_BORDER_LINE_NONE, CELL_BORDER_LINE_LIGHT, CELL_BORDER_LINE_NORMAL, CELL_BORDER_LINE_HEAVY,
  CELL_BORDER_LINE_HIGHLIGHT
}
 

Functions

GTableg_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. More...
 
void g_table_destroy (GTable *gtable)
 Free the table and all associated table elements. More...
 
gpointer g_table_index (GTable *gtable, int row, int col)
 Return the element at the given row and column. More...
 
void g_table_resize (GTable *gtable, int rows, int cols)
 Resize the table, allocating and deallocating extra table members if needed. More...
 
int g_table_rows (GTable *gtable)
 Return the number of table rows. More...
 
int g_table_cols (GTable *gtable)
 Return the number of table columns. More...
 
void gnc_table_set_default_gui_handlers (TableGUIHandlers *gui_handlers)
 Set the default gui handlers used by new tables. More...
 
Table * gnc_table_new (TableLayout *layout, TableModel *model, TableControl *control)
 
void gnc_virtual_location_init (VirtualLocation *vloc)
 
void gnc_table_save_state (Table *table, const gchar *state_section)
 Implementation.
 
void gnc_table_destroy (Table *table)
 
int gnc_table_current_cursor_changed (Table *table, gboolean include_conditional)
 
void gnc_table_clear_current_cursor_changes (Table *table)
 
void gnc_table_save_current_cursor (Table *table, CursorBuffer *buffer)
 
void gnc_table_restore_current_cursor (Table *table, CursorBuffer *buffer)
 
const char * gnc_table_get_current_cell_name (Table *table)
 
gboolean gnc_table_get_current_cell_location (Table *table, const char *cell_name, VirtualLocation *virt_loc)
 
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. More...
 
gboolean gnc_table_virtual_location_in_header (Table *table, VirtualLocation virt_loc)
 
VirtualCellgnc_table_get_virtual_cell (Table *table, VirtualCellLocation vcell_loc)
 returns the virtual cell associated with a particular virtual location. More...
 
const char * gnc_table_get_entry (Table *table, VirtualLocation virt_loc)
 
char * gnc_table_get_tooltip (Table *table, VirtualLocation virt_loc)
 
const char * gnc_table_get_label (Table *table, VirtualLocation virt_loc)
 
CellIOFlags gnc_table_get_io_flags (Table *table, VirtualLocation virt_loc)
 
guint32 gnc_table_get_color (Table *table, VirtualLocation virt_loc, gboolean *hatching)
 
void gnc_table_get_borders (Table *table, VirtualLocation virt_loc, PhysicalCellBorders *borders)
 
CellAlignment gnc_table_get_align (Table *table, VirtualLocation virt_loc)
 
gboolean gnc_table_is_popup (Table *table, VirtualLocation virt_loc)
 
char * gnc_table_get_help (Table *table)
 
BasicCell * gnc_table_get_cell (Table *table, VirtualLocation virt_loc)
 
const char * gnc_table_get_cell_name (Table *table, VirtualLocation virt_loc)
 
const gchar * gnc_table_get_cell_type_name (Table *table, VirtualLocation virt_loc)
 
gboolean gnc_table_get_cell_location (Table *table, const char *cell_name, VirtualCellLocation vcell_loc, VirtualLocation *virt_loc)
 
const char * gnc_table_get_model_entry (Table *table, const char *cell_name)
 
void gnc_table_save_cells (Table *table, gpointer save_data)
 
VirtualCellgnc_table_get_header_cell (Table *table)
 Return the virtual cell of the header.
 
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. More...
 
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.
 
void gnc_table_set_virt_cell_data (Table *table, VirtualCellLocation vcell_loc, gconstpointer vcell_data)
 Set the virtual cell data for a particular location. More...
 
void gnc_table_set_virt_cell_visible (Table *table, VirtualCellLocation vcell_loc, gboolean visible)
 Set the visibility flag for a particular location. More...
 
void gnc_table_set_virt_cell_cursor (Table *table, VirtualCellLocation vcell_loc, CellBlock *cursor)
 Set the cellblock handler for a virtual cell. More...
 
void gnc_table_move_cursor (Table *table, VirtualLocation virt_loc)
 will move the cursor (but not the cursor GUI) to the indicated location. More...
 
void gnc_table_move_cursor_gui (Table *table, VirtualLocation virt_loc)
 will move the cursor and its GUI to the indicated location. More...
 
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 virtual location has changed, repositions the cursor and gui to the new position. More...
 
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, or NULL if the coords are out of bounds. More...
 
gboolean gnc_table_find_close_valid_cell (Table *table, VirtualLocation *virt_loc, gboolean exact_cell)
 Find a close valid cell. More...
 
void gnc_table_init_gui (Table *table)
 UI-specific functions. More...
 
void gnc_table_realize_gui (Table *table)
 
void gnc_table_refresh_current_cursor_gui (Table *table, gboolean do_scroll)
 Refresh the current cursor gui.
 
void gnc_table_refresh_gui (Table *table, gboolean do_scroll)
 Refresh the whole GUI from the table. More...
 
void gnc_table_show_range (Table *table, VirtualCellLocation start_loc, VirtualCellLocation end_loc)
 Try to show the whole range in the register. More...
 
void gnc_table_refresh_cursor_gui (Table *table, VirtualCellLocation vcell_loc, gboolean do_scroll)
 Refresh the cursor in the given location. More...
 
void gnc_table_wrap_verify_cursor_position (Table *table, VirtualLocation virt_loc)
 
gboolean gnc_table_virtual_loc_valid (Table *table, VirtualLocation virt_loc, gboolean exact_pointer)
 
gboolean gnc_table_move_tab (Table *table, VirtualLocation *virt_loc, gboolean move_right)
 
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. More...
 
gboolean gnc_table_enter_update (Table *table, VirtualLocation virt_loc, int *cursor_position, int *start_selection, int *end_selection)
 
void gnc_table_leave_update (Table *table, VirtualLocation virt_loc)
 
gboolean gnc_table_confirm_change (Table *table, VirtualLocation virt_loc)
 
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 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 gnc_table_traverse_update (Table *table, VirtualLocation virt_loc, gncTableTraversalDir dir, VirtualLocation *dest_loc)
 
TableControlgnc_table_control_new (void)
 
void gnc_table_control_destroy (TableControl *control)
 
void gnc_table_control_allow_move (TableControl *control, gboolean allow_move)
 
TableLayout * gnc_table_layout_new (void)
 API Declarations.
 
void gnc_table_layout_destroy (TableLayout *layout)
 
void gnc_table_layout_add_cell (TableLayout *layout, BasicCell *cell)
 
BasicCell * gnc_table_layout_get_cell (TableLayout *layout, const char *cell_name)
 
const char * gnc_table_layout_get_cell_value (TableLayout *layout, const char *cell_name)
 
gboolean gnc_table_layout_get_cell_changed (TableLayout *layout, const char *cell_name, gboolean include_conditional)
 
GList * gnc_table_layout_get_cells (TableLayout *layout)
 
void gnc_table_layout_add_cursor (TableLayout *layout, CellBlock *cursor)
 
CellBlockgnc_table_layout_get_cursor (TableLayout *layout, const char *cursor_name)
 
GList * gnc_table_layout_get_cursors (TableLayout *layout)
 
void gnc_table_layout_set_primary_cursor (TableLayout *layout, CellBlock *cursor)
 
void gnc_table_layout_set_cell (TableLayout *layout, CellBlock *cursor, const char *cell_name, int row, int col)
 
CursorBuffer * gnc_cursor_buffer_new (void)
 
void gnc_cursor_buffer_destroy (CursorBuffer *buffer)
 
void gnc_table_layout_save_cursor (TableLayout *layout, CellBlock *cursor, CursorBuffer *buffer)
 
void gnc_table_layout_restore_cursor (TableLayout *layout, CellBlock *cursor, CursorBuffer *buffer)
 
TableModelgnc_table_model_new (void)
 
void gnc_table_model_destroy (TableModel *model)
 
void gnc_table_model_set_read_only (TableModel *model, gboolean read_only)
 
gboolean gnc_table_model_read_only (TableModel *model)
 
void gnc_table_model_set_reverse_sort (TableModel *model, gboolean read_only)
 
void gnc_table_model_set_entry_handler (TableModel *model, TableGetEntryHandler entry_handler, const char *cell_name)
 
void gnc_table_model_set_default_entry_handler (TableModel *model, TableGetEntryHandler entry_handler)
 
TableGetEntryHandler gnc_table_model_get_entry_handler (TableModel *model, const char *cell_name)
 
void gnc_table_model_set_label_handler (TableModel *model, TableGetLabelHandler label_handler, const char *cell_name)
 
void gnc_table_model_set_default_label_handler (TableModel *model, TableGetLabelHandler label_handler)
 
TableGetLabelHandler gnc_table_model_get_label_handler (TableModel *model, const char *cell_name)
 
void gnc_table_model_set_help_handler (TableModel *model, TableGetHelpHandler help_handler, const char *cell_name)
 
void gnc_table_model_set_default_help_handler (TableModel *model, TableGetHelpHandler help_handler)
 
TableGetHelpHandler gnc_table_model_get_help_handler (TableModel *model, const char *cell_name)
 
void gnc_table_model_set_tooltip_handler (TableModel *model, TableGetTooltipHandler tooltip_handler, const char *cell_name)
 
void gnc_table_model_set_default_tooltip_handler (TableModel *model, TableGetTooltipHandler tooltip_handler)
 
TableGetTooltipHandler gnc_table_model_get_tooltip_handler (TableModel *model, const char *cell_name)
 
void gnc_table_model_set_io_flags_handler (TableModel *model, TableGetCellIOFlagsHandler io_flags_handler, const char *cell_name)
 
void gnc_table_model_set_default_io_flags_handler (TableModel *model, TableGetCellIOFlagsHandler io_flags_handler)
 
TableGetCellIOFlagsHandler gnc_table_model_get_io_flags_handler (TableModel *model, const char *cell_name)
 
void gnc_table_model_set_cell_color_handler (TableModel *model, TableGetCellColorHandler io_flags_handler, const char *cell_name)
 
void gnc_table_model_set_default_cell_color_handler (TableModel *model, TableGetCellColorHandler io_flags_handler)
 
TableGetCellColorHandler gnc_table_model_get_cell_color_handler (TableModel *model, const char *cell_name)
 
void gnc_table_model_set_cell_border_handler (TableModel *model, TableGetCellBorderHandler io_flags_handler, const char *cell_name)
 
void gnc_table_model_set_default_cell_border_handler (TableModel *model, TableGetCellBorderHandler io_flags_handler)
 
TableGetCellBorderHandler gnc_table_model_get_cell_border_handler (TableModel *model, const char *cell_name)
 
void gnc_table_model_set_confirm_handler (TableModel *model, TableConfirmHandler io_flags_handler, const char *cell_name)
 
void gnc_table_model_set_default_confirm_handler (TableModel *model, TableConfirmHandler io_flags_handler)
 
TableConfirmHandler gnc_table_model_get_confirm_handler (TableModel *model, const char *cell_name)
 
void gnc_table_model_set_save_handler (TableModel *model, TableSaveCellHandler save_handler, const char *cell_name)
 
void gnc_table_model_set_pre_save_handler (TableModel *model, TableSaveHandler save_handler)
 
void gnc_table_model_set_post_save_handler (TableModel *model, TableSaveHandler save_handler)
 
TableSaveCellHandler gnc_table_model_get_save_handler (TableModel *model, const char *cell_name)
 
TableSaveHandler gnc_table_model_get_pre_save_handler (TableModel *model)
 
TableSaveHandler gnc_table_model_get_post_save_handler (TableModel *model)
 

Detailed Description

The "Table" is a displayed matrix.

The table is a complex object; it is not merely a Cellblock. The table provides all of the GUI infrastructure for displaying a row-column matrix of strings.

The table provides one very important function for minimizing memory usage for large matrixes - the notion of a "Cursor". The cursor is a Cellblock (an array of active cells) that is moved to the location that the user is currently editing. The cursor "virtualizes" Cell functions; that is, it makes it seem to the user as if all cells in the table are active, when in fact the only cell that actually needs to be active is the one that the user is currently editing.

The table design allows multiple cursors to be defined. When a user enters a cell, the appropriate cursor is positioned within the table. Cursors cannot overlap: any given cell can be mapped to at most one cursor. Multiple-cursor support allows tables to be designed that have a non-uniform layout. For example, the multiple-cursor support can be used to define a tree structure of headings and sub-headings, where the layout/format of the heading is different from the sub-headings. A financial example is a table which lists splits underneath their parent transaction. This is very different from a checkbook register, where all entries are uniform, and can be handled with a single repeated cursor.

Users of the table must provide a TableView object which provides an API the table uses to obtain information about the data it is displaying such as strings, colors, etc. Thus, the table represents the non-GUI portion of the View object in the Model-View-Controller paradigm.

Function Documentation

◆ g_table_cols()

int g_table_cols ( GTable gtable)

Return the number of table columns.

Definition at line 165 of file gtable.c.

166 {
167  if (gtable == NULL)
168  return 0;
169 
170  return gtable->cols;
171 }

◆ g_table_destroy()

void g_table_destroy ( GTable gtable)

Free the table and all associated table elements.

Definition at line 69 of file gtable.c.

70 {
71  if (gtable == NULL)
72  return;
73 
74  g_table_resize (gtable, 0, 0);
75 
76  g_array_free (gtable->array, TRUE);
77 
78  gtable->array = NULL;
79 
80  g_free(gtable);
81 }
void g_table_resize(GTable *gtable, int rows, int cols)
Resize the table, allocating and deallocating extra table members if needed.
Definition: gtable.c:104

◆ g_table_index()

gpointer g_table_index ( GTable gtable,
int  row,
int  col 
)

Return the element at the given row and column.

If the coordinates are out-of-bounds, return NULL

Definition at line 84 of file gtable.c.

85 {
86  guint index = row * gtable->cols + col;
87  guint offset = index * gtable->entry_size;
88 
89  if (gtable == NULL)
90  return NULL;
91  if ((row < 0) || (col < 0))
92  return NULL;
93  if (row >= gtable->rows)
94  return NULL;
95  if (col >= gtable->cols)
96  return NULL;
97 
98  g_return_val_if_fail (gtable->array != NULL, NULL);
99  g_return_val_if_fail (gtable->array->len > index, NULL);
100  return &gtable->array->data[offset];
101 }

◆ g_table_new()

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.

Both functions must be given. They are used to initialize the table entries and free unneeded memory when resizing and destroying.

Definition at line 44 of file gtable.c.

48 {
49  GTable *gtable;
50 
51  gtable = g_new(GTable, 1);
52 
53  gtable->array = g_array_new(FALSE, FALSE, entry_size);
54 
55  gtable->entry_size = entry_size;
56 
57  gtable->rows = 0;
58  gtable->cols = 0;
59 
60  gtable->constructor = constructor;
61  gtable->destroyer = destroyer;
62 
63  gtable->user_data = user_data;
64 
65  return gtable;
66 }
Definition: gtable.c:28

◆ g_table_resize()

void g_table_resize ( GTable gtable,
int  rows,
int  cols 
)

Resize the table, allocating and deallocating extra table members if needed.

The relationship between table members before and after resizing is undefined, except in the case where the number of rows changes, but not the number of columns. In that case, higher-numbered rows are discarded first.

Definition at line 104 of file gtable.c.

105 {
106  guint old_len;
107  guint new_len;
108 
109  if (gtable == NULL)
110  return;
111  if ((rows < 0) || (cols < 0))
112  return;
113 
114  old_len = gtable->array->len;
115  new_len = rows * cols;
116 
117  if (new_len == old_len)
118  return;
119 
120  /* If shrinking, destroy extra cells */
121  if ((new_len < old_len) && gtable->destroyer)
122  {
123  gchar *entry;
124  guint i;
125 
126  entry = &gtable->array->data[new_len * gtable->entry_size];
127  for (i = new_len; i < old_len; i++)
128  {
129  gtable->destroyer(entry, gtable->user_data);
130  entry += gtable->entry_size;
131  }
132  }
133 
134  /* Change the size */
135  g_array_set_size(gtable->array, new_len);
136 
137  /* If expanding, construct the new cells */
138  if ((new_len > old_len) && gtable->constructor)
139  {
140  gchar *entry;
141  guint i;
142 
143  entry = &gtable->array->data[old_len * gtable->entry_size];
144  for (i = old_len; i < new_len; i++)
145  {
146  gtable->constructor(entry, gtable->user_data);
147  entry += gtable->entry_size;
148  }
149  }
150 
151  gtable->rows = rows;
152  gtable->cols = cols;
153 }

◆ g_table_rows()

int g_table_rows ( GTable gtable)

Return the number of table rows.

Definition at line 156 of file gtable.c.

157 {
158  if (gtable == NULL)
159  return 0;
160 
161  return gtable->rows;
162 }

◆ gnc_table_find_close_valid_cell()

gboolean gnc_table_find_close_valid_cell ( Table *  table,
VirtualLocation *  virt_loc,
gboolean  exact_cell 
)

Find a close valid cell.

If exact_cell is true, cells that must be explicitly selected by the user (as opposed to just tabbing into), are considered valid cells.

Definition at line 1509 of file table-allgui.c.

1511 {
1512  if (!gnc_table_find_valid_row_vert (table, virt_loc))
1513  return FALSE;
1514 
1515  return gnc_table_find_valid_cell_horiz (table, virt_loc, exact_pointer);
1516 }

◆ gnc_table_get_vcell_data()

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, or NULL if the coords are out of bounds.

Definition at line 931 of file table-allgui.c.

932 {
933  VirtualCell *vcell;
934 
935  if (!table) return NULL;
936 
937  vcell = gnc_table_get_virtual_cell (table, vcell_loc);
938  if (vcell == NULL)
939  return NULL;
940 
941  return vcell->vcell_data;
942 }
gpointer vcell_data
Array of physical cells.
Definition: table-allgui.h:135
holds information about each virtual cell.
Definition: table-allgui.h:132
VirtualCell * gnc_table_get_virtual_cell(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell associated with a particular virtual location.
Definition: table-allgui.c:227

◆ gnc_table_get_virtual_cell()

VirtualCell* gnc_table_get_virtual_cell ( Table *  table,
VirtualCellLocation  vcell_loc 
)

returns the virtual cell associated with a particular virtual location.

If the location is out of bounds, NULL is * returned.

Definition at line 227 of file table-allgui.c.

228 {
229  if (table == NULL)
230  return NULL;
231 
232  return g_table_index (table->virt_cells,
233  vcell_loc.virt_row, vcell_loc.virt_col);
234 }
gpointer g_table_index(GTable *gtable, int row, int col)
Return the element at the given row and column.
Definition: gtable.c:84

◆ gnc_table_init_gui()

void gnc_table_init_gui ( Table *  table)

UI-specific functions.

Initialize the GUI from a table

Definition at line 173 of file table-gnome.c.

174 {
175  table->gui_handlers.redraw_help = table_ui_redraw_cb;
176  table->gui_handlers.destroy = table_destroy_cb;
177  table->gui_handlers.default_direct_update = table_default_direct_update;
178 }

◆ gnc_table_move_cursor()

void gnc_table_move_cursor ( Table *  table,
VirtualLocation  virt_loc 
)

will move the cursor (but not the cursor GUI) to the indicated location.

This function is useful when loading the table from the cursor: data can be loaded into the cursor, then committed to the table, all without the annoying screen flashing associated with GUI redraw.

Definition at line 877 of file table-allgui.c.

878 {
879  if (!table) return;
880 
881  gnc_table_move_cursor_internal (table, new_virt_loc, FALSE);
882 }

◆ gnc_table_move_cursor_gui()

void gnc_table_move_cursor_gui ( Table *  table,
VirtualLocation  virt_loc 
)

will move the cursor and its GUI to the indicated location.

Through a series of callbacks, all GUI elements get repositioned.

Definition at line 886 of file table-allgui.c.

887 {
888  if (!table) return;
889 
890  gnc_table_move_cursor_internal (table, new_virt_loc, TRUE);
891 }

◆ gnc_table_move_vertical_position()

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.

Virtual cells that are not visible are skipped over.

Parameters
tableThe table
virt_locThe virtual location to start from. If the move succeeds, it is updated with the new location.
phys_row_offsetThe number of physical rows to move. A positive number moves down and a negative number moves up.
Returns
TRUE if the location changed, FALSE otherwise

Definition at line 1607 of file table-allgui.c.

1610 {
1611  VirtualLocation vloc;
1612  VirtualCell *vcell;
1613  gint last_visible_row;
1614 
1615  if ((table == NULL) || (virt_loc == NULL))
1616  return FALSE;
1617 
1618  vloc = *virt_loc;
1619  last_visible_row = vloc.vcell_loc.virt_row;
1620 
1621  vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1622  if ((vcell == NULL) || (vcell->cellblock == NULL))
1623  return FALSE;
1624 
1625  while (phys_row_offset != 0)
1626  {
1627  /* going up */
1628  if (phys_row_offset < 0)
1629  {
1630  phys_row_offset++;
1631 
1632  /* room left in the current cursor */
1633  if (vloc.phys_row_offset > 0)
1634  {
1635  vloc.phys_row_offset--;
1636  continue;
1637  }
1638 
1639  /* end of the line */
1640  if (vloc.vcell_loc.virt_row == 1)
1641  break;
1642 
1643  do
1644  {
1645  vloc.vcell_loc.virt_row--;
1646 
1647  vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1648  }
1649  while (vcell && vcell->cellblock && !vcell->visible);
1650 
1651  if (!vcell || !vcell->cellblock)
1652  break;
1653 
1654  last_visible_row = vloc.vcell_loc.virt_row;
1655  vloc.phys_row_offset = vcell->cellblock->num_rows - 1;
1656  }
1657  /* going down */
1658  else
1659  {
1660  phys_row_offset--;
1661 
1662  /* room left in the current cursor */
1663  if (vloc.phys_row_offset < (vcell->cellblock->num_rows - 1))
1664  {
1665  vloc.phys_row_offset++;
1666  continue;
1667  }
1668 
1669  /* end of the line */
1670  if (vloc.vcell_loc.virt_row == (table->num_virt_rows - 1))
1671  break;
1672 
1673  do
1674  {
1675  vloc.vcell_loc.virt_row++;
1676 
1677  vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1678  }
1679  while (vcell && vcell->cellblock && !vcell->visible);
1680 
1681  if (!vcell || !vcell->cellblock)
1682  break;
1683 
1684  last_visible_row = vloc.vcell_loc.virt_row;
1685  vloc.phys_row_offset = 0;
1686  }
1687  }
1688 
1689  vloc.vcell_loc.virt_row = last_visible_row;
1690 
1691  {
1692  gboolean changed = !virt_loc_equal (vloc, *virt_loc);
1693 
1694  *virt_loc = vloc;
1695 
1696  return changed;
1697  }
1698 }
holds information about each virtual cell.
Definition: table-allgui.h:132
VirtualCell * gnc_table_get_virtual_cell(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell associated with a particular virtual location.
Definition: table-allgui.c:227
unsigned int visible
Used by higher-level code.
Definition: table-allgui.h:138

◆ gnc_table_refresh_cursor_gui()

void gnc_table_refresh_cursor_gui ( Table *  table,
VirtualCellLocation  vcell_loc,
gboolean  do_scroll 
)

Refresh the cursor in the given location.

If do_scroll is TRUE, scroll the register so the location is in view.

Definition at line 1519 of file table-allgui.c.

1522 {
1523  g_return_if_fail (table != NULL);
1524  g_return_if_fail (table->gui_handlers.cursor_refresh != NULL);
1525 
1526  table->gui_handlers.cursor_refresh (table, vcell_loc, do_scroll);
1527 }

◆ gnc_table_refresh_gui()

void gnc_table_refresh_gui ( Table *  table,
gboolean  do_scroll 
)

Refresh the whole GUI from the table.

Definition at line 181 of file table-gnome.c.

182 {
183  GnucashSheet *sheet;
184 
185  if (!table)
186  return;
187  if (!table->ui_data)
188  return;
189 
190  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
191 
192  sheet = GNUCASH_SHEET(table->ui_data);
193 
194  gnucash_sheet_styles_recompile (sheet);
195  gnucash_sheet_table_load (sheet, do_scroll);
196  gnucash_sheet_redraw_all (sheet);
197 }

◆ gnc_table_set_default_gui_handlers()

void gnc_table_set_default_gui_handlers ( TableGUIHandlers gui_handlers)

Set the default gui handlers used by new tables.

Set the default gui handlers used by new tables.

Definition at line 67 of file table-allgui.c.

68 {
69  if (!gui_handlers)
70  memset (&default_gui_handlers, 0, sizeof (default_gui_handlers));
71  else
72  default_gui_handlers = *gui_handlers;
73 }

◆ gnc_table_set_size()

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.

Definition at line 586 of file table-allgui.c.

587 {
588  /* Invalidate the current cursor position, if the array is
589  * shrinking. This must be done since the table is probably
590  * shrinking because some rows were deleted, and the cursor
591  * could be on the deleted rows. */
592  if ((virt_rows < table->num_virt_rows) ||
593  (virt_cols < table->num_virt_cols))
594  {
595  gnc_virtual_location_init (&table->current_cursor_loc);
596  table->current_cursor = NULL;
597  }
598 
599  gnc_table_resize (table, virt_rows, virt_cols);
600 }

◆ gnc_table_set_virt_cell_cursor()

void gnc_table_set_virt_cell_cursor ( Table *  table,
VirtualCellLocation  vcell_loc,
CellBlock cursor 
)

Set the cellblock handler for a virtual cell.

Definition at line 736 of file table-allgui.c.

739 {
740  VirtualCell *vcell;
741 
742  if (table == NULL)
743  return;
744 
745  vcell = gnc_table_get_virtual_cell (table, vcell_loc);
746  if (vcell == NULL)
747  return;
748 
749  vcell->cellblock = cursor;
750 }
holds information about each virtual cell.
Definition: table-allgui.h:132
VirtualCell * gnc_table_get_virtual_cell(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell associated with a particular virtual location.
Definition: table-allgui.c:227

◆ gnc_table_set_virt_cell_data()

void gnc_table_set_virt_cell_data ( Table *  table,
VirtualCellLocation  vcell_loc,
gconstpointer  vcell_data 
)

Set the virtual cell data for a particular location.

Definition at line 699 of file table-allgui.c.

702 {
703  VirtualCell *vcell;
704 
705  if (table == NULL)
706  return;
707 
708  vcell = gnc_table_get_virtual_cell (table, vcell_loc);
709  if (vcell == NULL)
710  return;
711 
712  if (table->model->cell_data_copy)
713  table->model->cell_data_copy (vcell->vcell_data, vcell_data);
714  else
715  vcell->vcell_data = (gpointer) vcell_data;
716 }
gpointer vcell_data
Array of physical cells.
Definition: table-allgui.h:135
holds information about each virtual cell.
Definition: table-allgui.h:132
VirtualCell * gnc_table_get_virtual_cell(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell associated with a particular virtual location.
Definition: table-allgui.c:227

◆ gnc_table_set_virt_cell_visible()

void gnc_table_set_virt_cell_visible ( Table *  table,
VirtualCellLocation  vcell_loc,
gboolean  visible 
)

Set the visibility flag for a particular location.

Definition at line 719 of file table-allgui.c.

722 {
723  VirtualCell *vcell;
724 
725  if (table == NULL)
726  return;
727 
728  vcell = gnc_table_get_virtual_cell (table, vcell_loc);
729  if (vcell == NULL)
730  return;
731 
732  vcell->visible = visible ? 1 : 0;
733 }
holds information about each virtual cell.
Definition: table-allgui.h:132
VirtualCell * gnc_table_get_virtual_cell(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell associated with a particular virtual location.
Definition: table-allgui.c:227
unsigned int visible
Used by higher-level code.
Definition: table-allgui.h:138

◆ gnc_table_show_range()

void gnc_table_show_range ( Table *  table,
VirtualCellLocation  start_loc,
VirtualCellLocation  end_loc 
)

Try to show the whole range in the register.

Definition at line 231 of file table-gnome.c.

234 {
235  GnucashSheet *sheet;
236 
237  if (!table || !table->ui_data)
238  return;
239 
240  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
241 
243  return;
244 
246  return;
247 
248  sheet = GNUCASH_SHEET (table->ui_data);
249 
250  gnucash_sheet_show_range (sheet, start_loc, end_loc);
251 }
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.
Definition: table-allgui.c:207

◆ gnc_table_verify_cursor_position()

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 virtual location has changed, repositions the cursor and gui to the new position.

Returns true if the cell cursor was repositioned.

Definition at line 897 of file table-allgui.c.

898 {
899  gboolean do_move = FALSE;
900  gboolean moved_cursor = FALSE;
901 
902  if (!table) return FALSE;
903 
904  /* Someone may be trying to intentionally invalidate the cursor, in
905  * which case the physical addresses could be out of bounds. For
906  * example, in order to unmap it in preparation for a reconfig.
907  * So, if the specified location is out of bounds, then the cursor
908  * MUST be moved. */
909  if (gnc_table_virtual_cell_out_of_bounds (table, virt_loc.vcell_loc))
910  do_move = TRUE;
911 
912  if (!virt_cell_loc_equal (virt_loc.vcell_loc,
913  table->current_cursor_loc.vcell_loc))
914  do_move = TRUE;
915 
916  if (do_move)
917  {
918  gnc_table_move_cursor_gui (table, virt_loc);
919  moved_cursor = TRUE;
920  }
921  else if (!virt_loc_equal (virt_loc, table->current_cursor_loc))
922  {
923  table->current_cursor_loc = virt_loc;
924  moved_cursor = TRUE;
925  }
926 
927  return moved_cursor;
928 }
void gnc_table_move_cursor_gui(Table *table, VirtualLocation new_virt_loc)
will move the cursor and its GUI to the indicated location.
Definition: table-allgui.c:886
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.
Definition: table-allgui.c:207

◆ gnc_table_virtual_cell_out_of_bounds()

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.

Definition at line 207 of file table-allgui.c.

209 {
210  if (!table)
211  return TRUE;
212 
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));
217 }