FXTreeList.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                         T r e e   L i s t   W i d g e t                       *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXTreeList.h,v 1.101 2006/01/22 17:58:11 fox Exp $                       *
00023 ********************************************************************************/
00024 #ifndef FXTREELIST_H
00025 #define FXTREELIST_H
00026 
00027 #ifndef FXSCROLLAREA_H
00028 #include "FXScrollArea.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 class FXIcon;
00035 class FXFont;
00036 class FXTreeList;
00037 class FXDirList;
00038 
00039 
00041 enum {
00042   TREELIST_EXTENDEDSELECT = 0,            
00043   TREELIST_SINGLESELECT   = 0x00100000,   
00044   TREELIST_BROWSESELECT   = 0x00200000,   
00045   TREELIST_MULTIPLESELECT = 0x00300000,   
00046   TREELIST_AUTOSELECT     = 0x00400000,   
00047   TREELIST_SHOWS_LINES    = 0x00800000,   
00048   TREELIST_SHOWS_BOXES    = 0x01000000,   
00049   TREELIST_ROOT_BOXES     = 0x02000000,   
00050   TREELIST_NORMAL         = TREELIST_EXTENDEDSELECT
00051   };
00052 
00053 
00055 class FXAPI FXTreeItem : public FXObject {
00056   FXDECLARE(FXTreeItem)
00057   friend class FXTreeList;
00058   friend class FXDirList;
00059 protected:
00060   FXTreeItem *parent;           // Parent item
00061   FXTreeItem *prev;             // Previous item
00062   FXTreeItem *next;             // Next item
00063   FXTreeItem *first;            // First child item
00064   FXTreeItem *last;             // Last child item
00065   FXString    label;            // Text of item
00066   FXIcon     *openIcon;         // Icon of item
00067   FXIcon     *closedIcon;       // Icon of item
00068   void       *data;             // Item user data pointer
00069   FXuint      state;            // Item state flags
00070   FXint       x,y;
00071 private:
00072   FXTreeItem(const FXTreeItem&);
00073   FXTreeItem& operator=(const FXTreeItem&);
00074 protected:
00075   FXTreeItem():parent(NULL),prev(NULL),next(NULL),first(NULL),last(NULL),openIcon(NULL),closedIcon(NULL),data(NULL),state(0),x(0),y(0){}
00076   virtual void draw(const FXTreeList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00077   virtual FXint hitItem(const FXTreeList* list,FXint x,FXint y) const;
00078 public:
00079   enum{
00080     SELECTED        = 1,        
00081     FOCUS           = 2,        
00082     DISABLED        = 4,        
00083     OPENED          = 8,        
00084     EXPANDED        = 16,       
00085     HASITEMS        = 32,       
00086     DRAGGABLE       = 64,       
00087     OPENICONOWNED   = 128,      
00088     CLOSEDICONOWNED = 256       
00089     };
00090 public:
00091 
00093   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){}
00094 
00096   FXTreeItem* getParent() const { return parent; }
00097 
00099   FXTreeItem* getNext() const { return next; }
00100 
00102   FXTreeItem* getPrev() const { return prev; }
00103 
00105   FXTreeItem* getFirst() const { return first; }
00106 
00108   FXTreeItem* getLast() const { return last; }
00109 
00111   FXTreeItem* getBelow() const;
00112 
00114   FXTreeItem* getAbove() const;
00115 
00117   FXint getNumChildren() const;
00118 
00120   virtual void setText(const FXString& txt);
00121 
00123   const FXString& getText() const { return label; }
00124 
00126   virtual void setOpenIcon(FXIcon* icn,FXbool owned=FALSE);
00127 
00129   FXIcon* getOpenIcon() const { return openIcon; }
00130 
00132   virtual void setClosedIcon(FXIcon* icn,FXbool owned=FALSE);
00133 
00135   FXIcon* getClosedIcon() const { return closedIcon; }
00136 
00138   void setData(void* ptr){ data=ptr; }
00139 
00141   void* getData() const { return data; }
00142 
00144   virtual void setFocus(FXbool focus);
00145 
00147   FXbool hasFocus() const { return (state&FOCUS)!=0; }
00148 
00150   virtual void setSelected(FXbool selected);
00151 
00153   FXbool isSelected() const { return (state&SELECTED)!=0; }
00154 
00156   virtual void setOpened(FXbool opened);
00157 
00159   FXbool isOpened() const { return (state&OPENED)!=0; }
00160 
00162   virtual void setExpanded(FXbool expanded);
00163 
00165   FXbool isExpanded() const { return (state&EXPANDED)!=0; }
00166 
00168   virtual void setEnabled(FXbool enabled);
00169 
00171   FXbool isEnabled() const { return (state&DISABLED)==0; }
00172 
00174   virtual void setDraggable(FXbool draggable);
00175 
00177   FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
00178 
00180   FXbool hasItems() const { return (state&HASITEMS)!=0; }
00181 
00183   void setHasItems(FXbool flag);
00184 
00186   FXbool isChildOf(const FXTreeItem* item) const;
00187 
00189   FXbool isParentOf(const FXTreeItem* item) 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        *cursoritem;        // Item under cursor
00252   FXTreeItem        *viewableitem;      // Visible item
00253   FXFont            *font;              // Font
00254   FXTreeListSortFunc sortfunc;          // Item sort function
00255   FXColor            textColor;         // Text color
00256   FXColor            selbackColor;      // Selected background color
00257   FXColor            seltextColor;      // Selected text color
00258   FXColor            lineColor;         // Line color
00259   FXint              treeWidth;         // Tree width
00260   FXint              treeHeight;        // Tree height
00261   FXint              visible;           // Number of visible items
00262   FXint              indent;            // Parent to child indentation
00263   FXint              grabx;             // Grab point x
00264   FXint              graby;             // Grab point y
00265   FXString           lookup;            // Lookup string
00266   FXString           tip;
00267   FXString           help;              // Help string
00268   FXbool             state;             // State of item
00269 protected:
00270   FXTreeList();
00271   virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
00272   void sort(FXTreeItem*& f1,FXTreeItem*& t1,FXTreeItem*& f2,FXTreeItem*& t2,int n);
00273   void recompute();
00274 private:
00275   FXTreeList(const FXTreeList&);
00276   FXTreeList& operator=(const FXTreeList&);
00277 public:
00278   long onPaint(FXObject*,FXSelector,void*);
00279   long onEnter(FXObject*,FXSelector,void*);
00280   long onLeave(FXObject*,FXSelector,void*);
00281   long onUngrabbed(FXObject*,FXSelector,void*);
00282   long onMotion(FXObject*,FXSelector,void*);
00283   long onKeyPress(FXObject*,FXSelector,void*);
00284   long onKeyRelease(FXObject*,FXSelector,void*);
00285   long onLeftBtnPress(FXObject*,FXSelector,void*);
00286   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00287   long onRightBtnPress(FXObject*,FXSelector,void*);
00288   long onRightBtnRelease(FXObject*,FXSelector,void*);
00289   long onQueryTip(FXObject*,FXSelector,void*);
00290   long onQueryHelp(FXObject*,FXSelector,void*);
00291   long onTipTimer(FXObject*,FXSelector,void*);
00292   long onFocusIn(FXObject*,FXSelector,void*);
00293   long onFocusOut(FXObject*,FXSelector,void*);
00294   long onAutoScroll(FXObject*,FXSelector,void*);
00295   long onClicked(FXObject*,FXSelector,void*);
00296   long onDoubleClicked(FXObject*,FXSelector,void*);
00297   long onTripleClicked(FXObject*,FXSelector,void*);
00298   long onCommand(FXObject*,FXSelector,void*);
00299   long onLookupTimer(FXObject*,FXSelector,void*);
00300 public:
00301   static FXint ascending(const FXTreeItem*,const FXTreeItem*);
00302   static FXint descending(const FXTreeItem*,const FXTreeItem*);
00303   static FXint ascendingCase(const FXTreeItem*,const FXTreeItem*);
00304   static FXint descendingCase(const FXTreeItem*,const FXTreeItem*);
00305 public:
00306   enum {
00307     ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
00308     ID_LAST
00309     };
00310 public:
00311 
00313   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);
00314 
00316   virtual void create();
00317 
00319   virtual void detach();
00320 
00322   virtual void layout();
00323 
00325   virtual FXint getDefaultWidth();
00326 
00328   virtual FXint getDefaultHeight();
00329 
00331   virtual FXint getContentWidth();
00332 
00334   virtual FXint getContentHeight();
00335 
00337   virtual void recalc();
00338 
00340   virtual bool canFocus() const;
00341 
00343   virtual void setFocus();
00344 
00346   virtual void killFocus();
00347 
00349   FXint getNumItems() const;
00350 
00352   FXint getNumVisible() const { return visible; }
00353 
00355   void setNumVisible(FXint nvis);
00356 
00358   FXTreeItem* getFirstItem() const { return firstitem; }
00359 
00361   FXTreeItem* getLastItem() const { return lastitem; }
00362 
00364   FXint fillItems(FXTreeItem* father,const FXchar** strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00365 
00367   FXint fillItems(FXTreeItem* father,const FXString& strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00368 
00370   FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item,FXbool notify=FALSE);
00371 
00373   FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00374 
00376   FXTreeItem* appendItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=FALSE);
00377 
00379   FXTreeItem* appendItem(FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00380 
00382   FXTreeItem* prependItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=FALSE);
00383 
00385   FXTreeItem* prependItem(FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00386 
00388   FXTreeItem *moveItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item);
00389 
00391   FXTreeItem* extractItem(FXTreeItem* item,FXbool notify=FALSE);
00392 
00394   void removeItem(FXTreeItem* item,FXbool notify=FALSE);
00395 
00397   void removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify=FALSE);
00398 
00400   void clearItems(FXbool notify=FALSE);
00401 
00403   FXint getItemWidth(const FXTreeItem* item) const { return item->getWidth(this); }
00404 
00406   FXint getItemHeight(const FXTreeItem* item) const { return item->getHeight(this); }
00407 
00409   virtual FXTreeItem* getItemAt(FXint x,FXint y) const;
00410 
00421   FXTreeItem* findItem(const FXString& name,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00422 
00430   FXTreeItem* findItemByData(const void *ptr,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00431 
00433   virtual void makeItemVisible(FXTreeItem* item);
00434 
00436   void setItemText(FXTreeItem* item,const FXString& text);
00437 
00439   FXString getItemText(const FXTreeItem* item) const;
00440 
00442   void setItemOpenIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=FALSE);
00443 
00445   FXIcon* getItemOpenIcon(const FXTreeItem* item) const;
00446 
00448   void setItemClosedIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=FALSE);
00449 
00451   FXIcon* getItemClosedIcon(const FXTreeItem* item) const;
00452 
00454   void setItemData(FXTreeItem* item,void* ptr) const;
00455 
00457   void* getItemData(const FXTreeItem* item) const;
00458 
00460   FXbool isItemSelected(const FXTreeItem* item) const;
00461 
00463   FXbool isItemCurrent(const FXTreeItem* item) const;
00464 
00466   FXbool isItemVisible(const FXTreeItem* item) const;
00467 
00469   FXbool isItemOpened(const FXTreeItem* item) const;
00470 
00472   FXbool isItemExpanded(const FXTreeItem* item) const;
00473 
00475   FXbool isItemLeaf(const FXTreeItem* item) const;
00476 
00478   FXbool isItemEnabled(const FXTreeItem* item) const;
00479 
00481   FXint hitItem(const FXTreeItem* item,FXint x,FXint y) const;
00482 
00484   void updateItem(FXTreeItem* item) const;
00485 
00487   virtual FXbool enableItem(FXTreeItem* item);
00488 
00490   virtual FXbool disableItem(FXTreeItem* item);
00491 
00493   virtual FXbool selectItem(FXTreeItem* item,FXbool notify=FALSE);
00494 
00496   virtual FXbool deselectItem(FXTreeItem* item,FXbool notify=FALSE);
00497 
00499   virtual FXbool toggleItem(FXTreeItem* item,FXbool notify=FALSE);
00500 
00502   virtual FXbool extendSelection(FXTreeItem* item,FXbool notify=FALSE);
00503 
00505   virtual FXbool killSelection(FXbool notify=FALSE);
00506 
00508   virtual FXbool openItem(FXTreeItem* item,FXbool notify=FALSE);
00509 
00511   virtual FXbool closeItem(FXTreeItem* item,FXbool notify=FALSE);
00512 
00514   virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=FALSE);
00515 
00517   virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=FALSE);
00518 
00520   virtual void setCurrentItem(FXTreeItem* item,FXbool notify=FALSE);
00521 
00523   FXTreeItem* getCurrentItem() const { return currentitem; }
00524 
00526   void setAnchorItem(FXTreeItem* item);
00527 
00529   FXTreeItem* getAnchorItem() const { return anchoritem; }
00530 
00532   FXTreeItem* getCursorItem() const { return cursoritem; }
00533 
00535   void sortItems();
00536 
00538   void sortRootItems();
00539 
00541   void sortChildItems(FXTreeItem* item);
00542 
00544   FXTreeListSortFunc getSortFunc() const { return sortfunc; }
00545 
00547   void setSortFunc(FXTreeListSortFunc func){ sortfunc=func; }
00548 
00550   void setFont(FXFont* fnt);
00551 
00553   FXFont* getFont() const { return font; }
00554 
00556   void setIndent(FXint in);
00557 
00559   FXint getIndent() const { return indent; }
00560 
00562   FXColor getTextColor() const { return textColor; }
00563 
00565   void setTextColor(FXColor clr);
00566 
00568   FXColor getSelBackColor() const { return selbackColor; }
00569 
00571   void setSelBackColor(FXColor clr);
00572 
00574   FXColor getSelTextColor() const { return seltextColor; }
00575 
00577   void setSelTextColor(FXColor clr);
00578 
00580   FXColor getLineColor() const { return lineColor; }
00581 
00583   void setLineColor(FXColor clr);
00584 
00586   FXuint getListStyle() const;
00587 
00589   void setListStyle(FXuint style);
00590 
00592   void setHelpText(const FXString& text);
00593 
00595   const FXString& getHelpText() const { return help; }
00596 
00598   virtual void save(FXStream& store) const;
00599 
00601   virtual void load(FXStream& store);
00602 
00604   virtual ~FXTreeList();
00605   };
00606 
00607 }
00608 
00609 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:25 2009 for TnFOX by doxygen v1.4.7