00001
00002
00003
00004
00005 #ifndef FL_TREE_ITEM_H
00006 #define FL_TREE_ITEM_H
00007
00008 #include <FL/Fl.H>
00009 #include <FL/Fl_Widget.H>
00010 #include <FL/Fl_Image.H>
00011 #include <FL/fl_draw.H>
00012
00013 #include <FL/Fl_Tree_Item_Array.H>
00014 #include <FL/Fl_Tree_Prefs.H>
00015
00017
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00043
00059 class FL_EXPORT Fl_Tree_Item {
00060 const char *_label;
00061 int _labelfont;
00062 int _labelsize;
00063 Fl_Color _labelfgcolor;
00064 Fl_Color _labelbgcolor;
00065 char _open;
00066 char _visible;
00067 char _active;
00068 char _selected;
00069 int _xywh[4];
00070 int _collapse_xywh[4];
00071 int _label_xywh[4];
00072 Fl_Widget *_widget;
00073 Fl_Image *_usericon;
00074 Fl_Tree_Item_Array _children;
00075 Fl_Tree_Item *_parent;
00076 void *_userdata;
00077 protected:
00078 void show_widgets();
00079 void hide_widgets();
00080 void draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_Prefs &prefs);
00081 void draw_horizontal_connector(int x1, int x2, int y, const Fl_Tree_Prefs &prefs);
00082 public:
00083 Fl_Tree_Item(const Fl_Tree_Prefs &prefs);
00084 ~Fl_Tree_Item();
00085 Fl_Tree_Item(const Fl_Tree_Item *o);
00086 int x() const { return(_xywh[0]); }
00087 int y() const { return(_xywh[1]); }
00088 int w() const { return(_xywh[2]); }
00089 int h() const { return(_xywh[3]); }
00090 void draw(int X, int &Y, int W, Fl_Widget *tree, Fl_Tree_Item *itemfocus, const Fl_Tree_Prefs &prefs, int lastchild=1);
00091 void show_self(const char *indent = "") const;
00092 void label(const char *val);
00093 const char *label() const;
00094
00096 inline void user_data( void* data ) { _userdata = data; }
00097
00099 inline void* user_data() const { return _userdata; }
00100
00102 void labelfont(int val) {
00103 _labelfont = val;
00104 }
00106 int labelfont() const {
00107 return(_labelfont);
00108 }
00110 void labelsize(int val) {
00111 _labelsize = val;
00112 }
00114 int labelsize() const {
00115 return(_labelsize);
00116 }
00118 void labelfgcolor(Fl_Color val) {
00119 _labelfgcolor = val;
00120 }
00122 void labelcolor(Fl_Color val) {
00123 _labelfgcolor = val;
00124 }
00126 Fl_Color labelcolor() const {
00127 return(_labelfgcolor);
00128 }
00130 Fl_Color labelfgcolor() const {
00131 return(_labelfgcolor);
00132 }
00134 void labelbgcolor(Fl_Color val) {
00135 _labelbgcolor = val;
00136 }
00138 Fl_Color labelbgcolor() const {
00139 return(_labelbgcolor);
00140 }
00142 void widget(Fl_Widget *val) {
00143 _widget = val;
00144 }
00146 Fl_Widget *widget() const {
00147 return(_widget);
00148 }
00150 int children() const {
00151 return(_children.total());
00152 }
00154 Fl_Tree_Item *child(int index) {
00155 return(_children[index]);
00156 }
00158 const Fl_Tree_Item *child(int t) const;
00160 int has_children() const {
00161 return(children());
00162 }
00163 int find_child(const char *name);
00164 int find_child(Fl_Tree_Item *item);
00165 int remove_child(Fl_Tree_Item *item);
00166 int remove_child(const char *new_label);
00167 void clear_children();
00168 void swap_children(int ax, int bx);
00169 int swap_children(Fl_Tree_Item *a, Fl_Tree_Item *b);
00170 const Fl_Tree_Item *find_child_item(char **arr) const;
00171 Fl_Tree_Item *find_child_item(char **arr);
00172 const Fl_Tree_Item *find_item(char **arr) const;
00173 Fl_Tree_Item *find_item(char **arr);
00175
00177 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, const char *new_label);
00178 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, char **arr);
00179 Fl_Tree_Item *insert(const Fl_Tree_Prefs &prefs, const char *new_label, int pos=0);
00180 Fl_Tree_Item *insert_above(const Fl_Tree_Prefs &prefs, const char *new_label);
00181 int depth() const;
00182 Fl_Tree_Item *prev();
00183 Fl_Tree_Item *next();
00184 Fl_Tree_Item *next_sibling();
00185 Fl_Tree_Item *prev_sibling();
00186 Fl_Tree_Item *next_displayed(Fl_Tree_Prefs &prefs);
00187 Fl_Tree_Item *prev_displayed(Fl_Tree_Prefs &prefs);
00188
00190 Fl_Tree_Item *parent() {
00191 return(_parent);
00192 }
00194 const Fl_Tree_Item *parent() const {
00195 return(_parent);
00196 }
00200 void parent(Fl_Tree_Item *val) {
00201 _parent = val;
00202 }
00204
00206 void open();
00207 void close();
00209 int is_open() const {
00210 return(_open?1:0);
00211 }
00213 int is_close() const {
00214 return(_open?0:1);
00215 }
00217 void open_toggle() {
00218 _open?close():open();
00219 }
00223 void select(int val=1) {
00224 _selected = val;
00225 }
00227 void select_toggle() {
00228 if ( is_selected() ) {
00229 deselect();
00230 } else {
00231 select();
00232 }
00233 }
00238 int select_all() {
00239 int count = 0;
00240 if ( ! is_selected() ) {
00241 select();
00242 ++count;
00243 }
00244 for ( int t=0; t<children(); t++ ) {
00245 count += child(t)->select_all();
00246 }
00247 return(count);
00248 }
00250 void deselect() {
00251 _selected = 0;
00252 }
00257 int deselect_all() {
00258 int count = 0;
00259 if ( is_selected() ) {
00260 deselect();
00261 ++count;
00262 }
00263 for ( int t=0; t<children(); t++ ) {
00264 count += child(t)->deselect_all();
00265 }
00266 return(count);
00267 }
00269 char is_selected() const {
00270 return(_selected);
00271 }
00281 void activate(int val=1) {
00282 _active = val;
00283 if ( _widget && val != (int)_widget->active() ) {
00284 if ( val ) {
00285 _widget->activate();
00286 } else {
00287 _widget->deactivate();
00288 }
00289 _widget->redraw();
00290 }
00291 }
00295 void deactivate() {
00296 activate(0);
00297 }
00299 char is_activated() const {
00300 return(_active);
00301 }
00303 char is_active() const {
00304 return(_active);
00305 }
00307 int visible() const {
00308 return(_visible ? 1 : 0);
00309 }
00310 int visible_r() const;
00311
00313 void usericon(Fl_Image *val) {
00314 _usericon = val;
00315 }
00317 Fl_Image *usericon() const {
00318 return(_usericon);
00319 }
00321
00323 const Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs) const;
00324 Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs);
00325 int event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const;
00326 int event_on_label(const Fl_Tree_Prefs &prefs) const;
00328 int is_root() const {
00329 return(_parent==0?1:0);
00330 }
00331 };
00332
00333 #endif
00334
00335
00336
00337