• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

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 
00307 
00311 enum Fl_Tree_Reason {
00312   FL_TREE_REASON_NONE=0,        
00313   FL_TREE_REASON_SELECTED,      
00314   FL_TREE_REASON_DESELECTED,    
00315 #if FLTK_ABI_VERSION >= 10301
00316   FL_TREE_REASON_RESELECTED,    
00317 #endif /*FLTK_ABI_VERSION*/
00318   FL_TREE_REASON_OPENED,        
00319   FL_TREE_REASON_CLOSED,        
00320   FL_TREE_REASON_DRAGGED        
00321 };
00322 
00323 class FL_EXPORT Fl_Tree : public Fl_Group {
00324   friend class Fl_Tree_Item;
00325   Fl_Tree_Item  *_root;                         // can be null!
00326   Fl_Tree_Item  *_item_focus;                   // item that has focus box
00327   Fl_Tree_Item  *_callback_item;                // item invoked during callback (can be NULL)
00328   Fl_Tree_Reason _callback_reason;              // reason for the callback
00329   Fl_Tree_Prefs  _prefs;                        // all the tree's settings
00330   int            _scrollbar_size;               // size of scrollbar trough
00331 #if FLTK_ABI_VERSION >= 10301
00332   // NEW: 
00333   Fl_Tree_Item *_lastselect;                    // used to extend selections
00334 #else /*FLTK_ABI_VERSION*/
00335   // OLD: static data inside handle() method
00336 #endif /*FLTK_ABI_VERSION*/
00337   void fix_scrollbar_order();
00338 
00339 protected:
00340   Fl_Scrollbar *_vscroll;       
00341 #if FLTK_ABI_VERSION >= 10303
00342   Fl_Scrollbar *_hscroll;       
00343   int _tox,_toy,_tow,_toh;      
00344   int _tix,_tiy,_tiw,_tih;      
00345 
00347   int _tree_w;
00349   int _tree_h;
00350 #endif
00351   void item_clicked(Fl_Tree_Item* val);
00352   void do_callback_for_item(Fl_Tree_Item* item, Fl_Tree_Reason reason);
00353 #if FLTK_ABI_VERSION >= 10303
00354 // next_visible_item() and extend_selection() moved to 'public' in ABI 1.3.3
00355 // undocmented draw_tree() dropped -- draw() does all the work now
00356 #else
00357   Fl_Tree_Item *next_visible_item(Fl_Tree_Item *start, int dir);
00358   void extend_selection(Fl_Tree_Item *from, Fl_Tree_Item *to);
00359   int draw_tree();
00360 #endif
00361 
00362 public:
00363   Fl_Tree(int X, int Y, int W, int H, const char *L=0);
00364   ~Fl_Tree();
00365   int handle(int e);
00366   void draw();
00367   void show_self();
00368   void resize(int,int,int,int);
00369 
00371   // root methods
00373   void root_label(const char *new_label);
00374   Fl_Tree_Item* root();
00375   void root(Fl_Tree_Item *newitem);
00376   const Fl_Tree_Prefs& prefs() const { return _prefs; }
00377 
00379   // Item creation/removal methods
00381 #if FLTK_ABI_VERSION >= 10303
00382   Fl_Tree_Item *add(const char *path, Fl_Tree_Item *newitem=0);
00383 #else
00384   Fl_Tree_Item *add(const char *path);
00385   Fl_Tree_Item *add(const char *path, Fl_Tree_Item *newitem);
00386 #endif
00387   Fl_Tree_Item* add(Fl_Tree_Item *parent_item, const char *name);
00388   Fl_Tree_Item *insert_above(Fl_Tree_Item *above, const char *name);
00389   Fl_Tree_Item* insert(Fl_Tree_Item *item, const char *name, int pos);
00390   int remove(Fl_Tree_Item *item);
00391   void clear();
00392   void clear_children(Fl_Tree_Item *item);
00393 
00395   // Item lookup methods
00397   Fl_Tree_Item *find_item(const char *path);
00398   const Fl_Tree_Item *find_item(const char *path) const;
00399   int item_pathname(char *pathname, int pathnamelen, const Fl_Tree_Item *item) const;
00400 #if FLTK_ABI_VERSION >= 10303
00401   const Fl_Tree_Item* find_clicked(int yonly=0) const;
00402   Fl_Tree_Item* find_clicked(int yonly=0);
00403 #else
00404   const Fl_Tree_Item *find_clicked() const;
00405   Fl_Tree_Item *find_clicked();
00406 #endif
00407   Fl_Tree_Item *item_clicked();
00408   Fl_Tree_Item *first();
00409   Fl_Tree_Item *first_visible();                // deprecated in ABI 10303
00410   Fl_Tree_Item *first_visible_item();
00411   Fl_Tree_Item *next(Fl_Tree_Item *item=0);
00412   Fl_Tree_Item *prev(Fl_Tree_Item *item=0);
00413   Fl_Tree_Item *last();
00414   Fl_Tree_Item *last_visible();                 // deprecated in ABI 10303
00415   Fl_Tree_Item *last_visible_item();
00416 #if FLTK_ABI_VERSION >= 10303
00417   Fl_Tree_Item *next_visible_item(Fl_Tree_Item *start, int dir);        // made public in 1.3.3 ABI
00418 #endif
00419   Fl_Tree_Item *first_selected_item();
00420   Fl_Tree_Item *last_selected_item();
00421   Fl_Tree_Item *next_item(Fl_Tree_Item *item, int dir=FL_Down, bool visible=false);
00422 #if FLTK_ABI_VERSION >= 10303
00423   Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item=0, int dir=FL_Down);
00424   int get_selected_items(Fl_Tree_Item_Array &ret_items);
00425 #else
00426   Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item=0);
00427   Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item, int dir);
00428 #endif
00429 
00431   // Item open/close methods
00433   int open(Fl_Tree_Item *item, int docallback=1);
00434   int open(const char *path, int docallback=1);
00435   void open_toggle(Fl_Tree_Item *item, int docallback=1);
00436   int close(Fl_Tree_Item *item, int docallback=1);
00437   int close(const char *path, int docallback=1);
00438   int is_open(Fl_Tree_Item *item) const;
00439   int is_open(const char *path) const;
00440   int is_close(Fl_Tree_Item *item) const;
00441   int is_close(const char *path) const;
00442 
00444   // Item selection methods
00446   int select(Fl_Tree_Item *item, int docallback=1);
00447   int select(const char *path, int docallback=1);
00448   void select_toggle(Fl_Tree_Item *item, int docallback=1);
00449   int deselect(Fl_Tree_Item *item, int docallback=1);
00450   int deselect(const char *path, int docallback=1);
00451   int deselect_all(Fl_Tree_Item *item=0, int docallback=1);
00452   int select_only(Fl_Tree_Item *selitem, int docallback=1);
00453   int select_all(Fl_Tree_Item *item=0, int docallback=1);
00454   int extend_selection_dir(Fl_Tree_Item *from,
00455                            Fl_Tree_Item *to,
00456                            int dir,
00457                            int val,
00458                            bool visible);
00459 #if FLTK_ABI_VERSION >= 10303
00460   int extend_selection(Fl_Tree_Item *from,
00461                        Fl_Tree_Item *to,
00462                        int val=1,
00463                        bool visible=false);
00464 #else
00465 private:
00466   // Adding overload if not at least one overload breaks ABI, so avoid
00467   // by keeping private until we can break ABI. ref: http://www.ros.org/reps/rep-0009.html
00468   int extend_selection__(Fl_Tree_Item *from,
00469                          Fl_Tree_Item *to,
00470                          int val,
00471                          bool visible);
00472 public:
00473 #endif
00474   void set_item_focus(Fl_Tree_Item *item);
00475   Fl_Tree_Item *get_item_focus() const;
00476   int is_selected(Fl_Tree_Item *item) const;
00477   int is_selected(const char *path);
00478 
00480   // Item attribute related methods
00482   Fl_Font     item_labelfont() const;
00483   void        item_labelfont(Fl_Font val);
00484   Fl_Fontsize item_labelsize() const;
00485   void        item_labelsize(Fl_Fontsize val);
00486   Fl_Color    item_labelfgcolor(void) const;
00487   void        item_labelfgcolor(Fl_Color val);
00488   Fl_Color    item_labelbgcolor(void) const;
00489   void        item_labelbgcolor(Fl_Color val);
00490   Fl_Color connectorcolor() const;
00491   void connectorcolor(Fl_Color val);
00492   int marginleft() const;
00493   void marginleft(int val);
00494   int margintop() const;
00495   void margintop(int val);
00496 #if FLTK_ABI_VERSION >= 10301
00497   int marginbottom() const;
00498   void marginbottom(int val);
00499 #endif /*FLTK_ABI_VERSION*/
00500   int linespacing() const;
00501   void linespacing(int val);
00502   int openchild_marginbottom() const;
00503   void openchild_marginbottom(int val);
00504   int usericonmarginleft() const;
00505   void usericonmarginleft(int val);
00506   int labelmarginleft() const;
00507   void labelmarginleft(int val);
00508 #if FLTK_ABI_VERSION >= 10301
00509   int widgetmarginleft() const;
00510   void widgetmarginleft(int val);
00511 #endif /*FLTK_ABI_VERSION*/
00512   int connectorwidth() const;
00513   void connectorwidth(int val);
00514   Fl_Image* usericon() const;
00515   void usericon(Fl_Image *val);
00516   Fl_Image* openicon() const;
00517   void openicon(Fl_Image *val);
00518   Fl_Image* closeicon() const;
00519   void closeicon(Fl_Image *val);
00520   int showcollapse() const;
00521   void showcollapse(int val);
00522   int showroot() const;
00523   void showroot(int val);
00524   Fl_Tree_Connector connectorstyle() const;
00525   void connectorstyle(Fl_Tree_Connector val);
00526   Fl_Tree_Sort sortorder() const;
00527   void sortorder(Fl_Tree_Sort val);
00528   Fl_Boxtype selectbox() const;
00529   void selectbox(Fl_Boxtype val);
00530   Fl_Tree_Select selectmode() const;
00531   void selectmode(Fl_Tree_Select val);
00532 #if FLTK_ABI_VERSION >= 10301
00533   Fl_Tree_Item_Reselect_Mode item_reselect_mode() const;
00534   void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode);
00535   Fl_Tree_Item_Draw_Mode item_draw_mode() const;
00536   void item_draw_mode(Fl_Tree_Item_Draw_Mode mode);
00537   void item_draw_mode(int mode);
00538 #endif
00539 #if FLTK_ABI_VERSION >= 10303
00540   void calc_dimensions();
00541   void calc_tree();
00542 #endif
00543   void recalc_tree();
00544   int displayed(Fl_Tree_Item *item);
00545   void show_item(Fl_Tree_Item *item, int yoff);
00546   void show_item(Fl_Tree_Item *item);
00547   void show_item_top(Fl_Tree_Item *item);
00548   void show_item_middle(Fl_Tree_Item *item);
00549   void show_item_bottom(Fl_Tree_Item *item);
00550   void display(Fl_Tree_Item *item);
00551   int  vposition() const;
00552   void vposition(int pos);
00553   int  hposition() const;
00554   void hposition(int pos);
00555 
00556   int is_scrollbar(Fl_Widget *w);
00557   int scrollbar_size() const;
00558   void scrollbar_size(int size);
00559   int is_vscroll_visible() const;
00560   int is_hscroll_visible() const;
00561 
00563   // callback related
00565   void callback_item(Fl_Tree_Item* item);
00566   Fl_Tree_Item* callback_item();
00567   void callback_reason(Fl_Tree_Reason reason);
00568   Fl_Tree_Reason callback_reason() const;
00569 
00571   void load(class Fl_Preferences&);
00572 };
00573 
00574 #endif /*FL_TREE_H*/
00575 
00576 //
00577 // End of "$Id$".
00578 //
  • © 1998-2016 by Bill Spitzak and others.     FLTK

  • © 1998-2016 by Bill Spitzak and others.     FLTK

    Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.