00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "config.h"
00037
00038 #include "cellblock.h"
00039
00040 static void gnc_cellblock_init (CellBlock *cellblock, int rows, int cols);
00041
00042
00043 CellBlock *
00044 gnc_cellblock_new (int rows, int cols, const char *cursor_name)
00045 {
00046 CellBlock *cellblock;
00047
00048 g_return_val_if_fail (rows > 0, NULL);
00049 g_return_val_if_fail (cols > 0, NULL);
00050 g_return_val_if_fail (cursor_name != NULL, NULL);
00051
00052 cellblock = g_new0 (CellBlock, 1);
00053
00054 gnc_cellblock_init (cellblock, rows, cols);
00055
00056 cellblock->cursor_name = g_strdup (cursor_name);
00057
00058 return cellblock;
00059 }
00060
00061 static void
00062 gnc_cellblock_init (CellBlock *cellblock, int rows, int cols)
00063 {
00064
00065 cellblock->num_rows = rows;
00066 cellblock->num_cols = cols;
00067
00068 cellblock->start_col = cols;
00069 cellblock->stop_col = -1;
00070
00071
00072 cellblock->cells = g_ptr_array_new ();
00073
00074 g_ptr_array_set_size (cellblock->cells, rows * cols);
00075 }
00076
00077 void
00078 gnc_cellblock_destroy (CellBlock *cellblock)
00079 {
00080 if (!cellblock) return;
00081
00082 g_ptr_array_free (cellblock->cells, FALSE);
00083 cellblock->cells = NULL;
00084
00085 g_free (cellblock->cursor_name);
00086 cellblock->cursor_name = NULL;
00087
00088 g_free (cellblock);
00089 }
00090
00091 void
00092 gnc_cellblock_set_cell (CellBlock *cellblock,
00093 int row, int col,
00094 BasicCell *cell)
00095 {
00096 if (cellblock == NULL)
00097 return;
00098
00099 if (row < 0 || row >= cellblock->num_rows)
00100 return;
00101
00102 if (col < 0 || col >= cellblock->num_cols)
00103 return;
00104
00105 cellblock->cells->pdata[(row * cellblock->num_cols) + col] = cell;
00106 }
00107
00108 BasicCell *
00109 gnc_cellblock_get_cell (CellBlock *cellblock, int row, int col)
00110 {
00111 if (cellblock == NULL)
00112 return NULL;
00113
00114 if (row < 0 || row >= cellblock->num_rows)
00115 return NULL;
00116
00117 if (col < 0 || col >= cellblock->num_cols)
00118 return NULL;
00119
00120 return cellblock->cells->pdata[(row * cellblock->num_cols) + col];
00121 }
00122
00123 int
00124 gnc_cellblock_changed (CellBlock *cursor, gboolean include_conditional)
00125 {
00126 int changed = 0;
00127 int r, c;
00128
00129 if (!cursor)
00130 return FALSE;
00131
00132 for (r = 0; r < cursor->num_rows; r++)
00133 for (c = 0; c < cursor->num_cols; c++)
00134 {
00135 BasicCell *cell;
00136
00137 cell = gnc_cellblock_get_cell (cursor, r, c);
00138 if (cell == NULL)
00139 continue;
00140
00141 if (gnc_basic_cell_get_changed (cell))
00142 {
00143 changed++;
00144 continue;
00145 }
00146
00147 if (include_conditional &&
00148 gnc_basic_cell_get_conditionally_changed (cell))
00149 changed++;
00150 }
00151
00152 return changed;
00153 }
00154
00155 void
00156 gnc_cellblock_clear_changes (CellBlock *cursor)
00157 {
00158 int r, c;
00159
00160 if (!cursor)
00161 return;
00162
00163 for (r = 0; r < cursor->num_rows; r++)
00164 for (c = 0; c < cursor->num_cols; c++)
00165 {
00166 BasicCell *cell;
00167
00168 cell = gnc_cellblock_get_cell (cursor, r, c);
00169 if (cell == NULL)
00170 continue;
00171
00172 gnc_basic_cell_set_changed (cell, FALSE);
00173 gnc_basic_cell_set_conditionally_changed (cell, FALSE);
00174 }
00175 }