prefs: Remove unused hboxes.
[pidgin-git.git] / finch / libgnt / gnttree.h
blob8e238e2d47c03573b8bc638f70a46d1cb6c0f262
1 /*
2 * GNT - The GLib Ncurses Toolkit
4 * GNT is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #ifndef GNT_TREE_H
24 #define GNT_TREE_H
25 /**
26 * SECTION:gnttree
27 * @section_id: libgnt-gnttree
28 * @short_description: <filename>gnttree.h</filename>
29 * @title: Tree
32 #include "gntwidget.h"
33 #include "gnt.h"
34 #include "gntcolors.h"
35 #include "gntkeys.h"
36 #include "gnttextview.h"
38 #define GNT_TYPE_TREE (gnt_tree_get_type())
39 #define GNT_TREE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TREE, GntTree))
40 #define GNT_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TREE, GntTreeClass))
41 #define GNT_IS_TREE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_TREE))
42 #define GNT_IS_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_TREE))
43 #define GNT_TREE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_TREE, GntTreeClass))
45 #define GNT_TYPE_TREE_ROW (gnt_tree_row_get_type())
47 typedef guint (*GntTreeHashFunc)(gconstpointer key);
48 typedef gboolean (*GntTreeHashEqualityFunc)(gconstpointer a, gconstpointer b);
50 typedef struct _GntTree GntTree;
51 typedef struct _GntTreePriv GntTreePriv;
52 typedef struct _GntTreeClass GntTreeClass;
54 typedef struct _GntTreeRow GntTreeRow;
55 typedef struct _GntTreeCol GntTreeCol;
56 typedef struct _GntTreeColInfo GntTreeColInfo;
58 typedef enum {
59 GNT_TREE_COLUMN_INVISIBLE = 1 << 0,
60 GNT_TREE_COLUMN_FIXED_SIZE = 1 << 1,
61 GNT_TREE_COLUMN_BINARY_DATA = 1 << 2,
62 GNT_TREE_COLUMN_RIGHT_ALIGNED = 1 << 3,
63 } GntTreeColumnFlag;
65 struct _GntTreeColInfo
67 int width;
68 char *title;
69 int width_ratio;
70 GntTreeColumnFlag flags;
73 struct _GntTree
75 GntWidget parent;
77 GntTreeRow *current; /* current selection */
79 GntTreeRow *top; /* The topmost visible item */
80 GntTreeRow *bottom; /* The bottommost visible item */
82 GntTreeRow *root; /* The root of all evil */
84 GList *list; /* List of GntTreeRow s */
85 GHashTable *hash; /* We need this for quickly referencing the rows */
86 GntTreeHashFunc hash_func;
87 GntTreeHashEqualityFunc hash_eq_func;
88 GDestroyNotify key_destroy;
89 GDestroyNotify value_destroy;
91 int ncol; /* No. of columns */
92 GntTreeColInfo *columns; /* Would a GList be better? */
93 gboolean show_title;
94 gboolean show_separator; /* Whether to show column separators */
96 GntTreePriv *priv;
99 struct _GntTreeClass
101 GntWidgetClass parent;
103 void (*selection_changed)(GntTreeRow *old, GntTreeRow * current);
104 void (*toggled)(GntTree *tree, gpointer key);
106 /*< private >*/
107 void (*gnt_reserved1)(void);
108 void (*gnt_reserved2)(void);
109 void (*gnt_reserved3)(void);
110 void (*gnt_reserved4)(void);
113 G_BEGIN_DECLS
116 * gnt_tree_get_type:
118 * Returns: The GType for GntTree
120 GType gnt_tree_get_type(void);
123 * gnt_tree_row_get_type:
125 * Returns: The #GType for the #GntTreeRow boxed structure.
127 GType gnt_tree_row_get_type(void);
130 * gnt_tree_new:
132 * Create a tree with one column.
134 * See gnt_tree_new_with_columns().
136 * Returns: The newly created tree
138 GntWidget * gnt_tree_new(void);
141 * gnt_tree_new_with_columns:
142 * @columns: Number of columns
144 * Create a tree with a specified number of columns.
146 * See gnt_tree_new().
148 * Returns: The newly created tree
150 GntWidget * gnt_tree_new_with_columns(int columns);
153 * gnt_tree_set_visible_rows:
154 * @tree: The tree
155 * @rows: The number of rows
157 * The number of rows the tree should display at a time.
159 void gnt_tree_set_visible_rows(GntTree *tree, int rows);
162 * gnt_tree_get_visible_rows:
163 * @tree: The tree
165 * Get the number visible rows.
167 * Returns: The number of visible rows
169 int gnt_tree_get_visible_rows(GntTree *tree);
172 * gnt_tree_scroll:
173 * @tree: The tree
174 * @count: If positive, the tree will be scrolled down by count rows,
175 * otherwise, it will be scrolled up by count rows.
177 * Scroll the contents of the tree.
179 void gnt_tree_scroll(GntTree *tree, int count);
182 * gnt_tree_add_row_after:
183 * @tree: The tree
184 * @key: The key for the row
185 * @row: The row to insert
186 * @parent: The key for the parent row
187 * @bigbro: The key for the row to insert the new row after.
189 * Insert a row in the tree.
191 * See gnt_tree_create_row(), gnt_tree_add_row_last(), gnt_tree_add_choice().
193 * Returns: The inserted row
195 GntTreeRow * gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro);
198 * gnt_tree_add_row_last:
199 * @tree: The tree
200 * @key: The key for the row
201 * @row: The row to insert
202 * @parent: The key for the parent row
204 * Insert a row at the end of the tree.
206 * See gnt_tree_create_row(), gnt_tree_add_row_after(), gnt_tree_add_choice().
208 * Returns: The inserted row
210 GntTreeRow * gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent);
213 * gnt_tree_get_selection_data:
214 * @tree: The tree
216 * Get the key for the selected row.
218 * Returns: (transfer none): The key for the selected row
220 gpointer gnt_tree_get_selection_data(GntTree *tree);
223 * gnt_tree_get_selection_text:
224 * @tree: The tree
226 * Get the text displayed for the selected row.
228 * See gnt_tree_get_row_text_list(), gnt_tree_get_selection_text_list().
230 * Returns: The text, which needs to be freed by the caller
232 char * gnt_tree_get_selection_text(GntTree *tree);
235 * gnt_tree_get_row_text_list:
236 * @tree: The tree
237 * @key: A key corresponding to the row in question. If key
238 * is %NULL, the text list for the selected row will
239 * be returned.
241 * Get a list of text for a row.
243 * See gnt_tree_get_selection_text_list(), gnt_tree_get_selection_text().
245 * Returns: (transfer container) (element-type utf8): A list of texts of a row.
246 * The list and its data should be freed by the caller. The caller
247 * should make sure that if any column of the tree contains binary
248 * data, it's not freed.
250 /* TODO This leaks when used from introspection. The transfer mode for the
251 return type here should be 'full', but that would free binary data as
252 well. */
253 GList * gnt_tree_get_row_text_list(GntTree *tree, gpointer key);
256 * gnt_tree_row_get_key:
257 * @tree: The tree
258 * @row: The GntTreeRow object
260 * Get the key of a row.
262 * Returns: (transfer none): The key of the row.
264 * Since: 2.8.0 (gnt), 2.7.2 (pidgin)
266 gpointer gnt_tree_row_get_key(GntTree *tree, GntTreeRow *row);
269 * gnt_tree_row_get_next:
270 * @tree: The tree
271 * @row: The GntTreeRow object
273 * Get the next row.
275 * Returns: The next row.
277 * Since: 2.8.0 (gnt), 2.7.2 (pidgin)
279 GntTreeRow * gnt_tree_row_get_next(GntTree *tree, GntTreeRow *row);
282 * gnt_tree_row_get_prev:
283 * @tree: The tree
284 * @row: The GntTreeRow object
286 * Get the previous row.
288 * Returns: The previous row.
290 * Since: 2.8.0 (gnt), 2.7.2 (pidgin)
292 GntTreeRow * gnt_tree_row_get_prev(GntTree *tree, GntTreeRow *row);
295 * gnt_tree_row_get_child:
296 * @tree: The tree
297 * @row: The GntTreeRow object
299 * Get the child row.
301 * Returns: The child row.
303 * Since: 2.8.0 (gnt), 2.7.2 (pidgin)
305 GntTreeRow * gnt_tree_row_get_child(GntTree *tree, GntTreeRow *row);
308 * gnt_tree_row_get_parent:
309 * @tree: The tree
310 * @row: The GntTreeRow object
312 * Get the parent row.
314 * Returns: The parent row.
316 * Since: 2.8.0 (gnt), 2.7.2 (pidgin)
318 GntTreeRow * gnt_tree_row_get_parent(GntTree *tree, GntTreeRow *row);
321 * gnt_tree_get_selection_text_list:
322 * @tree: The tree
324 * Get a list of text of the current row.
326 * See gnt_tree_get_row_text_list(), gnt_tree_get_selection_text().
328 * Returns: (transfer container) (element-type utf8): A list of texts of the
329 * currently selected row. The list and its data should be freed by
330 * the caller. The caller should make sure that if any column of the
331 * tree contains binary data, it's not freed.
333 /* TODO This leaks when used from introspection. The transfer mode for the
334 return type here should be 'full', but that would free binary data as
335 well. */
336 GList * gnt_tree_get_selection_text_list(GntTree *tree);
339 * gnt_tree_get_rows:
340 * @tree: The tree
342 * Returns the list of rows in the tree.
344 * Returns: (transfer none) (element-type Gnt.TreeRow): The list of the rows.
345 * The list should not be modified by the caller.
347 GList *gnt_tree_get_rows(GntTree *tree);
350 * gnt_tree_remove:
351 * @tree: The tree
352 * @key: The key for the row to remove
354 * Remove a row from the tree.
356 void gnt_tree_remove(GntTree *tree, gpointer key);
359 * gnt_tree_remove_all:
360 * @tree: The tree
362 * Remove all the item from the tree.
364 void gnt_tree_remove_all(GntTree *tree);
367 * gnt_tree_get_selection_visible_line:
368 * @tree: The tree
370 * Get the visible line number of the selected row.
372 * Returns: The line number of the currently selected row
374 int gnt_tree_get_selection_visible_line(GntTree *tree);
377 * gnt_tree_change_text:
378 * @tree: The tree
379 * @key: The key for the row
380 * @colno: The index of the column
381 * @text: The new text
383 * Change the text of a column in a row.
385 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text);
388 * gnt_tree_add_choice:
389 * @tree: The tree
390 * @key: The key for the row
391 * @row: The row to add
392 * @parent: The parent of the row, or %NULL
393 * @bigbro: The row to insert after, or %NULL
395 * Add a checkable item in the tree.
397 * See gnt_tree_create_row(), gnt_tree_create_row_from_list(),
398 * gnt_tree_add_row_last(), gnt_tree_add_row_after().
400 * Returns: The row inserted.
402 GntTreeRow * gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro);
405 * gnt_tree_set_choice:
406 * @tree: The tree
407 * @key: The key for the row
408 * @set: %TRUE if the item should be checked, %FALSE if not
410 * Set whether a checkable item is checked or not.
412 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set);
415 * gnt_tree_get_choice:
416 * @tree: The tree
417 * @key: The key for the row
419 * Return whether a row is selected or not, where the row is a checkable item.
421 * Returns: %TRUE if the row is checked, %FALSE otherwise.
423 gboolean gnt_tree_get_choice(GntTree *tree, void *key);
426 * gnt_tree_set_row_flags:
427 * @tree: The tree
428 * @key: The key for the row
429 * @flags: The flags to set
431 * Set flags for the text in a row in the tree.
433 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags);
436 * gnt_tree_set_row_color:
437 * @tree: The tree
438 * @key: The key for the row
439 * @color: The color
441 * Set color for the text in a row in the tree.
443 * Since: 2.4.0
445 void gnt_tree_set_row_color(GntTree *tree, void *key, int color);
448 * gnt_tree_set_selected:
449 * @tree: The tree
450 * @key: The key of the row to select
452 * Select a row.
454 void gnt_tree_set_selected(GntTree *tree , void *key);
457 * gnt_tree_create_row:
458 * @tree: The tree
459 * @...: A string for each column in the tree
461 * Create a row to insert in the tree.
463 * See gnt_tree_create_row_from_list(), gnt_tree_add_row_after(),
464 * gnt_tree_add_row_last(), gnt_tree_add_choice().
466 * Returns: The row
468 GntTreeRow * gnt_tree_create_row(GntTree *tree, ...);
471 * gnt_tree_create_row_from_list:
472 * @tree: The tree
473 * @list: (element-type utf8): The list containing the text for each column
475 * Create a row from a list of text.
477 * See gnt_tree_create_row(), gnt_tree_add_row_after(), gnt_tree_add_row_last(),
478 * gnt_tree_add_choice().
480 * Returns: (transfer full): The row
482 GntTreeRow * gnt_tree_create_row_from_list(GntTree *tree, GList *list);
485 * gnt_tree_set_col_width:
486 * @tree: The tree
487 * @col: The index of the column
488 * @width: The width for the column
490 * Set the width of a column in the tree.
492 * See gnt_tree_set_column_width_ratio(), gnt_tree_set_column_resizable()
494 void gnt_tree_set_col_width(GntTree *tree, int col, int width);
497 * gnt_tree_set_column_title:
498 * @tree: The tree
499 * @index: The index of the column
500 * @title: The title for the column
502 * Set the title for a column.
504 * See gnt_tree_set_column_titles(), gnt_tree_set_show_title().
506 * Since: 2.0.0 (gnt), 2.1.0 (pidgin)
508 void gnt_tree_set_column_title(GntTree *tree, int index, const char *title);
511 * gnt_tree_set_column_titles:
512 * @tree: The tree
513 * @...: One title for each column in the tree
515 * Set the titles of the columns
517 * See gnt_tree_set_column_title(), gnt_tree_set_show_title().
519 void gnt_tree_set_column_titles(GntTree *tree, ...);
522 * gnt_tree_set_show_title:
523 * @tree: The tree
524 * @set: If %TRUE, the column titles are displayed
526 * Set whether to display the title of the columns.
528 * See gnt_tree_set_column_title(), gnt_tree_set_column_titles().
530 void gnt_tree_set_show_title(GntTree *tree, gboolean set);
533 * gnt_tree_set_compare_func:
534 * @tree: The tree
535 * @func: (scope call): The comparison function, which is used to compare
536 * the keys
538 * Set the compare function for sorting the data.
540 * See gnt_tree_sort_row().
542 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func);
545 * gnt_tree_set_expanded:
546 * @tree: The tree
547 * @key: The key of the row
548 * @expanded: Whether to expand the child rows
550 * Set whether a row, which has child rows, should be expanded.
552 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded);
555 * gnt_tree_set_show_separator:
556 * @tree: The tree
557 * @set: If %TRUE, the column separators are displayed
559 * Set whether to show column separators.
561 void gnt_tree_set_show_separator(GntTree *tree, gboolean set);
564 * gnt_tree_sort_row:
565 * @tree: The tree
566 * @row: The row to sort
568 * Sort a row in the tree.
570 * See gnt_tree_set_compare_func().
572 void gnt_tree_sort_row(GntTree *tree, void *row);
575 * gnt_tree_adjust_columns:
576 * @tree: The tree
578 * Automatically adjust the width of the columns in the tree.
580 void gnt_tree_adjust_columns(GntTree *tree);
583 * gnt_tree_set_hash_fns:
584 * @tree: The tree
585 * @hash: The hashing function
586 * @eq: The function to compare keys
587 * @kd: The function to use to free the keys when a row is removed
588 * from the tree
590 * Set the hash functions to use to hash, compare and free the keys.
592 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd);
595 * gnt_tree_set_column_visible:
596 * @tree: The tree
597 * @col: The index of the column
598 * @vis: If %FALSE, the column will not be displayed
600 * Set whether a column is visible or not.
601 * This can be useful when, for example, we want to store some data
602 * which we don't want/need to display.
604 void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis);
607 * gnt_tree_set_column_resizable:
608 * @tree: The tree
609 * @col: The index of the column
610 * @res: If %FALSE, the column will not be resized when the
611 * tree is resized
613 * Set whether a column can be resized to keep the same ratio when the
614 * tree is resized.
616 * See gnt_tree_set_col_width(), gnt_tree_set_column_width_ratio().
618 * Since: 2.0.0 (gnt), 2.1.0 (pidgin)
620 void gnt_tree_set_column_resizable(GntTree *tree, int col, gboolean res);
623 * gnt_tree_set_column_is_binary:
624 * @tree: The tree
625 * @col: The index of the column
626 * @bin: %TRUE if the data for the column is binary
628 * Set whether data in a column should be considered as binary data, and
629 * not as strings. A column containing binary data will be display empty text.
631 void gnt_tree_set_column_is_binary(GntTree *tree, int col, gboolean bin);
634 * gnt_tree_set_column_is_right_aligned:
635 * @tree: The tree
636 * @col: The index of the column
637 * @right: %TRUE if the text in the column should be right aligned
639 * Set whether text in a column should be right-aligned.
641 * Since: 2.0.0 (gnt), 2.1.0 (pidgin)
643 void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right);
646 * gnt_tree_set_column_width_ratio:
647 * @tree: The tree
648 * @cols: Array of widths. The width must have the same number
649 * of entries as the number of columns in the tree, or
650 * end with a negative value for a column-width.
652 * Set column widths to use when calculating column widths after a tree
653 * is resized.
655 * See gnt_tree_set_col_width(), gnt_tree_set_column_resizable().
657 * Since: 2.0.0 (gnt), 2.1.0 (pidgin)
659 void gnt_tree_set_column_width_ratio(GntTree *tree, int cols[]);
662 * gnt_tree_set_search_column:
663 * @tree: The tree
664 * @col: The index of the column
666 * Set the column to use for typeahead searching.
668 * Since: 2.0.0 (gnt), 2.1.0 (pidgin)
670 void gnt_tree_set_search_column(GntTree *tree, int col);
673 * gnt_tree_is_searching:
674 * @tree: The tree
676 * Check whether the user is currently in the middle of a search.
678 * Returns: %TRUE if the user is searching, %FALSE otherwise.
680 * Since: 2.0.0 (gnt), 2.1.0 (pidgin)
682 gboolean gnt_tree_is_searching(GntTree *tree);
685 * gnt_tree_set_search_function:
686 * @tree: The tree
687 * @func: The custom search function. The search function is
688 * sent the tree itself, the key of a row, the search
689 * string and the content of row in the search column.
690 * If the function returns %TRUE, the row is dislayed,
691 * otherwise it's not.
693 * Set a custom search function.
695 * Since: 2.0.0 (gnt), 2.1.0 (pidgin)
697 void gnt_tree_set_search_function(GntTree *tree,
698 gboolean (*func)(GntTree *tree, gpointer key, const char *search, const char *current));
701 * gnt_tree_get_parent_key:
702 * @tree: The tree
703 * @key: The key for the row.
705 * Get the parent key for a row.
707 * Returns: (transfer none): The key of the parent row.
709 * Since: 2.4.0
711 gpointer gnt_tree_get_parent_key(GntTree *tree, gpointer key);
713 G_END_DECLS
715 #endif /* GNT_TREE_H */