libgnt/libgnt

Merged in default (pull request #44)

2019-04-24, Gary Kramlich
9ed8d7ec255e
Merged in default (pull request #44)

Hide all GntTree internals

Approved-by: Gary Kramlich
  • +1 -1
    gntbindable.c
  • +4 -3
    gntcombobox.c
  • +3 -1
    gntfilesel.c
  • +1 -1
    gntmenu.c
  • +698 -379
    gnttree.c
  • +8 -48
    gnttree.h
  • +37 -0
    gnttreeprivate.h
  • --- a/gntbindable.c Tue Apr 23 18:42:19 2019 -0400
    +++ b/gntbindable.c Wed Apr 24 04:24:43 2019 +0000
    @@ -446,7 +446,7 @@
    gnt_tree_set_compare_func(bv.tree, (GCompareFunc)g_utf8_collate);
    g_hash_table_foreach(klass->actions, add_action, &bv);
    g_hash_table_foreach(klass->bindings, add_binding, &bv);
    - if (GNT_TREE(tree)->list == NULL) {
    + if (gnt_tree_get_rows(GNT_TREE(tree)) == NULL) {
    gnt_widget_destroy(GNT_WIDGET(tree));
    tree = NULL;
    } else
    --- a/gntcombobox.c Tue Apr 23 18:42:19 2019 -0400
    +++ b/gntcombobox.c Wed Apr 24 04:24:43 2019 +0000
    @@ -24,6 +24,7 @@
    #include "gntbox.h"
    #include "gntcombobox.h"
    #include "gnttree.h"
    +#include "gnttreeprivate.h"
    #include "gntstyle.h"
    #include "gntutils.h"
    @@ -134,7 +135,7 @@
    {
    GntWidget *widget = GNT_WIDGET(box);
    GntWidget *parent = gnt_widget_get_parent(box->dropdown);
    - int height = g_list_length(GNT_TREE(box->dropdown)->list);
    + int height = g_list_length(gnt_tree_get_rows(GNT_TREE(box->dropdown)));
    int y = widget->priv.y + widget->priv.height - 1;
    gnt_widget_set_size(box->dropdown, widget->priv.width, height + 2);
    @@ -203,10 +204,10 @@
    int len = strlen(text);
    GntTree *tree = GNT_TREE(box->dropdown);
    - GntTreeRow *current = tree->current;
    + GntTreeRow *current = gnt_tree_get_current(tree);
    SEARCH_IN_RANGE(gnt_tree_row_get_next(tree, current), NULL);
    - SEARCH_IN_RANGE(tree->top, current);
    + SEARCH_IN_RANGE(gnt_tree_get_top(tree), current);
    #undef SEARCH_IN_RANGE
    }
    --- a/gntfilesel.c Tue Apr 23 18:42:19 2019 -0400
    +++ b/gntfilesel.c Wed Apr 24 04:24:43 2019 +0000
    @@ -476,8 +476,10 @@
    g_list_free_full(priv->tags, g_free);
    priv->tags = NULL;
    - for (iter = GNT_TREE(tree)->list; iter; iter = iter->next)
    + for (iter = gnt_tree_get_rows(GNT_TREE(tree)); iter;
    + iter = iter->next) {
    gnt_tree_set_row_flags(GNT_TREE(tree), iter->data, GNT_TEXT_FLAG_NORMAL);
    + }
    return TRUE;
    }
    --- a/gntmenu.c Tue Apr 23 18:42:19 2019 -0400
    +++ b/gntmenu.c Wed Apr 24 04:24:43 2019 +0000
    @@ -482,7 +482,7 @@
    widget->priv.x = 0;
    widget->priv.y = 0;
    } else {
    - GNT_TREE(widget)->show_separator = FALSE;
    + gnt_tree_set_show_separator(GNT_TREE(widget), FALSE);
    g_object_set(G_OBJECT(widget), "columns", NUM_COLUMNS, NULL);
    gnt_tree_set_col_width(GNT_TREE(widget), ITEM_TRIGGER, 3);
    gnt_tree_set_column_resizable(GNT_TREE(widget), ITEM_TRIGGER, FALSE);
    --- 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 @@
    #include <ctype.h>
    #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)
    enum
    {
    @@ -51,8 +54,27 @@
    SIGS,
    };
    -struct _GntTreePriv
    +typedef struct
    {
    + 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_title;
    + gboolean show_separator; /* Whether to show column separators */
    +
    GString *search;
    int search_timeout;
    int search_column;
    @@ -61,7 +83,7 @@
    GCompareFunc compare;
    int lastvisible;
    int expander_level;
    -};
    +} GntTreePrivate;
    #define TAB_SIZE 3
    @@ -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)
    static void
    readjust_columns(GntTree *tree)
    {
    + GntTreePrivate *priv = gnt_tree_get_instance_private(tree);
    int i, col, total;
    int width;
    -#define WIDTH(i) (tree->columns[i].width_ratio ? tree->columns[i].width_ratio : tree->columns[i].width)
    +#define WIDTH(i) \
    + (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 -= 2;
    }
    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) {
    continue;
    - if (tree->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE)
    - width -= WIDTH(i) + (tree->priv->lastvisible != i);
    - else
    - total += WIDTH(i) + (tree->priv->lastvisible != i);
    + }
    + if (priv->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE) {
    + width -= WIDTH(i) + (priv->lastvisible != i);
    + } else {
    + total += WIDTH(i) + (priv->lastvisible != i);
    + }
    }
    if (total == 0)
    return;
    - 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) {
    continue;
    - if (tree->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE)
    + }
    + if (priv->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE) {
    col = WIDTH(i);
    - else
    + } else {
    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 @@
    static gboolean
    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 (SEARCHING(priv)) {
    + GntTreeCol *col;
    char *one, *two, *z;
    - 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);
    + if (!col) {
    + 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);
    z = strstr(one, two);
    g_free(one);
    g_free(two);
    @@ -308,15 +348,15 @@
    }
    static char *
    -update_row_text(GntTree *tree, GntTreeRow *row)
    +update_row_text(GntTreePrivate *priv, GntTreeRow *row)
    {
    GString *string = g_string_new(NULL);
    GList *iter;
    int i;
    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;
    const char *text;
    int len;
    @@ -325,17 +365,19 @@
    int width;
    const char *display;
    - if (COLUMN_INVISIBLE(tree, i))
    + if (COLUMN_INVISIBLE(priv, i)) {
    continue;
    + }
    - if (BINARY_DATA(tree, i))
    + if (BINARY_DATA(priv, i)) {
    display = "";
    - else
    + } else {
    display = col->text;
    + }
    len = gnt_util_onscreen_width(display, NULL);
    - width = tree->columns[i].width;
    + width = priv->columns[i].width;
    if (i == 0)
    {
    @@ -344,9 +386,8 @@
    g_string_append_printf(string, "[%c] ",
    row->isselected ? 'X' : ' ');
    fl = 4;
    - }
    - else if (find_depth(row) < tree->priv->expander_level && row->child)
    - {
    + } else if (find_depth(row) < priv->expander_level &&
    + row->child) {
    if (row->collapsed)
    {
    string = g_string_append(string, "+ ");
    @@ -356,17 +397,16 @@
    string = g_string_append(string, "- ");
    }
    fl = 2;
    - }
    - else
    - {
    + } else {
    fl = TAB_SIZE * find_depth(row);
    g_string_append_printf(string, "%*s", fl, "");
    }
    len += fl;
    - } else if (notfirst && tree->show_separator)
    + } else if (notfirst && priv->show_separator) {
    g_string_append_c(string, '|');
    - else
    + } else {
    g_string_append_c(string, ' ');
    + }
    notfirst = TRUE;
    @@ -375,7 +415,7 @@
    cut = TRUE;
    }
    - 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 @@
    len++;
    }
    - if (!RIGHT_ALIGNED(tree, i) && len < tree->columns[i].width && iter->next)
    + if (!RIGHT_ALIGNED(priv, i) && len < priv->columns[i].width &&
    + iter->next) {
    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)
    static void
    tree_mark_columns(GntTree *tree, int pos, int y, chtype type)
    {
    + GntTreePrivate *priv = gnt_tree_get_instance_private(tree);
    GntWidget *widget = GNT_WIDGET(tree);
    int i;
    int x = pos;
    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)) {
    notfirst = TRUE;
    NEXT_X;
    }
    - if (!COLUMN_INVISIBLE(tree, i+1) && notfirst)
    + if (!COLUMN_INVISIBLE(priv, i + 1) && notfirst) {
    mvwaddch(widget->window, y, x, type);
    + }
    }
    }
    static void
    redraw_tree(GntTree *tree)
    {
    + GntTreePrivate *priv = gnt_tree_get_instance_private(tree);
    int start, i;
    GntWidget *widget = GNT_WIDGET(tree);
    GntTreeRow *row;
    @@ -431,18 +475,18 @@
    pos = gnt_widget_get_has_border(widget) ? 1 : 0;
    - if (tree->top == NULL)
    - 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));
    start = 0;
    - if (tree->show_title)
    - {
    + if (priv->show_title) {
    int i;
    int x = pos;
    @@ -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)) {
    continue;
    }
    - 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);
    NEXT_X;
    }
    if (pos)
    {
    - 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));
    + tree_mark_columns(
    + tree, pos, 0,
    + (priv->show_separator ? ACS_TTEE : ACS_HLINE) |
    + gnt_color_pair(GNT_COLOR_NORMAL));
    + tree_mark_columns(
    + 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));
    + tree_mark_columns(
    + tree, pos, pos + 1,
    + (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));
    start = 2;
    }
    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);
    if (down < rows)
    {
    - tree->top = get_prev_n(tree->bottom, rows);
    - if (tree->top == NULL)
    - 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);
    if (up < 0)
    - 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);
    - row = tree->top;
    + if (priv->top && !row_matches_search(priv->top)) {
    + priv->top = get_next(priv->top);
    + }
    + row = 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))
    continue;
    - 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)
    attr |= A_BLINK;
    - if (row == tree->current)
    - {
    + if (row == priv->current) {
    current = i;
    attr |= A_BOLD;
    if (gnt_widget_has_focus(widget))
    attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT);
    else
    attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT_D);
    - }
    - else
    - {
    + } else {
    if (flags & GNT_TEXT_FLAG_DIM)
    if (row->color)
    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->bottom = row;
    + priv->bottom = row;
    g_free(str);
    tree_mark_columns(tree, pos, i,
    - (tree->show_separator ? ACS_VLINE : ' ') | attr);
    + (priv->show_separator ? ACS_VLINE : ' ') |
    + attr);
    }
    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 : ' '));
    i++;
    }
    @@ -575,16 +627,16 @@
    int total = 0;
    int showing, position;
    - 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);
    total -= rows;
    - up = get_distance(tree->root, tree->top);
    + up = get_distance(priv->root, priv->top);
    down = total - up;
    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);
    + if (SEARCHING(priv)) {
    + 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);
    int i, width = 0;
    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) {
    width++;
    + }
    }
    + }
    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;
    - GNTDEBUG;
    + priv->top = priv->root;
    + priv->current = priv->root;
    }
    static void
    @@ -676,17 +732,20 @@
    {
    int dist;
    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 (row == NULL)
    return FALSE;
    - tree->current = row;
    - if ((dist = get_distance(tree->current, tree->bottom)) < 0)
    + priv->current = row;
    + if ((dist = get_distance(priv->current, priv->bottom)) < 0) {
    gnt_tree_scroll(tree, -dist);
    - else
    + } else {
    redraw_tree(tree);
    - if (old != tree->current)
    - tree_selection_changed(tree, old, tree->current);
    + }
    + if (old != priv->current) {
    + tree_selection_changed(tree, old, priv->current);
    + }
    return TRUE;
    }
    @@ -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;
    int dist;
    - if (!row || !row->parent || SEARCHING(tree))
    + if (!row || !row->parent || SEARCHING(priv)) {
    return FALSE;
    + }
    - 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);
    - else
    + } else {
    redraw_tree(tree);
    - tree_selection_changed(tree, row, tree->current);
    + }
    + tree_selection_changed(tree, row, priv->current);
    return TRUE;
    }
    @@ -714,17 +776,20 @@
    {
    int dist;
    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 (!row)
    return FALSE;
    - tree->current = row;
    - if ((dist = get_distance(tree->current, tree->top)) > 0)
    + priv->current = row;
    + if ((dist = get_distance(priv->current, priv->top)) > 0) {
    gnt_tree_scroll(tree, -dist);
    - else
    + } else {
    redraw_tree(tree);
    - if (old != tree->current)
    - tree_selection_changed(tree, old, tree->current);
    + }
    + if (old != priv->current) {
    + tree_selection_changed(tree, old, priv->current);
    + }
    return TRUE;
    }
    @@ -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);
    if (row)
    {
    - 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);
    redraw_tree(tree);
    - }
    - else if (tree->current != tree->bottom)
    - {
    - tree->current = tree->bottom;
    + } else if (priv->current != priv->bottom) {
    + priv->current = priv->bottom;
    redraw_tree(tree);
    }
    - if (old != tree->current)
    - tree_selection_changed(tree, old, tree->current);
    + if (old != priv->current) {
    + tree_selection_changed(tree, old, priv->current);
    + }
    return TRUE;
    }
    @@ -758,40 +823,40 @@
    {
    GntWidget *widget = GNT_WIDGET(bind);
    GntTree *tree = GNT_TREE(bind);
    + GntTreePrivate *priv = gnt_tree_get_instance_private(tree);
    GntTreeRow *row;
    - 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);
    row = get_prev_n(
    - tree->top,
    - widget->priv.height - 1 - tree->show_title * 2 -
    + priv->top,
    + widget->priv.height - 1 - priv->show_title * 2 -
    (gnt_widget_get_has_border(widget) ? 2 : 0));
    if (row == NULL)
    - row = tree->root;
    - tree->top = row;
    - tree->current = get_next_n_opt(tree->top, dist, NULL);
    + row = priv->root;
    + priv->top = row;
    + priv->current = get_next_n_opt(priv->top, dist, NULL);
    + redraw_tree(tree);
    + } else if (priv->current != priv->top) {
    + priv->current = priv->top;
    redraw_tree(tree);
    }
    - else if (tree->current != tree->top)
    - {
    - tree->current = tree->top;
    - redraw_tree(tree);
    + if (old != priv->current) {
    + tree_selection_changed(tree, old, priv->current);
    }
    - if (old != tree->current)
    - tree_selection_changed(tree, old, tree->current);
    return TRUE;
    }
    static void
    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);
    + if (priv->search) {
    + g_source_remove(priv->search_timeout);
    + g_string_free(priv->search, TRUE);
    + priv->search = NULL;
    + 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') {
    end_search(tree);
    gnt_widget_activate(widget);
    - } else if (tree->priv->search) {
    + } else if (priv->search) {
    gboolean changed = TRUE;
    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';
    + }
    } else
    changed = FALSE;
    if (changed) {
    @@ -830,12 +897,13 @@
    } else {
    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);
    return TRUE;
    } else if (text[0] == ' ' && text[1] == 0) {
    /* Space pressed */
    - GntTreeRow *row = tree->current;
    + GntTreeRow *row = priv->current;
    if (row && row->child)
    {
    row->collapsed = !row->collapsed;
    @@ -852,35 +920,35 @@
    return FALSE;
    }
    - if (old != tree->current)
    - {
    - tree_selection_changed(tree, old, tree->current);
    + if (old != priv->current) {
    + tree_selection_changed(tree, old, priv->current);
    }
    return TRUE;
    }
    static void
    -gnt_tree_free_columns(GntTree *tree)
    +gnt_tree_free_columns(GntTreePrivate *priv)
    {
    int i;
    - 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);
    }
    - g_free(tree->columns);
    + g_free(priv->columns);
    }
    static void
    gnt_tree_destroy(GntWidget *widget)
    {
    GntTree *tree = GNT_TREE(widget);
    + GntTreePrivate *priv = gnt_tree_get_instance_private(tree);
    end_search(tree);
    - if (tree->hash)
    - g_hash_table_destroy(tree->hash);
    - g_list_free(tree->list);
    - gnt_tree_free_columns(tree);
    - g_free(tree->priv);
    + if (priv->hash) {
    + g_hash_table_destroy(priv->hash);
    + }
    + g_list_free(priv->list);
    + gnt_tree_free_columns(priv);
    }
    static gboolean
    @@ -888,25 +956,27 @@
    G_GNUC_UNUSED int y)
    {
    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) {
    GntTreeRow *row;
    - GntTree *tree = GNT_TREE(widget);
    int pos = gnt_widget_get_has_border(widget) ? 1 : 0;
    - if (tree->show_title)
    + if (priv->show_title) {
    pos += 2;
    + }
    pos = y - widget->priv.y - pos;
    - row = get_next_n(tree->top, pos);
    - if (row && tree->current != row) {
    - GntTreeRow *old = tree->current;
    - tree->current = row;
    + row = get_next_n(priv->top, pos);
    + if (row && priv->current != row) {
    + GntTreeRow *old = priv->current;
    + priv->current = row;
    redraw_tree(tree);
    - 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) {
    if (row->choice) {
    row->isselected = !row->isselected;
    g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key);
    @@ -918,8 +988,8 @@
    } else {
    return FALSE;
    }
    - if (old != tree->current) {
    - tree_selection_changed(tree, old, tree->current);
    + if (old != priv->current) {
    + tree_selection_changed(tree, old, priv->current);
    }
    return TRUE;
    }
    @@ -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);
    +
    + if (priv->search) {
    return FALSE;
    + }
    +
    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);
    + priv->search_timeout =
    + g_timeout_add_seconds(SEARCH_TIMEOUT_S, search_timeout, tree);
    return TRUE;
    }
    @@ -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) {
    return FALSE;
    + }
    +
    gnt_widget_set_disable_actions(GNT_WIDGET(tree), FALSE);
    end_search(tree);
    redraw_tree(tree);
    @@ -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)) {
    row = get_next(row);
    + }
    if (row) {
    - tree->current = row;
    + priv->current = row;
    redraw_tree(tree);
    - if (old != tree->current)
    - tree_selection_changed(tree, old, tree->current);
    + if (old != priv->current)
    + tree_selection_changed(tree, old, priv->current);
    }
    return TRUE;
    @@ -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;
    GntTreeRow *next;
    while ((next = get_next(row)))
    row = next;
    if (row) {
    - tree->current = row;
    + priv->current = row;
    redraw_tree(tree);
    - if (old != tree->current)
    - tree_selection_changed(tree, old, tree->current);
    + if (old != priv->current) {
    + tree_selection_changed(tree, old, priv->current);
    + }
    }
    return TRUE;
    @@ -1003,14 +1086,17 @@
    G_GNUC_UNUSED GParamSpec *spec)
    {
    GntTree *tree = GNT_TREE(obj);
    + GntTreePrivate *priv = gnt_tree_get_instance_private(tree);
    +
    switch (prop_id) {
    case PROP_COLUMNS:
    _gnt_tree_init_internals(tree, g_value_get_int(value));
    break;
    case PROP_EXPANDER:
    - if (tree->priv->expander_level == g_value_get_int(value))
    + if (priv->expander_level == g_value_get_int(value)) {
    break;
    - tree->priv->expander_level = g_value_get_int(value);
    + }
    + priv->expander_level = g_value_get_int(value);
    default:
    break;
    }
    @@ -1021,12 +1107,14 @@
    G_GNUC_UNUSED GParamSpec *spec)
    {
    GntTree *tree = GNT_TREE(obj);
    + GntTreePrivate *priv = gnt_tree_get_instance_private(tree);
    +
    switch (prop_id) {
    case PROP_COLUMNS:
    - g_value_set_int(value, tree->ncol);
    + g_value_set_int(value, priv->ncol);
    break;
    case PROP_EXPANDER:
    - g_value_set_int(value, tree->priv->expander_level);
    + g_value_set_int(value, priv->expander_level);
    break;
    default:
    break;
    @@ -1124,10 +1212,10 @@
    static void
    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)
    {
    - return tree->list;
    + GntTreePrivate *priv = NULL;
    +
    + g_return_val_if_fail(GNT_IS_TREE(tree), NULL);
    + priv = gnt_tree_get_instance_private(tree);
    +
    + return priv->list;
    }
    void gnt_tree_scroll(GntTree *tree, int count)
    {
    + GntTreePrivate *priv = NULL;
    GntTreeRow *row;
    + g_return_if_fail(GNT_IS_TREE(tree));
    + priv = gnt_tree_get_instance_private(tree);
    +
    if (count < 0)
    {
    - if (get_root_distance(tree->top) == 0)
    + if (get_root_distance(priv->top) == 0) {
    return;
    - row = get_prev_n(tree->top, -count);
    + }
    + row = get_prev_n(priv->top, -count);
    if (row == NULL)
    - row = tree->root;
    - tree->top = row;
    + row = priv->root;
    + priv->top = row;
    }
    else
    {
    - 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);
    }
    redraw_tree(tree);
    @@ -1215,17 +1313,18 @@
    }
    static gpointer
    -find_position(GntTree *tree, gpointer key, gpointer parent)
    +find_position(GntTreePrivate *priv, gpointer key, gpointer parent)
    {
    GntTreeRow *row;
    - if (tree->priv->compare == NULL)
    + if (priv->compare == NULL) {
    return NULL;
    + }
    if (parent == NULL)
    - row = tree->root;
    + row = priv->root;
    else
    - row = g_hash_table_lookup(tree->hash, parent);
    + row = g_hash_table_lookup(priv->hash, parent);
    if (!row)
    return NULL;
    @@ -1235,8 +1334,9 @@
    while (row)
    {
    - if (tree->priv->compare(key, row->key) < 0)
    + if (priv->compare(key, row->key) < 0) {
    return (row->prev ? row->prev->key : NULL);
    + }
    if (row->next)
    row = row->next;
    else
    @@ -1247,26 +1347,32 @@
    void gnt_tree_sort_row(GntTree *tree, gpointer key)
    {
    + GntTreePrivate *priv = NULL;
    GntTreeRow *row, *q, *s;
    int current, newp;
    - if (!tree->priv->compare)
    + g_return_if_fail(GNT_IS_TREE(tree));
    + priv = gnt_tree_get_instance_private(tree);
    +
    + if (!priv->compare) {
    return;
    + }
    - 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 (row->parent)
    s = row->parent->child;
    else
    - s = tree->root;
    + s = priv->root;
    q = NULL;
    while (s) {
    - if (tree->priv->compare(row->key, s->key) < 0)
    + if (priv->compare(row->key, s->key) < 0) {
    break;
    + }
    q = s;
    s = s->next;
    }
    @@ -1283,12 +1389,12 @@
    if (row->parent)
    row->parent->child = row;
    else
    - tree->root = row;
    + priv->root = row;
    row->next = s;
    g_return_if_fail(s != NULL); /* s cannot be NULL */
    s->prev = row;
    row->prev = NULL;
    - newp = g_list_index(tree->list, s) - 1;
    + newp = g_list_index(priv->list, s) - 1;
    } else {
    if (row->prev) {
    row->prev->next = row->next;
    @@ -1297,7 +1403,7 @@
    if (row->parent)
    row->parent->child = row->next;
    else
    - tree->top = row->next;
    + priv->top = row->next;
    }
    if (row->next)
    @@ -1308,43 +1414,43 @@
    if (s)
    s->prev = row;
    row->next = s;
    - 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);
    redraw_tree(tree);
    }
    GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
    {
    + GntTreePrivate *priv = NULL;
    GntTreeRow *pr = 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);
    }
    row->tree = tree;
    row->key = key;
    row->data = NULL;
    - 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->root = row;
    - tree->list = g_list_prepend(tree->list, key);
    - }
    - else
    - {
    + if (priv->root == NULL) {
    + priv->root = row;
    + priv->list = g_list_prepend(priv->list, key);
    + } else {
    int position = 0;
    if (bigbro)
    {
    - pr = g_hash_table_lookup(tree->hash, bigbro);
    + pr = g_hash_table_lookup(priv->hash, bigbro);
    if (pr)
    {
    if (pr->next) pr->next->prev = row;
    @@ -1353,13 +1459,13 @@
    pr->next = row;
    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)
    {
    if (pr->child) pr->child->prev = row;
    @@ -1367,23 +1473,25 @@
    pr->child = row;
    row->parent = pr;
    - position = g_list_index(tree->list, parent);
    + position = g_list_index(priv->list, parent);
    }
    }
    if (pr == NULL)
    {
    - GntTreeRow *r = tree->root;
    + GntTreeRow *r = priv->root;
    row->next = r;
    if (r) r->prev = row;
    - if (tree->current == tree->root)
    - tree->current = row;
    - tree->root = row;
    - tree->list = g_list_prepend(tree->list, key);
    + if (priv->current == priv->root) {
    + priv->current = row;
    + }
    + priv->root = row;
    + priv->list = g_list_prepend(priv->list, key);
    }
    else
    {
    - tree->list = g_list_insert(tree->list, key, position + 1);
    + priv->list =
    + g_list_insert(priv->list, key, position + 1);
    }
    }
    redraw_tree(tree);
    @@ -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);
    +
    if (parent)
    - pr = g_hash_table_lookup(tree->hash, parent);
    + pr = g_hash_table_lookup(priv->hash, parent);
    if (pr)
    br = pr->child;
    else
    - br = tree->root;
    + br = priv->root;
    if (br)
    {
    @@ -1414,32 +1526,52 @@
    gpointer gnt_tree_get_selection_data(GntTree *tree)
    {
    - if (tree->current)
    - 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);
    +
    + if (priv->current) {
    + /* XXX: perhaps we should just get rid of 'data' */
    + return priv->current->key;
    + }
    return NULL;
    }
    char *gnt_tree_get_selection_text(GntTree *tree)
    {
    - if (tree->current)
    - 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);
    +
    + if (priv->current) {
    + return update_row_text(priv, priv->current);
    + }
    return NULL;
    }
    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;
    int i;
    + 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;
    +
    if (!row)
    return NULL;
    - 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)
    + ? col->text
    + : g_strdup(col->text));
    }
    return list;
    @@ -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);
    if (row)
    {
    gboolean redraw = FALSE;
    @@ -1466,30 +1604,32 @@
    depth--;
    }
    - 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) {
    redraw = TRUE;
    + }
    /* Update root/top/current/bottom if necessary */
    - if (tree->root == row)
    - tree->root = get_next(row);
    - if (tree->top == row)
    - {
    - if (tree->top != tree->root)
    - tree->top = get_prev(row);
    - else
    - 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);
    + } else {
    + priv->top = get_next(row);
    + }
    }
    - if (tree->current == row)
    - {
    - if (tree->current != tree->root)
    - tree->current = get_prev(row);
    - else
    - 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);
    + } else {
    + 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);
    }
    /* Fix the links */
    @@ -1500,8 +1640,8 @@
    if (row->prev)
    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)
    {
    - tree->root = NULL;
    - g_hash_table_remove_all(tree->hash);
    - g_list_free(tree->list);
    - tree->list = NULL;
    - 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);
    +
    + priv->root = NULL;
    + g_hash_table_remove_all(priv->hash);
    + g_list_free(priv->list);
    + priv->list = NULL;
    + 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;
    GntTreeRow *row;
    GntTreeCol *col;
    - 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);
    if (row)
    {
    col = g_list_nth_data(row->columns, colno);
    - if (BINARY_DATA(tree, colno)) {
    + if (BINARY_DATA(priv, colno)) {
    col->text = (gpointer)text;
    } else {
    g_free(col->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) {
    redraw_tree(tree);
    }
    }
    @@ -1553,17 +1706,22 @@
    GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
    {
    + GntTreePrivate *priv = NULL;
    GntTreeRow *r;
    - 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 (bigbro == NULL) {
    - if (tree->priv->compare)
    - bigbro = find_position(tree, key, parent);
    - else {
    - r = g_hash_table_lookup(tree->hash, parent);
    + if (priv->compare) {
    + bigbro = find_position(priv, key, parent);
    + } else {
    + r = g_hash_table_lookup(priv->hash, parent);
    if (!r)
    - r = tree->root;
    + r = priv->root;
    else
    r = r->child;
    if (r) {
    @@ -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;
    + GntTreeRow *row;
    +
    + 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)
    return;
    @@ -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;
    + GntTreeRow *row;
    +
    + 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);
    if (!row)
    return FALSE;
    @@ -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;
    + GntTreeRow *row;
    +
    + 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)
    return;
    @@ -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;
    + GntTreeRow *row;
    +
    + 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)
    return;
    @@ -1624,40 +1806,73 @@
    void gnt_tree_set_selected(GntTree *tree , void *key)
    {
    + GntTreePrivate *priv = NULL;
    + GntTreeRow *row;
    int dist;
    - 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) {
    return;
    + }
    +
    + if (priv->top == NULL) {
    + priv->top = row;
    + }
    + if (priv->bottom == NULL) {
    + priv->bottom = row;
    + }
    - if (tree->top == NULL)
    - tree->top = row;
    - if (tree->bottom == NULL)
    - tree->bottom = row;
    + priv->current = row;
    + 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);
    + } else {
    + redraw_tree(tree);
    + }
    + tree_selection_changed(tree, row, priv->current);
    +}
    - tree->current = row;
    - 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);
    - else
    - redraw_tree(tree);
    - tree_selection_changed(tree, row, tree->current);
    +/* Internal. */
    +GntTreeRow *
    +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);
    + return priv->current;
    +}
    +
    +/* Internal. */
    +GntTreeRow *
    +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);
    + return priv->top;
    }
    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->ncol = col;
    - 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->ncol = col;
    + priv->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
    + free_tree_row);
    + priv->columns = g_new0(struct _GntTreeColInfo, col);
    + priv->lastvisible = col - 1;
    while (col--)
    {
    - tree->columns[col].width = 15;
    + priv->columns[col].width = 15;
    }
    - tree->list = NULL;
    - tree->show_title = FALSE;
    + priv->list = NULL;
    + 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;
    GList *iter;
    int i;
    - GntTreeRow *row = g_new0(GntTreeRow, 1);
    + GntTreeRow *row;
    - 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);
    col->span = 1;
    - if (BINARY_DATA(tree, i)) {
    + if (BINARY_DATA(priv, i)) {
    col->text = iter->data;
    col->isbinary = TRUE;
    } else {
    @@ -1697,14 +1917,17 @@
    GntTreeRow *gnt_tree_create_row(GntTree *tree, ...)
    {
    + GntTreePrivate *priv = NULL;
    int i;
    va_list args;
    GList *list = NULL;
    GntTreeRow *row;
    + g_return_val_if_fail(GNT_IS_TREE(tree), NULL);
    + priv = gnt_tree_get_instance_private(tree);
    +
    va_start(args, tree);
    - for (i = 0; i < tree->ncol; i++)
    - {
    + for (i = 0; i < priv->ncol; i++) {
    list = g_list_append(list, va_arg(args, char *));
    }
    va_end(args);
    @@ -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;
    int i;
    va_list args;
    + g_return_if_fail(GNT_IS_TREE(tree));
    + priv = gnt_tree_get_instance_private(tree);
    +
    va_start(args, 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);
    }
    va_end(args);
    }
    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);
    +
    + priv->compare = func;
    }
    void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded)
    {
    - GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
    + GntTreePrivate *priv = NULL;
    + GntTreeRow *row;
    +
    + 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->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;
    + GntTreeRow *row;
    int *widths, i, twidth;
    - 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);
    + row = priv->root;
    while (row) {
    GList *iter;
    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) {
    twidth += 1;
    + }
    }
    }
    g_free(widths);
    @@ -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);
    }
    static void
    -set_column_flag(GntTree *tree, int col, GntTreeColumnFlag flag, gboolean set)
    +set_column_flag(GntTreePrivate *priv, int col, GntTreeColumnFlag flag, gboolean set)
    {
    if (set)
    - tree->columns[col].flags |= flag;
    + priv->columns[col].flags |= flag;
    else
    - 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);
    if (vis) {
    /* the column is visible */
    - if (tree->priv->lastvisible < col)
    - tree->priv->lastvisible = col;
    + if (priv->lastvisible < col) {
    + priv->lastvisible = col;
    + }
    } else {
    - 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) {
    + priv->lastvisible--;
    + if (!COLUMN_INVISIBLE(priv,
    + priv->lastvisible)) {
    break;
    + }
    }
    + }
    }
    if (gnt_widget_get_mapped(GNT_WIDGET(tree)))
    readjust_columns(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;
    int i;
    - 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;
    + GntTreeRow *row;
    +
    + 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;
    }
    --- a/gnttree.h Tue Apr 23 18:42:19 2019 -0400
    +++ b/gnttree.h Wed Apr 24 04:24:43 2019 +0000
    @@ -35,22 +35,13 @@
    #include "gnttextview.h"
    #include "gntwidget.h"
    -#define GNT_TYPE_TREE (gnt_tree_get_type())
    -#define GNT_TREE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TREE, GntTree))
    -#define GNT_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TREE, GntTreeClass))
    -#define GNT_IS_TREE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_TREE))
    -#define GNT_IS_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_TREE))
    -#define GNT_TREE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_TREE, GntTreeClass))
    +#define GNT_TYPE_TREE gnt_tree_get_type()
    #define GNT_TYPE_TREE_ROW (gnt_tree_row_get_type())
    typedef guint (*GntTreeHashFunc)(gconstpointer key);
    typedef gboolean (*GntTreeHashEqualityFunc)(gconstpointer a, gconstpointer b);
    -typedef struct _GntTree GntTree;
    -typedef struct _GntTreePriv GntTreePriv;
    -typedef struct _GntTreeClass GntTreeClass;
    -
    typedef struct _GntTreeRow GntTreeRow;
    typedef struct _GntTreeCol GntTreeCol;
    typedef struct _GntTreeColInfo GntTreeColInfo;
    @@ -70,36 +61,14 @@
    GntTreeColumnFlag flags;
    };
    -/**
    - * GntTree:
    - *
    - * Access to any fields is deprecated. See inline comments for replacements.
    - */
    -struct _GntTree
    -{
    - GntWidget parent;
    -
    - GntTreeRow *GNTSEAL(current); /* current selection */
    -
    - GntTreeRow *GNTSEAL(top); /* The topmost visible item */
    - GntTreeRow *GNTSEAL(bottom); /* The bottommost visible item */
    +G_BEGIN_DECLS
    - GntTreeRow *GNTSEAL(root); /* The root of all evil */
    -
    - GList *GNTSEAL(list); /* List of GntTreeRow s */
    - GHashTable *GNTSEAL(hash); /* We need this for quickly referencing the rows */
    - GntTreeHashFunc GNTSEAL(hash_func);
    - GntTreeHashEqualityFunc GNTSEAL(hash_eq_func);
    - GDestroyNotify GNTSEAL(key_destroy);
    - GDestroyNotify GNTSEAL(value_destroy);
    -
    - int GNTSEAL(ncol); /* No. of columns */
    - GntTreeColInfo *GNTSEAL(columns); /* Would a GList be better? */
    - gboolean GNTSEAL(show_title);
    - gboolean GNTSEAL(show_separator); /* Whether to show column separators */
    -
    - GntTreePriv *GNTSEAL(priv);
    -};
    +/**
    + * gnt_tree_get_type:
    + *
    + * Returns: The GType for GntTree
    + */
    +G_DECLARE_DERIVABLE_TYPE(GntTree, gnt_tree, GNT, TREE, GntWidget)
    struct _GntTreeClass
    {
    @@ -115,15 +84,6 @@
    void (*gnt_reserved4)(void);
    };
    -G_BEGIN_DECLS
    -
    -/**
    - * gnt_tree_get_type:
    - *
    - * Returns: The GType for GntTree
    - */
    -GType gnt_tree_get_type(void);
    -
    /**
    * gnt_tree_row_get_type:
    *
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/gnttreeprivate.h Wed Apr 24 04:24:43 2019 +0000
    @@ -0,0 +1,37 @@
    +/*
    + * GNT - The GLib Ncurses Toolkit
    + *
    + * GNT is the legal property of its developers, whose names are too numerous
    + * to list here. Please refer to the COPYRIGHT file distributed with this
    + * source distribution.
    + *
    + * This library is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License as published by
    + * the Free Software Foundation; either version 2 of the License, or
    + * (at your option) any later version.
    + *
    + * This program is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    + * GNU General Public License for more details.
    + *
    + * You should have received a copy of the GNU General Public License along with
    + * this program; if not, write to the Free Software Foundation, Inc.,
    + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    + */
    +
    +#ifndef GNT_TREE_PRIVATE_H
    +#define GNT_TREE_PRIVATE_H
    +
    +#include "gnt.h"
    +#include "gnttree.h"
    +
    +G_BEGIN_DECLS
    +
    +/* Private access to some internals. Contact us if you need these. */
    +GntTreeRow *gnt_tree_get_current(GntTree *tree);
    +GntTreeRow *gnt_tree_get_top(GntTree *tree);
    +
    +G_END_DECLS
    +
    +#endif /* GNT_TREE_PRIVATE_H */