FLTK 1.3.0
Fl_Tree.H
Go to the documentation of this file.
00001 //
00002 // "$Id$"
00003 //
00004 
00005 #ifndef FL_TREE_H
00006 #define FL_TREE_H
00007 
00008 #include <FL/Fl.H>
00009 #include <FL/Fl_Group.H>
00010 #include <FL/Fl_Scrollbar.H>
00011 #include <FL/fl_draw.H>
00012 
00013 #include <FL/Fl_Tree_Item.H>
00014 #include <FL/Fl_Tree_Prefs.H>
00015 
00017 // FL/Fl_Tree.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. Distribution and use rights are outlined in
00024 // the file "COPYING" which should have been included with this file.  If this
00025 // file is missing or damaged, see the license at:
00026 //
00027 //     http://www.fltk.org/COPYING.php
00028 //
00029 // Please report all bugs and problems on the following page:
00030 //
00031 //     http://www.fltk.org/str.php
00032 //
00033 
00038 
00295 
00299 enum Fl_Tree_Reason {
00300   FL_TREE_REASON_NONE=0,        
00301   FL_TREE_REASON_SELECTED,      
00302   FL_TREE_REASON_DESELECTED,    
00303 #if FLTK_ABI_VERSION >= 10302
00304   FL_TREE_REASON_RESELECTED,    
00305 #endif /*FLTK_ABI_VERSION*/
00306   FL_TREE_REASON_OPENED,        
00307   FL_TREE_REASON_CLOSED         
00308 };
00309 
00310 class FL_EXPORT Fl_Tree : public Fl_Group {
00311   friend class Fl_Tree_Item;
00312   Fl_Tree_Item  *_root;                         // can be null!
00313   Fl_Tree_Item  *_item_focus;                   // item that has focus box
00314   Fl_Tree_Item  *_callback_item;                // item invoked during callback (can be NULL)
00315   Fl_Tree_Reason _callback_reason;              // reason for the callback
00316   Fl_Tree_Prefs  _prefs;                        // all the tree's settings
00317   int            _scrollbar_size;               // size of scrollbar trough
00318 
00319 #if FLTK_ABI_VERSION >= 10302
00320   // NEW: 
00321   Fl_Tree_Item *_lastselect;
00322 #else /*FLTK_ABI_VERSION*/
00323   // OLD: static data inside handle() method
00324 #endif /*FLTK_ABI_VERSION*/
00325 
00326   void fix_scrollbar_order();
00327 
00328 protected:
00329   Fl_Scrollbar *_vscroll;                       
00330   void item_clicked(Fl_Tree_Item* val);
00331   void do_callback_for_item(Fl_Tree_Item* item, Fl_Tree_Reason reason);
00332   Fl_Tree_Item *next_visible_item(Fl_Tree_Item *start, int dir);
00333   void extend_selection(Fl_Tree_Item *from, Fl_Tree_Item *to);
00334   int draw_tree();
00335 
00336 public:
00337   Fl_Tree(int X, int Y, int W, int H, const char *L=0);
00338   ~Fl_Tree();
00339   int handle(int e);
00340   void draw();
00341   void show_self();
00342   
00344   // root methods
00346   void root_label(const char *new_label);
00347   Fl_Tree_Item* root();
00348 
00350   // Item creation/removal methods
00352   Fl_Tree_Item *add(const char *path);
00353   Fl_Tree_Item* add(Fl_Tree_Item *item, const char *name);
00354   Fl_Tree_Item *insert_above(Fl_Tree_Item *above, const char *name);
00355   Fl_Tree_Item* insert(Fl_Tree_Item *item, const char *name, int pos);
00356   int remove(Fl_Tree_Item *item);
00357   void clear();
00358   void clear_children(Fl_Tree_Item *item);
00359 
00361   // Item lookup methods
00363   Fl_Tree_Item *find_item(const char *path);
00364   const Fl_Tree_Item *find_item(const char *path) const;
00365   int item_pathname(char *pathname, int pathnamelen, const Fl_Tree_Item *item) const;
00366   const Fl_Tree_Item *find_clicked() const;
00367   Fl_Tree_Item *item_clicked();
00368   Fl_Tree_Item *first();
00369   Fl_Tree_Item *first_visible();
00370   Fl_Tree_Item *next(Fl_Tree_Item *item=0);
00371   Fl_Tree_Item *prev(Fl_Tree_Item *item=0);
00372   Fl_Tree_Item *last();
00373   Fl_Tree_Item *last_visible();
00374   Fl_Tree_Item *first_selected_item();
00375   Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item=0);
00376 
00378   // Item open/close methods
00380   int open(Fl_Tree_Item *item, int docallback=1);
00381   int open(const char *path, int docallback=1);
00382   void open_toggle(Fl_Tree_Item *item, int docallback=1);
00383   int close(Fl_Tree_Item *item, int docallback=1);
00384   int close(const char *path, int docallback=1);
00385   int is_open(Fl_Tree_Item *item) const;
00386   int is_open(const char *path) const;
00387   int is_close(Fl_Tree_Item *item) const;
00388   int is_close(const char *path) const;
00389 
00391   // Item selection methods
00393   int select(Fl_Tree_Item *item, int docallback=1);
00394   int select(const char *path, int docallback=1);
00395   void select_toggle(Fl_Tree_Item *item, int docallback=1);
00396   int deselect(Fl_Tree_Item *item, int docallback=1);
00397   int deselect(const char *path, int docallback=1);
00398   int deselect_all(Fl_Tree_Item *item=0, int docallback=1);
00399   int select_only(Fl_Tree_Item *selitem, int docallback=1);
00400   int select_all(Fl_Tree_Item *item=0, int docallback=1);
00401   void set_item_focus(Fl_Tree_Item *item);
00402   Fl_Tree_Item *get_item_focus() const;
00403   int is_selected(Fl_Tree_Item *item) const;
00404   int is_selected(const char *path);
00405 
00407   // Item attribute related methods
00409   Fl_Font     item_labelfont() const;
00410   void        item_labelfont(Fl_Font val);
00411   Fl_Fontsize item_labelsize() const;
00412   void        item_labelsize(Fl_Fontsize val);
00413   Fl_Color    item_labelfgcolor(void) const;
00414   void        item_labelfgcolor(Fl_Color val);
00415   Fl_Color    item_labelbgcolor(void) const;
00416   void        item_labelbgcolor(Fl_Color val);
00417   Fl_Color connectorcolor() const;
00418   void connectorcolor(Fl_Color val);
00419   int marginleft() const;
00420   void marginleft(int val);
00421   int margintop() const;
00422   void margintop(int val);
00423 #if FLTK_ABI_VERSION >= 10302
00424   int marginbottom() const;
00425   void marginbottom(int val);
00426 #endif /*FLTK_ABI_VERSION*/
00427   int linespacing() const;
00428   void linespacing(int val);
00429   int openchild_marginbottom() const;
00430   void openchild_marginbottom(int val);
00431   int usericonmarginleft() const;
00432   void usericonmarginleft(int val);
00433   int labelmarginleft() const;
00434   void labelmarginleft(int val);
00435 #if FLTK_ABI_VERSION >= 10302
00436   int widgetmarginleft() const;
00437   void widgetmarginleft(int val);
00438 #endif /*FLTK_ABI_VERSION*/
00439   int connectorwidth() const;
00440   void connectorwidth(int val);
00441   Fl_Image* usericon() const;
00442   void usericon(Fl_Image *val);
00443   Fl_Image* openicon() const;
00444   void openicon(Fl_Image *val);
00445   Fl_Image* closeicon() const;
00446   void closeicon(Fl_Image *val);
00447   int showcollapse() const;
00448   void showcollapse(int val);
00449   int showroot() const;
00450   void showroot(int val);
00451   Fl_Tree_Connector connectorstyle() const;
00452   void connectorstyle(Fl_Tree_Connector val);
00453   Fl_Tree_Sort sortorder() const;
00454   void sortorder(Fl_Tree_Sort val);
00455   Fl_Boxtype selectbox() const;
00456   void selectbox(Fl_Boxtype val);
00457   Fl_Tree_Select selectmode() const;
00458   void selectmode(Fl_Tree_Select val);
00459 #if FLTK_ABI_VERSION >= 10302
00460   Fl_Tree_Item_Reselect_Mode item_reselect_mode() const;
00461   void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode);
00462   Fl_Tree_Item_Draw_Mode item_draw_mode() const;
00463   void item_draw_mode(Fl_Tree_Item_Draw_Mode mode);
00464   void item_draw_mode(int mode);
00465 #endif /*FLTK_ABI_VERSION*/
00466   int displayed(Fl_Tree_Item *item);
00467   void show_item(Fl_Tree_Item *item, int yoff);
00468   void show_item(Fl_Tree_Item *item);
00469   void show_item_top(Fl_Tree_Item *item);
00470   void show_item_middle(Fl_Tree_Item *item);
00471   void show_item_bottom(Fl_Tree_Item *item);
00472   void display(Fl_Tree_Item *item);
00473   int  vposition() const;
00474   void vposition(int pos);
00475 
00476   int is_scrollbar(Fl_Widget *w);
00477   int scrollbar_size() const;
00478   void scrollbar_size(int size);
00479   int is_vscroll_visible() const;
00480 
00482   // callback related
00484   void callback_item(Fl_Tree_Item* item);
00485   Fl_Tree_Item* callback_item();
00486   void callback_reason(Fl_Tree_Reason reason);
00487   Fl_Tree_Reason callback_reason() const;
00488 
00490   void load(class Fl_Preferences&);
00491 };
00492 
00493 #endif /*FL_TREE_H*/
00494 
00495 //
00496 // End of "$Id$".
00497 //