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
20 #include "gsheetmodel.h"
21 #include "gtkextra-marshal.h"
30 static guint sheet_model_signals[LAST_SIGNAL] = { 0 };
33 static void g_sheet_model_base_init (gpointer g_class);
37 g_sheet_model_get_type (void)
39 static GType sheet_model_type = 0;
41 if (! sheet_model_type)
43 static const GTypeInfo sheet_model_info =
45 sizeof (GSheetModelIface), /* class_size */
46 g_sheet_model_base_init, /* base_init */
47 NULL, /* base_finalize */
49 NULL, /* class_finalize */
50 NULL, /* class_data */
57 g_type_register_static (G_TYPE_INTERFACE, "GSheetModel",
58 &sheet_model_info, 0);
60 g_type_interface_add_prerequisite (sheet_model_type, G_TYPE_OBJECT);
63 return sheet_model_type;
67 g_sheet_model_base_init (gpointer g_class)
69 static gboolean initialized = FALSE;
73 sheet_model_signals[RANGE_CHANGED] =
74 g_signal_new ("range_changed",
77 G_STRUCT_OFFSET (GSheetModelIface, range_changed),
79 gtkextra_VOID__INT_INT_INT_INT,
88 sheet_model_signals[ROWS_INSERTED] =
89 g_signal_new ("rows_inserted",
92 G_STRUCT_OFFSET (GSheetModelIface, rows_inserted),
94 gtkextra_VOID__INT_INT,
100 sheet_model_signals[ROWS_DELETED] =
101 g_signal_new ("rows_deleted",
104 G_STRUCT_OFFSET (GSheetModelIface, rows_deleted),
106 gtkextra_VOID__INT_INT,
118 * g_sheet_model_free_strings
119 * @sheet_model: A #GSheetModel
121 * Returns: True if strings obtained with get_string should be freed by the
122 * sheet when no longer required.
125 g_sheet_model_free_strings (const GSheetModel *sheet_model)
127 g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), FALSE);
129 return G_SHEET_MODEL_GET_IFACE (sheet_model)->free_strings;
134 * g_sheet_model_get_string:
135 * @sheet_model: A #GSheetModel
136 * @row: The row of the cell to be retrieved.
137 * @column: The column of the cell to be retrieved.
139 * Retrieves the datum at location ROW, COLUMN in the form of a string.
140 * Returns: The string representation of the datum, or NULL on error.
143 g_sheet_model_get_string (const GSheetModel *sheet_model,
144 gint row, gint column)
146 g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), 0);
148 g_assert (G_SHEET_MODEL_GET_IFACE (sheet_model)->get_string);
150 return (G_SHEET_MODEL_GET_IFACE (sheet_model)->get_string) (sheet_model, row, column);
154 * g_sheet_model_set_string
155 * @sheet_model: A #GSheetModel
156 * @text: The text describing the datum to be set.
157 * @row: The row of the cell to be cleared.
158 * @column: The column of the cell to be cleared.
160 * Sets the datum at a location from a string.
161 * Returns: TRUE if the datum was changed, FALSE otherwise.
164 g_sheet_model_set_string (GSheetModel *sheet_model,
166 gint row, gint column)
168 g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), FALSE);
170 g_assert (G_SHEET_MODEL_GET_IFACE (sheet_model)->set_string);
172 return G_SHEET_MODEL_GET_IFACE (sheet_model)->set_string (sheet_model,
179 * g_sheet_model_datum_clear:
180 * @sheet_model: A #GSheetModel
181 * @row: The row of the cell to be cleared.
182 * @column: The column of the cell to be cleared.
184 * Called when the datum at a location is to be cleared.
185 * Returns: TRUE if the datum was cleared, FALSE otherwise.
188 g_sheet_model_datum_clear (GSheetModel *sheet_model,
189 gint row, gint column)
191 g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), FALSE);
193 g_assert (G_SHEET_MODEL_GET_IFACE (sheet_model)->clear_datum);
195 return G_SHEET_MODEL_GET_IFACE (sheet_model)->clear_datum (sheet_model,
201 * g_sheet_model_range_changed:
202 * @sheet_model: A #GSheetModel
203 * @range: The #GSheetRange range of cells which have changed.
205 * Emits the "range_changed" signal on @sheet_model.
208 g_sheet_model_range_changed (GSheetModel *sheet_model,
209 gint row0, gint col0,
210 gint rowi, gint coli)
212 g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
214 g_signal_emit (sheet_model, sheet_model_signals[RANGE_CHANGED], 0,
215 row0, col0, rowi, coli);
222 * g_sheet_model_rows_inserted:
223 * @sheet_model: A #GSheetModel
224 * @row: The row before which the new rows should be inserted.
225 * @n_rows: The number of rows to insert.
227 * Emits the "rows_inserted" signal on @sheet_model.
230 g_sheet_model_rows_inserted (GSheetModel *sheet_model,
231 gint row, gint n_rows)
233 g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
235 g_signal_emit (sheet_model, sheet_model_signals[ROWS_INSERTED], 0,
243 * g_sheet_model_rows_deleted:
244 * @sheet_model: A #GSheetModel
245 * @row: The first row to be deleted.
246 * @n_rows: The number of rows to delete.
248 * Emits the "rows_deleted" signal on @sheet_model.
251 g_sheet_model_rows_deleted (GSheetModel *sheet_model,
252 gint row, gint n_rows)
254 g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
256 g_signal_emit (sheet_model, sheet_model_signals[ROWS_DELETED], 0,
264 * g_sheet_model_is_editable:
265 * @sheet_model: A #GSheetModel
267 * @column: The column
269 * Returns: TRUE if the cell is editable, FALSE otherwise
272 g_sheet_model_is_editable (const GSheetModel *model,
273 gint row, gint column)
275 g_return_val_if_fail (G_IS_SHEET_MODEL (model), TRUE);
277 if ( ! G_SHEET_MODEL_GET_IFACE (model)->is_editable )
280 return G_SHEET_MODEL_GET_IFACE (model)->is_editable (model,
285 * g_sheet_model_is_visible:
286 * @sheet_model: A #GSheetModel
288 * @column: The column
290 * Returns: TRUE if the cell is visible, FALSE otherwise
293 g_sheet_model_is_visible (const GSheetModel *model,
294 gint row, gint column)
296 g_return_val_if_fail (G_IS_SHEET_MODEL (model), TRUE);
298 if ( ! G_SHEET_MODEL_GET_IFACE (model)->is_visible )
301 return G_SHEET_MODEL_GET_IFACE (model)->is_visible (model,
307 * g_sheet_model_get_foreground:
308 * @sheet_model: A #GSheetModel
310 * @column: The column
312 * Returns the foreground colour of the cell at @row, @column
313 * Returns: the foreground colour, or NULL on error.
315 inline const GdkColor *
316 g_sheet_model_get_foreground (const GSheetModel *model,
317 gint row, gint column)
319 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
321 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_foreground )
324 return G_SHEET_MODEL_GET_IFACE (model)->get_foreground (model,
329 * g_sheet_model_get_background:
330 * @sheet_model: A #GSheetModel
332 * @column: The column
334 * Returns the background colour of the cell at @row, @column
335 * Returns: the background colour, or NULL on error.
337 inline const GdkColor *
338 g_sheet_model_get_background (const GSheetModel *model,
339 gint row, gint column)
341 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
343 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_background )
346 return G_SHEET_MODEL_GET_IFACE (model)->get_background (model,
351 * g_sheet_model_get_justification:
352 * @sheet_model: A #GSheetModel
354 * @column: The column
356 * Returns the justification of the cell at @row, @column
357 * Returns: the justification, or NULL on error.
359 inline const GtkJustification *
360 g_sheet_model_get_justification (const GSheetModel *model,
361 gint row, gint column)
363 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
365 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_justification)
368 return G_SHEET_MODEL_GET_IFACE (model)->get_justification (model,
373 * g_sheet_model_get_font_desc:
374 * @sheet_model: A #GSheetModel
376 * @column: The column
378 * Returns the font description of the cell at @row, @column
379 * Returns: the font description, or NULL on error.
381 inline const PangoFontDescription *
382 g_sheet_model_get_font_desc(const GSheetModel *model,
383 gint row, gint column)
385 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
386 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_font_desc)
389 return G_SHEET_MODEL_GET_IFACE (model)->get_font_desc (model,
394 * g_sheet_model_get_cell_border:
395 * @sheet_model: A #GSheetModel
397 * @column: The column
399 * Returns the cell border of the cell at @row, @column
400 * Returns: the cell border, or NULL on error.
402 inline const GtkSheetCellBorder *
403 g_sheet_model_get_cell_border (const GSheetModel *model,
404 gint row, gint column)
406 g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
407 if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_cell_border)
410 return G_SHEET_MODEL_GET_IFACE (model)->get_cell_border (model,