49 guint32 conditionally_changed;
63 layout = g_new0 (TableLayout, 1);
69 gnc_table_layout_destroy (TableLayout *layout)
76 for (node = layout->cells; node; node = node->next)
78 BasicCell *cell = node->data;
80 gnc_basic_cell_destroy (cell);
82 g_list_free (layout->cells);
85 for (node = layout->cursors; node; node = node->next)
91 g_list_free (layout->cursors);
92 layout->cursors = NULL;
98 gnc_table_layout_add_cell (TableLayout *layout,
103 g_return_if_fail (layout != NULL);
104 g_return_if_fail (cell != NULL);
106 for (node = layout->cells; node; node = node->next)
108 BasicCell *list_cell = node->data;
110 if (gnc_basic_cell_has_name (list_cell, cell->cell_name))
112 if (list_cell == cell)
115 gnc_basic_cell_destroy (list_cell);
121 layout->cells = g_list_append (layout->cells, cell);
127 gnc_table_layout_get_cell (TableLayout *layout,
const char *cell_name)
131 g_return_val_if_fail (layout != NULL, NULL);
133 for (node = layout->cells; node; node = node->next)
135 BasicCell *list_cell = node->data;
137 if (gnc_basic_cell_has_name (list_cell, cell_name))
145 gnc_table_layout_get_cell_value (TableLayout *layout,
const char * cell_name)
149 g_return_val_if_fail (layout != NULL, NULL);
151 cell = gnc_table_layout_get_cell (layout, cell_name);
152 if (!cell)
return NULL;
154 return gnc_basic_cell_get_value (cell);
158 gnc_table_layout_get_cell_changed (TableLayout *layout,
159 const char *cell_name,
160 gboolean include_conditional)
164 g_return_val_if_fail (layout != NULL, FALSE);
166 cell = gnc_table_layout_get_cell (layout, cell_name);
167 if (!cell)
return FALSE;
169 if (!include_conditional)
170 return gnc_basic_cell_get_changed (cell);
172 return (gnc_basic_cell_get_changed (cell) ||
173 gnc_basic_cell_get_conditionally_changed (cell));
177 gnc_table_layout_get_cells (TableLayout *layout)
182 return layout->cells;
186 gnc_table_layout_add_cursor (TableLayout *layout,
191 g_return_if_fail (layout != NULL);
192 g_return_if_fail (cursor != NULL);
194 if (g_list_find (layout->cursors, cursor))
197 for (node = layout->cursors; node; node = node->next)
201 if (strcmp (list_cursor->cursor_name, cursor->cursor_name) == 0)
203 layout->cursors = g_list_remove (layout->cursors, list_cursor);
209 layout->cursors = g_list_append (layout->cursors, cursor);
213 gnc_table_layout_get_cursor (TableLayout *layout,
214 const char *cursor_name)
218 g_return_val_if_fail (layout != NULL, NULL);
223 for (node = layout->cursors; node; node = node->next)
227 if (strcmp (cursor_name, cursor->cursor_name) == 0)
235 gnc_table_layout_get_cursors (TableLayout *layout)
237 g_return_val_if_fail (layout != NULL, NULL);
238 return layout->cursors;
242 gnc_table_layout_set_primary_cursor (TableLayout *layout,
245 g_return_if_fail (layout != NULL);
246 layout->primary_cursor = cursor;
250 gnc_table_layout_set_cell (TableLayout *layout,
252 const char *cell_name,
258 g_return_if_fail (layout != NULL);
259 g_return_if_fail (layout->primary_cursor != NULL);
260 g_return_if_fail (cursor != NULL);
261 g_return_if_fail (cell_name != NULL);
262 g_return_if_fail (row >= 0);
263 g_return_if_fail (col >= 0);
264 g_return_if_fail (row < cursor->num_rows);
265 g_return_if_fail (col < cursor->num_cols);
267 header = gnc_table_layout_get_cursor (layout,
CURSOR_HEADER);
268 cell = gnc_table_layout_get_cell (layout, cell_name);
270 g_return_if_fail (header != NULL);
271 g_return_if_fail (cell != NULL);
273 cursor->start_col = MIN (cursor->start_col, col);
274 cursor->stop_col = MAX (cursor->stop_col, col);
276 header->start_col = MIN (header->start_col, col);
277 header->stop_col = MAX (header->stop_col, col);
281 if (cursor == layout->primary_cursor)
286 gnc_cursor_buffer_new (
void)
288 CursorBuffer *buffer;
290 buffer = g_new0 (CursorBuffer, 1);
296 destroy_cell_buffer (CellBuffer *cb)
301 g_free (cb->cell_name);
302 cb->cell_name = NULL;
311 gnc_cursor_buffer_clear (CursorBuffer *buffer)
317 for (node = buffer->cell_buffers; node; node = node->next)
319 CellBuffer *cb = node->data;
321 destroy_cell_buffer (cb);
324 g_list_free (buffer->cell_buffers);
325 buffer->cell_buffers = NULL;
329 gnc_cursor_buffer_destroy (CursorBuffer *buffer)
333 gnc_cursor_buffer_clear (buffer);
339 save_cell (BasicCell *bcell)
346 cb = g_new0 (CellBuffer, 1);
348 cb->cell_name = g_strdup (bcell->cell_name);
349 cb->value = g_strdup (bcell->value);
350 cb->changed = bcell->changed;
351 cb->conditionally_changed = bcell->conditionally_changed;
357 gnc_table_layout_save_cursor (TableLayout *layout,
359 CursorBuffer *buffer)
363 if (!layout || !cursor || !buffer)
366 gnc_cursor_buffer_clear (buffer);
368 for (node = layout->cells; node; node = node->next)
370 BasicCell *list_cell = node->data;
373 if (!gnc_basic_cell_get_changed (list_cell) &&
374 !gnc_basic_cell_get_conditionally_changed (list_cell))
377 cb = save_cell (list_cell);
379 buffer->cell_buffers = g_list_prepend (buffer->cell_buffers, cb);
384 restore_cell (BasicCell *bcell, CellBuffer *cb,
CellBlock *cursor)
388 if (!bcell || !cb || !cursor)
391 if (!cb->changed && !cb->conditionally_changed)
395 for (r = 0; r < cursor->num_rows; r++)
396 for (c = 0; c < cursor->num_cols; c++)
406 gnc_basic_cell_set_value (bcell, cb->value);
407 bcell->changed = cb->changed;
408 bcell->conditionally_changed = cb->conditionally_changed;
415 gnc_table_layout_restore_cursor (TableLayout *layout,
417 CursorBuffer *buffer)
421 if (!layout || !cursor || !buffer)
424 for (node = buffer->cell_buffers; node; node = node->next)
426 CellBuffer *cb = node->data;
429 cell = gnc_table_layout_get_cell (layout, cb->cell_name);
431 restore_cell (cell, cb, cursor);
TableLayout * gnc_table_layout_new(void)
API Declarations.
#define CURSOR_HEADER
Standard Cursor Names.
void gnc_cellblock_destroy(CellBlock *cellblock)
Delete a CellBlock and its Cells.
Declarations for the CellBlock object.
void gnc_cellblock_set_cell(CellBlock *cellblock, int row, int col, BasicCell *cell)
Add a cell to the CellBlock at the specified coordinates.
BasicCell * gnc_cellblock_get_cell(CellBlock *cellblock, int row, int col)
Retrieve the Cell at the specified coordinates.