summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-ctree.h
blob: 1802b3c3499c4229fd6e6e16168d95e0c8a5f408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball, Josh MacDonald
 * Copyright (C) 1997-1998 Jay Painter <jpaint@serv.net><jpaint@gimp.org>
 *
 * NautilusCTree widget for GTK+
 * Copyright (C) 1998 Lars Hamann and Stefan Jeske
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

#ifndef NAUTILUS_CTREE_H
#define NAUTILUS_CTREE_H

#include <gtk/gtkclist.h>

#ifdef __cplusplus
extern "C" {
#endif				/* __cplusplus */

#define NAUTILUS_TYPE_CTREE            		(nautilus_ctree_get_type ())
#define NAUTILUS_CTREE(obj)            		(GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_CTREE, NautilusCTree))
#define NAUTILUS_CTREE_CLASS(klass)    		(GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_CTREE, NautilusCTreeClass))
#define NAUTILUS_IS_CTREE(obj)         		(GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_CTREE))
#define NAUTILUS_IS_CTREE_CLASS(klass) 		(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_CTREE))

#define NAUTILUS_CTREE_ROW(_node_) 		((NautilusCTreeRow *)(((GList *)(_node_))->data))
#define NAUTILUS_CTREE_NODE(_node_) 		((NautilusCTreeNode *)((_node_)))
#define NAUTILUS_CTREE_NODE_NEXT(_nnode_) 	((NautilusCTreeNode *)(((GList *)(_nnode_))->next))
#define NAUTILUS_CTREE_NODE_PREV(_pnode_) 	((NautilusCTreeNode *)(((GList *)(_pnode_))->prev))
#define NAUTILUS_CTREE_FUNC(_func_) 		((NautilusCTreeFunc)(_func_))

typedef enum
{
	NAUTILUS_CTREE_POS_BEFORE,
	NAUTILUS_CTREE_POS_AS_CHILD,
	NAUTILUS_CTREE_POS_AFTER
} NautilusCTreePos;

typedef enum
{
	NAUTILUS_CTREE_LINES_NONE,
	NAUTILUS_CTREE_LINES_SOLID,
	NAUTILUS_CTREE_LINES_DOTTED,
	NAUTILUS_CTREE_LINES_TABBED
} NautilusCTreeLineStyle;

typedef enum
{
	NAUTILUS_CTREE_EXPANDER_TRIANGLE
} NautilusCTreeExpanderStyle;

typedef enum
{
	NAUTILUS_CTREE_EXPANSION_EXPAND,
	NAUTILUS_CTREE_EXPANSION_EXPAND_RECURSIVE,
	NAUTILUS_CTREE_EXPANSION_COLLAPSE,
	NAUTILUS_CTREE_EXPANSION_COLLAPSE_RECURSIVE,
	NAUTILUS_CTREE_EXPANSION_TOGGLE,
	NAUTILUS_CTREE_EXPANSION_TOGGLE_RECURSIVE
} NautilusCTreeExpansionType;

typedef struct _NautilusCTree      NautilusCTree;
typedef struct _NautilusCTreeClass NautilusCTreeClass;
typedef struct _NautilusCTreeRow   NautilusCTreeRow;
typedef struct _NautilusCTreeNode  NautilusCTreeNode;

typedef void (*NautilusCTreeFunc) 	(NautilusCTree     *ctree,
			      		 NautilusCTreeNode *node,
			      		 gpointer      data);

typedef gboolean (*NautilusCTreeGNodeFunc) (NautilusCTree     *ctree,
					    guint         depth,
					    GNode        *gnode,
					    NautilusCTreeNode *cnode,
					    gpointer      data);

typedef gboolean (*NautilusCTreeCompareDragFunc) (NautilusCTree     *ctree,
						  NautilusCTreeNode *source_node,
						  NautilusCTreeNode *new_parent,
						  NautilusCTreeNode *new_sibling);

struct _NautilusCTree
{
	GtkCList clist;
	
	GdkGC *lines_gc;
	
	gint tree_indent;
	gint tree_spacing;
	gint tree_column;
	
	guint line_style     : 2;
	guint show_stub      : 1;
	
	NautilusCTreeNode *prelight_node;

	NautilusCTreeRow *dnd_prelighted_row;

	NautilusCTreeCompareDragFunc drag_compare;
};

struct _NautilusCTreeClass
{
  GtkCListClass parent_class;
  
  void (*tree_select_row)   (NautilusCTree     *ctree,
			     NautilusCTreeNode *row,
			     gint          column);
  void (*tree_unselect_row) (NautilusCTree     *ctree,
			     NautilusCTreeNode *row,
			     gint          column);
  void (*tree_expand)       (NautilusCTree     *ctree,
			     NautilusCTreeNode *node);
  void (*tree_collapse)     (NautilusCTree     *ctree,
			     NautilusCTreeNode *node);
  void (*tree_move)         (NautilusCTree     *ctree,
			     NautilusCTreeNode *node,
			     NautilusCTreeNode *new_parent,
			     NautilusCTreeNode *new_sibling);
  void (*change_focus_row_expansion) (NautilusCTree *ctree,
				      NautilusCTreeExpansionType action);
};

struct _NautilusCTreeRow
{
	GtkCListRow row;
  
	NautilusCTreeNode *parent;
	NautilusCTreeNode *sibling;
	NautilusCTreeNode *children;
  
	GdkPixmap *pixmap_closed;
	GdkBitmap *mask_closed;
	GdkPixmap *pixmap_opened;
	GdkBitmap *mask_opened;
  
	guint16 level;
  
	guint is_leaf  : 1;
	guint expanded : 1;

	gboolean mouse_down;
	gboolean in_hotspot;

};

struct _NautilusCTreeNode {
  GList list;
};


/***********************************************************
 *           Creation, insertion, deletion                 *
 ***********************************************************/

GtkType nautilus_ctree_get_type                       (void);
void nautilus_ctree_construct                         (NautilusCTree          *ctree,
						       gint                    columns, 
						       gint                    tree_column,
						       gchar                  *titles[]);
GtkWidget * nautilus_ctree_new_with_titles            (gint                    columns, 
						       gint                    tree_column,
						       gchar                  *titles[]);
GtkWidget * nautilus_ctree_new                        (gint                    columns, 
						       gint                    tree_column);
NautilusCTreeNode * nautilus_ctree_insert_node        (NautilusCTree          *ctree,
						       NautilusCTreeNode      *parent, 
						       NautilusCTreeNode      *sibling,
						       gchar                  *text[],
						       guint8                  spacing,
						       GdkPixmap              *pixmap_closed,
						       GdkBitmap              *mask_closed,
						       GdkPixmap              *pixmap_opened,
						       GdkBitmap              *mask_opened,
						       gboolean                is_leaf,
						       gboolean                expanded);
void nautilus_ctree_remove_node                       (NautilusCTree          *ctree, 
						       NautilusCTreeNode      *node);
NautilusCTreeNode * nautilus_ctree_insert_gnode       (NautilusCTree          *ctree,
						       NautilusCTreeNode      *parent,
						       NautilusCTreeNode      *sibling,
						       GNode                  *gnode,
						       NautilusCTreeGNodeFunc  func,
						       gpointer                data);
GNode * nautilus_ctree_export_to_gnode                (NautilusCTree          *ctree,
						       GNode                  *parent,
						       GNode                  *sibling,
						       NautilusCTreeNode      *node,
						       NautilusCTreeGNodeFunc  func,
						       gpointer                data);

/***********************************************************
 *  Generic recursive functions, querying / finding tree   *
 *  information                                            *
 ***********************************************************/

void nautilus_ctree_post_recursive                    (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node,
						       NautilusCTreeFunc  func,
						       gpointer      data);
void nautilus_ctree_post_recursive_to_depth           (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node,
						       gint          depth,
						       NautilusCTreeFunc  func,
						       gpointer      data);
void nautilus_ctree_pre_recursive                     (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node,
						       NautilusCTreeFunc  func,
						       gpointer      data);
void nautilus_ctree_pre_recursive_to_depth            (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node,
						       gint          depth,
						       NautilusCTreeFunc  func,
						       gpointer      data);
gboolean nautilus_ctree_is_viewable                   (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node);
NautilusCTreeNode * nautilus_ctree_last                    (NautilusCTree     *ctree,
							    NautilusCTreeNode *node);
NautilusCTreeNode * nautilus_ctree_find_node_ptr           (NautilusCTree     *ctree,
							    NautilusCTreeRow  *ctree_row);
NautilusCTreeNode * nautilus_ctree_node_nth                (NautilusCTree     *ctree,
							    int         row);
gboolean nautilus_ctree_find                          (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       NautilusCTreeNode *child);
gboolean nautilus_ctree_is_ancestor                   (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       NautilusCTreeNode *child);
NautilusCTreeNode * nautilus_ctree_find_by_row_data        (NautilusCTree     *ctree,
							    NautilusCTreeNode *node,
							    gpointer      data);
/* returns a GList of all NautilusCTreeNodes with row->data == data. */
GList * nautilus_ctree_find_all_by_row_data           (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gpointer      data);
NautilusCTreeNode * nautilus_ctree_find_by_row_data_custom (NautilusCTree     *ctree,
							    NautilusCTreeNode *node,
							    gpointer      data,
							    GCompareFunc  func);
/* returns a GList of all NautilusCTreeNodes with row->data == data. */
GList * nautilus_ctree_find_all_by_row_data_custom    (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gpointer      data,
						       GCompareFunc  func);
gboolean nautilus_ctree_is_hot_spot                   (NautilusCTree     *ctree,
						       gint          x,
						       gint          y);

/***********************************************************
 *   Tree signals : move, expand, collapse, (un)select     *
 ***********************************************************/

void nautilus_ctree_move                              (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       NautilusCTreeNode *new_parent, 
						       NautilusCTreeNode *new_sibling);
void nautilus_ctree_expand                            (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);
void nautilus_ctree_expand_recursive                  (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);
void nautilus_ctree_expand_to_depth                   (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          depth);
void nautilus_ctree_collapse                          (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);
void nautilus_ctree_collapse_recursive                (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);
void nautilus_ctree_collapse_to_depth                 (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          depth);
void nautilus_ctree_toggle_expansion                  (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);
void nautilus_ctree_toggle_expansion_recursive        (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);
void nautilus_ctree_select                            (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node);
void nautilus_ctree_select_recursive                  (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node);
void nautilus_ctree_unselect                          (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node);
void nautilus_ctree_unselect_recursive                (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node);
void nautilus_ctree_real_select_recursive             (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node, 
						       gint          state);
void nautilus_ctree_draw_node 			 (NautilusCTree 	*ctree, 
						  NautilusCTreeNode 	*node);

/***********************************************************
 *           Analogons of GtkCList functions               *
 ***********************************************************/

void nautilus_ctree_node_set_text                     (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column,
						       const gchar  *text);
void nautilus_ctree_node_set_pixmap                   (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column,
						       GdkPixmap    *pixmap,
						       GdkBitmap    *mask);
void nautilus_ctree_node_set_pixtext                  (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column,
						       const gchar  *text,
						       guint8        spacing,
						       GdkPixmap    *pixmap,
						       GdkBitmap    *mask);
void nautilus_ctree_set_node_info                     (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       const gchar  *text,
						       guint8        spacing,
						       GdkPixmap    *pixmap_closed,
						       GdkBitmap    *mask_closed,
						       GdkPixmap    *pixmap_opened,
						       GdkBitmap    *mask_opened,
						       gboolean      is_leaf,
						       gboolean      expanded);
void nautilus_ctree_node_set_shift                    (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column,
						       gint          vertical,
						       gint          horizontal);
void nautilus_ctree_node_set_selectable               (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gboolean      selectable);
gboolean nautilus_ctree_node_get_selectable           (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);
GtkCellType nautilus_ctree_node_get_cell_type         (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column);
gint nautilus_ctree_node_get_text                     (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column,
						       gchar       **text);
gint nautilus_ctree_node_get_pixmap                   (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column,
						       GdkPixmap   **pixmap,
						       GdkBitmap   **mask);
gint nautilus_ctree_node_get_pixtext                  (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column,
						       gchar       **text,
						       guint8       *spacing,
						       GdkPixmap   **pixmap,
						       GdkBitmap   **mask);
gint nautilus_ctree_get_node_info                     (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gchar       **text,
						       guint8       *spacing,
						       GdkPixmap   **pixmap_closed,
						       GdkBitmap   **mask_closed,
						       GdkPixmap   **pixmap_opened,
						       GdkBitmap   **mask_opened,
						       gboolean     *is_leaf,
						       gboolean     *expanded);

void nautilus_ctree_set_prelight                 (NautilusCTree *ctree,
						  int            y);

void nautilus_ctree_node_set_row_style           (NautilusCTree     *ctree,
						  NautilusCTreeNode *node,
						  GtkStyle     *style);
GtkStyle * nautilus_ctree_node_get_row_style          (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);
void nautilus_ctree_node_set_cell_style               (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column,
						       GtkStyle     *style);
GtkStyle * nautilus_ctree_node_get_cell_style         (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column);
void nautilus_ctree_node_set_foreground               (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       GdkColor     *color);
void nautilus_ctree_node_set_background               (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       GdkColor     *color);
void nautilus_ctree_node_set_row_data                 (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gpointer      data);
void nautilus_ctree_node_set_row_data_full            (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gpointer      data,
						       GtkDestroyNotify destroy);
gpointer nautilus_ctree_node_get_row_data             (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);
void nautilus_ctree_node_moveto                       (NautilusCTree     *ctree,
						       NautilusCTreeNode *node,
						       gint          column,
						       gfloat        row_align,
						       gfloat        col_align);
GtkVisibility nautilus_ctree_node_is_visible          (NautilusCTree     *ctree,
						       NautilusCTreeNode *node);

/***********************************************************
 *             NautilusCTree specific functions            *
 ***********************************************************/

void nautilus_ctree_set_indent            	(NautilusCTree        		*ctree, 
					   	 gint                     	indent);
void nautilus_ctree_set_spacing           	(NautilusCTree                	*ctree, 
				      		 gint                     	spacing);
void nautilus_ctree_set_show_stub         	(NautilusCTree                	*ctree, 
				      		 gboolean                 	show_stub);
void nautilus_ctree_set_line_style        	(NautilusCTree                	*ctree, 
				      		 NautilusCTreeLineStyle        	line_style);
void nautilus_ctree_set_drag_compare_func 	(NautilusCTree     	      	*ctree,
				      		 NautilusCTreeCompareDragFunc  	cmp_func);

/***********************************************************
 *             Tree sorting functions                      *
 ***********************************************************/

void nautilus_ctree_sort_node                         (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node);
void nautilus_ctree_sort_recursive                    (NautilusCTree     *ctree, 
						       NautilusCTreeNode *node);



#ifdef __cplusplus
}
#endif				/* __cplusplus */

#endif				/* NAUTILUS_CTREE_H */