FLTK 1.3.0
|
00001 // 00002 // "$Id$" 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 // FL/Fl_Tree_Item.H 00019 // 00020 // Fl_Tree -- This file is part of the Fl_Tree widget for FLTK 00021 // Copyright (C) 2009-2010 by Greg Ercolano. 00022 // 00023 // This library is free software; you can redistribute it and/or 00024 // modify it under the terms of the GNU Library General Public 00025 // License as published by the Free Software Foundation; either 00026 // version 2 of the License, or (at your option) any later version. 00027 // 00028 // This library is distributed in the hope that it will be useful, 00029 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00030 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00031 // Library General Public License for more details. 00032 // 00033 // You should have received a copy of the GNU Library General Public 00034 // License along with this library; if not, write to the Free Software 00035 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00036 // USA. 00037 // 00038 00043 00059 class FL_EXPORT Fl_Tree_Item { 00060 const char *_label; // label (memory managed) 00061 Fl_Font _labelfont; // label's font face 00062 Fl_Fontsize _labelsize; // label's font size 00063 Fl_Color _labelfgcolor; // label's fg color 00064 Fl_Color _labelbgcolor; // label's bg color 00065 char _open; // item is open? 00066 char _visible; // item is visible? 00067 char _active; // item activated? 00068 char _selected; // item selected? 00069 int _xywh[4]; // xywh of this widget (if visible) 00070 int _collapse_xywh[4]; // xywh of collapse icon (if any) 00071 int _label_xywh[4]; // xywh of label 00072 Fl_Widget *_widget; // item's label widget (optional) 00073 Fl_Image *_usericon; // item's user-specific icon (optional) 00074 Fl_Tree_Item_Array _children; // array of child items 00075 Fl_Tree_Item *_parent; // parent item (=0 if root) 00076 void *_userdata; // user data that can be associated with an item 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); // CTOR 00084 ~Fl_Tree_Item(); // DTOR 00085 Fl_Tree_Item(const Fl_Tree_Item *o); // COPY CTOR 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(Fl_Font val) { 00103 _labelfont = val; 00104 } 00106 Fl_Font labelfont() const { 00107 return(_labelfont); 00108 } 00110 void labelsize(Fl_Fontsize val) { 00111 _labelsize = val; 00112 } 00114 Fl_Fontsize 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; // const 00171 Fl_Tree_Item *find_child_item(char **arr); // non-const 00172 const Fl_Tree_Item *find_item(char **arr) const; // const 00173 Fl_Tree_Item *find_item(char **arr); // non-const 00175 // Adding items 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 // State 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(); // deselect if selected 00230 } else { 00231 select(); // select if deselected 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 // Events 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 /*FL_TREE_ITEM_H*/ 00334 00335 // 00336 // End of "$Id$". 00337 //