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 
00236 GList * gnt_tree_get_selection_text_list(GntTree *tree);
00237 
00245 GList *gnt_tree_get_rows(GntTree *tree);
00246 
00253 void gnt_tree_remove(GntTree *tree, gpointer key);
00254 
00260 void gnt_tree_remove_all(GntTree *tree);
00261 
00269 int gnt_tree_get_selection_visible_line(GntTree *tree);
00270 
00279 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text);
00280 
00297 GntTreeRow * gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro);
00298 
00306 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set);
00307 
00316 gboolean gnt_tree_get_choice(GntTree *tree, void *key);
00317 
00325 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags);
00326 
00335 void gnt_tree_set_row_color(GntTree *tree, void *key, int color);
00336 
00343 void gnt_tree_set_selected(GntTree *tree , void *key);
00344 
00358 GntTreeRow * gnt_tree_create_row(GntTree *tree, ...);
00359 
00373 GntTreeRow * gnt_tree_create_row_from_list(GntTree *tree, GList *list);
00374 
00385 void gnt_tree_set_col_width(GntTree *tree, int col, int width);
00386 
00399 void gnt_tree_set_column_title(GntTree *tree, int index, const char *title);
00400 
00410 void gnt_tree_set_column_titles(GntTree *tree, ...);
00411 
00421 void gnt_tree_set_show_title(GntTree *tree, gboolean set);
00422 
00432 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func);
00433 
00441 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded);
00442 
00449 void gnt_tree_set_show_separator(GntTree *tree, gboolean set);
00450 
00459 void gnt_tree_sort_row(GntTree *tree, void *row);
00460 
00466 void gnt_tree_adjust_columns(GntTree *tree);
00467 
00477 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd);
00478 
00488 void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis);
00489 
00504 void gnt_tree_set_column_resizable(GntTree *tree, int col, gboolean res);
00505 
00514 void gnt_tree_set_column_is_binary(GntTree *tree, int col, gboolean bin);
00515 
00525 void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right);
00526 
00541 void gnt_tree_set_column_width_ratio(GntTree *tree, int cols[]);
00542 
00551 void gnt_tree_set_search_column(GntTree *tree, int col);
00552 
00561 gboolean gnt_tree_is_searching(GntTree *tree);
00562 
00575 void gnt_tree_set_search_function(GntTree *tree,
00576         gboolean (*func)(GntTree *tree, gpointer key, const char *search, const char *current));
00577 
00587 gpointer gnt_tree_get_parent_key(GntTree *tree, gpointer key);
00588 
00589 G_END_DECLS
00590 
00591 #endif /* GNT_TREE_H */