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
00034 class Fl_Tree_Item {
00035 const char *_label;
00036 int _labelfont;
00037 int _labelsize;
00038 Fl_Color _labelfgcolor;
00039 Fl_Color _labelbgcolor;
00040 char _open;
00041 char _visible;
00042 char _active;
00043 char _selected;
00044 int _xywh[4];
00045 int _collapse_xywh[4];
00046 int _label_xywh[4];
00047 Fl_Widget *_widget;
00048 Fl_Pixmap *_usericon;
00049 Fl_Tree_Item_Array _children;
00050 Fl_Tree_Item *_parent;
00051 protected:
00052 void show_widgets();
00053 void hide_widgets();
00054 void draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_Prefs &prefs);
00055 void draw_horizontal_connector(int x1, int x2, int y, const Fl_Tree_Prefs &prefs);
00056 public:
00057 Fl_Tree_Item(const Fl_Tree_Prefs &prefs);
00058 ~Fl_Tree_Item();
00059 Fl_Tree_Item(const Fl_Tree_Item *o);
00060 void draw(int X, int &Y, int W, Fl_Widget *tree, const Fl_Tree_Prefs &prefs, int lastchild=1);
00061 void show_self(const char *indent = "") const;
00062 void label(const char *val);
00063 const char *label() const;
00064
00066 void labelfont(int val) {
00067 _labelfont = val;
00068 }
00070 int labelfont() const {
00071 return(_labelfont);
00072 }
00074 void labelsize(int val) {
00075 _labelsize = val;
00076 }
00078 int labelsize() const {
00079 return(_labelsize);
00080 }
00082 void labelfgcolor(Fl_Color val) {
00083 _labelfgcolor = val;
00084 }
00086 void labelcolor(Fl_Color val) {
00087 _labelfgcolor = val;
00088 }
00090 Fl_Color labelcolor() const {
00091 return(_labelfgcolor);
00092 }
00094 Fl_Color labelfgcolor() const {
00095 return(_labelfgcolor);
00096 }
00098 void labelbgcolor(Fl_Color val) {
00099 _labelbgcolor = val;
00100 }
00102 Fl_Color labelbgcolor() const {
00103 return(_labelbgcolor);
00104 }
00106 void widget(Fl_Widget *val) {
00107 _widget = val;
00108 }
00110 Fl_Widget *widget() const {
00111 return(_widget);
00112 }
00114 int children() const {
00115 return(_children.total());
00116 }
00118 Fl_Tree_Item *child(int index) {
00119 return(_children[index]);
00120 }
00122 const Fl_Tree_Item *child(int t) const;
00124 int has_children() const {
00125 return(children());
00126 }
00127 int find_child(const char *name);
00128 int find_child(Fl_Tree_Item *item);
00129 int remove_child(Fl_Tree_Item *item);
00130 int remove_child(const char *new_label);
00131 void clear_children();
00132 void swap_children(int ax, int bx);
00133 int swap_children(Fl_Tree_Item *a, Fl_Tree_Item *b);
00134 const Fl_Tree_Item *find_item(char **arr) const;
00135 Fl_Tree_Item *find_item(char **arr);
00137
00139 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, const char *new_label);
00140 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, char **arr);
00141 Fl_Tree_Item *insert(const Fl_Tree_Prefs &prefs, const char *new_label, int pos=0);
00142 Fl_Tree_Item *insert_above(const Fl_Tree_Prefs &prefs, const char *new_label);
00143 int depth() const;
00144 Fl_Tree_Item *prev();
00145 Fl_Tree_Item *next();
00146
00148 Fl_Tree_Item *parent() {
00149 return(_parent);
00150 }
00152 const Fl_Tree_Item *parent() const {
00153 return(_parent);
00154 }
00158 void parent(Fl_Tree_Item *val) {
00159 _parent = val;
00160 }
00162
00164 void open();
00165 void close();
00167 int is_open() const {
00168 return(_open?1:0);
00169 }
00171 int is_close() const {
00172 return(_open?0:1);
00173 }
00175 void open_toggle() {
00176 _open?close():open();
00177 }
00181 void select(int val=1) {
00182 _selected = val;
00183 }
00185 void select_toggle() {
00186 if ( is_selected() ) {
00187 deselect();
00188 } else {
00189 select();
00190 }
00191 }
00193 void deselect() {
00194 _selected = 0;
00195 }
00200 int deselect_all() {
00201 int count = 0;
00202 if ( is_selected() ) {
00203 deselect();
00204 ++count;
00205 }
00206 for ( int t=0; t<children(); t++ ) {
00207 count += child(t)->deselect_all();
00208 }
00209 return(count);
00210 }
00212 char is_selected() const {
00213 return(_selected);
00214 }
00224 void activate(int val=1) {
00225 _active = val;
00226 if ( _widget && val != _widget->active() ) {
00227 if ( val ) {
00228 _widget->activate();
00229 } else {
00230 _widget->deactivate();
00231 }
00232 _widget->redraw();
00233 }
00234 }
00238 void deactivate() {
00239 activate(0);
00240 }
00242 char is_activated() const {
00243 return(_active);
00244 }
00246 char is_active() const {
00247 return(_active);
00248 }
00250 void usericon(Fl_Pixmap *val) {
00251 _usericon = val;
00252 }
00254 Fl_Pixmap *usericon() const {
00255 return(_usericon);
00256 }
00258
00260 const Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs) const;
00261 Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs);
00262 int event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const;
00263 int event_on_label(const Fl_Tree_Prefs &prefs) const;
00265 int is_root() const {
00266 return(_parent==0?1:0);
00267 }
00268 };
00269
00270 #endif