4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "e-table-model.h"
22 d (static gint depth
= 0;)
24 G_DEFINE_INTERFACE (ETableModel
, e_table_model
, G_TYPE_OBJECT
)
38 static guint signals
[LAST_SIGNAL
] = { 0, };
41 table_model_is_frozen (ETableModel
*table_model
)
45 data
= g_object_get_data (G_OBJECT (table_model
), "frozen");
47 return (GPOINTER_TO_INT (data
) != 0);
51 e_table_model_default_init (ETableModelInterface
*iface
)
53 signals
[MODEL_NO_CHANGE
] = g_signal_new (
55 G_TYPE_FROM_INTERFACE (iface
),
57 G_STRUCT_OFFSET (ETableModelInterface
, model_no_change
),
61 signals
[MODEL_CHANGED
] = g_signal_new (
63 G_TYPE_FROM_INTERFACE (iface
),
65 G_STRUCT_OFFSET (ETableModelInterface
, model_changed
),
69 signals
[MODEL_PRE_CHANGE
] = g_signal_new (
71 G_TYPE_FROM_INTERFACE (iface
),
73 G_STRUCT_OFFSET (ETableModelInterface
, model_pre_change
),
77 signals
[MODEL_ROW_CHANGED
] = g_signal_new (
79 G_TYPE_FROM_INTERFACE (iface
),
81 G_STRUCT_OFFSET (ETableModelInterface
, model_row_changed
),
86 signals
[MODEL_CELL_CHANGED
] = g_signal_new (
88 G_TYPE_FROM_INTERFACE (iface
),
90 G_STRUCT_OFFSET (ETableModelInterface
, model_cell_changed
),
96 signals
[MODEL_ROWS_INSERTED
] = g_signal_new (
97 "model_rows_inserted",
98 G_TYPE_FROM_INTERFACE (iface
),
100 G_STRUCT_OFFSET (ETableModelInterface
, model_rows_inserted
),
106 signals
[MODEL_ROWS_DELETED
] = g_signal_new (
107 "model_rows_deleted",
108 G_TYPE_FROM_INTERFACE (iface
),
110 G_STRUCT_OFFSET (ETableModelInterface
, model_rows_deleted
),
118 * e_table_model_column_count:
119 * @table_model: The e-table-model to operate on
121 * Returns: the number of columns in the table model.
124 e_table_model_column_count (ETableModel
*table_model
)
126 ETableModelInterface
*iface
;
128 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), 0);
130 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
131 g_return_val_if_fail (iface
->column_count
!= NULL
, 0);
133 return iface
->column_count (table_model
);
137 * e_table_model_row_count:
138 * @table_model: the e-table-model to operate on
140 * Returns: the number of rows in the Table model.
143 e_table_model_row_count (ETableModel
*table_model
)
145 ETableModelInterface
*iface
;
147 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), 0);
149 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
150 g_return_val_if_fail (iface
->row_count
!= NULL
, 0);
152 return iface
->row_count (table_model
);
156 * e_table_model_append_row:
157 * @table_model: the table model to append the a row to.
163 e_table_model_append_row (ETableModel
*table_model
,
167 ETableModelInterface
*iface
;
169 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
171 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
173 if (iface
->append_row
!= NULL
)
174 iface
->append_row (table_model
, source
, row
);
179 * @table_model: the e-table-model to operate on
180 * @col: column in the model to pull data from.
181 * @row: row in the model to pull data from.
183 * Return value: This function returns the value that is stored
184 * by the @table_model in column @col and row @row. The data
185 * returned can be a pointer or any data value that can be stored
188 * The data returned is typically used by an ECell renderer.
190 * The data returned must be valid until the model sends a signal that
191 * affect that piece of data. model_changed affects all data.
192 * row_changed affects the data in that row. cell_changed affects the
193 * data in that cell. rows_deleted affects all data in those rows.
194 * rows_inserted and no_change don't affect any data in this way.
197 e_table_model_value_at (ETableModel
*table_model
,
201 ETableModelInterface
*iface
;
203 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), NULL
);
205 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
206 g_return_val_if_fail (iface
->value_at
!= NULL
, NULL
);
208 return iface
->value_at (table_model
, col
, row
);
212 * e_table_model_set_value_at:
213 * @table_model: the table model to operate on.
214 * @col: the column where the data will be stored in the model.
215 * @row: the row where the data will be stored in the model.
216 * @value: the data to be stored.
218 * This function instructs the model to store the value in @data in the
219 * the @table_model at column @col and row @row. The @data typically
220 * comes from one of the ECell rendering objects.
222 * There should be an agreement between the Table Model and the user
223 * of this function about the data being stored. Typically it will
224 * be a pointer to a set of data, or a datum that fits inside a gpointer .
227 e_table_model_set_value_at (ETableModel
*table_model
,
232 ETableModelInterface
*iface
;
234 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
236 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
237 g_return_if_fail (iface
->set_value_at
!= NULL
);
239 iface
->set_value_at (table_model
, col
, row
, value
);
243 * e_table_model_is_cell_editable:
244 * @table_model: the table model to query.
245 * @col: column to query.
246 * @row: row to query.
248 * Returns: %TRUE if the cell in @table_model at @col,@row can be
249 * edited, %FALSE otherwise
252 e_table_model_is_cell_editable (ETableModel
*table_model
,
256 ETableModelInterface
*iface
;
258 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), FALSE
);
260 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
261 g_return_val_if_fail (iface
->is_cell_editable
!= NULL
, FALSE
);
263 return iface
->is_cell_editable (table_model
, col
, row
);
267 e_table_model_duplicate_value (ETableModel
*table_model
,
271 ETableModelInterface
*iface
;
273 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), NULL
);
275 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
277 if (iface
->duplicate_value
== NULL
)
280 return iface
->duplicate_value (table_model
, col
, value
);
284 e_table_model_free_value (ETableModel
*table_model
,
288 ETableModelInterface
*iface
;
290 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
292 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
294 if (iface
->free_value
!= NULL
)
295 iface
->free_value (table_model
, col
, value
);
299 e_table_model_has_save_id (ETableModel
*table_model
)
301 ETableModelInterface
*iface
;
303 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), FALSE
);
305 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
307 if (iface
->has_save_id
== NULL
)
310 return iface
->has_save_id (table_model
);
314 e_table_model_get_save_id (ETableModel
*table_model
,
317 ETableModelInterface
*iface
;
319 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), NULL
);
321 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
323 if (iface
->get_save_id
== NULL
)
326 return iface
->get_save_id (table_model
, row
);
330 e_table_model_has_change_pending (ETableModel
*table_model
)
332 ETableModelInterface
*iface
;
334 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), FALSE
);
336 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
338 if (iface
->has_change_pending
== NULL
)
341 return iface
->has_change_pending (table_model
);
345 e_table_model_initialize_value (ETableModel
*table_model
,
348 ETableModelInterface
*iface
;
350 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), NULL
);
352 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
354 if (iface
->initialize_value
== NULL
)
357 return iface
->initialize_value (table_model
, col
);
361 e_table_model_value_is_empty (ETableModel
*table_model
,
365 ETableModelInterface
*iface
;
367 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), FALSE
);
369 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
371 if (iface
->value_is_empty
== NULL
)
374 return iface
->value_is_empty (table_model
, col
, value
);
378 e_table_model_value_to_string (ETableModel
*table_model
,
382 ETableModelInterface
*iface
;
384 g_return_val_if_fail (E_IS_TABLE_MODEL (table_model
), NULL
);
386 iface
= E_TABLE_MODEL_GET_INTERFACE (table_model
);
388 if (iface
->value_to_string
== NULL
)
389 return g_strdup ("");
391 return iface
->value_to_string (table_model
, col
, value
);
399 for (i
= 0; i
< depth
; i
++)
405 e_table_model_pre_change (ETableModel
*table_model
)
407 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
409 if (table_model_is_frozen (table_model
))
414 g_signal_emit (table_model
, signals
[MODEL_PRE_CHANGE
], 0);
419 * e_table_model_no_change:
420 * @table_model: the table model to notify of the lack of a change
422 * Use this function to notify any views of this table model that
423 * the contents of the table model have changed. This will emit
424 * the signal "model_no_change" on the @table_model object.
426 * It is preferable to use the e_table_model_row_changed() and
427 * the e_table_model_cell_changed() to notify of smaller changes
428 * than to invalidate the entire model, as the views might have
429 * ways of caching the information they render from the model.
432 e_table_model_no_change (ETableModel
*table_model
)
434 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
436 if (table_model_is_frozen (table_model
))
441 g_signal_emit (table_model
, signals
[MODEL_NO_CHANGE
], 0);
446 * e_table_model_changed:
447 * @table_model: the table model to notify of the change
449 * Use this function to notify any views of this table model that
450 * the contents of the table model have changed. This will emit
451 * the signal "model_changed" on the @table_model object.
453 * It is preferable to use the e_table_model_row_changed() and
454 * the e_table_model_cell_changed() to notify of smaller changes
455 * than to invalidate the entire model, as the views might have
456 * ways of caching the information they render from the model.
459 e_table_model_changed (ETableModel
*table_model
)
461 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
463 if (table_model_is_frozen (table_model
))
468 g_signal_emit (table_model
, signals
[MODEL_CHANGED
], 0);
473 * e_table_model_row_changed:
474 * @table_model: the table model to notify of the change
475 * @row: the row that was changed in the model.
477 * Use this function to notify any views of the table model that
478 * the contents of row @row have changed in model. This function
479 * will emit the "model_row_changed" signal on the @table_model
483 e_table_model_row_changed (ETableModel
*table_model
,
486 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
488 if (table_model_is_frozen (table_model
))
493 g_signal_emit (table_model
, signals
[MODEL_ROW_CHANGED
], 0, row
);
498 * e_table_model_cell_changed:
499 * @table_model: the table model to notify of the change
503 * Use this function to notify any views of the table model that
504 * contents of the cell at @col,@row has changed. This will emit
505 * the "model_cell_changed" signal on the @table_model
509 e_table_model_cell_changed (ETableModel
*table_model
,
513 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
515 if (table_model_is_frozen (table_model
))
521 table_model
, signals
[MODEL_CELL_CHANGED
], 0, col
, row
);
526 * e_table_model_rows_inserted:
527 * @table_model: the table model to notify of the change
528 * @row: the row that was inserted into the model.
529 * @count: The number of rows that were inserted.
531 * Use this function to notify any views of the table model that
532 * @count rows at row @row have been inserted into the model. This
533 * function will emit the "model_rows_inserted" signal on the
534 * @table_model object
537 e_table_model_rows_inserted (ETableModel
*table_model
,
541 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
543 if (table_model_is_frozen (table_model
))
549 table_model
, signals
[MODEL_ROWS_INSERTED
], 0, row
, count
);
554 * e_table_model_row_inserted:
555 * @table_model: the table model to notify of the change
556 * @row: the row that was inserted into the model.
558 * Use this function to notify any views of the table model that the
559 * row @row has been inserted into the model. This function will emit
560 * the "model_rows_inserted" signal on the @table_model object
563 e_table_model_row_inserted (ETableModel
*table_model
,
566 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
568 e_table_model_rows_inserted (table_model
, row
, 1);
572 * e_table_model_row_deleted:
573 * @table_model: the table model to notify of the change
574 * @row: the row that was deleted
575 * @count: The number of rows deleted
577 * Use this function to notify any views of the table model that
578 * @count rows at row @row have been deleted from the model. This
579 * function will emit the "model_rows_deleted" signal on the
580 * @table_model object
583 e_table_model_rows_deleted (ETableModel
*table_model
,
587 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
589 if (table_model_is_frozen (table_model
))
595 table_model
, signals
[MODEL_ROWS_DELETED
], 0, row
, count
);
600 * e_table_model_row_deleted:
601 * @table_model: the table model to notify of the change
602 * @row: the row that was deleted
604 * Use this function to notify any views of the table model that the
605 * row @row has been deleted from the model. This function will emit
606 * the "model_rows_deleted" signal on the @table_model object
609 e_table_model_row_deleted (ETableModel
*table_model
,
612 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
614 e_table_model_rows_deleted (table_model
, row
, 1);
618 e_table_model_freeze (ETableModel
*table_model
)
622 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
624 e_table_model_pre_change (table_model
);
626 data
= g_object_get_data (G_OBJECT (table_model
), "frozen");
627 data
= GINT_TO_POINTER (GPOINTER_TO_INT (data
) + 1);
628 g_object_set_data (G_OBJECT (table_model
), "frozen", data
);
632 e_table_model_thaw (ETableModel
*table_model
)
636 g_return_if_fail (E_IS_TABLE_MODEL (table_model
));
638 data
= g_object_get_data (G_OBJECT (table_model
), "frozen");
639 data
= GINT_TO_POINTER (GPOINTER_TO_INT (data
) - 1);
640 g_object_set_data (G_OBJECT (table_model
), "frozen", data
);
642 e_table_model_changed (table_model
);