gnttree.h
Go to the documentation of this file.
/*
* 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 02111-1301 USA
*/
#ifndef GNT_TREE_H
#define GNT_TREE_H
#include "gntwidget.h"
#include "gnt.h"
#include "gntcolors.h"
#include "gntkeys.h"
#include "gnttextview.h"
#define GNT_TYPE_TREE (gnt_tree_get_gtype())
#define GNT_TREE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TREE, GntTree))
#define GNT_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TREE, GntTreeClass))
#define GNT_IS_TREE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_TREE))
#define GNT_IS_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_TREE))
#define GNT_TREE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_TREE, GntTreeClass))
typedef struct _GntTree GntTree;
typedef struct _GntTreePriv GntTreePriv;
typedef struct _GntTreeClass GntTreeClass;
typedef struct _GntTreeRow GntTreeRow;
typedef struct _GntTreeCol GntTreeCol;
typedef enum _GntTreeColumnFlag {
GNT_TREE_COLUMN_INVISIBLE = 1 << 0,
GNT_TREE_COLUMN_FIXED_SIZE = 1 << 1,
GNT_TREE_COLUMN_BINARY_DATA = 1 << 2,
GNT_TREE_COLUMN_RIGHT_ALIGNED = 1 << 3,
} GntTreeColumnFlag;
struct _GntTree
{
GntWidget parent;
GntTreeRow *current; /* current selection */
GntTreeRow *top; /* The topmost visible item */
GntTreeRow *bottom; /* The bottommost visible item */
GntTreeRow *root; /* The root of all evil */
GList *list; /* List of GntTreeRow s */
GHashTable *hash; /* We need this for quickly referencing the rows */
guint (*hash_func)(gconstpointer);
gboolean (*hash_eq_func)(gconstpointer, gconstpointer);
GDestroyNotify key_destroy;
GDestroyNotify value_destroy;
int ncol; /* No. of columns */
struct _GntTreeColInfo
{
int width;
char *title;
int width_ratio;
GntTreeColumnFlag flags;
} *columns; /* Would a GList be better? */
gboolean show_title;
gboolean show_separator; /* Whether to show column separators */
GntTreePriv *priv;
};
struct _GntTreeClass
{
GntWidgetClass parent;
void (*selection_changed)(GntTreeRow *old, GntTreeRow * current);
void (*toggled)(GntTree *tree, gpointer key);
void (*gnt_reserved1)(void);
void (*gnt_reserved2)(void);
void (*gnt_reserved3)(void);
void (*gnt_reserved4)(void);
};
G_BEGIN_DECLS
GType gnt_tree_get_gtype(void);
GntWidget * gnt_tree_new(void);
GntWidget * gnt_tree_new_with_columns(int columns);
void gnt_tree_set_visible_rows(GntTree *tree, int rows);
int gnt_tree_get_visible_rows(GntTree *tree);
void gnt_tree_scroll(GntTree *tree, int count);
GntTreeRow * gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro);
GntTreeRow * gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent);
gpointer gnt_tree_get_selection_data(GntTree *tree);
char * gnt_tree_get_selection_text(GntTree *tree);
GList * gnt_tree_get_row_text_list(GntTree *tree, gpointer key);
gpointer gnt_tree_row_get_key(GntTree *tree, GntTreeRow *row);
GntTreeRow * gnt_tree_row_get_next(GntTree *tree, GntTreeRow *row);
GntTreeRow * gnt_tree_row_get_prev(GntTree *tree, GntTreeRow *row);
GntTreeRow * gnt_tree_row_get_child(GntTree *tree, GntTreeRow *row);
GntTreeRow * gnt_tree_row_get_parent(GntTree *tree, GntTreeRow *row);
GList * gnt_tree_get_selection_text_list(GntTree *tree);
GList *gnt_tree_get_rows(GntTree *tree);
void gnt_tree_remove(GntTree *tree, gpointer key);
void gnt_tree_remove_all(GntTree *tree);
int gnt_tree_get_selection_visible_line(GntTree *tree);
void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text);
GntTreeRow * gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro);
void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set);
gboolean gnt_tree_get_choice(GntTree *tree, void *key);
void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags);
void gnt_tree_set_row_color(GntTree *tree, void *key, int color);
void gnt_tree_set_selected(GntTree *tree , void *key);
GntTreeRow * gnt_tree_create_row(GntTree *tree, ...);
GntTreeRow * gnt_tree_create_row_from_list(GntTree *tree, GList *list);
void gnt_tree_set_col_width(GntTree *tree, int col, int width);
void gnt_tree_set_column_title(GntTree *tree, int index, const char *title);
void gnt_tree_set_column_titles(GntTree *tree, ...);
void gnt_tree_set_show_title(GntTree *tree, gboolean set);
void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func);
void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded);
void gnt_tree_set_show_separator(GntTree *tree, gboolean set);
void gnt_tree_sort_row(GntTree *tree, void *row);
void gnt_tree_adjust_columns(GntTree *tree);
void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd);
void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis);
void gnt_tree_set_column_resizable(GntTree *tree, int col, gboolean res);
void gnt_tree_set_column_is_binary(GntTree *tree, int col, gboolean bin);
void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right);
void gnt_tree_set_column_width_ratio(GntTree *tree, int cols[]);
void gnt_tree_set_search_column(GntTree *tree, int col);
gboolean gnt_tree_is_searching(GntTree *tree);
void gnt_tree_set_search_function(GntTree *tree,
gboolean (*func)(GntTree *tree, gpointer key, const char *search, const char *current));
gpointer gnt_tree_get_parent_key(GntTree *tree, gpointer key);
G_END_DECLS
#endif /* GNT_TREE_H */
gnt_tree_set_row_color
void gnt_tree_set_row_color(GntTree *tree, void *key, int color)
Set color for the text in a row in the tree.
gnt_tree_get_rows
GList * gnt_tree_get_rows(GntTree *tree)
Returns the list of rows in the tree.
gntcolors.h
Colors API.
gnt_tree_set_column_resizable
void gnt_tree_set_column_resizable(GntTree *tree, int col, gboolean res)
Set whether a column can be resized to keep the same ratio when the tree is resized.
gnt_tree_create_row_from_list
GntTreeRow * gnt_tree_create_row_from_list(GntTree *tree, GList *list)
Create a row from a list of text.
gnt_tree_set_show_title
void gnt_tree_set_show_title(GntTree *tree, gboolean set)
Set whether to display the title of the columns.
gntwidget.h
Widget API.
gnt_tree_new
GntWidget * gnt_tree_new(void)
Create a tree with one column.
gnt_tree_scroll
void gnt_tree_scroll(GntTree *tree, int count)
Scroll the contents of the tree.
gnt_tree_row_get_key
gpointer gnt_tree_row_get_key(GntTree *tree, GntTreeRow *row)
Get the key of a row.
gnt_tree_adjust_columns
void gnt_tree_adjust_columns(GntTree *tree)
Automatically adjust the width of the columns in the tree.
gnt_tree_set_visible_rows
void gnt_tree_set_visible_rows(GntTree *tree, int rows)
The number of rows the tree should display at a time.
gnt_tree_is_searching
gboolean gnt_tree_is_searching(GntTree *tree)
Check whether the user is currently in the middle of a search.
gnt.h
GNT API.
gnt_tree_set_search_column
void gnt_tree_set_search_column(GntTree *tree, int col)
Set the column to use for typeahead searching.
gnt_tree_get_row_text_list
GList * gnt_tree_get_row_text_list(GntTree *tree, gpointer key)
Get a list of text for a row.
gnt_tree_add_choice
GntTreeRow * gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
Add a checkable item in the tree.
gnt_tree_add_row_after
GntTreeRow * gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
Insert a row in the tree.
gnt_tree_remove
void gnt_tree_remove(GntTree *tree, gpointer key)
Remove a row from the tree.
gnt_tree_set_choice
void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set)
Set whether a checkable item is checked or not.
gnt_tree_get_parent_key
gpointer gnt_tree_get_parent_key(GntTree *tree, gpointer key)
Get the parent key for a row.
gntkeys.h
Keys API.
gnt_tree_set_show_separator
void gnt_tree_set_show_separator(GntTree *tree, gboolean set)
Set whether to show column separators.
gnt_tree_row_get_next
GntTreeRow * gnt_tree_row_get_next(GntTree *tree, GntTreeRow *row)
Get the next row.
gnt_tree_get_selection_visible_line
int gnt_tree_get_selection_visible_line(GntTree *tree)
Get the visible line number of the selected row.
gnt_tree_set_selected
void gnt_tree_set_selected(GntTree *tree, void *key)
Select a row.
_GntTree::_GntTreeColInfo
Definition: gnttree.h:76
gnt_tree_get_gtype
G_BEGIN_DECLS GType gnt_tree_get_gtype(void)
gnt_tree_row_get_prev
GntTreeRow * gnt_tree_row_get_prev(GntTree *tree, GntTreeRow *row)
Get the previous row.
gnt_tree_get_visible_rows
int gnt_tree_get_visible_rows(GntTree *tree)
Get the number visible rows.
gnt_tree_set_column_width_ratio
void gnt_tree_set_column_width_ratio(GntTree *tree, int cols[])
Set column widths to use when calculating column widths after a tree is resized.
gnttextview.h
Textview API.
_GntTree
Definition: gnttree.h:57
gnt_tree_set_compare_func
void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func)
Set the compare function for sorting the data.
gnt_tree_add_row_last
GntTreeRow * gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent)
Insert a row at the end of the tree.
gnt_tree_sort_row
void gnt_tree_sort_row(GntTree *tree, void *row)
Sort a row in the tree.
gnt_tree_create_row
GntTreeRow * gnt_tree_create_row(GntTree *tree,...)
Create a row to insert in the tree.
gnt_tree_set_expanded
void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded)
Set whether a row, which has child rows, should be expanded.
gnt_tree_get_choice
gboolean gnt_tree_get_choice(GntTree *tree, void *key)
Return whether a row is selected or not, where the row is a checkable item.
gnt_tree_get_selection_data
gpointer gnt_tree_get_selection_data(GntTree *tree)
Get the key for the selected row.
gnt_tree_set_column_titles
void gnt_tree_set_column_titles(GntTree *tree,...)
Set the titles of the columns.
gnt_tree_get_selection_text
char * gnt_tree_get_selection_text(GntTree *tree)
Get the text displayed for the selected row.
_GntTreeClass
Definition: gnttree.h:89
gnt_tree_set_col_width
void gnt_tree_set_col_width(GntTree *tree, int col, int width)
Set the width of a column in the tree.
gnt_tree_set_search_function
void gnt_tree_set_search_function(GntTree *tree, gboolean(*func)(GntTree *tree, gpointer key, const char *search, const char *current))
Set a custom search function.
gnt_tree_set_column_is_right_aligned
void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right)
Set whether text in a column should be right-aligned.
gnt_tree_set_row_flags
void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags)
Set flags for the text in a row in the tree.
gnt_tree_remove_all
void gnt_tree_remove_all(GntTree *tree)
Remove all the item from the tree.
gnt_tree_set_column_visible
void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis)
Set whether a column is visible or not.
gnt_tree_set_column_title
void gnt_tree_set_column_title(GntTree *tree, int index, const char *title)
Set the title for a column.
_GntWidgetClass
Definition: gntwidget.h:113
gnt_tree_set_hash_fns
void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd)
Set the hash functions to use to hash, compare and free the keys.
_GntWidget
Definition: gntwidget.h:98
gnt_tree_get_selection_text_list
GList * gnt_tree_get_selection_text_list(GntTree *tree)
Get a list of text of the current row.
gnt_tree_change_text
void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text)
Change the text of a column in a row.
gnt_tree_row_get_parent
GntTreeRow * gnt_tree_row_get_parent(GntTree *tree, GntTreeRow *row)
Get the parent row.
gnt_tree_row_get_child
GntTreeRow * gnt_tree_row_get_child(GntTree *tree, GntTreeRow *row)
Get the child row.
gnt_tree_set_column_is_binary
void gnt_tree_set_column_is_binary(GntTree *tree, int col, gboolean bin)
Set whether data in a column should be considered as binary data, and not as strings.
gnt_tree_new_with_columns
GntWidget * gnt_tree_new_with_columns(int columns)
Create a tree with a specified number of columns.