--- a/gnttree.c Tue Apr 23 18:42:19 2019 -0400
+++ b/gnttree.c Wed Apr 24 04:24:43 2019 +0000
@@ -29,11 +29,14 @@
#define SEARCH_TIMEOUT_S 4 /* 4 secs */
-#define SEARCHING(tree) (tree->priv->search && tree->priv->search->len > 0)
+#define SEARCHING(priv) (priv->search && priv->search->len > 0) -#define COLUMN_INVISIBLE(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_INVISIBLE)
-#define BINARY_DATA(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_BINARY_DATA)
-#define RIGHT_ALIGNED(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_RIGHT_ALIGNED)
+#define COLUMN_INVISIBLE(priv, index) \ + (priv->columns[index].flags & GNT_TREE_COLUMN_INVISIBLE) +#define BINARY_DATA(priv, index) \ + (priv->columns[index].flags & GNT_TREE_COLUMN_BINARY_DATA) +#define RIGHT_ALIGNED(priv, index) \ + (priv->columns[index].flags & GNT_TREE_COLUMN_RIGHT_ALIGNED) @@ -51,8 +54,27 @@
+ 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 */ + GntTreeHashFunc hash_func; + GntTreeHashEqualityFunc hash_eq_func; + GDestroyNotify key_destroy; + GDestroyNotify value_destroy; + int ncol; /* No. of columns */ + GntTreeColInfo *columns; /* Would a GList be better? */ + gboolean show_separator; /* Whether to show column separators */ @@ -61,7 +83,7 @@
@@ -102,39 +124,46 @@
static guint signals[SIGS] = { 0 };
-G_DEFINE_TYPE(GntTree, gnt_tree, GNT_TYPE_WIDGET)
+G_DEFINE_TYPE_WITH_PRIVATE(GntTree, gnt_tree, GNT_TYPE_WIDGET) readjust_columns(GntTree *tree)
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); -#define WIDTH(i) (tree->columns[i].width_ratio ? tree->columns[i].width_ratio : tree->columns[i].width)
+ (priv->columns[i].width_ratio ? priv->columns[i].width_ratio \ + : priv->columns[i].width) gnt_widget_get_size(GNT_WIDGET(tree), &width, NULL);
if (gnt_widget_get_has_border(GNT_WIDGET(tree))) {
width -= 1; /* Exclude the scrollbar from the calculation */
- for (i = 0, total = 0; i < tree->ncol ; i++) {
- if (tree->columns[i].flags & GNT_TREE_COLUMN_INVISIBLE)
+ for (i = 0, total = 0; i < priv->ncol; i++) { + if (priv->columns[i].flags & GNT_TREE_COLUMN_INVISIBLE) { - if (tree->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE)
- width -= WIDTH(i) + (tree->priv->lastvisible != i);
- total += WIDTH(i) + (tree->priv->lastvisible != i);
+ if (priv->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE) { + width -= WIDTH(i) + (priv->lastvisible != i); + total += WIDTH(i) + (priv->lastvisible != i); - for (i = 0; i < tree->ncol; i++) {
- if (tree->columns[i].flags & GNT_TREE_COLUMN_INVISIBLE)
+ for (i = 0; i < priv->ncol; i++) { + if (priv->columns[i].flags & GNT_TREE_COLUMN_INVISIBLE) { - if (tree->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE)
+ if (priv->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE) {
col = (WIDTH(i) * width) / total;
- gnt_tree_set_col_width(GNT_TREE(tree), i, col);
+ gnt_tree_set_col_width(tree, i, col); @@ -165,14 +194,25 @@
row_matches_search(GntTreeRow *row)
- GntTree *t = row->tree;
- if (t->priv->search && t->priv->search->len > 0) {
- GntTreeCol *col = (col = g_list_nth_data(row->columns, t->priv->search_column)) ? col : row->columns->data;
+ GntTree *tree = row->tree; + GntTreePrivate *priv = gnt_tree_get_instance_private(tree); - if (t->priv->search_func)
- return t->priv->search_func(t, row->key, t->priv->search->str, col->text);
+ col = g_list_nth_data(row->columns, priv->search_column); + col = row->columns->data; + if (priv->search_func) { + return priv->search_func(tree, row->key, + priv->search->str, col->text); one = g_utf8_casefold(col->text, -1);
- two = g_utf8_casefold(t->priv->search->str, -1);
+ two = g_utf8_casefold(priv->search->str, -1); @@ -308,15 +348,15 @@
-update_row_text(GntTree *tree, GntTreeRow *row)
+update_row_text(GntTreePrivate *priv, GntTreeRow *row) GString *string = g_string_new(NULL);
gboolean notfirst = FALSE;
- for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next)
+ for (i = 0, iter = row->columns; i < priv->ncol && iter; + i++, iter = iter->next) { GntTreeCol *col = iter->data;
@@ -325,17 +365,19 @@
- if (COLUMN_INVISIBLE(tree, i))
+ if (COLUMN_INVISIBLE(priv, i)) { - if (BINARY_DATA(tree, i))
+ if (BINARY_DATA(priv, i)) {
len = gnt_util_onscreen_width(display, NULL);
- width = tree->columns[i].width;
+ width = priv->columns[i].width; @@ -344,9 +386,8 @@
g_string_append_printf(string, "[%c] ",
row->isselected ? 'X' : ' ');
- else if (find_depth(row) < tree->priv->expander_level && row->child)
+ } else if (find_depth(row) < priv->expander_level && string = g_string_append(string, "+ ");
@@ -356,17 +397,16 @@
string = g_string_append(string, "- ");
fl = TAB_SIZE * find_depth(row);
g_string_append_printf(string, "%*s", fl, "");
- } else if (notfirst && tree->show_separator)
+ } else if (notfirst && priv->show_separator) { g_string_append_c(string, '|');
g_string_append_c(string, ' ');
@@ -375,7 +415,7 @@
- if (RIGHT_ALIGNED(tree, i) && len < tree->columns[i].width) {
+ if (RIGHT_ALIGNED(priv, i) && len < priv->columns[i].width) { g_string_append_printf(string, "%*s", width - len - cut, "");
@@ -389,36 +429,40 @@
- if (!RIGHT_ALIGNED(tree, i) && len < tree->columns[i].width && iter->next)
+ if (!RIGHT_ALIGNED(priv, i) && len < priv->columns[i].width && g_string_append_printf(string, "%*s", width - len, "");
return g_string_free(string, FALSE);
-#define NEXT_X x += tree->columns[i].width + (i > 0 ? 1 : 0)
+#define NEXT_X x += priv->columns[i].width + (i > 0 ? 1 : 0) tree_mark_columns(GntTree *tree, int pos, int y, chtype type)
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); GntWidget *widget = GNT_WIDGET(tree);
gboolean notfirst = FALSE;
- for (i = 0; i < tree->ncol - 1; i++)
- if (!COLUMN_INVISIBLE(tree, i)) {
+ for (i = 0; i < priv->ncol - 1; i++) { + if (!COLUMN_INVISIBLE(priv, i)) { - if (!COLUMN_INVISIBLE(tree, i+1) && notfirst)
+ if (!COLUMN_INVISIBLE(priv, i + 1) && notfirst) { mvwaddch(widget->window, y, x, type);
redraw_tree(GntTree *tree)
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); GntWidget *widget = GNT_WIDGET(tree);
@@ -431,18 +475,18 @@
pos = gnt_widget_get_has_border(widget) ? 1 : 0;
- tree->top = tree->root;
- if (tree->current == NULL && tree->root != NULL) {
- tree->current = tree->root;
- tree_selection_changed(tree, NULL, tree->current);
+ if (priv->top == NULL) { + priv->top = priv->root; + if (priv->current == NULL && priv->root != NULL) { + priv->current = priv->root; + tree_selection_changed(tree, NULL, priv->current); wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL));
+ if (priv->show_title) { @@ -451,52 +495,62 @@
mvwhline(widget->window, pos, pos, ' ' | gnt_color_pair(GNT_COLOR_NORMAL),
widget->priv.width - pos - 1);
- for (i = 0; i < tree->ncol; i++)
- if (COLUMN_INVISIBLE(tree, i)) {
+ for (i = 0; i < priv->ncol; i++) { + if (COLUMN_INVISIBLE(priv, i)) { - mvwaddnstr(widget->window, pos, x + (x != pos), tree->columns[i].title, tree->columns[i].width);
+ mvwaddnstr(widget->window, pos, x + (x != pos), + priv->columns[i].title, + priv->columns[i].width); - tree_mark_columns(tree, pos, 0,
- (tree->show_separator ? ACS_TTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL));
- tree_mark_columns(tree, pos, widget->priv.height - pos,
- (tree->show_separator ? ACS_BTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL));
+ (priv->show_separator ? ACS_TTEE : ACS_HLINE) | + gnt_color_pair(GNT_COLOR_NORMAL)); + tree, pos, widget->priv.height - pos, + (priv->show_separator ? ACS_BTEE : ACS_HLINE) | + gnt_color_pair(GNT_COLOR_NORMAL)); - tree_mark_columns(tree, pos, pos + 1,
- (tree->show_separator ? ACS_PLUS : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL));
+ (priv->show_separator ? ACS_PLUS : ACS_HLINE) | + gnt_color_pair(GNT_COLOR_NORMAL)); tree_mark_columns(tree, pos, pos,
- (tree->show_separator ? ACS_VLINE : ' ') | gnt_color_pair(GNT_COLOR_NORMAL));
+ (priv->show_separator ? ACS_VLINE : ' ') | + gnt_color_pair(GNT_COLOR_NORMAL)); rows = widget->priv.height - pos * 2 - start - 1;
- tree->bottom = get_next_n_opt(tree->top, rows, &down);
+ priv->bottom = get_next_n_opt(priv->top, rows, &down); - tree->top = get_prev_n(tree->bottom, rows);
- tree->top = tree->root;
+ priv->top = get_prev_n(priv->bottom, rows); + if (priv->top == NULL) { + priv->top = priv->root; - up = get_distance(tree->top, tree->current);
+ up = get_distance(priv->top, priv->current); - tree->top = tree->current;
+ priv->top = priv->current; else if (up >= widget->priv.height - pos)
- tree->top = get_prev_n(tree->current, rows);
+ priv->top = get_prev_n(priv->current, rows); - if (tree->top && !row_matches_search(tree->top))
- tree->top = get_next(tree->top);
+ if (priv->top && !row_matches_search(priv->top)) { + priv->top = get_next(priv->top); scrcol = widget->priv.width - 1 - 2 * pos; /* exclude the borders and the scrollbar */
- if (tree->current && !row_matches_search(tree->current)) {
- GntTreeRow *old = tree->current;
- tree->current = tree->top;
- tree_selection_changed(tree, old, tree->current);
+ if (priv->current && !row_matches_search(priv->current)) { + GntTreeRow *old = priv->current; + priv->current = priv->top; + tree_selection_changed(tree, old, priv->current); for (i = start + pos; row && i < widget->priv.height - pos;
@@ -510,7 +564,7 @@
if (!row_matches_search(row))
- str = update_row_text(tree, row);
+ str = update_row_text(priv, row); if ((wr = gnt_util_onscreen_width(str, NULL)) > scrcol)
@@ -525,17 +579,14 @@
if (flags & GNT_TEXT_FLAG_BLINK)
- if (row == tree->current)
+ if (row == priv->current) { if (gnt_widget_has_focus(widget))
attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT);
attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT_D);
if (flags & GNT_TEXT_FLAG_DIM)
attr |= (A_DIM | gnt_color_pair(row->color));
@@ -552,10 +603,11 @@
wbkgdset(widget->window, '\0' | attr);
mvwaddstr(widget->window, i, pos, C_(str));
whline(widget->window, ' ', scrcol - wr);
tree_mark_columns(tree, pos, i,
- (tree->show_separator ? ACS_VLINE : ' ') | attr);
+ (priv->show_separator ? ACS_VLINE : ' ') | wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL));
@@ -564,7 +616,7 @@
mvwhline(widget->window, i, pos, ' ',
widget->priv.width - pos * 2 - 1);
tree_mark_columns(tree, pos, i,
- (tree->show_separator ? ACS_VLINE : ' '));
+ (priv->show_separator ? ACS_VLINE : ' ')); @@ -575,16 +627,16 @@
- get_next_n_opt(tree->root, g_list_length(tree->list), &total);
+ get_next_n_opt(priv->root, g_list_length(priv->list), &total); showing = rows * rows / MAX(total, 1) + 1;
showing = MIN(rows, showing);
- up = get_distance(tree->root, tree->top);
+ up = get_distance(priv->root, priv->top); position = (rows - showing) * up / MAX(1, up + down);
- position = MAX((tree->top != tree->root), position);
+ position = MAX((priv->top != priv->root), position); if (showing + position > rows)
position = rows - showing;
@@ -603,18 +655,19 @@
mvwaddch(widget->window, start + pos, scrcol,
- ((tree->top != tree->root) ? ACS_UARROW : ' ') |
- gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
+ ((priv->top != priv->root) ? ACS_UARROW : ' ') | + gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol,
(row ? ACS_DARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
/* If there's a search-text, show it in the bottom of the tree */
- if (tree->priv->search && tree->priv->search->len > 0) {
- const char *str = gnt_util_onscreen_width_to_pointer(tree->priv->search->str, scrcol - 1, NULL);
+ const char *str = gnt_util_onscreen_width_to_pointer( + priv->search->str, scrcol - 1, NULL); wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
mvwaddnstr(widget->window, widget->priv.height - pos - 1, pos,
- tree->priv->search->str, str - tree->priv->search->str);
+ priv->search->str, str - priv->search->str); wmove(widget->window, current, pos);
@@ -639,14 +692,17 @@
if (widget->priv.width == 0)
GntTree *tree = GNT_TREE(widget);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); width = gnt_widget_get_has_border(GNT_WIDGET(tree)) ? 3 : 1;
- for (i = 0; i < tree->ncol; i++)
- if (!COLUMN_INVISIBLE(tree, i)) {
- width = width + tree->columns[i].width;
- if (tree->priv->lastvisible != i)
+ for (i = 0; i < priv->ncol; i++) { + if (!COLUMN_INVISIBLE(priv, i)) { + width = width + priv->columns[i].width; + if (priv->lastvisible != i) { widget->priv.width = width;
@@ -655,13 +711,13 @@
gnt_tree_map(GntWidget *widget)
GntTree *tree = GNT_TREE(widget);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); if (widget->priv.width == 0 || widget->priv.height == 0)
gnt_widget_size_request(widget);
- tree->top = tree->root;
- tree->current = tree->root;
+ priv->top = priv->root; + priv->current = priv->root; @@ -676,17 +732,20 @@
GntTree *tree = GNT_TREE(bind);
- GntTreeRow *old = tree->current;
- GntTreeRow *row = get_next(tree->current);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + GntTreeRow *old = priv->current; + GntTreeRow *row = get_next(priv->current);
- if ((dist = get_distance(tree->current, tree->bottom)) < 0)
+ if ((dist = get_distance(priv->current, priv->bottom)) < 0) { gnt_tree_scroll(tree, -dist);
- if (old != tree->current)
- tree_selection_changed(tree, old, tree->current);
+ if (old != priv->current) { + tree_selection_changed(tree, old, priv->current); @@ -694,18 +753,21 @@
action_move_parent(GntBindable *bind, G_GNUC_UNUSED GList *unused)
GntTree *tree = GNT_TREE(bind);
- GntTreeRow *row = tree->current;
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + GntTreeRow *row = priv->current; - if (!row || !row->parent || SEARCHING(tree))
+ if (!row || !row->parent || SEARCHING(priv)) { - tree->current = row->parent;
- if ((dist = get_distance(tree->current, tree->top)) > 0)
+ priv->current = row->parent; + if ((dist = get_distance(priv->current, priv->top)) > 0) { gnt_tree_scroll(tree, -dist);
- tree_selection_changed(tree, row, tree->current);
+ tree_selection_changed(tree, row, priv->current); @@ -714,17 +776,20 @@
GntTree *tree = GNT_TREE(bind);
- GntTreeRow *old = tree->current;
- GntTreeRow *row = get_prev(tree->current);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + GntTreeRow *old = priv->current; + GntTreeRow *row = get_prev(priv->current);
- if ((dist = get_distance(tree->current, tree->top)) > 0)
+ if ((dist = get_distance(priv->current, priv->top)) > 0) { gnt_tree_scroll(tree, -dist);
- if (old != tree->current)
- tree_selection_changed(tree, old, tree->current);
+ if (old != priv->current) { + tree_selection_changed(tree, old, priv->current); @@ -733,23 +798,23 @@
action_page_down(GntBindable *bind, G_GNUC_UNUSED GList *unused)
GntTree *tree = GNT_TREE(bind);
- GntTreeRow *old = tree->current;
- GntTreeRow *row = get_next(tree->bottom);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + GntTreeRow *old = priv->current; + GntTreeRow *row = get_next(priv->bottom); - int dist = get_distance(tree->top, tree->current);
- tree->top = tree->bottom;
- tree->current = get_next_n_opt(tree->top, dist, NULL);
+ int dist = get_distance(priv->top, priv->current); + priv->top = priv->bottom; + priv->current = get_next_n_opt(priv->top, dist, NULL);
- else if (tree->current != tree->bottom)
- tree->current = tree->bottom;
+ } else if (priv->current != priv->bottom) { + priv->current = priv->bottom; - if (old != tree->current)
- tree_selection_changed(tree, old, tree->current);
+ if (old != priv->current) { + tree_selection_changed(tree, old, priv->current); @@ -758,40 +823,40 @@
GntWidget *widget = GNT_WIDGET(bind);
GntTree *tree = GNT_TREE(bind);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); - GntTreeRow *old = tree->current;
+ GntTreeRow *old = priv->current; - if (tree->top != tree->root)
- int dist = get_distance(tree->top, tree->current);
+ if (priv->top != priv->root) { + int dist = get_distance(priv->top, priv->current);
- widget->priv.height - 1 - tree->show_title * 2 -
+ widget->priv.height - 1 - priv->show_title * 2 - (gnt_widget_get_has_border(widget) ? 2 : 0));
- tree->current = get_next_n_opt(tree->top, dist, NULL);
+ priv->current = get_next_n_opt(priv->top, dist, NULL); + } else if (priv->current != priv->top) { + priv->current = priv->top; - else if (tree->current != tree->top)
- tree->current = tree->top;
+ if (old != priv->current) { + tree_selection_changed(tree, old, priv->current); - if (old != tree->current)
- tree_selection_changed(tree, old, tree->current);
end_search(GntTree *tree)
- if (tree->priv->search) {
- g_source_remove(tree->priv->search_timeout);
- g_string_free(tree->priv->search, TRUE);
- tree->priv->search = NULL;
- tree->priv->search_timeout = 0;
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + g_source_remove(priv->search_timeout); + g_string_free(priv->search, TRUE); + priv->search_timeout = 0; gnt_widget_set_disable_actions(GNT_WIDGET(tree), FALSE);
@@ -811,18 +876,20 @@
gnt_tree_key_pressed(GntWidget *widget, const char *text)
GntTree *tree = GNT_TREE(widget);
- GntTreeRow *old = tree->current;
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + GntTreeRow *old = priv->current; if (text[0] == '\r' || text[0] == '\n') {
gnt_widget_activate(widget);
- } else if (tree->priv->search) {
+ } else if (priv->search) { if (g_unichar_isprint(*text)) {
- tree->priv->search = g_string_append_c(tree->priv->search, *text);
+ priv->search = g_string_append_c(priv->search, *text); } else if (g_utf8_collate(text, GNT_KEY_BACKSPACE) == 0) {
- if (tree->priv->search->len)
- tree->priv->search->str[--tree->priv->search->len] = '\0';
+ if (priv->search->len) { + priv->search->str[--priv->search->len] = '\0'; @@ -830,12 +897,13 @@
gnt_bindable_perform_action_key(GNT_BINDABLE(tree), text);
- g_source_remove(tree->priv->search_timeout);
- tree->priv->search_timeout = g_timeout_add_seconds(SEARCH_TIMEOUT_S, search_timeout, tree);
+ g_source_remove(priv->search_timeout); + priv->search_timeout = g_timeout_add_seconds( + SEARCH_TIMEOUT_S, search_timeout, tree); } else if (text[0] == ' ' && text[1] == 0) {
- GntTreeRow *row = tree->current;
+ GntTreeRow *row = priv->current; row->collapsed = !row->collapsed;
@@ -852,35 +920,35 @@
- if (old != tree->current)
- tree_selection_changed(tree, old, tree->current);
+ if (old != priv->current) { + tree_selection_changed(tree, old, priv->current); -gnt_tree_free_columns(GntTree *tree)
+gnt_tree_free_columns(GntTreePrivate *priv) - for (i = 0; i < tree->ncol; i++) {
- g_free(tree->columns[i].title);
+ for (i = 0; i < priv->ncol; i++) { + g_free(priv->columns[i].title);
gnt_tree_destroy(GntWidget *widget)
GntTree *tree = GNT_TREE(widget);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree);
- g_hash_table_destroy(tree->hash);
- g_list_free(tree->list);
- gnt_tree_free_columns(tree);
+ g_hash_table_destroy(priv->hash); + g_list_free(priv->list); + gnt_tree_free_columns(priv); @@ -888,25 +956,27 @@
GntTree *tree = GNT_TREE(widget);
- GntTreeRow *old = tree->current;
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + GntTreeRow *old = priv->current; if (event == GNT_MOUSE_SCROLL_UP) {
action_up(GNT_BINDABLE(widget), NULL);
} else if (event == GNT_MOUSE_SCROLL_DOWN) {
action_down(GNT_BINDABLE(widget), NULL);
} else if (event == GNT_LEFT_MOUSE_DOWN) {
- GntTree *tree = GNT_TREE(widget);
int pos = gnt_widget_get_has_border(widget) ? 1 : 0;
+ if (priv->show_title) { pos = y - widget->priv.y - pos;
- row = get_next_n(tree->top, pos);
- if (row && tree->current != row) {
- GntTreeRow *old = tree->current;
+ row = get_next_n(priv->top, pos); + if (row && priv->current != row) { + GntTreeRow *old = priv->current; - tree_selection_changed(tree, old, tree->current);
- } else if (row && row == tree->current) {
+ tree_selection_changed(tree, old, priv->current); + } else if (row && row == priv->current) { row->isselected = !row->isselected;
g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key);
@@ -918,8 +988,8 @@
- if (old != tree->current) {
- tree_selection_changed(tree, old, tree->current);
+ if (old != priv->current) { + tree_selection_changed(tree, old, priv->current); @@ -939,11 +1009,16 @@
start_search(GntBindable *bindable, G_GNUC_UNUSED GList *params)
GntTree *tree = GNT_TREE(bindable);
- if (tree->priv->search)
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); gnt_widget_set_disable_actions(GNT_WIDGET(tree), TRUE);
- tree->priv->search = g_string_new(NULL);
- tree->priv->search_timeout = g_timeout_add_seconds(SEARCH_TIMEOUT_S, search_timeout, tree);
+ priv->search = g_string_new(NULL); + g_timeout_add_seconds(SEARCH_TIMEOUT_S, search_timeout, tree); @@ -951,8 +1026,12 @@
end_search_action(GntBindable *bindable, G_GNUC_UNUSED GList *params)
GntTree *tree = GNT_TREE(bindable);
- if (tree->priv->search == NULL)
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + if (priv->search == NULL) { gnt_widget_set_disable_actions(GNT_WIDGET(tree), FALSE);
@@ -963,15 +1042,17 @@
move_first_action(GntBindable *bind, G_GNUC_UNUSED GList *params)
GntTree *tree = GNT_TREE(bind);
- GntTreeRow *row = tree->root;
- GntTreeRow *old = tree->current;
- if (row && !row_matches_search(row))
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + GntTreeRow *row = priv->root; + GntTreeRow *old = priv->current; + if (row && !row_matches_search(row)) {
- if (old != tree->current)
- tree_selection_changed(tree, old, tree->current);
+ if (old != priv->current) + tree_selection_changed(tree, old, priv->current); @@ -981,18 +1062,20 @@
move_last_action(GntBindable *bind, G_GNUC_UNUSED GList *params)
GntTree *tree = GNT_TREE(bind);
- GntTreeRow *old = tree->current;
- GntTreeRow *row = tree->bottom;
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + GntTreeRow *old = priv->current; + GntTreeRow *row = priv->bottom; while ((next = get_next(row)))
- if (old != tree->current)
- tree_selection_changed(tree, old, tree->current);
+ if (old != priv->current) { + tree_selection_changed(tree, old, priv->current); @@ -1003,14 +1086,17 @@
G_GNUC_UNUSED GParamSpec *spec)
GntTree *tree = GNT_TREE(obj);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); _gnt_tree_init_internals(tree, g_value_get_int(value));
- if (tree->priv->expander_level == g_value_get_int(value))
+ if (priv->expander_level == g_value_get_int(value)) { - tree->priv->expander_level = g_value_get_int(value);
+ priv->expander_level = g_value_get_int(value); @@ -1021,12 +1107,14 @@
G_GNUC_UNUSED GParamSpec *spec)
GntTree *tree = GNT_TREE(obj);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); - g_value_set_int(value, tree->ncol);
+ g_value_set_int(value, priv->ncol); - g_value_set_int(value, tree->priv->expander_level);
+ g_value_set_int(value, priv->expander_level); @@ -1124,10 +1212,10 @@
gnt_tree_init(GntTree *tree)
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); GntWidget *widget = GNT_WIDGET(tree);
- tree->show_separator = TRUE;
- tree->priv = g_new0(GntTreePriv, 1);
+ priv->show_separator = TRUE; gnt_widget_set_grow_x(widget, TRUE);
gnt_widget_set_grow_y(widget, TRUE);
@@ -1188,26 +1276,36 @@
GList *gnt_tree_get_rows(GntTree *tree)
+ GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); void gnt_tree_scroll(GntTree *tree, int count)
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); - if (get_root_distance(tree->top) == 0)
+ if (get_root_distance(priv->top) == 0) { - row = get_prev_n(tree->top, -count);
+ row = get_prev_n(priv->top, -count);
- get_next_n_opt(tree->bottom, count, &count);
- tree->top = get_next_n(tree->top, count);
+ get_next_n_opt(priv->bottom, count, &count); + priv->top = get_next_n(priv->top, count); @@ -1215,17 +1313,18 @@
-find_position(GntTree *tree, gpointer key, gpointer parent)
+find_position(GntTreePrivate *priv, gpointer key, gpointer parent) - if (tree->priv->compare == NULL)
+ if (priv->compare == NULL) {
- row = g_hash_table_lookup(tree->hash, parent);
+ row = g_hash_table_lookup(priv->hash, parent); @@ -1235,8 +1334,9 @@
- if (tree->priv->compare(key, row->key) < 0)
+ if (priv->compare(key, row->key) < 0) { return (row->prev ? row->prev->key : NULL);
@@ -1247,26 +1347,32 @@
void gnt_tree_sort_row(GntTree *tree, gpointer key)
+ GntTreePrivate *priv = NULL; - if (!tree->priv->compare)
+ g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); - row = g_hash_table_lookup(tree->hash, key);
+ row = g_hash_table_lookup(priv->hash, key); g_return_if_fail(row != NULL);
- current = g_list_index(tree->list, key);
+ current = g_list_index(priv->list, key);
- if (tree->priv->compare(row->key, s->key) < 0)
+ if (priv->compare(row->key, s->key) < 0) { @@ -1283,12 +1389,12 @@
row->parent->child = row;
g_return_if_fail(s != NULL); /* s cannot be NULL */
- newp = g_list_index(tree->list, s) - 1;
+ newp = g_list_index(priv->list, s) - 1; row->prev->next = row->next;
@@ -1297,7 +1403,7 @@
row->parent->child = row->next;
@@ -1308,43 +1414,43 @@
- newp = g_list_index(tree->list, q) + 1;
+ newp = g_list_index(priv->list, q) + 1; - tree->list = g_list_reposition_child(tree->list, current, newp);
+ priv->list = g_list_reposition_child(priv->list, current, newp); GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
+ GntTreePrivate *priv = NULL; - if (g_hash_table_lookup(tree->hash, key)) {
+ g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); + if (g_hash_table_lookup(priv->hash, key)) { gnt_tree_remove(tree, key);
- g_hash_table_replace(tree->hash, key, row);
+ g_hash_table_replace(priv->hash, key, row); - if (bigbro == NULL && tree->priv->compare)
- bigbro = find_position(tree, key, parent);
+ if (bigbro == NULL && priv->compare) { + bigbro = find_position(priv, key, parent); - if (tree->root == NULL)
- tree->list = g_list_prepend(tree->list, key);
+ if (priv->root == NULL) { + priv->list = g_list_prepend(priv->list, key); - pr = g_hash_table_lookup(tree->hash, bigbro);
+ pr = g_hash_table_lookup(priv->hash, bigbro); if (pr->next) pr->next->prev = row;
@@ -1353,13 +1459,13 @@
row->parent = pr->parent;
- position = g_list_index(tree->list, bigbro);
+ position = g_list_index(priv->list, bigbro); if (pr == NULL && parent)
- pr = g_hash_table_lookup(tree->hash, parent);
+ pr = g_hash_table_lookup(priv->hash, parent); if (pr->child) pr->child->prev = row;
@@ -1367,23 +1473,25 @@
- position = g_list_index(tree->list, parent);
+ position = g_list_index(priv->list, parent); - GntTreeRow *r = tree->root;
+ GntTreeRow *r = priv->root; - if (tree->current == tree->root)
- tree->list = g_list_prepend(tree->list, key);
+ if (priv->current == priv->root) { + priv->list = g_list_prepend(priv->list, key); - tree->list = g_list_insert(tree->list, key, position + 1);
+ g_list_insert(priv->list, key, position + 1); @@ -1393,15 +1501,19 @@
GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent)
+ GntTreePrivate *priv = NULL; GntTreeRow *pr = NULL, *br = NULL;
+ g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); - pr = g_hash_table_lookup(tree->hash, parent);
+ pr = g_hash_table_lookup(priv->hash, parent);
@@ -1414,32 +1526,52 @@
gpointer gnt_tree_get_selection_data(GntTree *tree)
- return tree->current->key; /* XXX: perhaps we should just get rid of 'data' */
+ GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); + /* XXX: perhaps we should just get rid of 'data' */ + return priv->current->key; char *gnt_tree_get_selection_text(GntTree *tree)
- return update_row_text(tree, tree->current);
+ GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); + return update_row_text(priv, priv->current); GList *gnt_tree_get_row_text_list(GntTree *tree, gpointer key)
+ GntTreePrivate *priv = NULL; GList *list = NULL, *iter;
- GntTreeRow *row = key ? g_hash_table_lookup(tree->hash, key) : tree->current;
+ GntTreeRow *row = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); + row = key ? g_hash_table_lookup(priv->hash, key) : priv->current; - for (i = 0, iter = row->columns; i < tree->ncol && iter;
- i++, iter = iter->next)
+ for (i = 0, iter = row->columns; i < priv->ncol && iter; + i++, iter = iter->next) { GntTreeCol *col = iter->data;
- list = g_list_append(list, BINARY_DATA(tree, i) ? col->text : g_strdup(col->text));
+ list = g_list_append(list, BINARY_DATA(priv, i) + : g_strdup(col->text)); @@ -1452,8 +1584,14 @@
void gnt_tree_remove(GntTree *tree, gpointer key)
- GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
+ GntTreePrivate *priv = NULL; + GntTreeRow *row = NULL; static int depth = 0; /* Only redraw after all child nodes are removed */
+ g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + row = g_hash_table_lookup(priv->hash, key); @@ -1466,30 +1604,32 @@
- if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0)
+ if (get_distance(priv->top, row) >= 0 && + get_distance(row, priv->bottom) >= 0) { /* Update root/top/current/bottom if necessary */
- tree->root = get_next(row);
- if (tree->top != tree->root)
- tree->top = get_prev(row);
- tree->top = get_next(row);
+ if (priv->root == row) { + priv->root = get_next(row); + if (priv->top == row) { + if (priv->top != priv->root) { + priv->top = get_prev(row); + priv->top = get_next(row); - if (tree->current == row)
- if (tree->current != tree->root)
- tree->current = get_prev(row);
- tree->current = get_next(row);
- tree_selection_changed(tree, row, tree->current);
+ if (priv->current == row) { + if (priv->current != priv->root) { + priv->current = get_prev(row); + priv->current = get_next(row); + tree_selection_changed(tree, row, priv->current); - if (tree->bottom == row)
- tree->bottom = get_prev(row);
+ if (priv->bottom == row) { + priv->bottom = get_prev(row); @@ -1500,8 +1640,8 @@
row->prev->next = row->next;
- g_hash_table_remove(tree->hash, key);
- tree->list = g_list_remove(tree->list, key);
+ g_hash_table_remove(priv->hash, key); + priv->list = g_list_remove(priv->list, key); if (redraw && depth == 0)
@@ -1512,31 +1652,44 @@
void gnt_tree_remove_all(GntTree *tree)
- g_hash_table_remove_all(tree->hash);
- g_list_free(tree->list);
- tree->current = tree->top = tree->bottom = NULL;
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_hash_table_remove_all(priv->hash); + g_list_free(priv->list); + priv->current = priv->top = priv->bottom = NULL; int gnt_tree_get_selection_visible_line(GntTree *tree)
- return get_distance(tree->top, tree->current) +
+ GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), 0); + priv = gnt_tree_get_instance_private(tree); + return get_distance(priv->top, priv->current) + !gnt_widget_get_has_border(GNT_WIDGET(tree));
void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text)
+ GntTreePrivate *priv = NULL; - g_return_if_fail(colno < tree->ncol);
+ g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_return_if_fail(colno < priv->ncol); - row = g_hash_table_lookup(tree->hash, key);
+ row = g_hash_table_lookup(priv->hash, key); col = g_list_nth_data(row->columns, colno);
- if (BINARY_DATA(tree, colno)) {
+ if (BINARY_DATA(priv, colno)) { col->text = (gpointer)text;
@@ -1544,8 +1697,8 @@
if (gnt_widget_get_mapped(GNT_WIDGET(tree)) &&
- get_distance(tree->top, row) >= 0 &&
- get_distance(row, tree->bottom) >= 0) {
+ get_distance(priv->top, row) >= 0 && + get_distance(row, priv->bottom) >= 0) { @@ -1553,17 +1706,22 @@
GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
+ GntTreePrivate *priv = NULL; - r = g_hash_table_lookup(tree->hash, key);
+ g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); + r = g_hash_table_lookup(priv->hash, key); g_return_val_if_fail(!r || !r->choice, NULL);
- if (tree->priv->compare)
- bigbro = find_position(tree, key, parent);
- r = g_hash_table_lookup(tree->hash, parent);
+ bigbro = find_position(priv, key, parent); + r = g_hash_table_lookup(priv->hash, parent);
@@ -1581,7 +1739,13 @@
void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set)
- GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + row = g_hash_table_lookup(priv->hash, key); @@ -1593,7 +1757,13 @@
gboolean gnt_tree_get_choice(GntTree *tree, void *key)
- GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
+ GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), FALSE); + priv = gnt_tree_get_instance_private(tree); + row = g_hash_table_lookup(priv->hash, key); @@ -1604,7 +1774,13 @@
void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags)
- GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + row = g_hash_table_lookup(priv->hash, key); if (!row || row->flags == flags)
@@ -1614,7 +1790,13 @@
void gnt_tree_set_row_color(GntTree *tree, void *key, int color)
- GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + row = g_hash_table_lookup(priv->hash, key); if (!row || row->color == color)
@@ -1624,40 +1806,73 @@
void gnt_tree_set_selected(GntTree *tree , void *key)
+ GntTreePrivate *priv = NULL; - GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
- if (!row || row == tree->current)
+ g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + row = g_hash_table_lookup(priv->hash, key); + if (!row || row == priv->current) { + if (priv->top == NULL) { + if (priv->bottom == NULL) {
- if (tree->bottom == NULL)
+ if ((dist = get_distance(priv->current, priv->bottom)) < 0) { + gnt_tree_scroll(tree, -dist); + } else if ((dist = get_distance(priv->current, priv->top)) > 0) { + gnt_tree_scroll(tree, -dist); + tree_selection_changed(tree, row, priv->current);
- if ((dist = get_distance(tree->current, tree->bottom)) < 0)
- gnt_tree_scroll(tree, -dist);
- else if ((dist = get_distance(tree->current, tree->top)) > 0)
- gnt_tree_scroll(tree, -dist);
- tree_selection_changed(tree, row, tree->current);
+gnt_tree_get_current(GntTree *tree) + GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); +gnt_tree_get_top(GntTree *tree) + GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); static void _gnt_tree_init_internals(GntTree *tree, int col)
- gnt_tree_free_columns(tree);
+ GntTreePrivate *priv = gnt_tree_get_instance_private(tree); + gnt_tree_free_columns(priv);
- tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row);
- tree->columns = g_new0(struct _GntTreeColInfo, col);
- tree->priv->lastvisible = col - 1;
+ priv->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, + priv->columns = g_new0(struct _GntTreeColInfo, col); + priv->lastvisible = col - 1; - tree->columns[col].width = 15;
+ priv->columns[col].width = 15;
- tree->show_title = FALSE;
+ priv->show_title = FALSE; g_object_notify(G_OBJECT(tree), "columns");
@@ -1673,15 +1888,20 @@
GntTreeRow *gnt_tree_create_row_from_list(GntTree *tree, GList *list)
+ GntTreePrivate *priv = NULL; - GntTreeRow *row = g_new0(GntTreeRow, 1);
- for (i = 0, iter = list; i < tree->ncol && iter; iter = iter->next, i++)
+ g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); + row = g_new0(GntTreeRow, 1); + for (i = 0, iter = list; i < priv->ncol && iter; + iter = iter->next, i++) { GntTreeCol *col = g_new0(GntTreeCol, 1);
- if (BINARY_DATA(tree, i)) {
+ if (BINARY_DATA(priv, i)) { @@ -1697,14 +1917,17 @@
GntTreeRow *gnt_tree_create_row(GntTree *tree, ...)
+ GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); - for (i = 0; i < tree->ncol; i++)
+ for (i = 0; i < priv->ncol; i++) { list = g_list_append(list, va_arg(args, char *));
@@ -1717,47 +1940,76 @@
void gnt_tree_set_col_width(GntTree *tree, int col, int width)
- g_return_if_fail(col < tree->ncol);
+ GntTreePrivate *priv = NULL; - tree->columns[col].width = width;
- if (tree->columns[col].width_ratio == 0)
- tree->columns[col].width_ratio = width;
+ g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_return_if_fail(col < priv->ncol); + priv->columns[col].width = width; + if (priv->columns[col].width_ratio == 0) { + priv->columns[col].width_ratio = width; void gnt_tree_set_column_title(GntTree *tree, int index, const char *title)
- g_free(tree->columns[index].title);
- tree->columns[index].title = g_strdup(title);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_free(priv->columns[index].title); + priv->columns[index].title = g_strdup(title); void gnt_tree_set_column_titles(GntTree *tree, ...)
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); - for (i = 0; i < tree->ncol; i++)
+ for (i = 0; i < priv->ncol; i++) { const char *title = va_arg(args, const char *);
- tree->columns[i].title = g_strdup(title);
+ priv->columns[i].title = g_strdup(title); void gnt_tree_set_show_title(GntTree *tree, gboolean set)
- tree->show_title = set;
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + priv->show_title = set; GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4);
void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func)
- tree->priv->compare = func;
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded)
- GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + row = g_hash_table_lookup(priv->hash, key); row->collapsed = !expanded;
if (GNT_WIDGET(tree)->window)
@@ -1768,15 +2020,25 @@
void gnt_tree_set_show_separator(GntTree *tree, gboolean set)
- tree->show_separator = set;
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + priv->show_separator = set; void gnt_tree_adjust_columns(GntTree *tree)
- GntTreeRow *row = tree->root;
+ GntTreePrivate *priv = NULL; - widths = g_new0(int, tree->ncol);
+ g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + widths = g_new0(int, priv->ncol); for (i = 0, iter = row->columns; iter; iter = iter->next, i++) {
@@ -1794,14 +2056,16 @@
twidth = gnt_widget_get_has_border(GNT_WIDGET(tree)) ? 3 : 1;
- for (i = 0; i < tree->ncol; i++) {
- if (tree->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE)
- widths[i] = tree->columns[i].width;
+ for (i = 0; i < priv->ncol; i++) { + if (priv->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE) { + widths[i] = priv->columns[i].width; gnt_tree_set_col_width(tree, i, widths[i]);
- if (!COLUMN_INVISIBLE(tree, i)) {
+ if (!COLUMN_INVISIBLE(priv, i)) { twidth = twidth + widths[i];
- if (tree->priv->lastvisible != i)
+ if (priv->lastvisible != i) { @@ -1811,34 +2075,48 @@
void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd)
- g_hash_table_destroy(tree->hash);
- tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_hash_table_destroy(priv->hash); + priv->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row); -set_column_flag(GntTree *tree, int col, GntTreeColumnFlag flag, gboolean set)
+set_column_flag(GntTreePrivate *priv, int col, GntTreeColumnFlag flag, gboolean set) - tree->columns[col].flags |= flag;
+ priv->columns[col].flags |= flag; - tree->columns[col].flags &= ~flag;
+ priv->columns[col].flags &= ~flag; void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis)
- g_return_if_fail(col < tree->ncol);
- set_column_flag(tree, col, GNT_TREE_COLUMN_INVISIBLE, !vis);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_return_if_fail(col < priv->ncol); + set_column_flag(priv, col, GNT_TREE_COLUMN_INVISIBLE, !vis); /* the column is visible */
- if (tree->priv->lastvisible < col)
- tree->priv->lastvisible = col;
+ if (priv->lastvisible < col) { + priv->lastvisible = col; - if (tree->priv->lastvisible == col)
- while (tree->priv->lastvisible) {
- tree->priv->lastvisible--;
- if (!COLUMN_INVISIBLE(tree, tree->priv->lastvisible))
+ if (priv->lastvisible == col) { + while (priv->lastvisible) { + if (!COLUMN_INVISIBLE(priv, if (gnt_widget_get_mapped(GNT_WIDGET(tree)))
@@ -1846,51 +2124,92 @@
void gnt_tree_set_column_resizable(GntTree *tree, int col, gboolean res)
- g_return_if_fail(col < tree->ncol);
- set_column_flag(tree, col, GNT_TREE_COLUMN_FIXED_SIZE, !res);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_return_if_fail(col < priv->ncol); + set_column_flag(priv, col, GNT_TREE_COLUMN_FIXED_SIZE, !res); void gnt_tree_set_column_is_binary(GntTree *tree, int col, gboolean bin)
- g_return_if_fail(col < tree->ncol);
- set_column_flag(tree, col, GNT_TREE_COLUMN_BINARY_DATA, bin);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_return_if_fail(col < priv->ncol); + set_column_flag(priv, col, GNT_TREE_COLUMN_BINARY_DATA, bin); void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right)
- g_return_if_fail(col < tree->ncol);
- set_column_flag(tree, col, GNT_TREE_COLUMN_RIGHT_ALIGNED, right);
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_return_if_fail(col < priv->ncol); + set_column_flag(priv, col, GNT_TREE_COLUMN_RIGHT_ALIGNED, right); void gnt_tree_set_column_width_ratio(GntTree *tree, int cols[])
+ GntTreePrivate *priv = NULL; - for (i = 0; i < tree->ncol && cols[i]; i++) {
- tree->columns[i].width_ratio = cols[i];
+ g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + for (i = 0; i < priv->ncol && cols[i]; i++) { + priv->columns[i].width_ratio = cols[i]; void gnt_tree_set_search_column(GntTree *tree, int col)
- g_return_if_fail(col < tree->ncol);
- g_return_if_fail(!BINARY_DATA(tree, col));
- tree->priv->search_column = col;
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + g_return_if_fail(col < priv->ncol); + g_return_if_fail(!BINARY_DATA(priv, col)); + priv->search_column = col; gboolean gnt_tree_is_searching(GntTree *tree)
- return (tree->priv->search != NULL);
+ GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), FALSE); + priv = gnt_tree_get_instance_private(tree); + return (priv->search != NULL); void gnt_tree_set_search_function(GntTree *tree,
gboolean (*func)(GntTree *tree, gpointer key, const char *search, const char *current))
- tree->priv->search_func = func;
+ GntTreePrivate *priv = NULL; + g_return_if_fail(GNT_IS_TREE(tree)); + priv = gnt_tree_get_instance_private(tree); + priv->search_func = func; gpointer gnt_tree_get_parent_key(GntTree *tree, gpointer key)
- GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
+ GntTreePrivate *priv = NULL; + g_return_val_if_fail(GNT_IS_TREE(tree), NULL); + priv = gnt_tree_get_instance_private(tree); + row = g_hash_table_lookup(priv->hash, key); return (row && row->parent) ? row->parent->key : NULL;