00001 #ifndef FL_TREE_ITEM_H
00002 #define FL_TREE_ITEM_H
00003
00004 #include <FL/Fl.H>
00005 #include <FL/Fl_Widget.H>
00006 #include <FL/Fl_Pixmap.H>
00007 #include <FL/fl_draw.H>
00008
00009 #include <FL/Fl_Tree_Item_Array.H>
00010 #include <FL/Fl_Tree_Prefs.H>
00011
00012
00013
00018
00035 class Fl_Tree_Item {
00036 const char *_label;
00037 int _labelfont;
00038 int _labelsize;
00039 Fl_Color _labelfgcolor;
00040 Fl_Color _labelbgcolor;
00041 char _open;
00042 char _visible;
00043 char _active;
00044 char _selected;
00045 int _xywh[4];
00046 int _collapse_xywh[4];
00047 int _label_xywh[4];
00048 Fl_Widget *_widget;
00049 Fl_Pixmap *_usericon;
00050 Fl_Tree_Item_Array _children;
00051 Fl_Tree_Item *_parent;
00052 protected:
00053 void show_widgets();
00054 void hide_widgets();
00055 void draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_Prefs &prefs);
00056 void draw_horizontal_connector(int x1, int x2, int y, const Fl_Tree_Prefs &prefs);
00057 public:
00058 Fl_Tree_Item(const Fl_Tree_Prefs &prefs);
00059 ~Fl_Tree_Item();
00060 Fl_Tree_Item(const Fl_Tree_Item *o);
00061 void draw(int X, int &Y, int W, Fl_Widget *tree, const Fl_Tree_Prefs &prefs, int lastchild=1);
00062 void show_self(const char *indent = "") const;
00063 void label(const char *val);
00064 const char *label() const;
00065
00067 void labelfont(int val) {
00068 _labelfont = val;
00069 }
00071 int labelfont() const {
00072 return(_labelfont);
00073 }
00075 void labelsize(int val) {
00076 _labelsize = val;
00077 }
00079 int labelsize() const {
00080 return(_labelsize);
00081 }
00083 void labelfgcolor(Fl_Color val) {
00084 _labelfgcolor = val;
00085 }
00087 void labelcolor(Fl_Color val) {
00088 _labelfgcolor = val;
00089 }
00091 Fl_Color labelcolor() const {
00092 return(_labelfgcolor);
00093 }
00095 Fl_Color labelfgcolor() const {
00096 return(_labelfgcolor);
00097 }
00099 void labelbgcolor(Fl_Color val) {
00100 _labelbgcolor = val;
00101 }
00103 Fl_Color labelbgcolor() const {
00104 return(_labelbgcolor);
00105 }
00107 void widget(Fl_Widget *val) {
00108 _widget = val;
00109 }
00111 Fl_Widget *widget() const {
00112 return(_widget);
00113 }
00115 int children() const {
00116 return(_children.total());
00117 }
00119 Fl_Tree_Item *child(int index) {
00120 return(_children[index]);
00121 }
00123 const Fl_Tree_Item *child(int t) const;
00125 int has_children() const {
00126 return(children());
00127 }
00128 int find_child(const char *name);
00129 int find_child(Fl_Tree_Item *item);
00130 int remove_child(Fl_Tree_Item *item);
00131 int remove_child(const char *new_label);
00132 void clear_children();
00133 void swap_children(int ax, int bx);
00134 int swap_children(Fl_Tree_Item *a, Fl_Tree_Item *b);
00135 const Fl_Tree_Item *find_item(char **arr) const;
00136 Fl_Tree_Item *find_item(char **arr);
00138
00140 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, const char *new_label);
00141 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, char **arr);
00142 Fl_Tree_Item *insert(const Fl_Tree_Prefs &prefs, const char *new_label, int pos=0);
00143 Fl_Tree_Item *insert_above(const Fl_Tree_Prefs &prefs, const char *new_label);
00144 int depth() const;
00145 Fl_Tree_Item *prev();
00146 Fl_Tree_Item *next();
00147
00149 Fl_Tree_Item *parent() {
00150 return(_parent);
00151 }
00153 const Fl_Tree_Item *parent() const {
00154 return(_parent);
00155 }
00159 void parent(Fl_Tree_Item *val) {
00160 _parent = val;
00161 }
00163
00165 void open();
00166 void close();
00168 int is_open() const {
00169 return(_open?1:0);
00170 }
00172 int is_close() const {
00173 return(_open?0:1);
00174 }
00176 void open_toggle() {
00177 _open?close():open();
00178 }
00182 void select(int val=1) {
00183 _selected = val;
00184 }
00186 void select_toggle() {
00187 if ( is_selected() ) {
00188 deselect();
00189 } else {
00190 select();
00191 }
00192 }
00194 void deselect() {
00195 _selected = 0;
00196 }
00201 int deselect_all() {
00202 int count = 0;
00203 if ( is_selected() ) {
00204 deselect();
00205 ++count;
00206 }
00207 for ( int t=0; t<children(); t++ ) {
00208 count += child(t)->deselect_all();
00209 }
00210 return(count);
00211 }
00213 char is_selected() const {
00214 return(_selected);
00215 }
00225 void activate(int val=1) {
00226 _active = val;
00227 if ( _widget && val != _widget->active() ) {
00228 if ( val ) {
00229 _widget->activate();
00230 } else {
00231 _widget->deactivate();
00232 }
00233 _widget->redraw();
00234 }
00235 }
00239 void deactivate() {
00240 activate(0);
00241 }
00243 char is_activated() const {
00244 return(_active);
00245 }
00247 char is_active() const {
00248 return(_active);
00249 }
00251 void usericon(Fl_Pixmap *val) {
00252 _usericon = val;
00253 }
00255 Fl_Pixmap *usericon() const {
00256 return(_usericon);
00257 }
00259
00261 const Fl_Tree_Item *find_clicked() const;
00262 Fl_Tree_Item *find_clicked();
00263 int event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const;
00264 int event_on_label(const Fl_Tree_Prefs &prefs) const;
00266 int is_root() const {
00267 return(_parent==0?1:0);
00268 }
00269 };
00270
00271 #endif