GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Data Structures | Macros | Typedefs | Enumerations | Functions

An infrastructure for building a modular matrix of cells like a spreadsheet or checkbook register. More...

Files

file  cellblock.h
 Declarations for the CellBlock object.
 
file  register-common.h
 Common declarations for the register core.
 
file  table-allgui.h
 Declarations for the Table object.
 

Data Structures

struct  CellBlock
 
struct  _VirtualCellLocation
 
struct  _VirtualLocation
 
struct  VirtualCell
 
struct  TableGUIHandlers
 
struct  table
 

Macros

#define BASIC_CELL_TYPE_NAME   "basic-cell"
 
#define COMBO_CELL_TYPE_NAME   "combo-cell"
 
#define DATE_CELL_TYPE_NAME   "date-cell"
 
#define NUM_CELL_TYPE_NAME   "num-cell"
 
#define PRICE_CELL_TYPE_NAME   "price-cell"
 
#define RECN_CELL_TYPE_NAME   "recn-cell"
 
#define QUICKFILL_CELL_TYPE_NAME   "quickfill-cell"
 
#define FORMULA_CELL_TYPE_NAME   "formula-cell"
 
#define CHECKBOX_CELL_TYPE_NAME   "checkbox-cell"
 

Typedefs

typedef struct _VirtualCellLocation VirtualCellLocation
 
typedef struct _VirtualLocation VirtualLocation
 
typedef struct table Table
 
typedef void(* TableCursorRefreshCB )(Table *table, VirtualCellLocation vcell_loc, gboolean do_scroll)
 
typedef void(* TableRedrawHelpCB )(Table *table)
 
typedef void(* TableDestroyCB )(Table *table)
 

Enumerations

enum  RegisterColor {
  COLOR_UNKNOWN_BG, COLOR_HEADER_BG, COLOR_PRIMARY_BG, COLOR_PRIMARY_BG_ACTIVE,
  COLOR_SECONDARY_BG, COLOR_SECONDARY_BG_ACTIVE, COLOR_SPLIT_BG, COLOR_SPLIT_BG_ACTIVE,
  COLOR_UNKNOWN_FG, COLOR_HEADER_FG, COLOR_PRIMARY_FG, COLOR_PRIMARY_FG_ACTIVE,
  COLOR_SECONDARY_FG, COLOR_SECONDARY_FG_ACTIVE, COLOR_SPLIT_FG, COLOR_SPLIT_FG_ACTIVE,
  COLOR_NEGATIVE
}
 

Functions

CellBlockgnc_cellblock_new (int rows, int cols, const char *cursor_name)
 
void gnc_cellblock_destroy (CellBlock *cellblock)
 
void gnc_cellblock_set_cell (CellBlock *cellblock, int row, int col, BasicCell *cell)
 
BasicCellgnc_cellblock_get_cell (CellBlock *cellblock, int row, int col)
 
BasicCellgnc_cellblock_get_cell_by_name (CellBlock *cellblock, const char *cell_name, int *row, int *col)
 
int gnc_cellblock_changed (CellBlock *cursor, gboolean include_conditional)
 
void gnc_cellblock_clear_changes (CellBlock *cursor)
 
void gnc_register_init (void)
 
void gnc_register_shutdown (void)
 
void gnc_register_add_cell_type (const char *cell_type_name, CellCreateFunc cell_creator)
 
BasicCellgnc_register_make_cell (const char *cell_type_name)
 
gboolean virt_cell_loc_equal (VirtualCellLocation vcl1, VirtualCellLocation vcl2)
 
gboolean virt_loc_equal (VirtualLocation vl1, VirtualLocation vl2)
 
void gnc_table_set_default_gui_handlers (TableGUIHandlers *gui_handlers)
 
Tablegnc_table_new (TableLayout *layout, TableModel *model, TableControl *control)
 
void gnc_virtual_location_init (VirtualLocation *vloc)
 
void gnc_table_save_state (Table *table, gchar *state_section)
 
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)
 
gboolean gnc_table_virtual_location_in_header (Table *table, VirtualLocation virt_loc)
 
VirtualCellgnc_table_get_virtual_cell (Table *table, VirtualCellLocation vcell_loc)
 
const char * gnc_table_get_entry (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_fg_color (Table *table, VirtualLocation virt_loc)
 
guint32 gnc_table_get_gtkrc_fg_color (Table *table, VirtualLocation virt_loc)
 
guint32 gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc, gboolean *hatching)
 
guint32 gnc_table_get_gtkrc_bg_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)
 
BasicCellgnc_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)
 
void gnc_table_set_size (Table *table, int virt_rows, int virt_cols)
 
void gnc_table_set_vcell (Table *table, CellBlock *cursor, gconstpointer vcell_data, gboolean visible, gboolean start_primary_color, VirtualCellLocation vcell_loc)
 
void gnc_table_set_virt_cell_data (Table *table, VirtualCellLocation vcell_loc, gconstpointer vcell_data)
 
void gnc_table_set_virt_cell_visible (Table *table, VirtualCellLocation vcell_loc, gboolean visible)
 
void gnc_table_set_virt_cell_cursor (Table *table, VirtualCellLocation vcell_loc, CellBlock *cursor)
 
void gnc_table_move_cursor (Table *table, VirtualLocation virt_loc)
 
void gnc_table_move_cursor_gui (Table *table, VirtualLocation virt_loc)
 
gboolean gnc_table_verify_cursor_position (Table *table, VirtualLocation virt_loc)
 
gpointer gnc_table_get_vcell_data (Table *table, VirtualCellLocation vcell_loc)
 
gboolean gnc_table_find_close_valid_cell (Table *table, VirtualLocation *virt_loc, gboolean exact_cell)
 
void gnc_table_init_gui (GtkWidget *widget, gchar *state_section)
 
void gnc_table_realize_gui (Table *table)
 
void gnc_table_refresh_current_cursor_gui (Table *table, gboolean do_scroll)
 
void gnc_table_refresh_gui (Table *table, gboolean do_scroll)
 
void gnc_table_show_range (Table *table, VirtualCellLocation start_loc, VirtualCellLocation end_loc)
 
void gnc_table_refresh_cursor_gui (Table *table, VirtualCellLocation vcell_loc, gboolean do_scroll)
 
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)
 
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)
 

Detailed Description

An infrastructure for building a modular matrix of cells like a spreadsheet or checkbook register.

Each cell may be specialized to perform a particular function, e.g. to read dates, numerical amounts, or text. The register core has been designed to be easy to extend, modular, easy to maintain, and memory efficient. It is intended to be used for building financial apps and spreadsheets.

The register core is built from several types of components: Cells, Cellblocks, Cursors, and the Table.

The register core should not have any 'knowledge' of the accounting model of GnuCash or of the workings of the main application. It should not be specific to a particular GUI (such as Gnome/GTK). It should be possible to use the register core in a stand-alone fashion.

For information on the GnuCash-specific register implementation that has been built atop this core, see Split Register.

Enumeration Type Documentation

Color definitions used for table elements

Definition at line 160 of file table-allgui.h.

161 {
162  /* Colors used for background drawing */
163  COLOR_UNKNOWN_BG,
164  COLOR_HEADER_BG,
165  COLOR_PRIMARY_BG,
166  COLOR_PRIMARY_BG_ACTIVE,
167  COLOR_SECONDARY_BG,
168  COLOR_SECONDARY_BG_ACTIVE,
169  COLOR_SPLIT_BG,
170  COLOR_SPLIT_BG_ACTIVE,
171 
172  /* Colors used for foreground drawing (text etc)
173  * ATTENTION: the background and foreground lists should have
174  * the same types (the same amount of entries) !
175  * The code relies on this ! */
176  COLOR_UNKNOWN_FG,
177  COLOR_HEADER_FG,
178  COLOR_PRIMARY_FG,
179  COLOR_PRIMARY_FG_ACTIVE,
180  COLOR_SECONDARY_FG,
181  COLOR_SECONDARY_FG_ACTIVE,
182  COLOR_SPLIT_FG,
183  COLOR_SPLIT_FG_ACTIVE,
184 
185  /* Other colors */
186  COLOR_NEGATIVE, /* Color to use for negative numbers */
187 } RegisterColor;
RegisterColor
Definition: table-allgui.h:160

Function Documentation

BasicCell* gnc_cellblock_get_cell_by_name ( CellBlock cellblock,
const char *  cell_name,
int *  row,
int *  col 
)

Searches by name for a particular cell in a CellBlock. Parameters row and/or col may be NULL.

Parameters
cellblocka CellBlock to search
cell_namethe name of the cell to find
rowpointer for returning the row in which the cell was found, or NULL
colpointer for returning the column in which the cell was found, or NULL
Returns
the matching cell, or NULL

Definition at line 124 of file cellblock.c.

127 {
128  int r, c, num_rows, num_cols;
129 
130  if (cellblock == NULL)
131  return NULL;
132 
133  if (cell_name == NULL)
134  return NULL;
135 
136  num_rows = cellblock->num_rows;
137  num_cols = cellblock->num_cols;
138  for (r = 0; r < num_rows; r++)
139  for (c = 0; c < num_cols; c++)
140  {
141  BasicCell *cell = cellblock->cells->pdata[(r * num_cols) + c];
142  if (!cell) continue;
143  if (gnc_cell_name_equal(cell->cell_name, cell_name))
144  {
145  if (row)
146  *row = r;
147  if (col)
148  *col = c;
149  return cell;
150  }
151  }
152 
153  return NULL;
154 }
void gnc_table_init_gui ( GtkWidget *  widget,
gchar *  state_section 
)

UI-specific functions

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

158 {
159  GNCHeaderWidths widths;
160  GnucashSheet *sheet;
161  GnucashRegister *greg;
162  Table *table;
163  GList *node;
164  gchar *key;
165  guint value;
166  GKeyFile *state_file = gnc_state_get_current();
167 
168  // Stuff for per-register settings load.
169  g_return_if_fail (widget != NULL);
170  g_return_if_fail (GNUCASH_IS_REGISTER (widget));
171 
172  PINFO("state_section=%s",state_section);
173 
174  ENTER("widget=%p, data=%p", widget, "");
175 
176 
177  greg = GNUCASH_REGISTER (widget);
178  sheet = GNUCASH_SHEET (greg->sheet);
179  table = sheet->table;
180 
181  table->gui_handlers.redraw_help = table_ui_redraw_cb;
182  table->gui_handlers.destroy = table_destroy_cb;
183  table->ui_data = sheet;
184 
185  g_object_ref (sheet);
186 
187  /* config the cell-block styles */
188 
189  widths = gnc_header_widths_new ();
190 
191  if (state_section && gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
192  {
193  node = gnc_table_layout_get_cells (table->layout);
194  for (; node; node = node->next)
195  {
196  BasicCell *cell = node->data;
197 
198  if (cell->expandable)
199  continue;
200 
201  /* Remember whether the column is visible */
202  key = g_strdup_printf("%s_width", cell->cell_name);
203  value = g_key_file_get_integer (state_file, state_section, key, NULL);
204  if (value != 0)
205  gnc_header_widths_set_width (widths, cell->cell_name, value);
206  g_free(key);
207  }
208  }
209 
210  gnucash_sheet_create_styles (sheet);
211 
212  gnucash_sheet_set_header_widths (sheet, widths);
213 
214  gnucash_sheet_compile_styles (sheet);
215 
216  gnucash_sheet_table_load (sheet, TRUE);
217  gnucash_sheet_cursor_set_from_table (sheet, TRUE);
218  gnucash_sheet_redraw_all (sheet);
219 
220  gnc_header_widths_destroy (widths);
221 
222  LEAVE(" ");
223 }
#define PINFO(format, args...)
Definition: qoflog.h:249
#define ENTER(format, args...)
Definition: qoflog.h:261
GKeyFile * gnc_state_get_current(void)
Definition: gnc-state.c:252
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:196
#define LEAVE(format, args...)
Definition: qoflog.h:271
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 1629 of file table-allgui.c.

1632 {
1633  VirtualLocation vloc;
1634  VirtualCell *vcell;
1635  gint last_visible_row;
1636 
1637  if ((table == NULL) || (virt_loc == NULL))
1638  return FALSE;
1639 
1640  vloc = *virt_loc;
1641  last_visible_row = vloc.vcell_loc.virt_row;
1642 
1643  vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1644  if ((vcell == NULL) || (vcell->cellblock == NULL))
1645  return FALSE;
1646 
1647  while (phys_row_offset != 0)
1648  {
1649  /* going up */
1650  if (phys_row_offset < 0)
1651  {
1652  phys_row_offset++;
1653 
1654  /* room left in the current cursor */
1655  if (vloc.phys_row_offset > 0)
1656  {
1657  vloc.phys_row_offset--;
1658  continue;
1659  }
1660 
1661  /* end of the line */
1662  if (vloc.vcell_loc.virt_row == 1)
1663  break;
1664 
1665  do
1666  {
1667  vloc.vcell_loc.virt_row--;
1668 
1669  vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1670  }
1671  while (vcell && vcell->cellblock && !vcell->visible);
1672 
1673  if (!vcell || !vcell->cellblock)
1674  break;
1675 
1676  last_visible_row = vloc.vcell_loc.virt_row;
1677  vloc.phys_row_offset = vcell->cellblock->num_rows - 1;
1678  }
1679  /* going down */
1680  else
1681  {
1682  phys_row_offset--;
1683 
1684  /* room left in the current cursor */
1685  if (vloc.phys_row_offset < (vcell->cellblock->num_rows - 1))
1686  {
1687  vloc.phys_row_offset++;
1688  continue;
1689  }
1690 
1691  /* end of the line */
1692  if (vloc.vcell_loc.virt_row == (table->num_virt_rows - 1))
1693  break;
1694 
1695  do
1696  {
1697  vloc.vcell_loc.virt_row++;
1698 
1699  vcell = gnc_table_get_virtual_cell (table, vloc.vcell_loc);
1700  }
1701  while (vcell && vcell->cellblock && !vcell->visible);
1702 
1703  if (!vcell || !vcell->cellblock)
1704  break;
1705 
1706  last_visible_row = vloc.vcell_loc.virt_row;
1707  vloc.phys_row_offset = 0;
1708  }
1709  }
1710 
1711  vloc.vcell_loc.virt_row = last_visible_row;
1712 
1713  {
1714  gboolean changed = !virt_loc_equal (vloc, *virt_loc);
1715 
1716  *virt_loc = vloc;
1717 
1718  return changed;
1719  }
1720 }
void gnc_table_save_state ( Table table,
gchar *  state_section 
)

Implementation

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

69 {
70  GnucashSheet *sheet;
71  GNCHeaderWidths widths;
72  GList *node;
73  gchar *key;
74  GKeyFile *state_file = gnc_state_get_current();
75 
76  if (!table)
77  return;
78 
79  if (table->ui_data == NULL)
80  return;
81 
82  if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
83  return;
84 
85  sheet = GNUCASH_SHEET (table->ui_data);
86 
87  widths = gnc_header_widths_new ();
88 
89  gnucash_sheet_get_header_widths (sheet, widths);
90 
91  node = gnc_table_layout_get_cells (table->layout);
92  for (; node; node = node->next)
93  {
94  BasicCell *cell = node->data;
95  int width;
96 
97  width = gnc_header_widths_get_width (widths, cell->cell_name);
98 
99  /* Remember whether the column is visible */
100  key = g_strdup_printf("%s_width", cell->cell_name);
101  if ((width > 0) && (!cell->expandable))
102  {
103  g_key_file_set_integer (state_file, state_section, key, width);
104  }
105  else if (g_key_file_has_key (state_file, state_section, key, NULL))
106  g_key_file_remove_key (state_file, state_section, key, NULL);
107  g_free (key);
108  }
109 
110  gnc_header_widths_destroy (widths);
111 }
GKeyFile * gnc_state_get_current(void)
Definition: gnc-state.c:252
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:196
void gnc_table_set_default_gui_handlers ( TableGUIHandlers gui_handlers)

Implementation

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 }