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)
 
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 1504 of file table-allgui.c.

1506 {
1507  if (!gnc_table_find_valid_row_vert (table, virt_loc))
1508  return FALSE;
1509 
1510  return gnc_table_find_valid_cell_horiz (table, virt_loc, exact_pointer);
1511 }

◆ 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 932 of file table-allgui.c.

933 {
934  VirtualCell *vcell;
935 
936  if (!table) return NULL;
937 
938  vcell = gnc_table_get_virtual_cell (table, vcell_loc);
939  if (vcell == NULL)
940  return NULL;
941 
942  return vcell->vcell_data;
943 }
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 158 of file table-gnome.c.

159 {
160  table->gui_handlers.redraw_help = table_ui_redraw_cb;
161  table->gui_handlers.destroy = table_destroy_cb;
162 }

◆ 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 878 of file table-allgui.c.

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

◆ 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 887 of file table-allgui.c.

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

◆ 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 1602 of file table-allgui.c.

1605 {
1606  VirtualLocation vloc;
1607  VirtualCell *vcell;
1608  gint last_visible_row;
1609 
1610  if ((table == NULL) || (virt_loc == NULL))
1611  return FALSE;
1612 
1613  vloc = *virt_loc;
1614  last_visible_row = vloc.vcell_loc.virt_row;
1615 
1616  vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1617  if ((vcell == NULL) || (vcell->cellblock == NULL))
1618  return FALSE;
1619 
1620  while (phys_row_offset != 0)
1621  {
1622  /* going up */
1623  if (phys_row_offset < 0)
1624  {
1625  phys_row_offset++;
1626 
1627  /* room left in the current cursor */
1628  if (vloc.phys_row_offset > 0)
1629  {
1630  vloc.phys_row_offset--;
1631  continue;
1632  }
1633 
1634  /* end of the line */
1635  if (vloc.vcell_loc.virt_row == 1)
1636  break;
1637 
1638  do
1639  {
1640  vloc.vcell_loc.virt_row--;
1641 
1642  vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1643  }
1644  while (vcell && vcell->cellblock && !vcell->visible);
1645 
1646  if (!vcell || !vcell->cellblock)
1647  break;
1648 
1649  last_visible_row = vloc.vcell_loc.virt_row;
1650  vloc.phys_row_offset = vcell->cellblock->num_rows - 1;
1651  }
1652  /* going down */
1653  else
1654  {
1655  phys_row_offset--;
1656 
1657  /* room left in the current cursor */
1658  if (vloc.phys_row_offset < (vcell->cellblock->num_rows - 1))
1659  {
1660  vloc.phys_row_offset++;
1661  continue;
1662  }
1663 
1664  /* end of the line */
1665  if (vloc.vcell_loc.virt_row == (table->num_virt_rows - 1))
1666  break;
1667 
1668  do
1669  {
1670  vloc.vcell_loc.virt_row++;
1671 
1672  vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1673  }
1674  while (vcell && vcell->cellblock && !vcell->visible);
1675 
1676  if (!vcell || !vcell->cellblock)
1677  break;
1678 
1679  last_visible_row = vloc.vcell_loc.virt_row;
1680  vloc.phys_row_offset = 0;
1681  }
1682  }
1683 
1684  vloc.vcell_loc.virt_row = last_visible_row;
1685 
1686  {
1687  gboolean changed = !virt_loc_equal (vloc, *virt_loc);
1688 
1689  *virt_loc = vloc;
1690 
1691  return changed;
1692  }
1693 }
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 1514 of file table-allgui.c.

1517 {
1518  g_return_if_fail (table != NULL);
1519  g_return_if_fail (table->gui_handlers.cursor_refresh != NULL);
1520 
1521  table->gui_handlers.cursor_refresh (table, vcell_loc, do_scroll);
1522 }

◆ gnc_table_refresh_gui()

void gnc_table_refresh_gui ( Table *  table,
gboolean  do_scroll 
)

Refresh the whole GUI from the table.

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

166 {
167  GnucashSheet *sheet;
168 
169  if (!table)
170  return;
171  if (!table->ui_data)
172  return;
173 
174  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
175 
176  sheet = GNUCASH_SHEET(table->ui_data);
177 
178  gnucash_sheet_styles_recompile (sheet);
179  gnucash_sheet_table_load (sheet, do_scroll);
180  gnucash_sheet_redraw_all (sheet);
181 }

◆ 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 587 of file table-allgui.c.

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

◆ 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 737 of file table-allgui.c.

740 {
741  VirtualCell *vcell;
742 
743  if (table == NULL)
744  return;
745 
746  vcell = gnc_table_get_virtual_cell (table, vcell_loc);
747  if (vcell == NULL)
748  return;
749 
750  vcell->cellblock = cursor;
751 }
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 700 of file table-allgui.c.

703 {
704  VirtualCell *vcell;
705 
706  if (table == NULL)
707  return;
708 
709  vcell = gnc_table_get_virtual_cell (table, vcell_loc);
710  if (vcell == NULL)
711  return;
712 
713  if (table->model->cell_data_copy)
714  table->model->cell_data_copy (vcell->vcell_data, vcell_data);
715  else
716  vcell->vcell_data = (gpointer) vcell_data;
717 }
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 720 of file table-allgui.c.

723 {
724  VirtualCell *vcell;
725 
726  if (table == NULL)
727  return;
728 
729  vcell = gnc_table_get_virtual_cell (table, vcell_loc);
730  if (vcell == NULL)
731  return;
732 
733  vcell->visible = visible ? 1 : 0;
734 }
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 215 of file table-gnome.c.

218 {
219  GnucashSheet *sheet;
220 
221  if (!table || !table->ui_data)
222  return;
223 
224  g_return_if_fail (GNUCASH_IS_SHEET (table->ui_data));
225 
227  return;
228 
230  return;
231 
232  sheet = GNUCASH_SHEET (table->ui_data);
233 
234  gnucash_sheet_show_range (sheet, start_loc, end_loc);
235 }
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 898 of file table-allgui.c.

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