1 /*
2  * e-table-model.h
3  *
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.
7  *
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
11  * for more details.
12  *
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/>.
15  *
16  */
17 
18 #if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
19 #error "Only <e-util/e-util.h> should be included directly."
20 #endif
21 
22 #ifndef E_TABLE_MODEL_H
23 #define E_TABLE_MODEL_H
24 
25 #include <glib-object.h>
26 
27 /* Standard GObject macros */
28 #define E_TYPE_TABLE_MODEL \
29 	(e_table_model_get_type ())
30 #define E_TABLE_MODEL(obj) \
31 	(G_TYPE_CHECK_INSTANCE_CAST \
32 	((obj), E_TYPE_TABLE_MODEL, ETableModel))
33 #define E_IS_TABLE_MODEL(obj) \
34 	(G_TYPE_CHECK_INSTANCE_TYPE \
35 	((obj), E_TYPE_TABLE_MODEL))
36 #define E_TABLE_MODEL_GET_INTERFACE(obj) \
37 	(G_TYPE_INSTANCE_GET_INTERFACE \
38 	((obj), E_TYPE_TABLE_MODEL, ETableModelInterface))
39 
40 G_BEGIN_DECLS
41 
42 typedef struct _ETableModel ETableModel;
43 typedef struct _ETableModelInterface ETableModelInterface;
44 
45 struct _ETableModelInterface {
46 	GTypeInterface parent_interface;
47 
48 	gint		(*column_count)		(ETableModel *table_model);
49 	gint		(*row_count)		(ETableModel *table_model);
50 	void		(*append_row)		(ETableModel *table_model,
51 						 ETableModel *source,
52 						 gint row);
53 
54 	gpointer	(*value_at)		(ETableModel *table_model,
55 						 gint col,
56 						 gint row);
57 	void		(*set_value_at)		(ETableModel *table_model,
58 						 gint col,
59 						 gint row,
60 						 gconstpointer value);
61 	gboolean	(*is_cell_editable)	(ETableModel *table_model,
62 						 gint col,
63 						 gint row);
64 
65 	gboolean	(*has_save_id)		(ETableModel *table_model);
66 	gchar *		(*get_save_id)		(ETableModel *table_model,
67 						 gint row);
68 
69 	gboolean	(*has_change_pending)	(ETableModel *table_model);
70 
71 	/* Allocate a copy of the given value. */
72 	gpointer	(*duplicate_value)	(ETableModel *table_model,
73 						 gint col,
74 						 gconstpointer value);
75 	/* Free an allocated value. */
76 	void		(*free_value)		(ETableModel *table_model,
77 						 gint col,
78 						 gpointer value);
79 	/* Return an allocated empty value. */
80 	gpointer	(*initialize_value)	(ETableModel *table_model,
81 						 gint col);
82 	/* Return TRUE if value is equivalent to an empty cell. */
83 	gboolean	(*value_is_empty)	(ETableModel *table_model,
84 						 gint col,
85 						 gconstpointer value);
86 	/* Return an allocated string. */
87 	gchar *		(*value_to_string)	(ETableModel *table_model,
88 						 gint col,
89 						 gconstpointer value);
90 
91 	/*
92 	 * Signals
93 	 */
94 
95 	/*
96 	 * These all come after the change has been made.
97 	 * No changes, cancel pre_change: no_change
98 	 * Major structural changes: model_changed
99 	 * Changes only in a row: row_changed
100 	 * Only changes in a cell: cell_changed
101 	 * A row inserted: row_inserted
102 	 * A row deleted: row_deleted
103 	 */
104 	void		(*model_pre_change)	(ETableModel *table_model);
105 
106 	void		(*model_no_change)	(ETableModel *table_model);
107 	void		(*model_changed)	(ETableModel *table_model);
108 	void		(*model_row_changed)	(ETableModel *table_model,
109 						 gint row);
110 	void		(*model_cell_changed)	(ETableModel *table_model,
111 						 gint col,
112 						 gint row);
113 	void		(*model_rows_inserted)	(ETableModel *table_model,
114 						 gint row,
115 						 gint count);
116 	void		(*model_rows_deleted)	(ETableModel *table_model,
117 						 gint row,
118 						 gint count);
119 };
120 
121 GType		e_table_model_get_type		(void) G_GNUC_CONST;
122 
123 /**/
124 gint		e_table_model_column_count	(ETableModel *table_model);
125 const gchar *	e_table_model_column_name	(ETableModel *table_model,
126 						 gint col);
127 gint		e_table_model_row_count		(ETableModel *table_model);
128 void		e_table_model_append_row	(ETableModel *table_model,
129 						 ETableModel *source,
130 						 gint row);
131 
132 /**/
133 gpointer	e_table_model_value_at		(ETableModel *table_model,
134 						 gint col,
135 						 gint row);
136 void		e_table_model_set_value_at	(ETableModel *table_model,
137 						 gint col,
138 						 gint row,
139 						 gconstpointer value);
140 gboolean	e_table_model_is_cell_editable	(ETableModel *table_model,
141 						gint col,
142 						 gint row);
143 
144 /**/
145 gboolean	e_table_model_has_save_id	(ETableModel *table_model);
146 gchar *		e_table_model_get_save_id	(ETableModel *table_model,
147 						 gint row);
148 
149 /**/
150 gboolean	e_table_model_has_change_pending
151 						(ETableModel *table_model);
152 
153 /**/
154 gpointer	e_table_model_duplicate_value	(ETableModel *table_model,
155 						 gint col,
156 						 gconstpointer value);
157 void		e_table_model_free_value	(ETableModel *table_model,
158 						 gint col,
159 						 gpointer value);
160 gpointer	e_table_model_initialize_value	(ETableModel *table_model,
161 						 gint col);
162 gboolean	e_table_model_value_is_empty	(ETableModel *table_model,
163 						 gint col,
164 						 gconstpointer value);
165 gchar *		e_table_model_value_to_string	(ETableModel *table_model,
166 						 gint col,
167 						 gconstpointer value);
168 
169 /*
170  * Routines for emitting signals on the e_table
171  */
172 void		e_table_model_pre_change	(ETableModel *table_model);
173 void		e_table_model_no_change		(ETableModel *table_model);
174 void		e_table_model_changed		(ETableModel *table_model);
175 void		e_table_model_row_changed	(ETableModel *table_model,
176 						 gint row);
177 void		e_table_model_cell_changed	(ETableModel *table_model,
178 						 gint col,
179 						 gint row);
180 void		e_table_model_rows_inserted	(ETableModel *table_model,
181 						 gint row,
182 						 gint count);
183 void		e_table_model_rows_deleted	(ETableModel *table_model,
184 						 gint row,
185 						 gint count);
186 
187 /**/
188 void		e_table_model_row_inserted	(ETableModel *table_model,
189 						 gint row);
190 void		e_table_model_row_deleted	(ETableModel *table_model,
191 						 gint row);
192 
193 void		e_table_model_freeze		(ETableModel *table_model);
194 void		e_table_model_thaw		(ETableModel *table_model);
195 
196 G_END_DECLS
197 
198 #endif /* E_TABLE_MODEL_H */
199