1 /*
2  * This program is free software; you can redistribute it and/or modify it
3  * under the terms of the GNU Lesser General Public License as published by
4  * the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful, but
7  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9  * for more details.
10  *
11  * You should have received a copy of the GNU Lesser General Public License
12  * along with this program; if not, see <http://www.gnu.org/licenses/>.
13  *
14  *
15  * Authors:
16  *		Chris Lahey <clahey@ximian.com>
17  *		Miguel de Icaza <miguel@ximian.com>
18  *
19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
20  *
21  */
22 
23 #if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
24 #error "Only <e-util/e-util.h> should be included directly."
25 #endif
26 
27 #ifndef _E_TABLE_H_
28 #define _E_TABLE_H_
29 
30 #include <libgnomecanvas/libgnomecanvas.h>
31 #include <gtk/gtk.h>
32 #include <libxml/tree.h>
33 
34 #include <e-util/e-printable.h>
35 #include <e-util/e-table-extras.h>
36 #include <e-util/e-table-group.h>
37 #include <e-util/e-table-header.h>
38 #include <e-util/e-table-item.h>
39 #include <e-util/e-table-model.h>
40 #include <e-util/e-table-search.h>
41 #include <e-util/e-table-selection-model.h>
42 #include <e-util/e-table-sort-info.h>
43 #include <e-util/e-table-sorter.h>
44 #include <e-util/e-table-specification.h>
45 #include <e-util/e-table-state.h>
46 
47 /* Standard GObject macros */
48 #define E_TYPE_TABLE \
49 	(e_table_get_type ())
50 #define E_TABLE(obj) \
51 	(G_TYPE_CHECK_INSTANCE_CAST \
52 	((obj), E_TYPE_TABLE, ETable))
53 #define E_TABLE_CLASS(cls) \
54 	(G_TYPE_CHECK_CLASS_CAST \
55 	((cls), E_TYPE_TABLE, ETableClass))
56 #define E_IS_TABLE(obj) \
57 	(G_TYPE_CHECK_INSTANCE_TYPE \
58 	((obj), E_TYPE_TABLE))
59 #define E_IS_TABLE_CLASS(cls) \
60 	(G_TYPE_CHECK_CLASS_TYPE \
61 	((cls), E_TYPE_TABLE))
62 #define E_TABLE_GET_CLASS(obj) \
63 	(G_TYPE_INSTANCE_GET_CLASS \
64 	((obj), E_TYPE_TABLE, ETableClass))
65 
66 G_BEGIN_DECLS
67 
68 typedef struct _ETable ETable;
69 typedef struct _ETablePrivate ETablePrivate;
70 typedef struct _ETableClass ETableClass;
71 
72 typedef struct _ETableDragSourceSite ETableDragSourceSite;
73 
74 typedef enum {
75 	E_TABLE_CURSOR_LOC_NONE = 0,
76 	E_TABLE_CURSOR_LOC_ETCTA = 1 << 0,
77 	E_TABLE_CURSOR_LOC_TABLE = 1 << 1
78 } ETableCursorLoc;
79 
80 struct _ETable {
81 	GtkTable parent;
82 
83 	ETablePrivate *priv;
84 
85 	ETableModel *model;
86 
87 	ETableHeader *full_header, *header;
88 
89 	GnomeCanvasItem *canvas_vbox;
90 	ETableGroup *group;
91 
92 	ETableSortInfo *sort_info;
93 	ETableSorter *sorter;
94 
95 	ETableSelectionModel *selection;
96 	ETableCursorLoc cursor_loc;
97 	ETableSpecification *spec;
98 
99 	ETableSearch *search;
100 
101 	ETableCol *current_search_col;
102 
103 	guint	 search_search_id;
104 	guint	 search_accept_id;
105 
106 	gint table_model_change_id;
107 	gint table_row_change_id;
108 	gint table_cell_change_id;
109 	gint table_rows_inserted_id;
110 	gint table_rows_deleted_id;
111 
112 	gint group_info_change_id;
113 	gint sort_info_change_id;
114 
115 	gint structure_change_id;
116 	gint expansion_change_id;
117 	gint dimension_change_id;
118 
119 	gint reflow_idle_id;
120 	gint scroll_idle_id;
121 
122 	GnomeCanvas *header_canvas, *table_canvas;
123 
124 	GnomeCanvasItem *header_item, *root;
125 
126 	GnomeCanvasItem *white_item;
127 
128 	gint length_threshold;
129 
130 	gint rebuild_idle_id;
131 	guint need_rebuild : 1;
132 	guint size_allocated : 1;
133 
134 	/*
135 	 * Configuration settings
136 	 */
137 	guint alternating_row_colors : 1;
138 	guint horizontal_draw_grid : 1;
139 	guint vertical_draw_grid : 1;
140 	guint draw_focus : 1;
141 	guint row_selection_active : 1;
142 
143 	guint horizontal_scrolling : 1;
144 	guint horizontal_resize : 1;
145 
146 	guint is_grouped : 1;
147 
148 	guint scroll_direction : 4;
149 
150 	guint do_drag : 1;
151 
152 	guint uniform_row_height : 1;
153 	guint allow_grouping : 1;
154 
155 	guint always_search : 1;
156 	guint search_col_set : 1;
157 
158 	gchar *click_to_add_message;
159 	GnomeCanvasItem *click_to_add;
160 	gboolean use_click_to_add;
161 	gboolean use_click_to_add_end;
162 
163 	ECursorMode cursor_mode;
164 
165 	gint drop_row;
166 	gint drop_col;
167 	GnomeCanvasItem *drop_highlight;
168 	gint last_drop_x;
169 	gint last_drop_y;
170 	gint last_drop_time;
171 	GdkDragContext *last_drop_context;
172 
173 	gint drag_row;
174 	gint drag_col;
175 	ETableDragSourceSite *site;
176 
177 	gint header_width;
178 
179 	gchar *domain;
180 
181 	gboolean state_changed;
182 	guint state_change_freeze;
183 };
184 
185 struct _ETableClass {
186 	GtkTableClass parent_class;
187 
188 	void		(*cursor_change)	(ETable *et,
189 						 gint row);
190 	void		(*cursor_activated)	(ETable *et,
191 						 gint row);
192 	void		(*selection_change)	(ETable *et);
193 	void		(*double_click)		(ETable *et,
194 						 gint row,
195 						 gint col,
196 						 GdkEvent *event);
197 	gboolean	(*right_click)		(ETable *et,
198 						 gint row,
199 						 gint col,
200 						 GdkEvent *event);
201 	gboolean	(*click)		(ETable *et,
202 						 gint row,
203 						 gint col,
204 						 GdkEvent *event);
205 	gboolean	(*key_press)		(ETable *et,
206 						 gint row,
207 						 gint col,
208 						 GdkEvent *event);
209 	gboolean	(*start_drag)		(ETable *et,
210 						 gint row,
211 						 gint col,
212 						 GdkEvent *event);
213 	void		(*state_change)		(ETable *et);
214 	gboolean	(*white_space_event)	(ETable *et,
215 						 GdkEvent *event);
216 
217 	/* Source side drag signals */
218 	void		(*table_drag_begin)	 (ETable *table,
219 						 gint row,
220 						 gint col,
221 						 GdkDragContext *context);
222 	void		(*table_drag_end)	(ETable *table,
223 						 gint row,
224 						 gint col,
225 						 GdkDragContext *context);
226 	void		(*table_drag_data_get)	(ETable *table,
227 						 gint row,
228 						 gint col,
229 						 GdkDragContext *context,
230 						 GtkSelectionData *selection_data,
231 						 guint info,
232 						 guint time);
233 	void		(*table_drag_data_delete)
234 						(ETable *table,
235 						 gint row,
236 						 gint col,
237 						 GdkDragContext *context);
238 
239 	/* Target side drag signals */
240 	void		(*table_drag_leave)	(ETable *table,
241 						 gint row,
242 						 gint col,
243 						 GdkDragContext *context,
244 						 guint time);
245 	gboolean	(*table_drag_motion)	(ETable *table,
246 						 gint row,
247 						 gint col,
248 						 GdkDragContext *context,
249 						 gint x,
250 						 gint y,
251 						 guint time);
252 	gboolean	(*table_drag_drop)	(ETable *table,
253 						 gint row,
254 						 gint col,
255 						 GdkDragContext *context,
256 						 gint x,
257 						 gint y,
258 						 guint time);
259 	void		(*table_drag_data_received)
260 						(ETable *table,
261 						 gint row,
262 						 gint col,
263 						 GdkDragContext *context,
264 						 gint x,
265 						 gint y,
266 						 GtkSelectionData *selection_data,
267 						 guint info,
268 						 guint time);
269 };
270 
271 GType		e_table_get_type		(void) G_GNUC_CONST;
272 ETable *	e_table_construct		(ETable *e_table,
273 						 ETableModel *etm,
274 						 ETableExtras *ete,
275 						 ETableSpecification *specification);
276 GtkWidget *	e_table_new			(ETableModel *etm,
277 						 ETableExtras *ete,
278 						 ETableSpecification *specification);
279 
280 /* To save the state */
281 void		e_table_save_state		(ETable *e_table,
282 						 const gchar *filename);
283 ETableState *	e_table_get_state_object	(ETable *e_table);
284 
285 /* note that it is more efficient to provide the state at creation time */
286 void		e_table_set_state_object	(ETable *e_table,
287 						 ETableState *state);
288 void		e_table_load_state		(ETable *e_table,
289 						 const gchar *filename);
290 void		e_table_set_cursor_row		(ETable *e_table,
291 						 gint row);
292 
293 /* -1 means we don't have the cursor. This is in model rows. */
294 gint		e_table_get_cursor_row		(ETable *e_table);
295 void		e_table_selected_row_foreach	(ETable *e_table,
296 						 EForeachFunc callback,
297 						 gpointer closure);
298 gint		e_table_selected_count		(ETable *e_table);
299 EPrintable *	e_table_get_printable		(ETable *e_table);
300 gint		e_table_get_next_row		(ETable *e_table,
301 						 gint model_row);
302 gint		e_table_get_prev_row		(ETable *e_table,
303 						 gint model_row);
304 gint		e_table_model_to_view_row	(ETable *e_table,
305 						 gint model_row);
306 gint		e_table_view_to_model_row	(ETable *e_table,
307 						 gint view_row);
308 void		e_table_get_cell_at		(ETable *table,
309 						 gint x,
310 						 gint y,
311 						 gint *row_return,
312 						 gint *col_return);
313 void		e_table_get_mouse_over_cell	(ETable *table,
314 						 gint *row,
315 						 gint *col);
316 void		e_table_get_cell_geometry	(ETable *table,
317 						 gint row,
318 						 gint col,
319 						 gint *x_return,
320 						 gint *y_return,
321 						 gint *width_return,
322 						 gint *height_return);
323 
324 /* Useful accessor functions. */
325 ESelectionModel *e_table_get_selection_model	(ETable *table);
326 
327 /* Drag & drop stuff. */
328 /* Target */
329 void		e_table_drag_get_data		(ETable *table,
330 						 gint row,
331 						 gint col,
332 						 GdkDragContext *context,
333 						 GdkAtom target,
334 						 guint32 time);
335 void		e_table_drag_highlight	(ETable *table,
336 						 gint row,
337 						 gint col); /* col == -1 to highlight entire row. */
338 void		e_table_drag_unhighlight	(ETable *table);
339 void		e_table_drag_dest_set		(ETable *table,
340 						 GtkDestDefaults flags,
341 						 const GtkTargetEntry *targets,
342 						 gint n_targets,
343 						 GdkDragAction actions);
344 void		e_table_drag_dest_set_proxy	(ETable *table,
345 						 GdkWindow *proxy_window,
346 						 GdkDragProtocol protocol,
347 						 gboolean use_coordinates);
348 
349 /* There probably should be functions for setting the targets
350  * as a GtkTargetList
351  */
352 void		e_table_drag_dest_unset		(GtkWidget *widget);
353 
354 /* Source side */
355 void		e_table_drag_source_set		(ETable *table,
356 						 GdkModifierType start_button_mask,
357 						 const GtkTargetEntry *targets,
358 						 gint n_targets,
359 						 GdkDragAction actions);
360 void		e_table_drag_source_unset	(ETable *table);
361 
362 /* There probably should be functions for setting the targets
363  * as a GtkTargetList
364  */
365 GdkDragContext *e_table_drag_begin		(ETable *table,
366 						 gint row,
367 						 gint col,
368 						 GtkTargetList *targets,
369 						 GdkDragAction actions,
370 						 gint button,
371 						 GdkEvent *event);
372 
373 /* selection stuff */
374 void		e_table_select_all		(ETable *table);
375 
376 /* This function is only needed in single_selection_mode. */
377 void		e_table_right_click_up		(ETable *table);
378 
379 void		e_table_commit_click_to_add	(ETable *table);
380 
381 void		e_table_freeze_state_change	(ETable *table);
382 void		e_table_thaw_state_change	(ETable *table);
383 gboolean	e_table_is_editing		(ETable *table);
384 void		e_table_customize_view		(ETable *table);
385 void		e_table_set_info_message	(ETable *table,
386 						 const gchar *info_message);
387 
388 G_END_DECLS
389 
390 #endif /* _E_TABLE_H_ */
391 
392