GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
table-allgui.h
Go to the documentation of this file.
1 /********************************************************************\
2  * table-allgui.h -- 2D grid table object, embeds cells for i/o *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, contact: *
16  * *
17  * Free Software Foundation Voice: +1-617-542-5942 *
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19  * Boston, MA 02110-1301, USA [email protected] *
20  * *
21 \********************************************************************/
96 #ifndef TABLE_ALLGUI_H
97 #define TABLE_ALLGUI_H
98 
99 #include <glib.h>
100 
101 #include "basiccell.h"
102 #include "cellblock.h"
103 #include "gtable.h"
104 #include "register-common.h"
105 #include "table-control.h"
106 #include "table-layout.h"
107 #include "table-model.h"
108 
109 /* The VirtualCell structure holds information about each virtual cell. */
110 typedef struct
111 {
112  CellBlock *cellblock; /* Array of physical cells */
113  gpointer vcell_data; /* Used by higher-level code */
114 
115  /* flags */
116  unsigned int visible : 1; /* visible in the GUI */
117  unsigned int start_primary_color : 1; /* color usage flag */
118 } VirtualCell;
119 
120 typedef struct table Table;
121 
122 typedef void (*TableCursorRefreshCB) (Table *table,
123  VirtualCellLocation vcell_loc,
124  gboolean do_scroll);
125 
126 typedef void (*TableRedrawHelpCB) (Table *table);
127 typedef void (*TableDestroyCB) (Table *table);
128 
129 typedef struct
130 {
131  TableCursorRefreshCB cursor_refresh;
132 
133  TableRedrawHelpCB redraw_help;
134  TableDestroyCB destroy;
136 
137 struct table
138 {
139  TableLayout *layout;
140  TableModel *model;
141  TableControl *control;
142 
143  int num_virt_rows;
144  int num_virt_cols;
145 
146  CellBlock *current_cursor;
147 
148  VirtualLocation current_cursor_loc;
149 
150  /* private data */
151 
152  /* The virtual cell table */
153  GTable *virt_cells;
154 
155  TableGUIHandlers gui_handlers;
156  gpointer ui_data;
157 };
158 
160 typedef enum
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;
188 
189 
190 
191 
192 /* Alternative color tables to use for the register.
193  * The colors in this array are ordered according to the RegisterColor Enum
194  * Be careful to respect this order !
195  */
196 static const guint32 reg_colors_default [] =
197 {
198  0xFFFFFF, // COLOR_UNKNOWN_BG
199  0x96B183, // COLOR_HEADER_BG
200  0xBFDEB9, // COLOR_PRIMARY_BG
201  0xFFEF98, // COLOR_PRIMARY_BG_ACTIVE
202  0xF6FFDA, // COLOR_SECONDARY_BG
203  0xFFEF98, // COLOR_SECONDARY_BG_ACTIVE
204  0xEDE7D3, // COLOR_SPLIT_BG
205  0xFFEF98, // COLOR_SPLIT_BG_ACTIVE
206 
207  0x000000, // COLOR_UNKNOWN_FG
208  0x000000, // COLOR_HEADER_FG
209  0x000000, // COLOR_PRIMARY_FG
210  0x000000, // COLOR_PRIMARY_FG_ACTIVE
211  0x000000, // COLOR_SECONDARY_FG
212  0x000000, // COLOR_SECONDARY_FG_ACTIVE
213  0x000000, // COLOR_SPLIT_FG
214  0x000000, // COLOR_SPLIT_FG_ACTIVE
215 
216  0xFF0000, // COLOR_NEGATIVE
217 };
218 
219 /* The colors in this array are ordered according to the RegisterColor Enum
220  * Be careful to respect this order !
221  */
222 static const guint32 reg_colors_gtkrc [] =
223 {
224  COLOR_UNKNOWN_BG, // COLOR_UNKNOWN_BG
225  COLOR_HEADER_BG, // COLOR_HEADER_BG
226  COLOR_PRIMARY_BG, // COLOR_PRIMARY_BG
227  COLOR_PRIMARY_BG_ACTIVE, // COLOR_PRIMARY_BG_ACTIVE
228  COLOR_SECONDARY_BG, // COLOR_SECONDARY_BG
229  COLOR_SECONDARY_BG_ACTIVE, // COLOR_SECONDARY_BG_ACTIVE
230  COLOR_SPLIT_BG, // COLOR_SPLIT_BG
231  COLOR_SPLIT_BG_ACTIVE, // COLOR_SPLIT_BG_ACTIVE
232 
233  COLOR_UNKNOWN_FG, // COLOR_UNKNOWN_FG
234  COLOR_HEADER_FG, // COLOR_HEADER_FG
235  COLOR_PRIMARY_FG, // COLOR_PRIMARY_FG
236  COLOR_PRIMARY_FG_ACTIVE, // COLOR_PRIMARY_FG_ACTIVE
237  COLOR_SECONDARY_FG, // COLOR_SECONDARY_FG
238  COLOR_SECONDARY_FG_ACTIVE, // COLOR_SECONDARY_FG_ACTIVE
239  COLOR_SPLIT_FG, // COLOR_SPLIT_FG
240  COLOR_SPLIT_FG_ACTIVE, // COLOR_SPLIT_FG_ACTIVE
241 
242  COLOR_NEGATIVE, // COLOR_NEGATIVE
243 };
244 
245 
246 /* Set the default gui handlers used by new tables. */
248 
249 /* Functions to create and destroy Tables. */
250 Table * gnc_table_new (TableLayout *layout,
251  TableModel *model,
252  TableControl *control);
253 void gnc_virtual_location_init (VirtualLocation *vloc);
254 
255 void gnc_table_save_state (Table *table, gchar *state_section);
256 void gnc_table_destroy (Table *table);
257 
258 
259 /* Functions to work with current cursor */
260 int gnc_table_current_cursor_changed (Table *table,
261  gboolean include_conditional);
262 
263 void gnc_table_clear_current_cursor_changes (Table *table);
264 
265 void gnc_table_save_current_cursor (Table *table, CursorBuffer *buffer);
266 void gnc_table_restore_current_cursor (Table *table,
267  CursorBuffer *buffer);
268 
269 const char * gnc_table_get_current_cell_name (Table *table);
270 
271 gboolean gnc_table_get_current_cell_location (Table *table,
272  const char *cell_name,
273  VirtualLocation *virt_loc);
274 
275 
276 /* This function checks the given location and returns true
277  * if it is out of bounds of the table. */
278 gboolean gnc_table_virtual_cell_out_of_bounds (Table *table,
279  VirtualCellLocation vcell_loc);
280 
281 gboolean gnc_table_virtual_location_in_header (Table *table,
282  VirtualLocation virt_loc);
283 
284 
285 /* This function returns the virtual cell associated with a particular
286  * virtual location. If the location is out of bounds, NULL is *
287  * returned. */
288 VirtualCell * gnc_table_get_virtual_cell (Table *table,
289  VirtualCellLocation vcell_loc);
290 
291 const char * gnc_table_get_entry (Table *table, VirtualLocation virt_loc);
292 
293 const char * gnc_table_get_label (Table *table, VirtualLocation virt_loc);
294 
295 CellIOFlags gnc_table_get_io_flags (Table *table, VirtualLocation virt_loc);
296 
297 guint32 gnc_table_get_fg_color (Table *table, VirtualLocation virt_loc);
298 
299 guint32 gnc_table_get_gtkrc_fg_color (Table *table, VirtualLocation virt_loc);
300 
301 guint32 gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc,
302  gboolean *hatching);
303 guint32 gnc_table_get_gtkrc_bg_color (Table *table, VirtualLocation virt_loc,
304  gboolean *hatching);
305 
306 void gnc_table_get_borders (Table *table, VirtualLocation virt_loc,
307  PhysicalCellBorders *borders);
308 
309 CellAlignment gnc_table_get_align (Table *table, VirtualLocation virt_loc);
310 
311 gboolean gnc_table_is_popup (Table *table, VirtualLocation virt_loc);
312 
313 char * gnc_table_get_help (Table *table);
314 
315 BasicCell * gnc_table_get_cell (Table *table, VirtualLocation virt_loc);
316 
317 const char * gnc_table_get_cell_name (Table *table,
318  VirtualLocation virt_loc);
319 const gchar * gnc_table_get_cell_type_name (Table *table,
320  VirtualLocation virt_loc);
321 gboolean gnc_table_get_cell_location (Table *table,
322  const char * cell_name,
323  VirtualCellLocation vcell_loc,
324  VirtualLocation *virt_loc);
325 
326 void gnc_table_save_cells (Table *table, gpointer save_data);
327 
328 
329 /* Return the virtual cell of the header */
330 VirtualCell * gnc_table_get_header_cell (Table *table);
331 
332 /* The gnc_table_set_size() method will resize the table to the
333  * indicated dimensions. */
334 void gnc_table_set_size (Table * table, int virt_rows, int virt_cols);
335 
336 /* Indicate what handler should be used for a given virtual block */
337 void gnc_table_set_vcell (Table *table, CellBlock *cursor,
338  gconstpointer vcell_data,
339  gboolean visible,
340  gboolean start_primary_color,
341  VirtualCellLocation vcell_loc);
342 
343 /* Set the virtual cell data for a particular location. */
344 void gnc_table_set_virt_cell_data (Table *table,
345  VirtualCellLocation vcell_loc,
346  gconstpointer vcell_data);
347 
348 /* Set the visibility flag for a particular location. */
349 void gnc_table_set_virt_cell_visible (Table *table,
350  VirtualCellLocation vcell_loc,
351  gboolean visible);
352 
353 /* Set the cellblock handler for a virtual cell. */
354 void gnc_table_set_virt_cell_cursor (Table *table,
355  VirtualCellLocation vcell_loc,
356  CellBlock *cursor);
357 
358 /* The gnc_table_move_cursor() method will move the cursor (but not
359  * the cursor GUI) to the indicated location. This function is
360  * useful when loading the table from the cursor: data can be loaded
361  * into the cursor, then committed to the table, all without the
362  * annoying screen flashing associated with GUI redraw. */
363 void gnc_table_move_cursor (Table *table, VirtualLocation virt_loc);
364 
365 /* The gnc_table_move_cursor_gui() method will move the cursor and its
366  * GUI to the indicated location. Through a series of callbacks, all
367  * GUI elements get repositioned. */
368 void gnc_table_move_cursor_gui (Table *table, VirtualLocation virt_loc);
369 
370 /* The gnc_table_verify_cursor_position() method checks the location
371  * of the cursor with respect to a virtual location position, and if
372  * the resulting virtual location has changed, repositions the
373  * cursor and gui to the new position. Returns true if the cell
374  * cursor was repositioned. */
375 gboolean gnc_table_verify_cursor_position (Table *table,
376  VirtualLocation virt_loc);
377 
378 /* The gnc_table_get_vcell_data() method returns the virtual cell data
379  * associated with a cursor located at the given virtual coords, or
380  * NULL if the coords are out of bounds. */
381 gpointer gnc_table_get_vcell_data (Table *table,
382  VirtualCellLocation vcell_loc);
383 
384 /* Find a close valid cell. If exact_cell is true, cells that must
385  * be explicitly selected by the user (as opposed to just tabbing
386  * into), are considered valid cells. */
387 gboolean gnc_table_find_close_valid_cell (Table *table,
388  VirtualLocation *virt_loc,
389  gboolean exact_cell);
390 
393 /* Initialize the GUI from a table */
394 void gnc_table_init_gui (GtkWidget *widget, gchar * state_section);
395 
396 void gnc_table_realize_gui (Table *table);
397 
398 /* Refresh the current cursor gui */
399 void gnc_table_refresh_current_cursor_gui (Table * table,
400  gboolean do_scroll);
401 
402 /* Refresh the whole GUI from the table. */
403 void gnc_table_refresh_gui (Table *table, gboolean do_scroll);
404 
405 /* Try to show the whole range in the register. */
406 void gnc_table_show_range (Table *table,
407  VirtualCellLocation start_loc,
408  VirtualCellLocation end_loc);
409 
410 /* Refresh the cursor in the given location. If do_scroll is TRUE,
411  * scroll the register so the location is in view. */
412 void gnc_table_refresh_cursor_gui (Table * table,
413  VirtualCellLocation vcell_loc,
414  gboolean do_scroll);
415 
416 /* ==================================================== */
417 
418 void gnc_table_wrap_verify_cursor_position (Table *table,
419  VirtualLocation virt_loc);
420 
421 gboolean gnc_table_virtual_loc_valid(Table *table,
422  VirtualLocation virt_loc,
423  gboolean exact_pointer);
424 
425 gboolean gnc_table_move_tab (Table *table,
426  VirtualLocation *virt_loc,
427  gboolean move_right);
428 
443  VirtualLocation *virt_loc,
444  int phys_row_offset);
445 
446 gboolean gnc_table_enter_update(Table *table,
447  VirtualLocation virt_loc,
448  int *cursor_position,
449  int *start_selection,
450  int *end_selection);
451 
452 void gnc_table_leave_update(Table *table, VirtualLocation virt_loc);
453 
454 gboolean gnc_table_confirm_change(Table *table, VirtualLocation virt_loc);
455 
456 const char * gnc_table_modify_update(Table *table,
457  VirtualLocation virt_loc,
458  const char *change,
459  int change_len,
460  const char *newval,
461  int newval_len,
462  int *cursor_position,
463  int *start_selection,
464  int *end_selection,
465  gboolean *cancelled);
466 
467 gboolean gnc_table_direct_update(Table *table,
468  VirtualLocation virt_loc,
469  char **newval_ptr,
470  int *cursor_position,
471  int *start_selection,
472  int *end_selection,
473  gpointer gui_data);
474 
475 gboolean gnc_table_traverse_update(Table *table,
476  VirtualLocation virt_loc,
477  gncTableTraversalDir dir,
478  VirtualLocation *dest_loc);
479 
480 #endif /* TABLE_ALLGUI_H */
481 
RegisterColor
Definition: table-allgui.h:160
gboolean gnc_table_move_vertical_position(Table *table, VirtualLocation *virt_loc, int phys_row_offset)
void gnc_table_set_default_gui_handlers(TableGUIHandlers *gui_handlers)
Definition: table-allgui.c:67
void gnc_table_save_state(Table *table, gchar *state_section)
Definition: table-gnome.c:68
Definition: gtable.c:28
void gnc_table_init_gui(GtkWidget *widget, gchar *state_section)
Definition: table-gnome.c:157
Declarations for the CellBlock object.
Common declarations for the register core.