Added new files resulting from directory restructuring.
[pspp-builds.git] / lib / gtksheet / gsheetmodel.c
1 /* GSheetModel --- an abstract model for the GSheet widget.
2  * Copyright (C) 2006 Free Software Foundation
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <glib.h>
20 #include "gsheetmodel.h"
21 #include "gtkextra-marshal.h"
22
23 enum {
24   RANGE_CHANGED,
25   ROWS_INSERTED,
26   ROWS_DELETED,
27   LAST_SIGNAL
28 };
29
30 static guint sheet_model_signals[LAST_SIGNAL] = { 0 };
31
32
33 static void      g_sheet_model_base_init   (gpointer           g_class);
34
35
36 inline GType
37 g_sheet_model_get_type (void)
38 {
39   static GType sheet_model_type = 0;
40
41   if (! sheet_model_type)
42     {
43       static const GTypeInfo sheet_model_info =
44       {
45         sizeof (GSheetModelIface), /* class_size */
46         g_sheet_model_base_init,   /* base_init */
47         NULL,           /* base_finalize */
48         NULL,
49         NULL,           /* class_finalize */
50         NULL,           /* class_data */
51         0,
52         0,              /* n_preallocs */
53         NULL
54       };
55
56       sheet_model_type =
57         g_type_register_static (G_TYPE_INTERFACE, "GSheetModel",
58                                 &sheet_model_info, 0);
59
60       g_type_interface_add_prerequisite (sheet_model_type, G_TYPE_OBJECT);
61     }
62
63   return sheet_model_type;
64 }
65
66 static void
67 g_sheet_model_base_init (gpointer g_class)
68 {
69   static gboolean initialized = FALSE;
70
71   if (! initialized)
72     {
73       sheet_model_signals[RANGE_CHANGED] =
74         g_signal_new ("range_changed",
75                       G_TYPE_SHEET_MODEL,
76                       G_SIGNAL_RUN_LAST,
77                       G_STRUCT_OFFSET (GSheetModelIface, range_changed),
78                       NULL, NULL,
79                       gtkextra_VOID__INT_INT_INT_INT,
80                       G_TYPE_NONE, 4,
81                       G_TYPE_INT,
82                       G_TYPE_INT,
83                       G_TYPE_INT,
84                       G_TYPE_INT);
85
86
87
88       sheet_model_signals[ROWS_INSERTED] =
89         g_signal_new ("rows_inserted",
90                       G_TYPE_SHEET_MODEL,
91                       G_SIGNAL_RUN_LAST,
92                       G_STRUCT_OFFSET (GSheetModelIface, rows_inserted),
93                       NULL, NULL,
94                       gtkextra_VOID__INT_INT,
95                       G_TYPE_NONE, 2,
96                       G_TYPE_INT,
97                       G_TYPE_INT);
98
99
100       sheet_model_signals[ROWS_DELETED] =
101         g_signal_new ("rows_deleted",
102                       G_TYPE_SHEET_MODEL,
103                       G_SIGNAL_RUN_LAST,
104                       G_STRUCT_OFFSET (GSheetModelIface, rows_deleted),
105                       NULL, NULL,
106                       gtkextra_VOID__INT_INT,
107                       G_TYPE_NONE, 2,
108                       G_TYPE_INT,
109                       G_TYPE_INT);
110
111                     
112       initialized = TRUE;
113     }
114 }
115
116 /**
117  * g_sheet_model_get_string:
118  * @sheet_model: A #GSheetModel
119  * @row: The row of the cell to be retrieved.
120  * @column: The column of the cell to be retrieved.
121  * 
122  * Retrieves the datum at location ROW, COLUMN in the form of a string.
123  * Returns: The string representation of the datum, or NULL on error.
124  **/
125 inline const gchar *const      
126 g_sheet_model_get_string (const GSheetModel *sheet_model, 
127                           gint row, gint column)
128 {
129   g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), 0);
130
131   g_assert (G_SHEET_MODEL_GET_IFACE (sheet_model)->get_string);
132   
133   return (G_SHEET_MODEL_GET_IFACE (sheet_model)->get_string) (sheet_model, row, column);
134 }
135
136 /**
137  * g_sheet_model_set_string
138  * @sheet_model: A #GSheetModel
139  * @text: The text describing the datum to be set.
140  * @row: The row of the cell to be cleared.
141  * @column: The column of the cell to be cleared.
142  * 
143  * Sets the datum at a location from a string.
144  * Returns: TRUE if the datum was changed, FALSE otherwise.
145  **/
146 gboolean
147 g_sheet_model_set_string      (GSheetModel *sheet_model, 
148                                  const gchar *text, 
149                                  gint row, gint column)
150 {
151   g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), FALSE);
152
153   g_assert (G_SHEET_MODEL_GET_IFACE (sheet_model)->set_string);
154
155   return G_SHEET_MODEL_GET_IFACE (sheet_model)->set_string (sheet_model, 
156                                                             text, row, column);
157 }
158
159
160
161 /**
162  * g_sheet_model_datum_clear:
163  * @sheet_model: A #GSheetModel
164  * @row: The row of the cell to be cleared.
165  * @column: The column of the cell to be cleared.
166  * 
167  * Called when the datum at a location is to be cleared.
168  * Returns: TRUE if the datum was cleared, FALSE otherwise.
169  **/
170 gboolean
171 g_sheet_model_datum_clear    (GSheetModel *sheet_model, 
172                                 gint row, gint column)
173 {
174   g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), FALSE);
175
176   g_assert (G_SHEET_MODEL_GET_IFACE (sheet_model)->clear_datum);
177
178   return G_SHEET_MODEL_GET_IFACE (sheet_model)->clear_datum (sheet_model, 
179                                                                 row, column);
180 }
181
182
183 /**
184  * g_sheet_model_range_changed:
185  * @sheet_model: A #GSheetModel
186  * @range: The #GSheetRange range of cells which have changed.
187  * 
188  * Emits the "range_changed" signal on @sheet_model.
189  **/
190 void
191 g_sheet_model_range_changed (GSheetModel *sheet_model,
192                                gint row0, gint col0,
193                                gint rowi, gint coli)
194 {
195   g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
196
197   g_signal_emit (sheet_model, sheet_model_signals[RANGE_CHANGED], 0, 
198                  row0, col0, rowi, coli);
199 }
200
201
202
203
204 /**
205  * g_sheet_model_rows_inserted:
206  * @sheet_model: A #GSheetModel
207  * @row: The row before which the new rows should be inserted.
208  * @n_rows: The number of rows to insert.
209  * 
210  * Emits the "rows_inserted" signal on @sheet_model.
211  **/
212 void
213 g_sheet_model_rows_inserted (GSheetModel *sheet_model,
214                                gint row, gint n_rows)
215 {
216   g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
217
218   g_signal_emit (sheet_model, sheet_model_signals[ROWS_INSERTED], 0, 
219                  row, n_rows);
220 }
221
222
223
224
225 /**
226  * g_sheet_model_rows_deleted:
227  * @sheet_model: A #GSheetModel
228  * @row: The first row to be deleted.
229  * @n_rows: The number of rows to delete.
230  * 
231  * Emits the "rows_deleted" signal on @sheet_model.
232  **/
233 void
234 g_sheet_model_rows_deleted (GSheetModel *sheet_model,
235                                gint row, gint n_rows)
236 {
237   g_return_if_fail (G_IS_SHEET_MODEL (sheet_model));
238
239   g_signal_emit (sheet_model, sheet_model_signals[ROWS_DELETED], 0, 
240                  row, n_rows);
241 }
242
243
244
245
246 /**
247  * g_sheet_model_is_editable:
248  * @sheet_model: A #GSheetModel
249  * @row: The row 
250  * @column: The column
251  * 
252  * Returns: TRUE if the cell is editable, FALSE otherwise
253  **/
254 inline gboolean 
255 g_sheet_model_is_editable (const GSheetModel *model, 
256                              gint row, gint column)
257 {
258   g_return_val_if_fail (G_IS_SHEET_MODEL (model), TRUE);
259
260   if ( ! G_SHEET_MODEL_GET_IFACE (model)->is_editable )
261     return TRUE;
262
263   return G_SHEET_MODEL_GET_IFACE (model)->is_editable (model, 
264                                                           row, column);
265 }
266
267 /**
268  * g_sheet_model_is_visible:
269  * @sheet_model: A #GSheetModel
270  * @row: The row 
271  * @column: The column
272  * 
273  * Returns: TRUE if the cell is visible, FALSE otherwise
274  **/
275 inline gboolean 
276 g_sheet_model_is_visible (const GSheetModel *model, 
277                           gint row, gint column)
278 {
279   g_return_val_if_fail (G_IS_SHEET_MODEL (model), TRUE);
280
281   if ( ! G_SHEET_MODEL_GET_IFACE (model)->is_visible )
282     return TRUE;
283
284   return G_SHEET_MODEL_GET_IFACE (model)->is_visible (model, 
285                                                         row, column);
286 }
287
288
289 /**
290  * g_sheet_model_get_foreground:
291  * @sheet_model: A #GSheetModel
292  * @row: The row 
293  * @column: The column
294  *
295  * Returns the foreground colour of the cell at @row, @column
296  * Returns: the foreground colour, or NULL on error.
297  **/
298 inline const GdkColor *
299 g_sheet_model_get_foreground (const GSheetModel *model, 
300                                 gint row, gint column)
301 {
302   g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
303
304   if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_foreground )
305     return NULL;
306
307   return G_SHEET_MODEL_GET_IFACE (model)->get_foreground (model, 
308                                                             row, column);
309 }
310
311 /**
312  * g_sheet_model_get_background:
313  * @sheet_model: A #GSheetModel
314  * @row: The row 
315  * @column: The column
316  *
317  * Returns the background colour of the cell at @row, @column
318  * Returns: the background colour, or NULL on error.
319  **/
320 inline const GdkColor *
321 g_sheet_model_get_background (const GSheetModel *model, 
322                                 gint row, gint column)
323 {
324   g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
325
326   if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_background )
327     return NULL;
328
329   return G_SHEET_MODEL_GET_IFACE (model)->get_background (model, 
330                                                             row, column);
331 }
332
333 /**
334  * g_sheet_model_get_justification:
335  * @sheet_model: A #GSheetModel
336  * @row: The row 
337  * @column: The column
338  *
339  * Returns the justification of the cell at @row, @column
340  * Returns: the justification, or NULL on error.
341  **/
342 inline const GtkJustification *
343 g_sheet_model_get_justification (const GSheetModel *model, 
344                                    gint row, gint column)
345 {
346   g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
347
348   if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_justification)
349     return NULL;
350
351   return G_SHEET_MODEL_GET_IFACE (model)->get_justification (model, 
352                                                                row, column);
353 }
354
355 /**
356  * g_sheet_model_get_font_desc:
357  * @sheet_model: A #GSheetModel
358  * @row: The row 
359  * @column: The column
360  *
361  * Returns the font description of the cell at @row, @column
362  * Returns: the font description, or NULL on error.
363  **/
364 inline const PangoFontDescription *
365 g_sheet_model_get_font_desc(const GSheetModel *model,
366                               gint row, gint column)
367 {
368   g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
369   if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_font_desc)
370     return NULL;
371
372   return G_SHEET_MODEL_GET_IFACE (model)->get_font_desc (model, 
373                                                            row, column);
374 }
375
376 /**
377  * g_sheet_model_get_cell_border:
378  * @sheet_model: A #GSheetModel
379  * @row: The row 
380  * @column: The column
381  *
382  * Returns the cell border of the cell at @row, @column
383  * Returns: the cell border, or NULL on error.
384  **/
385 inline const GtkSheetCellBorder * 
386 g_sheet_model_get_cell_border (const GSheetModel *model, 
387                                  gint row, gint column)
388 {
389   g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL);
390   if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_cell_border)
391     return NULL;
392
393   return G_SHEET_MODEL_GET_IFACE (model)->get_cell_border (model, 
394                                                            row, column);
395 }