gnttree.h
Go to the documentation of this file.
00001 
00005 /*
00006  * GNT - The GLib Ncurses Toolkit
00007  *
00008  * GNT is the legal property of its developers, whose names are too numerous
00009  * to list here.  Please refer to the COPYRIGHT file distributed with this
00010  * source distribution.
00011  *
00012  * This library is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00025  */
00026 
00027 #ifndef GNT_TREE_H
00028 #define GNT_TREE_H
00029 
00030 #include "gntwidget.h"
00031 #include "gnt.h"
00032 #include "gntcolors.h"
00033 #include "gntkeys.h"
00034 #include "gnttextview.h"
00035 
00036 #define GNT_TYPE_TREE               (gnt_tree_get_gtype())
00037 #define GNT_TREE(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TREE, GntTree))
00038 #define GNT_TREE_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TREE, GntTreeClass))
00039 #define GNT_IS_TREE(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_TREE))
00040 #define GNT_IS_TREE_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_TREE))
00041 #define GNT_TREE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_TREE, GntTreeClass))
00042 
00043 typedef struct _GntTree         GntTree;
00044 typedef struct _GntTreePriv     GntTreePriv;
00045 typedef struct _GntTreeClass        GntTreeClass;
00046 
00047 typedef struct _GntTreeRow      GntTreeRow;
00048 typedef struct _GntTreeCol      GntTreeCol;
00049 
00050 typedef enum _GntTreeColumnFlag {
00051     GNT_TREE_COLUMN_INVISIBLE    = 1 << 0,
00052     GNT_TREE_COLUMN_FIXED_SIZE   = 1 << 1,
00053     GNT_TREE_COLUMN_BINARY_DATA  = 1 << 2,
00054     GNT_TREE_COLUMN_RIGHT_ALIGNED = 1 << 3,
00055 } GntTreeColumnFlag;
00056 
00057 struct _GntTree
00058 {
00059     GntWidget parent;
00060 
00061     GntTreeRow *current;    /* current selection */
00062 
00063     GntTreeRow *top;        /* The topmost visible item */
00064     GntTreeRow *bottom;     /* The bottommost visible item */
00065 
00066     GntTreeRow *root;       /* The root of all evil */
00067 
00068     GList *list;            /* List of GntTreeRow s */
00069     GHashTable *hash;       /* We need this for quickly referencing the rows */
00070     guint (*hash_func)(gconstpointer);
00071     gboolean (*hash_eq_func)(gconstpointer, gconstpointer);
00072     GDestroyNotify key_destroy;
00073     GDestroyNotify value_destroy;
00074 
00075     int ncol;               /* No. of columns */
00076     struct _GntTreeColInfo
00077     {
00078         int width;
00079         char *title;
00080         int width_ratio;
00081         GntTreeColumnFlag flags;
00082     } *columns;             /* Would a GList be better? */
00083     gboolean show_title;
00084     gboolean show_separator; /* Whether to show column separators */
00085 
00086     GntTreePriv *priv;
00087 };
00088 
00089 struct _GntTreeClass
00090 {
00091     GntWidgetClass parent;
00092 
00093     void (*selection_changed)(GntTreeRow *old, GntTreeRow * current);
00094     void (*toggled)(GntTree *tree, gpointer key);
00095 
00096     void (*gnt_reserved1)(void);
00097     void (*gnt_reserved2)(void);
00098     void (*gnt_reserved3)(void);
00099     void (*gnt_reserved4)(void);
00100 };
00101 
00102 G_BEGIN_DECLS
00103 
00107 GType gnt_tree_get_gtype(void);
00108 
00116 GntWidget * gnt_tree_new(void);
00117 
00127 GntWidget * gnt_tree_new_with_columns(int columns);
00128 
00135 void gnt_tree_set_visible_rows(GntTree *tree, int rows);
00136 
00144 int gnt_tree_get_visible_rows(GntTree *tree);
00145 
00153 void gnt_tree_scroll(GntTree *tree, int count);
00154 
00170 GntTreeRow * gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro);
00171 
00186 GntTreeRow * gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent);
00187 
00195 gpointer gnt_tree_get_selection_data(GntTree *tree);
00196 
00206 char * gnt_tree_get_selection_text(GntTree *tree);
00207 
00222 GList * gnt_tree_get_row_text_list(GntTree *tree, gpointer key);
00223 
00233 gpointer gnt_tree_row_get_key(GntTree *tree, GntTreeRow *row);
00234 
00244 GntTreeRow * gnt_tree_row_get_next(GntTree *tree, GntTreeRow *row);
00245 
00255 GntTreeRow * gnt_tree_row_get_prev(GntTree *tree, GntTreeRow *row);
00256 
00266 GntTreeRow * gnt_tree_row_get_child(GntTree *tree, GntTreeRow *row);
00267 
00277 GntTreeRow * gnt_tree_row_get_parent(GntTree *tree, GntTreeRow *row);
00278 
00291 GList * gnt_tree_get_selection_text_list(GntTree *tree);
00292 
00300 GList *gnt_tree_get_rows(GntTree *tree);
00301 
00308 void gnt_tree_remove(GntTree *tree, gpointer key);
00309 
00315 void gnt_tree_remove_all(GntTree *tree);
00316 
00324 int gnt_tree_get_selection_visible_line(GntTree *tree);
00325 
00334 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text);
00335 
00352 GntTreeRow * gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro);
00353 
00361 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set);
00362 
00371 gboolean gnt_tree_get_choice(GntTree *tree, void *key);
00372 
00380 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags);
00381 
00390 void gnt_tree_set_row_color(GntTree *tree, void *key, int color);
00391 
00398 void gnt_tree_set_selected(GntTree *tree , void *key);
00399 
00413 GntTreeRow * gnt_tree_create_row(GntTree *tree, ...);
00414 
00428 GntTreeRow * gnt_tree_create_row_from_list(GntTree *tree, GList *list);
00429 
00440 void gnt_tree_set_col_width(GntTree *tree, int col, int width);
00441 
00454 void gnt_tree_set_column_title(GntTree *tree, int index, const char *title);
00455 
00465 void gnt_tree_set_column_titles(GntTree *tree, ...);
00466 
00476 void gnt_tree_set_show_title(GntTree *tree, gboolean set);
00477 
00487 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func);
00488 
00496 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded);
00497 
00504 void gnt_tree_set_show_separator(GntTree *tree, gboolean set);
00505 
00514 void gnt_tree_sort_row(GntTree *tree, void *row);
00515 
00521 void gnt_tree_adjust_columns(GntTree *tree);
00522 
00532 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd);
00533 
00543 void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis);
00544 
00559 void gnt_tree_set_column_resizable(GntTree *tree, int col, gboolean res);
00560 
00569 void gnt_tree_set_column_is_binary(GntTree *tree, int col, gboolean bin);
00570 
00580 void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right);
00581 
00596 void gnt_tree_set_column_width_ratio(GntTree *tree, int cols[]);
00597 
00606 void gnt_tree_set_search_column(GntTree *tree, int col);
00607 
00616 gboolean gnt_tree_is_searching(GntTree *tree);
00617 
00630 void gnt_tree_set_search_function(GntTree *tree,
00631         gboolean (*func)(GntTree *tree, gpointer key, const char *search, const char *current));
00632 
00642 gpointer gnt_tree_get_parent_key(GntTree *tree, gpointer key);
00643 
00644 G_END_DECLS
00645 
00646 #endif /* GNT_TREE_H */