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  *
18  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
19  *
20  */
21 
22 #if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
23 #error "Only <e-util/e-util.h> should be included directly."
24 #endif
25 
26 #ifndef E_TREE_H
27 #define E_TREE_H
28 
29 #include <gtk/gtk.h>
30 #include <libxml/tree.h>
31 #include <libgnomecanvas/libgnomecanvas.h>
32 
33 #include <e-util/e-printable.h>
34 #include <e-util/e-table-extras.h>
35 #include <e-util/e-table-item.h>
36 #include <e-util/e-table-specification.h>
37 #include <e-util/e-table-state.h>
38 #include <e-util/e-tree-model.h>
39 #include <e-util/e-tree-table-adapter.h>
40 #include <e-util/e-tree-selection-model.h>
41 
42 /* Standard GObject macros */
43 #define E_TYPE_TREE \
44 	(e_tree_get_type ())
45 #define E_TREE(obj) \
46 	(G_TYPE_CHECK_INSTANCE_CAST \
47 	((obj), E_TYPE_TREE, ETree))
48 #define E_TREE_CLASS(cls) \
49 	(G_TYPE_CHECK_CLASS_CAST \
50 	((cls), E_TYPE_TREE, ETreeClass))
51 #define E_IS_TREE(obj) \
52 	(G_TYPE_CHECK_INSTANCE_TYPE \
53 	((obj), E_TYPE_TREE))
54 #define E_IS_TREE_CLASS(cls) \
55 	(G_TYPE_CHECK_CLASS_TYPE \
56 	((cls), E_TYPE_TREE))
57 #define E_TREE_GET_CLASS(obj) \
58 	(G_TYPE_INSTANCE_GET_CLASS \
59 	((obj), E_TYPE_TREE))
60 
61 G_BEGIN_DECLS
62 
63 typedef struct _ETree ETree;
64 typedef struct _ETreeClass ETreeClass;
65 typedef struct _ETreePrivate ETreePrivate;
66 
67 struct _ETree {
68 	GtkTable parent;
69 	ETreePrivate *priv;
70 };
71 
72 struct _ETreeClass {
73 	GtkTableClass parent_class;
74 
75 	void		(*cursor_change)	(ETree *tree,
76 						 gint row,
77 						 ETreePath path);
78 	void		(*cursor_activated)	(ETree *tree,
79 						 gint row,
80 						 ETreePath path);
81 	void		(*selection_change)	(ETree *tree);
82 	void		(*double_click)		(ETree *tree,
83 						 gint row,
84 						 ETreePath path,
85 						 gint col,
86 						 GdkEvent *event);
87 	gboolean	(*right_click)		(ETree *tree,
88 						 gint row,
89 						 ETreePath path,
90 						 gint col,
91 						 GdkEvent *event);
92 	gboolean	(*click)		(ETree *tree,
93 						 gint row,
94 						 ETreePath path,
95 						 gint col,
96 						 GdkEvent *event);
97 	gboolean	(*key_press)		(ETree *tree,
98 						 gint row,
99 						 ETreePath path,
100 						 gint col,
101 						 GdkEvent *event);
102 	gboolean	(*start_drag)		(ETree *tree,
103 						 gint row,
104 						 ETreePath path,
105 						 gint col,
106 						 GdkEvent *event);
107 	void		(*state_change)		(ETree *tree);
108 	gboolean	(*white_space_event)	(ETree *tree,
109 						 GdkEvent *event);
110 
111 	/* Source side drag signals */
112 	void		(*tree_drag_begin)	(ETree *tree,
113 						 gint row,
114 						 ETreePath path,
115 						 gint col,
116 						 GdkDragContext *context);
117 	void		(*tree_drag_end)	(ETree *tree,
118 						 gint row,
119 						 ETreePath path,
120 						 gint col,
121 						 GdkDragContext *context);
122 	void		(*tree_drag_data_get)	(ETree *tree,
123 						 gint row,
124 						 ETreePath path,
125 						 gint col,
126 						 GdkDragContext *context,
127 						 GtkSelectionData *selection_data,
128 						 guint info,
129 						 guint time);
130 	void		(*tree_drag_data_delete)
131 						(ETree *tree,
132 						 gint row,
133 						 ETreePath path,
134 						 gint col,
135 						 GdkDragContext *context);
136 
137 	/* Target side drag signals */
138 	void		(*tree_drag_leave)	(ETree *tree,
139 						 gint row,
140 						 ETreePath path,
141 						 gint col,
142 						 GdkDragContext *context,
143 						 guint time);
144 	gboolean	(*tree_drag_motion)	(ETree *tree,
145 						 gint row,
146 						 ETreePath path,
147 						 gint col,
148 						 GdkDragContext *context,
149 						 gint x,
150 						 gint y,
151 						 guint time);
152 	gboolean	(*tree_drag_drop)	(ETree *tree,
153 						 gint row,
154 						 ETreePath path,
155 						 gint col,
156 						 GdkDragContext *context,
157 						 gint x,
158 						 gint y,
159 						 guint time);
160 	void		(*tree_drag_data_received)
161 						(ETree *tree,
162 						 gint row,
163 						 ETreePath path,
164 						 gint col,
165 						 GdkDragContext *context,
166 						 gint x,
167 						 gint y,
168 						 GtkSelectionData *selection_data,
169 						 guint info,
170 						 guint time);
171 };
172 
173 GType		e_tree_get_type			(void) G_GNUC_CONST;
174 gboolean	e_tree_construct		(ETree *tree,
175 						 ETreeModel *etm,
176 						 ETableExtras *ete,
177 						 ETableSpecification *specification);
178 GtkWidget *	e_tree_new			(ETreeModel *etm,
179 						 ETableExtras *ete,
180 						 ETableSpecification *specification);
181 
182 /* To save the state */
183 ETableState *	e_tree_get_state_object		(ETree *tree);
184 ETableSpecification *
185 		e_tree_get_spec			(ETree *tree);
186 
187 /* note that it is more efficient to provide the state at creation time */
188 void		e_tree_set_state_object		(ETree *tree,
189 						 ETableState *state);
190 void		e_tree_show_cursor_after_reflow	(ETree *tree);
191 
192 void		e_tree_set_cursor		(ETree *tree,
193 						 ETreePath path);
194 
195 /* NULL means we don't have the cursor. */
196 ETreePath	e_tree_get_cursor		(ETree *tree);
197 void		e_tree_path_foreach		(ETree *tree,
198 						 ETreeForeachFunc callback,
199 						 gpointer closure);
200 void		e_tree_get_cell_at		(ETree *tree,
201 						 gint x,
202 						 gint y,
203 						 gint *row_return,
204 						 gint *col_return);
205 void		e_tree_get_cell_geometry	(ETree *tree,
206 						 gint row,
207 						 gint col,
208 						 gint *x_return,
209 						 gint *y_return,
210 						 gint *width_return,
211 						 gint *height_return);
212 
213 /* Useful accessors */
214 ETreeModel *	e_tree_get_model		(ETree *tree);
215 ESelectionModel *
216 		e_tree_get_selection_model	(ETree *tree);
217 ETreeTableAdapter *
218 		e_tree_get_table_adapter	(ETree *tree);
219 
220 /* Drag & drop stuff. */
221 
222 /* Source side */
223 void		e_tree_drag_source_set		(ETree *tree,
224 						 GdkModifierType start_button_mask,
225 						 const GtkTargetEntry *targets,
226 						 gint n_targets,
227 						 GdkDragAction actions);
228 void		e_tree_drag_source_unset	(ETree *tree);
229 
230 /* There probably should be functions for setting the targets
231  * as a GtkTargetList
232  */
233 GdkDragContext *e_tree_drag_begin		(ETree *tree,
234 						 gint row,
235 						 gint col,
236 						 GtkTargetList *targets,
237 						 GdkDragAction actions,
238 						 gint button,
239 						 GdkEvent *event);
240 
241 gboolean	e_tree_is_dragging		(ETree *tree);
242 
243 ETableItem *	e_tree_get_item			(ETree *tree);
244 
245 GnomeCanvasItem *
246 		e_tree_get_header_item		(ETree *tree);
247 
248 void		e_tree_set_info_message		(ETree *tree,
249 						 const gchar *info_message);
250 
251 void		e_tree_freeze_state_change	(ETree *tree);
252 void		e_tree_thaw_state_change	(ETree *tree);
253 
254 gboolean	e_tree_is_editing		(ETree *tree);
255 
256 gboolean	e_tree_get_grouped_view		(ETree *tree);
257 void		e_tree_set_grouped_view		(ETree *tree,
258 						 gboolean grouped_view);
259 gboolean	e_tree_get_sort_children_ascending
260 						(ETree *tree);
261 void		e_tree_set_sort_children_ascending
262 						(ETree *tree,
263 						 gboolean sort_children_ascending);
264 void		e_tree_customize_view		(ETree *tree);
265 
266 G_END_DECLS
267 
268 #endif /* E_TREE_H */
269 
270