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
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 #include "gntmarshal.h"
31 #define SEARCH_TIMEOUT 4000 /* 4 secs */
32 #define SEARCHING(tree) (tree->priv->search && tree->priv->search->len > 0)
34 #define COLUMN_INVISIBLE(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_INVISIBLE)
35 #define BINARY_DATA(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_BINARY_DATA)
36 #define RIGHT_ALIGNED(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_RIGHT_ALIGNED)
47 SIG_SELECTION_CHANGED
,
59 gboolean (*search_func
)(GntTree
*tree
, gpointer key
, const char *search
, const char *current
);
68 /* XXX: Make this one into a GObject?
73 void *data
; /* XXX: unused */
76 gboolean choice
; /* Is this a choice-box?
77 If choice is true, then child will be NULL */
79 GntTextFormatFlags flags
;
95 int span
; /* How many columns does it span? */
98 static void tree_selection_changed(GntTree
*, GntTreeRow
*, GntTreeRow
*);
99 static void _gnt_tree_init_internals(GntTree
*tree
, int col
);
101 static GntWidgetClass
*parent_class
= NULL
;
102 static guint signals
[SIGS
] = { 0 };
105 readjust_columns(GntTree
*tree
)
109 #define WIDTH(i) (tree->columns[i].width_ratio ? tree->columns[i].width_ratio : tree->columns[i].width)
110 gnt_widget_get_size(GNT_WIDGET(tree
), &width
, NULL
);
111 if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree
), GNT_WIDGET_NO_BORDER
))
113 for (i
= 0, total
= 0; i
< tree
->ncol
; i
++) {
114 if (tree
->columns
[i
].flags
& GNT_TREE_COLUMN_INVISIBLE
)
116 if (tree
->columns
[i
].flags
& GNT_TREE_COLUMN_FIXED_SIZE
)
117 width
-= WIDTH(i
) + 1;
119 total
+= WIDTH(i
) + 1;
125 for (i
= 0; i
< tree
->ncol
; i
++) {
126 if (tree
->columns
[i
].flags
& GNT_TREE_COLUMN_INVISIBLE
)
128 if (tree
->columns
[i
].flags
& GNT_TREE_COLUMN_FIXED_SIZE
)
131 col
= (WIDTH(i
) * width
) / total
;
132 gnt_tree_set_col_width(GNT_TREE(tree
), i
, col
);
136 /* Move the item at position old to position new */
138 g_list_reposition_child(GList
*list
, int old
, int new)
140 gpointer item
= g_list_nth_data(list
, old
);
141 list
= g_list_remove(list
, item
);
143 new--; /* because the positions would have shifted after removing the item */
144 list
= g_list_insert(list
, item
, new);
149 _get_next(GntTreeRow
*row
, gboolean godeep
)
153 if (godeep
&& row
->child
)
157 return _get_next(row
->parent
, FALSE
);
161 row_matches_search(GntTreeRow
*row
)
163 GntTree
*t
= row
->tree
;
164 if (t
->priv
->search
&& t
->priv
->search
->len
> 0) {
165 GntTreeCol
*col
= (col
= g_list_nth_data(row
->columns
, t
->priv
->search_column
)) ? col
: row
->columns
->data
;
167 if (t
->priv
->search_func
)
168 return t
->priv
->search_func(t
, row
->key
, t
->priv
->search
->str
, col
->text
);
169 one
= g_utf8_casefold(col
->text
, -1);
170 two
= g_utf8_casefold(t
->priv
->search
->str
, -1);
171 z
= strstr(one
, two
);
181 get_next(GntTreeRow
*row
)
185 while ((row
= _get_next(row
, !row
->collapsed
)) != NULL
) {
186 if (row_matches_search(row
))
192 /* Returns the n-th next row. If it doesn't exist, returns NULL */
194 get_next_n(GntTreeRow
*row
, int n
)
201 /* Returns the n-th next row. If it doesn't exist, then the last non-NULL node */
203 get_next_n_opt(GntTreeRow
*row
, int n
, int *pos
)
205 GntTreeRow
*next
= row
;
228 get_last_child(GntTreeRow
*row
)
232 if (!row
->collapsed
&& row
->child
)
239 return get_last_child(row
);
243 get_prev(GntTreeRow
*row
)
249 row
= get_last_child(row
->prev
);
252 if (!row
|| row_matches_search(row
))
259 get_prev_n(GntTreeRow
*row
, int n
)
266 /* Distance of row from the root */
267 /* XXX: This is uber-inefficient */
269 get_root_distance(GntTreeRow
*row
)
273 return get_root_distance(get_prev(row
)) + 1;
276 /* Returns the distance between a and b.
277 * If a is 'above' b, then the distance is positive */
279 get_distance(GntTreeRow
*a
, GntTreeRow
*b
)
281 /* First get the distance from a to the root.
282 * Then the distance from b to the root.
284 * It's not that good, but it works. */
285 int ha
= get_root_distance(a
);
286 int hb
= get_root_distance(b
);
292 find_depth(GntTreeRow
*row
)
306 update_row_text(GntTree
*tree
, GntTreeRow
*row
)
308 GString
*string
= g_string_new(NULL
);
311 gboolean notfirst
= FALSE
;
313 for (i
= 0, iter
= row
->columns
; i
< tree
->ncol
&& iter
; i
++, iter
= iter
->next
)
315 GntTreeCol
*col
= iter
->data
;
319 gboolean cut
= FALSE
;
323 if (COLUMN_INVISIBLE(tree
, i
))
326 if (BINARY_DATA(tree
, i
))
331 len
= gnt_util_onscreen_width(display
, NULL
);
333 width
= tree
->columns
[i
].width
;
339 g_string_append_printf(string
, "[%c] ",
340 row
->isselected
? 'X' : ' ');
343 else if (find_depth(row
) < tree
->priv
->expander_level
&& row
->child
)
347 string
= g_string_append(string
, "+ ");
351 string
= g_string_append(string
, "- ");
357 fl
= TAB_SIZE
* find_depth(row
);
358 g_string_append_printf(string
, "%*s", fl
, "");
361 } else if (notfirst
&& tree
->show_separator
)
362 g_string_append_c(string
, '|');
364 g_string_append_c(string
, ' ');
369 len
= MAX(1, width
- 1);
373 if (RIGHT_ALIGNED(tree
, i
) && len
< tree
->columns
[i
].width
) {
374 g_string_append_printf(string
, "%*s", width
- len
- cut
, "");
377 text
= gnt_util_onscreen_width_to_pointer(display
, len
- fl
, NULL
);
378 string
= g_string_append_len(string
, display
, text
- display
);
379 if (cut
&& width
> 1) { /* ellipsis */
380 if (gnt_ascii_only())
381 g_string_append_c(string
, '~');
383 string
= g_string_append(string
, "\342\200\246");
387 if (!RIGHT_ALIGNED(tree
, i
) && len
< tree
->columns
[i
].width
&& iter
->next
)
388 g_string_append_printf(string
, "%*s", width
- len
, "");
390 return g_string_free(string
, FALSE
);
393 #define NEXT_X x += tree->columns[i].width + (i > 0 ? 1 : 0)
396 tree_mark_columns(GntTree
*tree
, int pos
, int y
, chtype type
)
398 GntWidget
*widget
= GNT_WIDGET(tree
);
401 gboolean notfirst
= FALSE
;
403 for (i
= 0; i
< tree
->ncol
- 1; i
++)
405 if (!COLUMN_INVISIBLE(tree
, i
)) {
409 if (!COLUMN_INVISIBLE(tree
, i
+1) && notfirst
)
410 mvwaddch(widget
->window
, y
, x
, type
);
415 redraw_tree(GntTree
*tree
)
418 GntWidget
*widget
= GNT_WIDGET(tree
);
420 int pos
, up
, down
= 0;
423 if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree
), GNT_WIDGET_MAPPED
))
426 if (GNT_WIDGET_IS_FLAG_SET(widget
, GNT_WIDGET_NO_BORDER
))
431 if (tree
->top
== NULL
)
432 tree
->top
= tree
->root
;
433 if (tree
->current
== NULL
) {
434 tree
->current
= tree
->root
;
435 tree_selection_changed(tree
, NULL
, tree
->current
);
438 wbkgd(widget
->window
, gnt_color_pair(GNT_COLOR_NORMAL
));
441 if (tree
->show_title
)
446 mvwhline(widget
->window
, pos
+ 1, pos
, ACS_HLINE
| gnt_color_pair(GNT_COLOR_NORMAL
),
447 widget
->priv
.width
- pos
- 1);
448 mvwhline(widget
->window
, pos
, pos
, ' ' | gnt_color_pair(GNT_COLOR_NORMAL
),
449 widget
->priv
.width
- pos
- 1);
451 for (i
= 0; i
< tree
->ncol
; i
++)
453 if (COLUMN_INVISIBLE(tree
, i
)) {
456 mvwaddnstr(widget
->window
, pos
, x
+ (x
!= pos
), tree
->columns
[i
].title
, tree
->columns
[i
].width
);
461 tree_mark_columns(tree
, pos
, 0,
462 (tree
->show_separator
? ACS_TTEE
: ACS_HLINE
) | gnt_color_pair(GNT_COLOR_NORMAL
));
463 tree_mark_columns(tree
, pos
, widget
->priv
.height
- pos
,
464 (tree
->show_separator
? ACS_BTEE
: ACS_HLINE
) | gnt_color_pair(GNT_COLOR_NORMAL
));
466 tree_mark_columns(tree
, pos
, pos
+ 1,
467 (tree
->show_separator
? ACS_PLUS
: ACS_HLINE
) | gnt_color_pair(GNT_COLOR_NORMAL
));
468 tree_mark_columns(tree
, pos
, pos
,
469 (tree
->show_separator
? ACS_VLINE
: ' ') | gnt_color_pair(GNT_COLOR_NORMAL
));
473 rows
= widget
->priv
.height
- pos
* 2 - start
- 1;
474 tree
->bottom
= get_next_n_opt(tree
->top
, rows
, &down
);
477 tree
->top
= get_prev_n(tree
->bottom
, rows
);
478 if (tree
->top
== NULL
)
479 tree
->top
= tree
->root
;
482 up
= get_distance(tree
->top
, tree
->current
);
484 tree
->top
= tree
->current
;
485 else if (up
>= widget
->priv
.height
- pos
)
486 tree
->top
= get_prev_n(tree
->current
, rows
);
488 if (tree
->top
&& !row_matches_search(tree
->top
))
489 tree
->top
= get_next(tree
->top
);
491 scrcol
= widget
->priv
.width
- 1 - 2 * pos
; /* exclude the borders and the scrollbar */
492 for (i
= start
+ pos
; row
&& i
< widget
->priv
.height
- pos
;
493 i
++, row
= get_next(row
))
498 GntTextFormatFlags flags
= row
->flags
;
501 if (!row_matches_search(row
))
503 str
= update_row_text(tree
, row
);
505 if ((wr
= gnt_util_onscreen_width(str
, NULL
)) > scrcol
)
507 char *s
= (char*)gnt_util_onscreen_width_to_pointer(str
, scrcol
, &wr
);
511 if (flags
& GNT_TEXT_FLAG_BOLD
)
513 if (flags
& GNT_TEXT_FLAG_UNDERLINE
)
515 if (flags
& GNT_TEXT_FLAG_BLINK
)
518 if (row
== tree
->current
)
520 if (gnt_widget_has_focus(widget
))
521 attr
|= gnt_color_pair(GNT_COLOR_HIGHLIGHT
);
523 attr
|= gnt_color_pair(GNT_COLOR_HIGHLIGHT_D
);
527 if (flags
& GNT_TEXT_FLAG_DIM
)
529 attr
|= (A_DIM
| gnt_color_pair(row
->color
));
531 attr
|= (A_DIM
| gnt_color_pair(GNT_COLOR_DISABLED
));
532 else if (flags
& GNT_TEXT_FLAG_HIGHLIGHT
)
533 attr
|= (A_DIM
| gnt_color_pair(GNT_COLOR_HIGHLIGHT
));
535 attr
|= gnt_color_pair(row
->color
);
537 attr
|= gnt_color_pair(GNT_COLOR_NORMAL
);
540 wbkgdset(widget
->window
, '\0' | attr
);
541 mvwaddstr(widget
->window
, i
, pos
, str
);
542 whline(widget
->window
, ' ', scrcol
- wr
);
545 tree_mark_columns(tree
, pos
, i
,
546 (tree
->show_separator
? ACS_VLINE
: ' ') | attr
);
549 wbkgdset(widget
->window
, '\0' | gnt_color_pair(GNT_COLOR_NORMAL
));
550 while (i
< widget
->priv
.height
- pos
)
552 mvwhline(widget
->window
, i
, pos
, ' ',
553 widget
->priv
.width
- pos
* 2 - 1);
554 tree_mark_columns(tree
, pos
, i
,
555 (tree
->show_separator
? ACS_VLINE
: ' '));
559 scrcol
= widget
->priv
.width
- pos
- 1; /* position of the scrollbar */
564 int showing
, position
;
566 get_next_n_opt(tree
->root
, g_list_length(tree
->list
), &total
);
567 showing
= rows
* rows
/ MAX(total
, 1) + 1;
568 showing
= MIN(rows
, showing
);
571 up
= get_distance(tree
->root
, tree
->top
);
574 position
= (rows
- showing
) * up
/ MAX(1, up
+ down
);
575 position
= MAX((tree
->top
!= tree
->root
), position
);
577 if (showing
+ position
> rows
)
578 position
= rows
- showing
;
580 if (showing
+ position
== rows
&& row
)
581 position
= MAX(0, rows
- 1 - showing
);
582 else if (showing
+ position
< rows
&& !row
)
583 position
= rows
- showing
;
585 position
+= pos
+ start
+ 1;
587 mvwvline(widget
->window
, pos
+ start
+ 1, scrcol
,
588 ' ' | gnt_color_pair(GNT_COLOR_NORMAL
), rows
);
589 mvwvline(widget
->window
, position
, scrcol
,
590 ACS_CKBOARD
| gnt_color_pair(GNT_COLOR_HIGHLIGHT_D
), showing
);
593 mvwaddch(widget
->window
, start
+ pos
, scrcol
,
594 ((tree
->top
!= tree
->root
) ? ACS_UARROW
: ' ') |
595 gnt_color_pair(GNT_COLOR_HIGHLIGHT_D
));
597 mvwaddch(widget
->window
, widget
->priv
.height
- pos
- 1, scrcol
,
598 (row
? ACS_DARROW
: ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D
));
600 /* If there's a search-text, show it in the bottom of the tree */
601 if (tree
->priv
->search
&& tree
->priv
->search
->len
> 0) {
602 const char *str
= gnt_util_onscreen_width_to_pointer(tree
->priv
->search
->str
, scrcol
- 1, NULL
);
603 wbkgdset(widget
->window
, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D
));
604 mvwaddnstr(widget
->window
, widget
->priv
.height
- pos
- 1, pos
,
605 tree
->priv
->search
->str
, str
- tree
->priv
->search
->str
);
608 gnt_widget_queue_update(widget
);
612 gnt_tree_draw(GntWidget
*widget
)
614 GntTree
*tree
= GNT_TREE(widget
);
622 gnt_tree_size_request(GntWidget
*widget
)
624 if (widget
->priv
.height
== 0)
625 widget
->priv
.height
= 10; /* XXX: Why?! */
626 if (widget
->priv
.width
== 0)
628 GntTree
*tree
= GNT_TREE(widget
);
630 width
= 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree
), GNT_WIDGET_NO_BORDER
));
631 for (i
= 0; i
< tree
->ncol
; i
++)
632 if (!COLUMN_INVISIBLE(tree
, i
)) {
633 width
= width
+ tree
->columns
[i
].width
;
634 if (tree
->priv
->lastvisible
!= i
)
637 widget
->priv
.width
= width
;
642 gnt_tree_map(GntWidget
*widget
)
644 GntTree
*tree
= GNT_TREE(widget
);
645 if (widget
->priv
.width
== 0 || widget
->priv
.height
== 0)
647 gnt_widget_size_request(widget
);
649 tree
->top
= tree
->root
;
650 tree
->current
= tree
->root
;
655 tree_selection_changed(GntTree
*tree
, GntTreeRow
*old
, GntTreeRow
*current
)
657 g_signal_emit(tree
, signals
[SIG_SELECTION_CHANGED
], 0, old
? old
->key
: NULL
,
658 current
? current
->key
: NULL
);
662 action_down(GntBindable
*bind
, GList
*null
)
665 GntTree
*tree
= GNT_TREE(bind
);
666 GntTreeRow
*old
= tree
->current
;
667 GntTreeRow
*row
= get_next(tree
->current
);
671 if ((dist
= get_distance(tree
->current
, tree
->bottom
)) < 0)
672 gnt_tree_scroll(tree
, -dist
);
675 if (old
!= tree
->current
)
676 tree_selection_changed(tree
, old
, tree
->current
);
681 action_move_parent(GntBindable
*bind
, GList
*null
)
683 GntTree
*tree
= GNT_TREE(bind
);
684 GntTreeRow
*row
= tree
->current
;
687 if (!row
|| !row
->parent
|| SEARCHING(tree
))
690 tree
->current
= row
->parent
;
691 if ((dist
= get_distance(tree
->current
, tree
->top
)) > 0)
692 gnt_tree_scroll(tree
, -dist
);
695 tree_selection_changed(tree
, row
, tree
->current
);
700 action_up(GntBindable
*bind
, GList
*list
)
703 GntTree
*tree
= GNT_TREE(bind
);
704 GntTreeRow
*old
= tree
->current
;
705 GntTreeRow
*row
= get_prev(tree
->current
);
709 if ((dist
= get_distance(tree
->current
, tree
->top
)) > 0)
710 gnt_tree_scroll(tree
, -dist
);
713 if (old
!= tree
->current
)
714 tree_selection_changed(tree
, old
, tree
->current
);
720 action_page_down(GntBindable
*bind
, GList
*null
)
722 GntTree
*tree
= GNT_TREE(bind
);
723 GntTreeRow
*old
= tree
->current
;
724 GntTreeRow
*row
= get_next(tree
->bottom
);
727 int dist
= get_distance(tree
->top
, tree
->current
);
728 tree
->top
= tree
->bottom
;
729 tree
->current
= get_next_n_opt(tree
->top
, dist
, NULL
);
732 else if (tree
->current
!= tree
->bottom
)
734 tree
->current
= tree
->bottom
;
738 if (old
!= tree
->current
)
739 tree_selection_changed(tree
, old
, tree
->current
);
744 action_page_up(GntBindable
*bind
, GList
*null
)
746 GntWidget
*widget
= GNT_WIDGET(bind
);
747 GntTree
*tree
= GNT_TREE(bind
);
749 GntTreeRow
*old
= tree
->current
;
751 if (tree
->top
!= tree
->root
)
753 int dist
= get_distance(tree
->top
, tree
->current
);
754 row
= get_prev_n(tree
->top
, widget
->priv
.height
- 1 -
755 tree
->show_title
* 2 - 2 * (GNT_WIDGET_IS_FLAG_SET(widget
, GNT_WIDGET_NO_BORDER
) == 0));
759 tree
->current
= get_next_n_opt(tree
->top
, dist
, NULL
);
762 else if (tree
->current
!= tree
->top
)
764 tree
->current
= tree
->top
;
767 if (old
!= tree
->current
)
768 tree_selection_changed(tree
, old
, tree
->current
);
773 end_search(GntTree
*tree
)
775 if (tree
->priv
->search
) {
776 g_source_remove(tree
->priv
->search_timeout
);
777 g_string_free(tree
->priv
->search
, TRUE
);
778 tree
->priv
->search
= NULL
;
779 tree
->priv
->search_timeout
= 0;
780 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(tree
), GNT_WIDGET_DISABLE_ACTIONS
);
785 search_timeout(gpointer data
)
787 GntTree
*tree
= data
;
796 gnt_tree_key_pressed(GntWidget
*widget
, const char *text
)
798 GntTree
*tree
= GNT_TREE(widget
);
799 GntTreeRow
*old
= tree
->current
;
801 if (text
[0] == '\r' || text
[0] == '\n') {
803 gnt_widget_activate(widget
);
804 } else if (tree
->priv
->search
) {
805 gboolean changed
= TRUE
;
806 if (isalnum(*text
)) {
807 tree
->priv
->search
= g_string_append_c(tree
->priv
->search
, *text
);
808 } else if (g_utf8_collate(text
, GNT_KEY_BACKSPACE
) == 0) {
809 if (tree
->priv
->search
->len
)
810 tree
->priv
->search
->str
[--tree
->priv
->search
->len
] = '\0';
815 g_source_remove(tree
->priv
->search_timeout
);
816 tree
->priv
->search_timeout
= g_timeout_add(SEARCH_TIMEOUT
, search_timeout
, tree
);
818 gnt_bindable_perform_action_key(GNT_BINDABLE(tree
), text
);
821 } else if (text
[0] == ' ' && text
[1] == 0) {
823 GntTreeRow
*row
= tree
->current
;
824 if (row
&& row
->child
)
826 row
->collapsed
= !row
->collapsed
;
828 g_signal_emit(tree
, signals
[SIG_COLLAPSED
], 0, row
->key
, row
->collapsed
);
830 else if (row
&& row
->choice
)
832 row
->isselected
= !row
->isselected
;
833 g_signal_emit(tree
, signals
[SIG_TOGGLED
], 0, row
->key
);
840 if (old
!= tree
->current
)
842 tree_selection_changed(tree
, old
, tree
->current
);
849 gnt_tree_free_columns(GntTree
*tree
)
852 for (i
= 0; i
< tree
->ncol
; i
++) {
853 g_free(tree
->columns
[i
].title
);
855 g_free(tree
->columns
);
859 gnt_tree_destroy(GntWidget
*widget
)
861 GntTree
*tree
= GNT_TREE(widget
);
865 g_hash_table_destroy(tree
->hash
);
866 g_list_free(tree
->list
);
867 gnt_tree_free_columns(tree
);
872 gnt_tree_clicked(GntWidget
*widget
, GntMouseEvent event
, int x
, int y
)
874 GntTree
*tree
= GNT_TREE(widget
);
875 GntTreeRow
*old
= tree
->current
;
876 if (event
== GNT_MOUSE_SCROLL_UP
) {
877 action_up(GNT_BINDABLE(widget
), NULL
);
878 } else if (event
== GNT_MOUSE_SCROLL_DOWN
) {
879 action_down(GNT_BINDABLE(widget
), NULL
);
880 } else if (event
== GNT_LEFT_MOUSE_DOWN
) {
882 GntTree
*tree
= GNT_TREE(widget
);
884 if (GNT_WIDGET_IS_FLAG_SET(widget
, GNT_WIDGET_NO_BORDER
))
886 if (tree
->show_title
)
888 pos
= y
- widget
->priv
.y
- pos
;
889 row
= get_next_n(tree
->top
, pos
);
890 if (row
&& tree
->current
!= row
) {
891 GntTreeRow
*old
= tree
->current
;
894 tree_selection_changed(tree
, old
, tree
->current
);
895 } else if (row
&& row
== tree
->current
) {
897 row
->isselected
= !row
->isselected
;
898 g_signal_emit(tree
, signals
[SIG_TOGGLED
], 0, row
->key
);
901 gnt_widget_activate(widget
);
907 if (old
!= tree
->current
) {
908 tree_selection_changed(tree
, old
, tree
->current
);
914 gnt_tree_size_changed(GntWidget
*widget
, int w
, int h
)
916 GntTree
*tree
= GNT_TREE(widget
);
917 if (widget
->priv
.width
<= 0)
920 readjust_columns(tree
);
924 start_search(GntBindable
*bindable
, GList
*list
)
926 GntTree
*tree
= GNT_TREE(bindable
);
927 if (tree
->priv
->search
)
929 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(tree
), GNT_WIDGET_DISABLE_ACTIONS
);
930 tree
->priv
->search
= g_string_new(NULL
);
931 tree
->priv
->search_timeout
= g_timeout_add(SEARCH_TIMEOUT
, search_timeout
, tree
);
936 end_search_action(GntBindable
*bindable
, GList
*list
)
938 GntTree
*tree
= GNT_TREE(bindable
);
939 if (tree
->priv
->search
== NULL
)
941 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(tree
), GNT_WIDGET_DISABLE_ACTIONS
);
948 gnt_tree_set_property(GObject
*obj
, guint prop_id
, const GValue
*value
,
951 GntTree
*tree
= GNT_TREE(obj
);
954 _gnt_tree_init_internals(tree
, g_value_get_int(value
));
957 if (tree
->priv
->expander_level
== g_value_get_int(value
))
959 tree
->priv
->expander_level
= g_value_get_int(value
);
960 g_object_notify(obj
, "expander-level");
967 gnt_tree_get_property(GObject
*obj
, guint prop_id
, GValue
*value
,
970 GntTree
*tree
= GNT_TREE(obj
);
973 g_value_set_int(value
, tree
->ncol
);
976 g_value_set_int(value
, tree
->priv
->expander_level
);
984 gnt_tree_class_init(GntTreeClass
*klass
)
986 GntBindableClass
*bindable
= GNT_BINDABLE_CLASS(klass
);
987 GObjectClass
*gclass
= G_OBJECT_CLASS(klass
);
989 parent_class
= GNT_WIDGET_CLASS(klass
);
990 parent_class
->destroy
= gnt_tree_destroy
;
991 parent_class
->draw
= gnt_tree_draw
;
992 parent_class
->map
= gnt_tree_map
;
993 parent_class
->size_request
= gnt_tree_size_request
;
994 parent_class
->key_pressed
= gnt_tree_key_pressed
;
995 parent_class
->clicked
= gnt_tree_clicked
;
996 parent_class
->size_changed
= gnt_tree_size_changed
;
998 gclass
->set_property
= gnt_tree_set_property
;
999 gclass
->get_property
= gnt_tree_get_property
;
1000 g_object_class_install_property(gclass
,
1002 g_param_spec_int("columns", "Columns",
1003 "Number of columns in the tree.",
1005 G_PARAM_READWRITE
|G_PARAM_STATIC_NAME
|G_PARAM_STATIC_NICK
|G_PARAM_STATIC_BLURB
1008 g_object_class_install_property(gclass
,
1010 g_param_spec_int("expander-level", "Expander level",
1011 "Number of levels to show expander in the tree.",
1013 G_PARAM_READWRITE
|G_PARAM_STATIC_NAME
|G_PARAM_STATIC_NICK
|G_PARAM_STATIC_BLURB
1017 signals
[SIG_SELECTION_CHANGED
] =
1018 g_signal_new("selection-changed",
1019 G_TYPE_FROM_CLASS(klass
),
1021 G_STRUCT_OFFSET(GntTreeClass
, selection_changed
),
1023 gnt_closure_marshal_VOID__POINTER_POINTER
,
1024 G_TYPE_NONE
, 2, G_TYPE_POINTER
, G_TYPE_POINTER
);
1025 signals
[SIG_SCROLLED
] =
1026 g_signal_new("scrolled",
1027 G_TYPE_FROM_CLASS(klass
),
1031 g_cclosure_marshal_VOID__INT
,
1032 G_TYPE_NONE
, 1, G_TYPE_INT
);
1033 signals
[SIG_TOGGLED
] =
1034 g_signal_new("toggled",
1035 G_TYPE_FROM_CLASS(klass
),
1037 G_STRUCT_OFFSET(GntTreeClass
, toggled
),
1039 g_cclosure_marshal_VOID__POINTER
,
1040 G_TYPE_NONE
, 1, G_TYPE_POINTER
);
1041 signals
[SIG_COLLAPSED
] =
1042 g_signal_new("collapse-toggled",
1043 G_TYPE_FROM_CLASS(klass
),
1047 gnt_closure_marshal_VOID__POINTER_BOOLEAN
,
1048 G_TYPE_NONE
, 2, G_TYPE_POINTER
, G_TYPE_BOOLEAN
);
1050 gnt_bindable_class_register_action(bindable
, "move-up", action_up
,
1052 gnt_bindable_register_binding(bindable
, "move-up", GNT_KEY_CTRL_P
, NULL
);
1053 gnt_bindable_class_register_action(bindable
, "move-down", action_down
,
1054 GNT_KEY_DOWN
, NULL
);
1055 gnt_bindable_register_binding(bindable
, "move-down", GNT_KEY_CTRL_N
, NULL
);
1056 gnt_bindable_class_register_action(bindable
, "move-parent", action_move_parent
,
1057 GNT_KEY_BACKSPACE
, NULL
);
1058 gnt_bindable_class_register_action(bindable
, "page-up", action_page_up
,
1059 GNT_KEY_PGUP
, NULL
);
1060 gnt_bindable_class_register_action(bindable
, "page-down", action_page_down
,
1061 GNT_KEY_PGDOWN
, NULL
);
1062 gnt_bindable_class_register_action(bindable
, "start-search", start_search
,
1064 gnt_bindable_class_register_action(bindable
, "end-search", end_search_action
,
1067 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass
), bindable
);
1072 gnt_tree_init(GTypeInstance
*instance
, gpointer
class)
1074 GntWidget
*widget
= GNT_WIDGET(instance
);
1075 GntTree
*tree
= GNT_TREE(widget
);
1076 tree
->show_separator
= TRUE
;
1077 tree
->priv
= g_new0(GntTreePriv
, 1);
1078 GNT_WIDGET_SET_FLAGS(widget
, GNT_WIDGET_GROW_X
| GNT_WIDGET_GROW_Y
|
1079 GNT_WIDGET_CAN_TAKE_FOCUS
| GNT_WIDGET_NO_SHADOW
);
1080 gnt_widget_set_take_focus(widget
, TRUE
);
1081 widget
->priv
.minw
= 4;
1082 widget
->priv
.minh
= 1;
1086 /******************************************************************************
1088 *****************************************************************************/
1090 gnt_tree_get_gtype(void)
1092 static GType type
= 0;
1096 static const GTypeInfo info
= {
1097 sizeof(GntTreeClass
),
1098 NULL
, /* base_init */
1099 NULL
, /* base_finalize */
1100 (GClassInitFunc
)gnt_tree_class_init
,
1101 NULL
, /* class_finalize */
1102 NULL
, /* class_data */
1104 0, /* n_preallocs */
1105 gnt_tree_init
, /* instance_init */
1106 NULL
/* value_table */
1109 type
= g_type_register_static(GNT_TYPE_WIDGET
,
1118 free_tree_col(gpointer data
)
1120 GntTreeCol
*col
= data
;
1127 free_tree_row(gpointer data
)
1129 GntTreeRow
*row
= data
;
1134 g_list_foreach(row
->columns
, (GFunc
)free_tree_col
, NULL
);
1135 g_list_free(row
->columns
);
1139 GntWidget
*gnt_tree_new()
1141 return gnt_tree_new_with_columns(1);
1144 void gnt_tree_set_visible_rows(GntTree
*tree
, int rows
)
1146 GntWidget
*widget
= GNT_WIDGET(tree
);
1147 widget
->priv
.height
= rows
;
1148 if (!GNT_WIDGET_IS_FLAG_SET(widget
, GNT_WIDGET_NO_BORDER
))
1149 widget
->priv
.height
+= 2;
1152 int gnt_tree_get_visible_rows(GntTree
*tree
)
1154 GntWidget
*widget
= GNT_WIDGET(tree
);
1155 int ret
= widget
->priv
.height
;
1156 if (!GNT_WIDGET_IS_FLAG_SET(widget
, GNT_WIDGET_NO_BORDER
))
1161 GList
*gnt_tree_get_rows(GntTree
*tree
)
1166 void gnt_tree_scroll(GntTree
*tree
, int count
)
1172 if (get_root_distance(tree
->top
) == 0)
1174 row
= get_prev_n(tree
->top
, -count
);
1181 get_next_n_opt(tree
->bottom
, count
, &count
);
1182 tree
->top
= get_next_n(tree
->top
, count
);
1186 g_signal_emit(tree
, signals
[SIG_SCROLLED
], 0, count
);
1190 find_position(GntTree
*tree
, gpointer key
, gpointer parent
)
1194 if (tree
->priv
->compare
== NULL
)
1200 row
= g_hash_table_lookup(tree
->hash
, parent
);
1210 if (tree
->priv
->compare(key
, row
->key
) < 0)
1211 return (row
->prev
? row
->prev
->key
: NULL
);
1220 void gnt_tree_sort_row(GntTree
*tree
, gpointer key
)
1222 GntTreeRow
*row
, *q
, *s
;
1225 if (!tree
->priv
->compare
)
1228 row
= g_hash_table_lookup(tree
->hash
, key
);
1229 g_return_if_fail(row
!= NULL
);
1231 current
= g_list_index(tree
->list
, key
);
1234 s
= row
->parent
->child
;
1240 if (tree
->priv
->compare(row
->key
, s
->key
) < 0)
1246 /* Move row between q and s */
1247 if (row
== q
|| row
== s
)
1251 /* row becomes the first child of its parent */
1252 row
->prev
->next
= row
->next
; /* row->prev cannot be NULL at this point */
1254 row
->next
->prev
= row
->prev
;
1256 row
->parent
->child
= row
;
1260 s
->prev
= row
; /* s cannot be NULL */
1262 newp
= g_list_index(tree
->list
, s
) - 1;
1265 row
->prev
->next
= row
->next
;
1267 /* row was the first child of its parent */
1269 row
->parent
->child
= row
->next
;
1271 tree
->top
= row
->next
;
1275 row
->next
->prev
= row
->prev
;
1282 newp
= g_list_index(tree
->list
, q
) + 1;
1284 tree
->list
= g_list_reposition_child(tree
->list
, current
, newp
);
1289 GntTreeRow
*gnt_tree_add_row_after(GntTree
*tree
, void *key
, GntTreeRow
*row
, void *parent
, void *bigbro
)
1291 GntTreeRow
*pr
= NULL
;
1296 g_hash_table_replace(tree
->hash
, key
, row
);
1298 if (bigbro
== NULL
&& tree
->priv
->compare
)
1300 bigbro
= find_position(tree
, key
, parent
);
1303 if (tree
->root
== NULL
)
1306 tree
->list
= g_list_prepend(tree
->list
, key
);
1314 pr
= g_hash_table_lookup(tree
->hash
, bigbro
);
1317 if (pr
->next
) pr
->next
->prev
= row
;
1318 row
->next
= pr
->next
;
1321 row
->parent
= pr
->parent
;
1323 position
= g_list_index(tree
->list
, bigbro
);
1327 if (pr
== NULL
&& parent
)
1329 pr
= g_hash_table_lookup(tree
->hash
, parent
);
1332 if (pr
->child
) pr
->child
->prev
= row
;
1333 row
->next
= pr
->child
;
1337 position
= g_list_index(tree
->list
, parent
);
1343 GntTreeRow
*r
= tree
->root
;
1345 if (r
) r
->prev
= row
;
1346 if (tree
->current
== tree
->root
)
1347 tree
->current
= row
;
1349 tree
->list
= g_list_prepend(tree
->list
, key
);
1353 tree
->list
= g_list_insert(tree
->list
, key
, position
+ 1);
1361 GntTreeRow
*gnt_tree_add_row_last(GntTree
*tree
, void *key
, GntTreeRow
*row
, void *parent
)
1363 GntTreeRow
*pr
= NULL
, *br
= NULL
;
1366 pr
= g_hash_table_lookup(tree
->hash
, parent
);
1379 return gnt_tree_add_row_after(tree
, key
, row
, parent
, br
? br
->key
: NULL
);
1382 gpointer
gnt_tree_get_selection_data(GntTree
*tree
)
1385 return tree
->current
->key
; /* XXX: perhaps we should just get rid of 'data' */
1389 char *gnt_tree_get_selection_text(GntTree
*tree
)
1392 return update_row_text(tree
, tree
->current
);
1396 GList
*gnt_tree_get_row_text_list(GntTree
*tree
, gpointer key
)
1398 GList
*list
= NULL
, *iter
;
1399 GntTreeRow
*row
= key
? g_hash_table_lookup(tree
->hash
, key
) : tree
->current
;
1405 for (i
= 0, iter
= row
->columns
; i
< tree
->ncol
&& iter
;
1406 i
++, iter
= iter
->next
)
1408 GntTreeCol
*col
= iter
->data
;
1409 list
= g_list_append(list
, BINARY_DATA(tree
, i
) ? col
->text
: g_strdup(col
->text
));
1415 GList
*gnt_tree_get_selection_text_list(GntTree
*tree
)
1417 return gnt_tree_get_row_text_list(tree
, NULL
);
1420 void gnt_tree_remove(GntTree
*tree
, gpointer key
)
1422 GntTreeRow
*row
= g_hash_table_lookup(tree
->hash
, key
);
1423 static int depth
= 0; /* Only redraw after all child nodes are removed */
1426 gboolean redraw
= FALSE
;
1430 while (row
->child
) {
1431 gnt_tree_remove(tree
, row
->child
->key
);
1436 if (get_distance(tree
->top
, row
) >= 0 && get_distance(row
, tree
->bottom
) >= 0)
1439 /* Update root/top/current/bottom if necessary */
1440 if (tree
->root
== row
)
1441 tree
->root
= get_next(row
);
1442 if (tree
->top
== row
)
1444 if (tree
->top
!= tree
->root
)
1445 tree
->top
= get_prev(row
);
1447 tree
->top
= get_next(row
);
1449 if (tree
->current
== row
)
1451 if (tree
->current
!= tree
->root
)
1452 tree
->current
= get_prev(row
);
1454 tree
->current
= get_next(row
);
1455 tree_selection_changed(tree
, row
, tree
->current
);
1457 if (tree
->bottom
== row
)
1459 tree
->bottom
= get_prev(row
);
1464 row
->next
->prev
= row
->prev
;
1465 if (row
->parent
&& row
->parent
->child
== row
)
1466 row
->parent
->child
= row
->next
;
1468 row
->prev
->next
= row
->next
;
1470 g_hash_table_remove(tree
->hash
, key
);
1471 tree
->list
= g_list_remove(tree
->list
, key
);
1473 if (redraw
&& depth
== 0)
1481 return_true(gpointer key
, gpointer data
, gpointer null
)
1486 void gnt_tree_remove_all(GntTree
*tree
)
1489 g_hash_table_foreach_remove(tree
->hash
, (GHRFunc
)return_true
, tree
);
1490 g_list_free(tree
->list
);
1492 tree
->current
= tree
->top
= tree
->bottom
= NULL
;
1495 int gnt_tree_get_selection_visible_line(GntTree
*tree
)
1497 return get_distance(tree
->top
, tree
->current
) +
1498 !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree
), GNT_WIDGET_NO_BORDER
));
1501 void gnt_tree_change_text(GntTree
*tree
, gpointer key
, int colno
, const char *text
)
1506 g_return_if_fail(colno
< tree
->ncol
);
1508 row
= g_hash_table_lookup(tree
->hash
, key
);
1511 col
= g_list_nth_data(row
->columns
, colno
);
1512 if (BINARY_DATA(tree
, colno
)) {
1513 col
->text
= (gpointer
)text
;
1516 col
->text
= g_strdup(text
? text
: "");
1519 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree
), GNT_WIDGET_MAPPED
) &&
1520 get_distance(tree
->top
, row
) >= 0 && get_distance(row
, tree
->bottom
) >= 0)
1525 GntTreeRow
*gnt_tree_add_choice(GntTree
*tree
, void *key
, GntTreeRow
*row
, void *parent
, void *bigbro
)
1528 r
= g_hash_table_lookup(tree
->hash
, key
);
1529 g_return_val_if_fail(!r
|| !r
->choice
, NULL
);
1531 if (bigbro
== NULL
) {
1532 if (tree
->priv
->compare
)
1533 bigbro
= find_position(tree
, key
, parent
);
1535 r
= g_hash_table_lookup(tree
->hash
, parent
);
1547 row
= gnt_tree_add_row_after(tree
, key
, row
, parent
, bigbro
);
1553 void gnt_tree_set_choice(GntTree
*tree
, void *key
, gboolean set
)
1555 GntTreeRow
*row
= g_hash_table_lookup(tree
->hash
, key
);
1559 g_return_if_fail(row
->choice
);
1561 row
->isselected
= set
;
1565 gboolean
gnt_tree_get_choice(GntTree
*tree
, void *key
)
1567 GntTreeRow
*row
= g_hash_table_lookup(tree
->hash
, key
);
1571 g_return_val_if_fail(row
->choice
, FALSE
);
1573 return row
->isselected
;
1576 void gnt_tree_set_row_flags(GntTree
*tree
, void *key
, GntTextFormatFlags flags
)
1578 GntTreeRow
*row
= g_hash_table_lookup(tree
->hash
, key
);
1579 if (!row
|| row
->flags
== flags
)
1583 redraw_tree(tree
); /* XXX: It shouldn't be necessary to redraw the whole darned tree */
1586 void gnt_tree_set_row_color(GntTree
*tree
, void *key
, int color
)
1588 GntTreeRow
*row
= g_hash_table_lookup(tree
->hash
, key
);
1589 if (!row
|| row
->color
== color
)
1596 void gnt_tree_set_selected(GntTree
*tree
, void *key
)
1599 GntTreeRow
*row
= g_hash_table_lookup(tree
->hash
, key
);
1600 if (!row
|| row
== tree
->current
)
1603 if (tree
->top
== NULL
)
1605 if (tree
->bottom
== NULL
)
1608 tree
->current
= row
;
1609 if ((dist
= get_distance(tree
->current
, tree
->bottom
)) < 0)
1610 gnt_tree_scroll(tree
, -dist
);
1611 else if ((dist
= get_distance(tree
->current
, tree
->top
)) > 0)
1612 gnt_tree_scroll(tree
, -dist
);
1615 tree_selection_changed(tree
, row
, tree
->current
);
1618 static void _gnt_tree_init_internals(GntTree
*tree
, int col
)
1620 gnt_tree_free_columns(tree
);
1623 tree
->hash
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
, NULL
, free_tree_row
);
1624 tree
->columns
= g_new0(struct _GntTreeColInfo
, col
);
1625 tree
->priv
->lastvisible
= col
- 1;
1628 tree
->columns
[col
].width
= 15;
1631 tree
->show_title
= FALSE
;
1632 g_object_notify(G_OBJECT(tree
), "columns");
1635 GntWidget
*gnt_tree_new_with_columns(int col
)
1637 GntWidget
*widget
= g_object_new(GNT_TYPE_TREE
,
1639 "expander-level", 1,
1645 GntTreeRow
*gnt_tree_create_row_from_list(GntTree
*tree
, GList
*list
)
1649 GntTreeRow
*row
= g_new0(GntTreeRow
, 1);
1651 for (i
= 0, iter
= list
; i
< tree
->ncol
&& iter
; iter
= iter
->next
, i
++)
1653 GntTreeCol
*col
= g_new0(GntTreeCol
, 1);
1655 if (BINARY_DATA(tree
, i
)) {
1656 col
->text
= iter
->data
;
1657 col
->isbinary
= TRUE
;
1659 col
->text
= g_strdup(iter
->data
? iter
->data
: "");
1660 col
->isbinary
= FALSE
;
1663 row
->columns
= g_list_append(row
->columns
, col
);
1669 GntTreeRow
*gnt_tree_create_row(GntTree
*tree
, ...)
1676 va_start(args
, tree
);
1677 for (i
= 0; i
< tree
->ncol
; i
++)
1679 list
= g_list_append(list
, va_arg(args
, char *));
1683 row
= gnt_tree_create_row_from_list(tree
, list
);
1689 void gnt_tree_set_col_width(GntTree
*tree
, int col
, int width
)
1691 g_return_if_fail(col
< tree
->ncol
);
1693 tree
->columns
[col
].width
= width
;
1694 if (tree
->columns
[col
].width_ratio
== 0)
1695 tree
->columns
[col
].width_ratio
= width
;
1698 void gnt_tree_set_column_title(GntTree
*tree
, int index
, const char *title
)
1700 g_free(tree
->columns
[index
].title
);
1701 tree
->columns
[index
].title
= g_strdup(title
);
1704 void gnt_tree_set_column_titles(GntTree
*tree
, ...)
1709 va_start(args
, tree
);
1710 for (i
= 0; i
< tree
->ncol
; i
++)
1712 const char *title
= va_arg(args
, const char *);
1713 tree
->columns
[i
].title
= g_strdup(title
);
1718 void gnt_tree_set_show_title(GntTree
*tree
, gboolean set
)
1720 tree
->show_title
= set
;
1721 GNT_WIDGET(tree
)->priv
.minh
= (set
? 6 : 4);
1724 void gnt_tree_set_compare_func(GntTree
*tree
, GCompareFunc func
)
1726 tree
->priv
->compare
= func
;
1729 void gnt_tree_set_expanded(GntTree
*tree
, void *key
, gboolean expanded
)
1731 GntTreeRow
*row
= g_hash_table_lookup(tree
->hash
, key
);
1733 row
->collapsed
= !expanded
;
1734 if (GNT_WIDGET(tree
)->window
)
1735 gnt_widget_draw(GNT_WIDGET(tree
));
1736 g_signal_emit(tree
, signals
[SIG_COLLAPSED
], 0, key
, row
->collapsed
);
1740 void gnt_tree_set_show_separator(GntTree
*tree
, gboolean set
)
1742 tree
->show_separator
= set
;
1745 void gnt_tree_adjust_columns(GntTree
*tree
)
1747 GntTreeRow
*row
= tree
->root
;
1748 int *widths
, i
, twidth
;
1750 widths
= g_new0(int, tree
->ncol
);
1753 for (i
= 0, iter
= row
->columns
; iter
; iter
= iter
->next
, i
++) {
1754 GntTreeCol
*col
= iter
->data
;
1755 int w
= gnt_util_onscreen_width(col
->text
, NULL
);
1756 if (i
== 0 && row
->choice
)
1759 w
+= find_depth(row
) * TAB_SIZE
;
1764 row
= get_next(row
);
1767 twidth
= 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree
), GNT_WIDGET_NO_BORDER
));
1768 for (i
= 0; i
< tree
->ncol
; i
++) {
1769 if (tree
->columns
[i
].flags
& GNT_TREE_COLUMN_FIXED_SIZE
)
1770 widths
[i
] = tree
->columns
[i
].width
;
1771 gnt_tree_set_col_width(tree
, i
, widths
[i
]);
1772 if (!COLUMN_INVISIBLE(tree
, i
)) {
1773 twidth
= twidth
+ widths
[i
];
1774 if (tree
->priv
->lastvisible
!= i
)
1780 gnt_widget_set_size(GNT_WIDGET(tree
), twidth
, -1);
1783 void gnt_tree_set_hash_fns(GntTree
*tree
, gpointer hash
, gpointer eq
, gpointer kd
)
1785 g_hash_table_foreach_remove(tree
->hash
, return_true
, NULL
);
1786 g_hash_table_destroy(tree
->hash
);
1787 tree
->hash
= g_hash_table_new_full(hash
, eq
, kd
, free_tree_row
);
1791 set_column_flag(GntTree
*tree
, int col
, GntTreeColumnFlag flag
, gboolean set
)
1794 tree
->columns
[col
].flags
|= flag
;
1796 tree
->columns
[col
].flags
&= ~flag
;
1799 void gnt_tree_set_column_visible(GntTree
*tree
, int col
, gboolean vis
)
1801 g_return_if_fail(col
< tree
->ncol
);
1802 set_column_flag(tree
, col
, GNT_TREE_COLUMN_INVISIBLE
, !vis
);
1804 /* the column is visible */
1805 if (tree
->priv
->lastvisible
< col
)
1806 tree
->priv
->lastvisible
= col
;
1808 if (tree
->priv
->lastvisible
== col
)
1809 while (tree
->priv
->lastvisible
) {
1810 tree
->priv
->lastvisible
--;
1811 if (!COLUMN_INVISIBLE(tree
, tree
->priv
->lastvisible
))
1815 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree
), GNT_WIDGET_MAPPED
))
1816 readjust_columns(tree
);
1819 void gnt_tree_set_column_resizable(GntTree
*tree
, int col
, gboolean res
)
1821 g_return_if_fail(col
< tree
->ncol
);
1822 set_column_flag(tree
, col
, GNT_TREE_COLUMN_FIXED_SIZE
, !res
);
1825 void gnt_tree_set_column_is_binary(GntTree
*tree
, int col
, gboolean bin
)
1827 g_return_if_fail(col
< tree
->ncol
);
1828 set_column_flag(tree
, col
, GNT_TREE_COLUMN_FIXED_SIZE
, bin
);
1831 void gnt_tree_set_column_is_right_aligned(GntTree
*tree
, int col
, gboolean right
)
1833 g_return_if_fail(col
< tree
->ncol
);
1834 set_column_flag(tree
, col
, GNT_TREE_COLUMN_RIGHT_ALIGNED
, right
);
1837 void gnt_tree_set_column_width_ratio(GntTree
*tree
, int cols
[])
1840 for (i
= 0; i
< tree
->ncol
&& cols
[i
]; i
++) {
1841 tree
->columns
[i
].width_ratio
= cols
[i
];
1845 void gnt_tree_set_search_column(GntTree
*tree
, int col
)
1847 g_return_if_fail(col
< tree
->ncol
);
1848 g_return_if_fail(!BINARY_DATA(tree
, col
));
1849 tree
->priv
->search_column
= col
;
1852 gboolean
gnt_tree_is_searching(GntTree
*tree
)
1854 return (tree
->priv
->search
!= NULL
);
1857 void gnt_tree_set_search_function(GntTree
*tree
,
1858 gboolean (*func
)(GntTree
*tree
, gpointer key
, const char *search
, const char *current
))
1860 tree
->priv
->search_func
= func
;
1863 gpointer
gnt_tree_get_parent_key(GntTree
*tree
, gpointer key
)
1865 GntTreeRow
*row
= g_hash_table_lookup(tree
->hash
, key
);
1866 return (row
&& row
->parent
) ? row
->parent
->key
: NULL
;