summaryrefslogtreecommitdiff
path: root/finch/libgnt/gnttree.h
blob: 289851fd43c0478747b617ac73c8d359d5e42ef9 (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
/**
 * GNT - The GLib Ncurses Toolkit
 *
 * GNT is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef GNT_TREE_H
#define GNT_TREE_H

#include "gntwidget.h"
#include "gnt.h"
#include "gntcolors.h"
#include "gntkeys.h"
#include "gnttextview.h"

#define GNT_TYPE_TREE				(gnt_tree_get_gtype())
#define GNT_TREE(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TREE, GntTree))
#define GNT_TREE_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TREE, GntTreeClass))
#define GNT_IS_TREE(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_TREE))
#define GNT_IS_TREE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_TREE))
#define GNT_TREE_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_TREE, GntTreeClass))

#define GNT_TREE_FLAGS(obj)				(GNT_TREE(obj)->priv.flags)
#define GNT_TREE_SET_FLAGS(obj, flags)		(GNT_TREE_FLAGS(obj) |= flags)
#define GNT_TREE_UNSET_FLAGS(obj, flags)	(GNT_TREE_FLAGS(obj) &= ~(flags))

typedef struct _GntTree			GntTree;
typedef struct _GntTreePriv		GntTreePriv;
typedef struct _GntTreeClass		GntTreeClass;

typedef struct _GntTreeRow		GntTreeRow;
typedef struct _GntTreeCol		GntTreeCol;

struct _GntTree
{
	GntWidget parent;

	GntTreeRow *current;    /* current selection */

	GntTreeRow *top;        /* The topmost visible item */
	GntTreeRow *bottom;     /* The bottommost visible item */
	
	GntTreeRow *root;       /* The root of all evil */
	
	GList *list;            /* List of GntTreeRow s */
	GHashTable *hash;       /* We need this for quickly referencing the rows */
	guint (*hash_func)(gconstpointer);
	gboolean (*hash_eq_func)(gconstpointer, gconstpointer);
	GDestroyNotify key_destroy;
	GDestroyNotify value_destroy;

	int ncol;               /* No. of columns */
	struct _GntTreeColInfo
	{
		int width;
		char *title;
		gboolean invisible;
	} *columns;             /* Would a GList be better? */
	gboolean show_title;
	gboolean show_separator; /* Whether to show column separators */

	GString *search;
	int search_timeout;

	GCompareFunc compare;
};

struct _GntTreeClass
{
	GntWidgetClass parent;

	void (*selection_changed)(GntTreeRow *old, GntTreeRow * current);
	void (*toggled)(GntTree *tree, gpointer key);

	void (*gnt_reserved1)(void);
	void (*gnt_reserved2)(void);
	void (*gnt_reserved3)(void);
	void (*gnt_reserved4)(void);
};

G_BEGIN_DECLS

/**
 * 
 *
 * @return
 */
GType gnt_tree_get_gtype(void);

/**
 * 
 *
 * @return
 */
GntWidget * gnt_tree_new(void);

      /* A tree with just one column */

/**
 * 
 * @param columns
 *
 * @return
 */
GntWidget * gnt_tree_new_with_columns(int columns);

/**
 * 
 * @param tree
 * @param rows
 */
void gnt_tree_set_visible_rows(GntTree *tree, int rows);

/**
 * 
 * @param tree
 *
 * @return
 */
int gnt_tree_get_visible_rows(GntTree *tree);

/**
 * 
 * @param tree
 * @param count
 */
void gnt_tree_scroll(GntTree *tree, int count);

/**
 * 
 * @param tree
 * @param key
 * @param row
 * @param parent
 * @param bigbro
 *
 * @return
 */
GntTreeRow * gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro);

/**
 * 
 * @param tree
 * @param key
 * @param row
 * @param parent
 *
 * @return
 */
GntTreeRow * gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent);

/**
 * 
 * @param tree
 *
 * @return
 */
gpointer gnt_tree_get_selection_data(GntTree *tree);

/* Returned string needs to be freed */
/**
 * 
 * @param tree
 *
 * @return
 */
char * gnt_tree_get_selection_text(GntTree *tree);

/**
 * 
 * @param tree
 *
 * @return
 */
GList * gnt_tree_get_selection_text_list(GntTree *tree);

/**
 *
 * @param tree
 *
 * @constreturn
 */
GList *gnt_tree_get_rows(GntTree *tree);

/**
 * 
 * @param tree
 * @param key
 */
void gnt_tree_remove(GntTree *tree, gpointer key);

/**
 * 
 * @param tree
 */
void gnt_tree_remove_all(GntTree *tree);

/* Returns the visible line number of the selected row */
/**
 * 
 * @param tree
 *
 * @return
 */
int gnt_tree_get_selection_visible_line(GntTree *tree);

/**
 * 
 * @param tree
 * @param key
 * @param colno
 * @param text
 */
void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text);

/**
 * 
 * @param tree
 * @param key
 * @param row
 * @param parent
 * @param bigbro
 *
 * @return
 */
GntTreeRow * gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro);

/**
 * 
 * @param tree
 * @param key
 * @param set
 */
void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set);

/**
 * 
 * @param tree
 * @param key
 *
 * @return
 */
gboolean gnt_tree_get_choice(GntTree *tree, void *key);

/**
 * 
 * @param tree
 * @param key
 * @param flags
 */
void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags);

/**
 * 
 * @param key
 */
void gnt_tree_set_selected(GntTree *tree , void *key);

/**
 * 
 * @param tree
 *
 * @return
 */
GntTreeRow * gnt_tree_create_row(GntTree *tree, ...);

/**
 * 
 * @param tree
 * @param list
 *
 * @return
 */
GntTreeRow * gnt_tree_create_row_from_list(GntTree *tree, GList *list);

/**
 * 
 * @param tree
 * @param col
 * @param width
 */
void gnt_tree_set_col_width(GntTree *tree, int col, int width);

/**
 * 
 * @param tree
 */
void gnt_tree_set_column_titles(GntTree *tree, ...);

/**
 * 
 * @param tree
 * @param set
 */
void gnt_tree_set_show_title(GntTree *tree, gboolean set);

/**
 * 
 * @param tree
 * @param func
 */
void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func);

/**
 * 
 * @param tree
 * @param key
 * @param expanded
 */
void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded);

/**
 * 
 * @param tree
 * @param set
 */
void gnt_tree_set_show_separator(GntTree *tree, gboolean set);

/**
 * 
 * @param tree
 * @param row
 */
void gnt_tree_sort_row(GntTree *tree, void *row);

/* This will try to automatically adjust the width of the columns in the tree */
/**
 * 
 * @param tree
 */
void gnt_tree_adjust_columns(GntTree *tree);

/**
 * 
 * @param tree
 * @param hash
 * @param eq
 * @param kd
 */
void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd);

/* This can be useful when, for example, we want to store some data
 * which we don't want/need to display. */
/**
 * 
 * @param tree
 * @param col
 * @param vis
 */
void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis);

G_END_DECLS

/* The following functions should NOT be used by applications. */

/* This should be called by the subclasses of GntTree's in their _new function */
/**
 * 
 * @param tree
 * @param col
 */
void _gnt_tree_init_internals(GntTree *tree, int col);

#endif /* GNT_TREE_H */