1
/********************************************************************\
2
* cellblock.c -- group of cells that act as cursor within a table *
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. *
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. *
14
* You should have received a copy of the GNU General Public License*
15
* along with this program; if not, contact: *
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 gnu@gnu.org *
21
\********************************************************************/
28
* implements a rectangular array of cells. See the header file for
29
* additional documentation.
32
* Copyright (c) 1998 Linas Vepstas
33
* Copyright (c) 2000-2001 Dave Peticolas <dave@krondo.com>
38
#include "cellblock.h"
40
static void gnc_cellblock_init (CellBlock *cellblock, int rows, int cols);
44
gnc_cellblock_new (int rows, int cols, const char *cursor_name)
48
g_return_val_if_fail (rows > 0, NULL);
49
g_return_val_if_fail (cols > 0, NULL);
50
g_return_val_if_fail (cursor_name != NULL, NULL);
52
cellblock = g_new0 (CellBlock, 1);
54
gnc_cellblock_init (cellblock, rows, cols);
56
cellblock->cursor_name = g_strdup (cursor_name);
62
gnc_cellblock_init (CellBlock *cellblock, int rows, int cols)
65
cellblock->num_rows = rows;
66
cellblock->num_cols = cols;
68
cellblock->start_col = cols;
69
cellblock->stop_col = -1;
71
/* malloc new cell table */
72
cellblock->cells = g_ptr_array_new ();
74
g_ptr_array_set_size (cellblock->cells, rows * cols);
78
gnc_cellblock_destroy (CellBlock *cellblock)
80
if (!cellblock) return;
82
g_ptr_array_free (cellblock->cells, FALSE);
83
cellblock->cells = NULL;
85
g_free (cellblock->cursor_name);
86
cellblock->cursor_name = NULL;
92
gnc_cellblock_set_cell (CellBlock *cellblock,
96
if (cellblock == NULL)
99
if (row < 0 || row >= cellblock->num_rows)
102
if (col < 0 || col >= cellblock->num_cols)
105
cellblock->cells->pdata[(row * cellblock->num_cols) + col] = cell;
109
gnc_cellblock_get_cell (CellBlock *cellblock, int row, int col)
111
if (cellblock == NULL)
114
if (row < 0 || row >= cellblock->num_rows)
117
if (col < 0 || col >= cellblock->num_cols)
120
return cellblock->cells->pdata[(row * cellblock->num_cols) + col];
124
gnc_cellblock_changed (CellBlock *cursor, gboolean include_conditional)
132
for (r = 0; r < cursor->num_rows; r++)
133
for (c = 0; c < cursor->num_cols; c++)
137
cell = gnc_cellblock_get_cell (cursor, r, c);
141
if (gnc_basic_cell_get_changed (cell))
147
if (include_conditional &&
148
gnc_basic_cell_get_conditionally_changed (cell))
156
gnc_cellblock_clear_changes (CellBlock *cursor)
163
for (r = 0; r < cursor->num_rows; r++)
164
for (c = 0; c < cursor->num_cols; c++)
168
cell = gnc_cellblock_get_cell (cursor, r, c);
172
gnc_basic_cell_set_changed (cell, FALSE);
173
gnc_basic_cell_set_conditionally_changed (cell, FALSE);