Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

/home/jeroen/FOX/fox/fox-1.7.33/include/FXTreeList.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *                         T r e e   L i s t   W i d g e t                       *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXTREELIST_H
00022 #define FXTREELIST_H
00023 
00024 #ifndef FXSCROLLAREA_H
00025 #include "FXScrollArea.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00031 class FXIcon;
00032 class FXFont;
00033 class FXTreeList;
00034 class FXDirList;
00035 
00036 
00038 enum {
00039   TREELIST_EXTENDEDSELECT = 0,            
00040   TREELIST_SINGLESELECT   = 0x00100000,   
00041   TREELIST_BROWSESELECT   = 0x00200000,   
00042   TREELIST_MULTIPLESELECT = 0x00300000,   
00043   TREELIST_AUTOSELECT     = 0x00400000,   
00044   TREELIST_SHOWS_LINES    = 0x00800000,   
00045   TREELIST_SHOWS_BOXES    = 0x01000000,   
00046   TREELIST_ROOT_BOXES     = 0x02000000,   
00047   TREELIST_NORMAL         = TREELIST_EXTENDEDSELECT
00048   };
00049 
00050 
00052 class FXAPI FXTreeItem : public FXObject {
00053   FXDECLARE(FXTreeItem)
00054   friend class FXTreeList;
00055   friend class FXDirList;
00056 protected:
00057   FXTreeItem *parent;           // Parent item
00058   FXTreeItem *prev;             // Previous item
00059   FXTreeItem *next;             // Next item
00060   FXTreeItem *first;            // First child item
00061   FXTreeItem *last;             // Last child item
00062   FXString    label;            // Text of item
00063   FXIcon     *openIcon;         // Icon of item
00064   FXIcon     *closedIcon;       // Icon of item
00065   void       *data;             // Item user data pointer
00066   FXuint      state;            // Item state flags
00067   FXint       x,y;
00068 private:
00069   FXTreeItem(const FXTreeItem&);
00070   FXTreeItem& operator=(const FXTreeItem&);
00071 protected:
00072   FXTreeItem():parent(NULL),prev(NULL),next(NULL),first(NULL),last(NULL),openIcon(NULL),closedIcon(NULL),data(NULL),state(0),x(0),y(0){}
00073   virtual void draw(const FXTreeList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00074   virtual FXint hitItem(const FXTreeList* list,FXint x,FXint y) const;
00075 public:
00076   enum{
00077     SELECTED        = 1,        
00078     FOCUS           = 2,        
00079     DISABLED        = 4,        
00080     OPENED          = 8,        
00081     EXPANDED        = 16,       
00082     HASITEMS        = 32,       
00083     DRAGGABLE       = 64,       
00084     OPENICONOWNED   = 128,      
00085     CLOSEDICONOWNED = 256       
00086     };
00087 public:
00088 
00090   FXTreeItem(const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL):parent(NULL),prev(NULL),next(NULL),first(NULL),last(NULL),label(text),openIcon(oi),closedIcon(ci),data(ptr),state(0),x(0),y(0){}
00091 
00093   FXTreeItem* getParent() const { return parent; }
00094 
00096   FXTreeItem* getNext() const { return next; }
00097 
00099   FXTreeItem* getPrev() const { return prev; }
00100 
00102   FXTreeItem* getFirst() const { return first; }
00103 
00105   FXTreeItem* getLast() const { return last; }
00106 
00108   FXTreeItem* getBelow() const;
00109 
00111   FXTreeItem* getAbove() const;
00112 
00114   FXint getNumChildren() const;
00115 
00117   virtual void setText(const FXString& txt);
00118 
00120   const FXString& getText() const { return label; }
00121 
00123   virtual void setOpenIcon(FXIcon* icn,FXbool owned=false);
00124 
00126   FXIcon* getOpenIcon() const { return openIcon; }
00127 
00129   virtual void setClosedIcon(FXIcon* icn,FXbool owned=false);
00130 
00132   FXIcon* getClosedIcon() const { return closedIcon; }
00133 
00135   void setData(void* ptr){ data=ptr; }
00136 
00138   void* getData() const { return data; }
00139 
00141   virtual void setFocus(FXbool focus);
00142 
00144   FXbool hasFocus() const { return (state&FOCUS)!=0; }
00145 
00147   virtual void setSelected(FXbool selected);
00148 
00150   FXbool isSelected() const { return (state&SELECTED)!=0; }
00151 
00153   virtual void setOpened(FXbool opened);
00154 
00156   FXbool isOpened() const { return (state&OPENED)!=0; }
00157 
00159   virtual void setExpanded(FXbool expanded);
00160 
00162   FXbool isExpanded() const { return (state&EXPANDED)!=0; }
00163 
00165   virtual void setEnabled(FXbool enabled);
00166 
00168   FXbool isEnabled() const { return (state&DISABLED)==0; }
00169 
00171   virtual void setDraggable(FXbool draggable);
00172 
00174   FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
00175 
00177   FXbool hasItems() const { return (state&HASITEMS)!=0; }
00178 
00180   void setHasItems(FXbool flag);
00181 
00183   FXbool isChildOf(const FXTreeItem* item) const;
00184 
00186   FXbool isParentOf(const FXTreeItem* item) const;
00187 
00189   virtual FXString getTipText() const;
00190 
00192   virtual FXint getWidth(const FXTreeList* list) const;
00193 
00195   virtual FXint getHeight(const FXTreeList* list) const;
00196 
00198   virtual void create();
00199 
00201   virtual void detach();
00202 
00204   virtual void destroy();
00205 
00207   virtual void save(FXStream& store) const;
00208 
00210   virtual void load(FXStream& store);
00211 
00213   virtual ~FXTreeItem();
00214   };
00215 
00216 
00217 
00219 typedef FXint (*FXTreeListSortFunc)(const FXTreeItem*,const FXTreeItem*);
00220 
00221 
00222 
00243 class FXAPI FXTreeList : public FXScrollArea {
00244   FXDECLARE(FXTreeList)
00245 protected:
00246   FXTreeItem        *firstitem;         // First root item
00247   FXTreeItem        *lastitem;          // Last root item
00248   FXTreeItem        *anchoritem;        // Selection anchor item
00249   FXTreeItem        *currentitem;       // Current item
00250   FXTreeItem        *extentitem;        // Selection extent
00251   FXTreeItem        *viewableitem;      // Visible item
00252   FXFont            *font;              // Font
00253   FXTreeListSortFunc sortfunc;          // Item sort function
00254   FXColor            textColor;         // Text color
00255   FXColor            selbackColor;      // Selected background color
00256   FXColor            seltextColor;      // Selected text color
00257   FXColor            lineColor;         // Line color
00258   FXint              treeWidth;         // Tree width
00259   FXint              treeHeight;        // Tree height
00260   FXint              visible;           // Number of visible items
00261   FXint              indent;            // Parent to child indentation
00262   FXint              grabx;             // Grab point x
00263   FXint              graby;             // Grab point y
00264   FXString           lookup;            // Lookup string
00265   FXString           tip;
00266   FXString           help;              // Help string
00267   FXbool             state;             // State of item
00268 protected:
00269   FXTreeList();
00270   virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
00271   void sort(FXTreeItem*& f1,FXTreeItem*& t1,FXTreeItem*& f2,FXTreeItem*& t2,int n);
00272   void recompute();
00273 private:
00274   FXTreeList(const FXTreeList&);
00275   FXTreeList& operator=(const FXTreeList&);
00276 public:
00277   long onPaint(FXObject*,FXSelector,void*);
00278   long onEnter(FXObject*,FXSelector,void*);
00279   long onLeave(FXObject*,FXSelector,void*);
00280   long onUngrabbed(FXObject*,FXSelector,void*);
00281   long onMotion(FXObject*,FXSelector,void*);
00282   long onKeyPress(FXObject*,FXSelector,void*);
00283   long onKeyRelease(FXObject*,FXSelector,void*);
00284   long onLeftBtnPress(FXObject*,FXSelector,void*);
00285   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00286   long onRightBtnPress(FXObject*,FXSelector,void*);
00287   long onRightBtnRelease(FXObject*,FXSelector,void*);
00288   long onQueryTip(FXObject*,FXSelector,void*);
00289   long onQueryHelp(FXObject*,FXSelector,void*);
00290   long onTipTimer(FXObject*,FXSelector,void*);
00291   long onFocusIn(FXObject*,FXSelector,void*);
00292   long onFocusOut(FXObject*,FXSelector,void*);
00293   long onAutoScroll(FXObject*,FXSelector,void*);
00294   long onClicked(FXObject*,FXSelector,void*);
00295   long onDoubleClicked(FXObject*,FXSelector,void*);
00296   long onTripleClicked(FXObject*,FXSelector,void*);
00297   long onCommand(FXObject*,FXSelector,void*);
00298   long onLookupTimer(FXObject*,FXSelector,void*);
00299 public:
00300   static FXint ascending(const FXTreeItem*,const FXTreeItem*);
00301   static FXint descending(const FXTreeItem*,const FXTreeItem*);
00302   static FXint ascendingCase(const FXTreeItem*,const FXTreeItem*);
00303   static FXint descendingCase(const FXTreeItem*,const FXTreeItem*);
00304 public:
00305   enum {
00306     ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
00307     ID_LAST
00308     };
00309 public:
00310 
00312   FXTreeList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=TREELIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00313 
00315   virtual void create();
00316 
00318   virtual void detach();
00319 
00321   virtual void layout();
00322 
00324   virtual FXint getDefaultWidth();
00325 
00327   virtual FXint getDefaultHeight();
00328 
00330   virtual FXint getContentWidth();
00331 
00333   virtual FXint getContentHeight();
00334 
00336   virtual void recalc();
00337 
00339   virtual FXbool canFocus() const;
00340 
00342   virtual void setFocus();
00343 
00345   virtual void killFocus();
00346 
00348   FXint getNumItems() const;
00349 
00351   FXint getNumVisible() const { return visible; }
00352 
00354   void setNumVisible(FXint nvis);
00355 
00357   FXTreeItem* getFirstItem() const { return firstitem; }
00358 
00360   FXTreeItem* getLastItem() const { return lastitem; }
00361 
00363   FXint fillItems(FXTreeItem* father,const FXchar** strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00364 
00366   FXint fillItems(FXTreeItem* father,const FXString& strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00367 
00369   FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item,FXbool notify=false);
00370 
00372   FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00373 
00375   FXTreeItem* appendItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=false);
00376 
00378   FXTreeItem* appendItem(FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00379 
00381   FXTreeItem* prependItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=false);
00382 
00384   FXTreeItem* prependItem(FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00385 
00387   FXTreeItem *moveItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item);
00388 
00390   FXTreeItem* extractItem(FXTreeItem* item,FXbool notify=false);
00391 
00393   void removeItem(FXTreeItem* item,FXbool notify=false);
00394 
00396   void removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify=false);
00397 
00399   void clearItems(FXbool notify=false);
00400 
00402   FXint getItemWidth(const FXTreeItem* item) const { return item->getWidth(this); }
00403 
00405   FXint getItemHeight(const FXTreeItem* item) const { return item->getHeight(this); }
00406 
00408   virtual FXTreeItem* getItemAt(FXint x,FXint y) const;
00409 
00420   FXTreeItem* findItem(const FXString& name,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00421 
00429   FXTreeItem* findItemByData(const void *ptr,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00430 
00432   virtual void makeItemVisible(FXTreeItem* item);
00433 
00435   void setItemText(FXTreeItem* item,const FXString& text);
00436 
00438   FXString getItemText(const FXTreeItem* item) const;
00439 
00441   void setItemOpenIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=false);
00442 
00444   FXIcon* getItemOpenIcon(const FXTreeItem* item) const;
00445 
00447   void setItemClosedIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=false);
00448 
00450   FXIcon* getItemClosedIcon(const FXTreeItem* item) const;
00451 
00453   void setItemData(FXTreeItem* item,void* ptr) const;
00454 
00456   void* getItemData(const FXTreeItem* item) const;
00457 
00459   FXbool isItemSelected(const FXTreeItem* item) const;
00460 
00462   FXbool isItemCurrent(const FXTreeItem* item) const;
00463 
00465   FXbool isItemVisible(const FXTreeItem* item) const;
00466 
00468   FXbool isItemOpened(const FXTreeItem* item) const;
00469 
00471   FXbool isItemExpanded(const FXTreeItem* item) const;
00472 
00474   FXbool isItemLeaf(const FXTreeItem* item) const;
00475 
00477   FXbool isItemEnabled(const FXTreeItem* item) const;
00478 
00480   FXint hitItem(const FXTreeItem* item,FXint x,FXint y) const;
00481 
00483   void updateItem(FXTreeItem* item) const;
00484 
00486   virtual FXbool enableItem(FXTreeItem* item);
00487 
00489   virtual FXbool disableItem(FXTreeItem* item);
00490 
00492   virtual FXbool selectItem(FXTreeItem* item,FXbool notify=false);
00493 
00495   virtual FXbool deselectItem(FXTreeItem* item,FXbool notify=false);
00496 
00498   virtual FXbool toggleItem(FXTreeItem* item,FXbool notify=false);
00499 
00501   virtual FXbool extendSelection(FXTreeItem* item,FXbool notify=false);
00502 
00504   virtual FXbool killSelection(FXbool notify=false);
00505 
00507   virtual FXbool openItem(FXTreeItem* item,FXbool notify=false);
00508 
00510   virtual FXbool closeItem(FXTreeItem* item,FXbool notify=false);
00511 
00513   virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=false);
00514 
00516   virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=false);
00517 
00519   virtual void setCurrentItem(FXTreeItem* item,FXbool notify=false);
00520 
00522   FXTreeItem* getCurrentItem() const { return currentitem; }
00523 
00525   void setAnchorItem(FXTreeItem* item);
00526 
00528   FXTreeItem* getAnchorItem() const { return anchoritem; }
00529 
00531   void sortItems();
00532 
00534   void sortRootItems();
00535 
00537   void sortChildItems(FXTreeItem* item);
00538 
00540   FXTreeListSortFunc getSortFunc() const { return sortfunc; }
00541 
00543   void setSortFunc(FXTreeListSortFunc func){ sortfunc=func; }
00544 
00546   void setFont(FXFont* fnt);
00547 
00549   FXFont* getFont() const { return font; }
00550 
00552   void setIndent(FXint in);
00553 
00555   FXint getIndent() const { return indent; }
00556 
00558   FXColor getTextColor() const { return textColor; }
00559 
00561   void setTextColor(FXColor clr);
00562 
00564   FXColor getSelBackColor() const { return selbackColor; }
00565 
00567   void setSelBackColor(FXColor clr);
00568 
00570   FXColor getSelTextColor() const { return seltextColor; }
00571 
00573   void setSelTextColor(FXColor clr);
00574 
00576   FXColor getLineColor() const { return lineColor; }
00577 
00579   void setLineColor(FXColor clr);
00580 
00582   FXuint getListStyle() const;
00583 
00585   void setListStyle(FXuint style);
00586 
00588   void setHelpText(const FXString& text);
00589 
00591   const FXString& getHelpText() const { return help; }
00592 
00594   virtual void save(FXStream& store) const;
00595 
00597   virtual void load(FXStream& store);
00598 
00600   virtual ~FXTreeList();
00601   };
00602 
00603 }
00604 
00605 #endif

Copyright © 1997-2011 Jeroen van der Zijp