1 /* GSheetModel --- an abstract model for the GSheet widget.
2 * Copyright (C) 2006 Free Software Foundation
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "gsheetmodel.h"
23 #include "gtkextra-marshal.h"
34 static guint sheet_model_signals[LAST_SIGNAL] = { 0 };
37 static void g_sheet_model_base_init (gpointer g_class);
41 g_sheet_model_get_type (void)
43 static GType sheet_model_type = 0;
45 if (! sheet_model_type)
47 static const GTypeInfo sheet_model_info =
49 sizeof (GSheetModelIface), /* class_size */
50 g_sheet_model_base_init, /* base_init */
51 NULL, /* base_finalize */
53 NULL, /* class_finalize */
54 NULL, /* class_data */
61 g_type_register_static (G_TYPE_INTERFACE, "GSheetModel",
62 &sheet_model_info, 0);
64 g_type_interface_add_prerequisite (sheet_model_type, G_TYPE_OBJECT);
67 return sheet_model_type;
71 g_sheet_model_base_init (gpointer g_class)
73 static gboolean initialized = FALSE;
77 sheet_model_signals[RANGE_CHANGED] =
78 g_signal_new ("range_changed",
81 G_STRUCT_OFFSET (GSheetModelIface, range_changed),
83 gtkextra_VOID__INT_INT_INT_INT,
92 sheet_model_signals[ROWS_INSERTED] =
93 g_signal_new ("rows_inserted",
96 G_STRUCT_OFFSET (GSheetModelIface, rows_inserted),
98 gtkextra_VOID__INT_INT,
104 sheet_model_signals[ROWS_DELETED] =
105 g_signal_new ("rows_deleted",
108 G_STRUCT_OFFSET (GSheetModelIface, rows_deleted),
110 gtkextra_VOID__INT_INT,
115 sheet_model_signals[COLUMNS_INSERTED] =
116 g_signal_new ("columns_inserted",
119 G_STRUCT_OFFSET (GSheetModelIface, columns_inserted),
121 gtkextra_VOID__INT_INT,
127 sheet_model_signals[COLUMNS_DELETED] =
128 g_signal_new ("columns_deleted",
131 G_STRUCT_OFFSET (GSheetModelIface, columns_deleted),
133 gtkextra_VOID__INT_INT,
145 * g_sheet_model_free_strings
146 * @sheet_model: A #GSheetModel
148 * Returns: True if strings obtained with get_string should be freed by the
149 * sheet when no longer required.
152 g_sheet_model_free_strings (const GSheetModel *sheet_model)
154 g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), FALSE);
156 return G_SHEET_MODEL_GET_IFACE (sheet_model)->free_strings;
161 * g_sheet_model_get_string:
162 * @sheet_model: A #GSheetModel
163 * @row: The row of the cell to be retrieved.
164 * @column: The column of the cell to be retrieved.
166 * Retrieves the datum at location ROW, COLUMN in the form of a string.
167 * Returns: The string representation of the datum, or NULL on error.
170 g_sheet_model_get_string (const GSheetModel *sheet_model,
171 glong row, glong column)
173 g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), 0);
175 g_assert (G_SHEET_MODEL_GET_IFACE (sheet_model)->get_string);
177 return (G_SHEET_MODEL_GET_IFACE (sheet_model)->get_string) (sheet_model, row, column);
181 * g_sheet_model_set_string
182 * @sheet_model: A #GSheetModel
183 * @text: The text describing the datum to be set.
184 * @row: The row of the cell to be cleared.
185 * @column: The column of the cell to be cleared.
187 * Sets the datum at a location from a string.
188 * Returns: TRUE if the datum was changed, FALSE otherwise.
191 g_sheet_model_set_string (GSheetModel *sheet_model,
193 glong row, glong column)
195 g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), FALSE);
197 g_assert (G_SHEET_MODEL_GET_IFACE (sheet_model)->set_string);
199 return G_SHEET_MODEL_GET_IFACE (sheet_model)->set_string (sheet_model,
206 * g_sheet_model_datum_clear:
207 * @sheet_model: A #GSheetModel
208 * @row: The row of the cell to be cleared.
209 * @column: The column of the cell to be cleared.
211 * Called when the datum at a location is to be cleared.
212 * Returns: TRUE if the datum was cleared, FALSE otherwise.
215 g_sheet_model_datum_clear (GSheetModel *sheet_model,
216 glong row, glong column)
218 g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), FALSE);
220 g_assert (G_SHEET_MODEL_GET_IFACE (sheet_model)->clear_datum);
222 return G_SHEET_MODEL_GET_IFACE (sheet_model)->clear_datum (sheet_model,
228 * g_sheet_model_range_changed:
229 * @sheet_model: A #GSheetModel
230 * @range: The #GSheetRange range of cells which have changed.
232 * Emits the "range_changed" signal on @sheet_model.
235 g_sheet_model_range_changed (GSheetModel *sheet_model,
236 glong row0, glong col0,
237 glong rowi, glong coli)
239 g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
241 g_signal_emit (sheet_model, sheet_model_signals[RANGE_CHANGED], 0,
242 row0, col0, rowi, coli);
249 * g_sheet_model_rows_inserted:
250 * @sheet_model: A #GSheetModel
251 * @row: The row before which the new rows should be inserted.
252 * @n_rows: The number of rows to insert.
254 * Emits the "rows_inserted" signal on @sheet_model.
257 g_sheet_model_rows_inserted (GSheetModel *sheet_model,
258 glong row, glong n_rows)
260 g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
262 g_signal_emit (sheet_model, sheet_model_signals[ROWS_INSERTED], 0,
268 * g_sheet_model_columns_inserted:
269 * @sheet_model: A #GSheetModel
270 * @column: The column before which the new columns should be inserted.
271 * @n_columns: The number of columns to insert.
273 * Emits the "columns_inserted" signal on @sheet_model.
276 g_sheet_model_columns_inserted (GSheetModel *sheet_model,
277 glong column, glong n_columns)
279 g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
281 g_signal_emit (sheet_model, sheet_model_signals[COLUMNS_INSERTED], 0,
289 * g_sheet_model_rows_deleted:
290 * @sheet_model: A #GSheetModel
291 * @row: The first row to be deleted.
292 * @n_rows: The number of rows to delete.
294 * Emits the "rows_deleted" signal on @sheet_model.
297 g_sheet_model_rows_deleted (GSheetModel *sheet_model,
298 glong row, glong n_rows)
300 g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
302 g_signal_emit (sheet_model, sheet_model_signals[ROWS_DELETED], 0,
309 * g_sheet_model_columns_deleted:
310 * @sheet_model: A #GSheetModel
311 * @column: The first column to be deleted.
312 * @n_columns: The number of columns to delete.
314 * Emits the "columns_deleted" signal on @sheet_model.
317 g_sheet_model_columns_deleted (GSheetModel *sheet_model,
318 glong column, glong n_columns)
320 g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
322 g_signal_emit (sheet_model, sheet_model_signals[COLUMNS_DELETED], 0,
331 * g_sheet_model_is_editable:
332 * @sheet_model: A #GSheetModel
334 * @column: The column
336 * Returns: TRUE if the cell is editable, FALSE otherwise
339 g_sheet_model_is_editable (const GSheetModel *model,
340 glong row, glong column)
342 g_return_val_if_fail (G_IS_SHEET_MODEL (model), TRUE);
344 if ( ! G_SHEET_MODEL_GET_IFACE (model)->is_editable )
347 return G_SHEET_MODEL_GET_IFACE (model)->is_editable (model,
352 * g_sheet_model_is_visible:
353 * @sheet_model: A #GSheetModel
355 * @column: The column
357 * Returns: TRUE if the cell is visible, FALSE otherwise
360 g_sheet_model_is_visible (const GSheetModel *model,
361 glong row, glong column)
363 g_return_val_if_fail (G_IS_SHEET_MODEL (model), TRUE);
365 if ( ! G_SHEET_MODEL_GET_IFACE (model)->is_visible )
368 return G_SHEET_MODEL_GET_IFACE (model)->is_visible (model,
374 * g_sheet_model_get_foreground:
375 * @sheet_model: A #GSheetModel
377 * @column: The column
379 * Returns the foreground colour of the cell at @row, @column
380 * Returns: the foreground colour, or NULL on error.
382 inline const GdkColor *
383 g_sheet_model_get_foreground (const GSheetModel *model,
384 glong row, glong column)
386 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
388 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_foreground )
391 return G_SHEET_MODEL_GET_IFACE (model)->get_foreground (model,
396 * g_sheet_model_get_background:
397 * @sheet_model: A #GSheetModel
399 * @column: The column
401 * Returns the background colour of the cell at @row, @column
402 * Returns: the background colour, or NULL on error.
404 inline const GdkColor *
405 g_sheet_model_get_background (const GSheetModel *model,
406 glong row, glong column)
408 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
410 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_background )
413 return G_SHEET_MODEL_GET_IFACE (model)->get_background (model,
418 * g_sheet_model_get_justification:
419 * @sheet_model: A #GSheetModel
421 * @column: The column
423 * Returns the justification of the cell at @row, @column
424 * Returns: the justification, or NULL on error.
426 inline const GtkJustification *
427 g_sheet_model_get_justification (const GSheetModel *model,
428 glong row, glong column)
430 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
432 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_justification)
435 return G_SHEET_MODEL_GET_IFACE (model)->get_justification (model,
440 * g_sheet_model_get_font_desc:
441 * @sheet_model: A #GSheetModel
443 * @column: The column
445 * Returns the font description of the cell at @row, @column
446 * Returns: the font description, or NULL on error.
448 inline const PangoFontDescription *
449 g_sheet_model_get_font_desc(const GSheetModel *model,
450 glong row, glong column)
452 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
453 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_font_desc)
456 return G_SHEET_MODEL_GET_IFACE (model)->get_font_desc (model,
461 * g_sheet_model_get_cell_border:
462 * @sheet_model: A #GSheetModel
464 * @column: The column
466 * Returns the cell border of the cell at @row, @column
467 * Returns: the cell border, or NULL on error.
469 inline const GtkSheetCellBorder *
470 g_sheet_model_get_cell_border (const GSheetModel *model,
471 glong row, glong column)
473 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
474 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_cell_border)
477 return G_SHEET_MODEL_GET_IFACE (model)->get_cell_border (model,
484 * g_sheet_model_get_column_count:
485 * @model: A #GSheetModel
487 * Returns the total number of columns represented by the model
490 g_sheet_model_get_column_count (const GSheetModel *model)
492 g_return_val_if_fail (G_IS_SHEET_MODEL (model), -1);
494 return G_SHEET_MODEL_GET_IFACE (model)->get_column_count (model);
498 * g_sheet_model_get_row_count:
499 * @model: A #GSheetModel
501 * Returns the total number of rows represented by the model
504 g_sheet_model_get_row_count(const GSheetModel *model)
506 g_return_val_if_fail (G_IS_SHEET_MODEL (model), -1);
509 return G_SHEET_MODEL_GET_IFACE (model)->get_row_count (model);