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

/home/jeroen/FOX/fox/fox-1.7.33/include/FXFoldingList.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *                    F o l d i n g   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 FXFOLDINGLIST_H
00022 #define FXFOLDINGLIST_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 FXHeader;
00034 class FXFoldingList;
00035 
00036 
00038 enum {
00039   FOLDINGLIST_EXTENDEDSELECT = 0,            
00040   FOLDINGLIST_SINGLESELECT   = 0x00100000,   
00041   FOLDINGLIST_BROWSESELECT   = 0x00200000,   
00042   FOLDINGLIST_MULTIPLESELECT = 0x00300000,   
00043   FOLDINGLIST_AUTOSELECT     = 0x00400000,   
00044   FOLDINGLIST_SHOWS_LINES    = 0x00800000,   
00045   FOLDINGLIST_SHOWS_BOXES    = 0x01000000,   
00046   FOLDINGLIST_ROOT_BOXES     = 0x02000000,   
00047   FOLDINGLIST_NORMAL         = FOLDINGLIST_EXTENDEDSELECT
00048   };
00049 
00050 
00052 class FXAPI FXFoldingItem : public FXObject {
00053   FXDECLARE(FXFoldingItem)
00054   friend class FXFoldingList;
00055   friend class FXDirList;
00056 protected:
00057   FXFoldingItem *parent;
00058   FXFoldingItem *prev;
00059   FXFoldingItem *next;
00060   FXFoldingItem *first;
00061   FXFoldingItem *last;
00062   FXString       label;
00063   FXIcon        *openIcon;
00064   FXIcon        *closedIcon;
00065   void          *data;
00066   FXuint         state;
00067   FXint          x,y;
00068 private:
00069   FXFoldingItem(const FXFoldingItem&);
00070   FXFoldingItem& operator=(const FXFoldingItem&);
00071 protected:
00072   FXFoldingItem():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 FXFoldingList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00074   virtual FXint hitItem(const FXFoldingList* 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   FXFoldingItem(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   FXFoldingItem* getParent() const { return parent; }
00094 
00096   FXFoldingItem* getNext() const { return next; }
00097 
00099   FXFoldingItem* getPrev() const { return prev; }
00100 
00102   FXFoldingItem* getFirst() const { return first; }
00103 
00105   FXFoldingItem* getLast() const { return last; }
00106 
00108   FXFoldingItem* getBelow() const;
00109 
00111   FXFoldingItem* 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 FXFoldingItem* item) const;
00184 
00186   FXbool isParentOf(const FXFoldingItem* item) const;
00187 
00189   virtual FXString getTipText() const;
00190 
00192   virtual FXint getWidth(const FXFoldingList* list) const;
00193 
00195   virtual FXint getHeight(const FXFoldingList* 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 ~FXFoldingItem();
00214   };
00215 
00216 
00217 
00219 typedef FXint (*FXFoldingListSortFunc)(const FXFoldingItem*,const FXFoldingItem*);
00220 
00221 
00222 
00249 class FXAPI FXFoldingList : public FXScrollArea {
00250   FXDECLARE(FXFoldingList)
00251 protected:
00252   FXHeader          *header;            // Tree header
00253   FXFoldingItem     *firstitem;         // First root item
00254   FXFoldingItem     *lastitem;          // Last root item
00255   FXFoldingItem     *anchoritem;        // Selection anchor item
00256   FXFoldingItem     *currentitem;       // Current item
00257   FXFoldingItem     *extentitem;        // Selection extent
00258   FXFoldingItem     *viewableitem;      // Viewable item
00259   FXFont            *font;              // Font
00260   FXFoldingListSortFunc sortfunc;       // Item sort function
00261   FXColor            textColor;         // Text color
00262   FXColor            selbackColor;      // Selected background color
00263   FXColor            seltextColor;      // Selected text color
00264   FXColor            lineColor;         // Line color
00265   FXint              treeWidth;         // Tree width
00266   FXint              treeHeight;        // Tree height
00267   FXint              visible;           // Number of visible items
00268   FXint              indent;            // Parent to child indentation
00269   FXint              grabx;             // Grab point x
00270   FXint              graby;             // Grab point y
00271   FXString           lookup;            // Lookup string
00272   FXString           help;              // Help string
00273   FXbool             state;             // State of item
00274 protected:
00275   FXFoldingList();
00276   void recompute();
00277   void mergesort(FXFoldingItem*& list);
00278   void sort(FXFoldingItem*& f1,FXFoldingItem*& t1,FXFoldingItem*& f2,FXFoldingItem*& t2,int n);
00279   virtual void moveContents(FXint x,FXint y);
00280   virtual FXFoldingItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
00281   static FXint compareSection(const FXchar *p,const FXchar* q,FXint s);
00282   static FXint compareSectionCase(const FXchar *p,const FXchar* q,FXint s);
00283 private:
00284   FXFoldingList(const FXFoldingList&);
00285   FXFoldingList& operator=(const FXFoldingList&);
00286 public:
00287   long onPaint(FXObject*,FXSelector,void*);
00288   long onEnter(FXObject*,FXSelector,void*);
00289   long onLeave(FXObject*,FXSelector,void*);
00290   long onUngrabbed(FXObject*,FXSelector,void*);
00291   long onMotion(FXObject*,FXSelector,void*);
00292   long onKeyPress(FXObject*,FXSelector,void*);
00293   long onKeyRelease(FXObject*,FXSelector,void*);
00294   long onLeftBtnPress(FXObject*,FXSelector,void*);
00295   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00296   long onRightBtnPress(FXObject*,FXSelector,void*);
00297   long onRightBtnRelease(FXObject*,FXSelector,void*);
00298   long onChgHeader(FXObject*,FXSelector,void*);
00299   long onQueryTip(FXObject*,FXSelector,void*);
00300   long onQueryHelp(FXObject*,FXSelector,void*);
00301   long onTipTimer(FXObject*,FXSelector,void*);
00302   long onFocusIn(FXObject*,FXSelector,void*);
00303   long onFocusOut(FXObject*,FXSelector,void*);
00304   long onAutoScroll(FXObject*,FXSelector,void*);
00305   long onClicked(FXObject*,FXSelector,void*);
00306   long onDoubleClicked(FXObject*,FXSelector,void*);
00307   long onTripleClicked(FXObject*,FXSelector,void*);
00308   long onCommand(FXObject*,FXSelector,void*);
00309   long onLookupTimer(FXObject*,FXSelector,void*);
00310 public:
00311   static FXint ascending(const FXFoldingItem*,const FXFoldingItem*);
00312   static FXint descending(const FXFoldingItem*,const FXFoldingItem*);
00313   static FXint ascendingCase(const FXFoldingItem*,const FXFoldingItem*);
00314   static FXint descendingCase(const FXFoldingItem*,const FXFoldingItem*);
00315 public:
00316   enum {
00317     ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
00318     ID_HEADER,
00319     ID_LAST
00320     };
00321 public:
00322 
00324   FXFoldingList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=FOLDINGLIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00325 
00327   virtual void create();
00328 
00330   virtual void detach();
00331 
00333   virtual void layout();
00334 
00336   virtual FXint getDefaultWidth();
00337 
00339   virtual FXint getDefaultHeight();
00340 
00342   virtual FXint getVisibleY() const;
00343 
00345   virtual FXint getVisibleHeight() const;
00346 
00348   virtual FXint getContentWidth();
00349 
00351   virtual FXint getContentHeight();
00352 
00354   virtual void recalc();
00355 
00357   virtual FXbool canFocus() const;
00358 
00360   virtual void setFocus();
00361 
00363   virtual void killFocus();
00364 
00366   FXHeader* getHeader() const { return header; }
00367 
00369   void setHeaders(const FXchar** strings,FXint size=1);
00370 
00372   void setHeaders(const FXString& strings,FXint size=1);
00373 
00375   void appendHeader(const FXString& text,FXIcon *icon=NULL,FXint size=1);
00376 
00378   void removeHeader(FXint index);
00379 
00381   void setHeaderText(FXint index,const FXString& text);
00382 
00384   FXString getHeaderText(FXint index) const;
00385 
00387   void setHeaderIcon(FXint index,FXIcon *icon);
00388 
00390   FXIcon* getHeaderIcon(FXint index) const;
00391 
00393   void setHeaderSize(FXint index,FXint size);
00394 
00396   FXint getHeaderSize(FXint index) const;
00397 
00399   FXint getNumHeaders() const;
00400 
00402   FXint getNumItems() const;
00403 
00405   FXint getNumVisible() const { return visible; }
00406 
00408   void setNumVisible(FXint nvis);
00409 
00411   FXFoldingItem* getFirstItem() const { return firstitem; }
00412 
00414   FXFoldingItem* getLastItem() const { return lastitem; }
00415 
00417   FXint fillItems(FXFoldingItem* father,const FXchar** strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00418 
00420   FXint fillItems(FXFoldingItem* father,const FXString& strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00421 
00423   FXFoldingItem* insertItem(FXFoldingItem* other,FXFoldingItem* father,FXFoldingItem* item,FXbool notify=false);
00424 
00426   FXFoldingItem* insertItem(FXFoldingItem* other,FXFoldingItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00427 
00429   FXFoldingItem* appendItem(FXFoldingItem* father,FXFoldingItem* item,FXbool notify=false);
00430 
00432   FXFoldingItem* appendItem(FXFoldingItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00433 
00435   FXFoldingItem* prependItem(FXFoldingItem* father,FXFoldingItem* item,FXbool notify=false);
00436 
00438   FXFoldingItem* prependItem(FXFoldingItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=false);
00439 
00441   FXFoldingItem *moveItem(FXFoldingItem* other,FXFoldingItem* father,FXFoldingItem* item);
00442 
00444   FXFoldingItem* extractItem(FXFoldingItem* item,FXbool notify=false);
00445 
00447   void removeItem(FXFoldingItem* item,FXbool notify=false);
00448 
00450   void removeItems(FXFoldingItem* fm,FXFoldingItem* to,FXbool notify=false);
00451 
00453   void clearItems(FXbool notify=false);
00454 
00456   FXint getItemWidth(const FXFoldingItem* item) const { return item->getWidth(this); }
00457 
00459   FXint getItemHeight(const FXFoldingItem* item) const { return item->getHeight(this); }
00460 
00462   virtual FXFoldingItem* getItemAt(FXint x,FXint y) const;
00463 
00474   FXFoldingItem* findItem(const FXString& text,FXFoldingItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00475 
00483   FXFoldingItem* findItemByData(const void *ptr,FXFoldingItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00484 
00486   virtual void makeItemVisible(FXFoldingItem* item);
00487 
00489   void setItemText(FXFoldingItem* item,const FXString& text);
00490 
00492   FXString getItemText(const FXFoldingItem* item) const;
00493 
00495   void setItemOpenIcon(FXFoldingItem* item,FXIcon* icon,FXbool owned=false);
00496 
00498   FXIcon* getItemOpenIcon(const FXFoldingItem* item) const;
00499 
00501   void setItemClosedIcon(FXFoldingItem* item,FXIcon* icon,FXbool owned=false);
00502 
00504   FXIcon* getItemClosedIcon(const FXFoldingItem* item) const;
00505 
00507   void setItemData(FXFoldingItem* item,void* ptr) const;
00508 
00510   void* getItemData(const FXFoldingItem* item) const;
00511 
00513   FXbool isItemSelected(const FXFoldingItem* item) const;
00514 
00516   FXbool isItemCurrent(const FXFoldingItem* item) const;
00517 
00519   FXbool isItemVisible(const FXFoldingItem* item) const;
00520 
00522   FXbool isItemOpened(const FXFoldingItem* item) const;
00523 
00525   FXbool isItemExpanded(const FXFoldingItem* item) const;
00526 
00528   FXbool isItemLeaf(const FXFoldingItem* item) const;
00529 
00531   FXbool isItemEnabled(const FXFoldingItem* item) const;
00532 
00534   FXint hitItem(const FXFoldingItem* item,FXint x,FXint y) const;
00535 
00537   void updateItem(FXFoldingItem* item);
00538 
00540   virtual FXbool enableItem(FXFoldingItem* item);
00541 
00543   virtual FXbool disableItem(FXFoldingItem* item);
00544 
00546   virtual FXbool selectItem(FXFoldingItem* item,FXbool notify=false);
00547 
00549   virtual FXbool deselectItem(FXFoldingItem* item,FXbool notify=false);
00550 
00552   virtual FXbool toggleItem(FXFoldingItem* item,FXbool notify=false);
00553 
00555   virtual FXbool extendSelection(FXFoldingItem* item,FXbool notify=false);
00556 
00558   virtual FXbool killSelection(FXbool notify=false);
00559 
00561   virtual FXbool openItem(FXFoldingItem* item,FXbool notify=false);
00562 
00564   virtual FXbool closeItem(FXFoldingItem* item,FXbool notify=false);
00565 
00567   virtual FXbool collapseTree(FXFoldingItem* tree,FXbool notify=false);
00568 
00570   virtual FXbool expandTree(FXFoldingItem* tree,FXbool notify=false);
00571 
00573   virtual void setCurrentItem(FXFoldingItem* item,FXbool notify=false);
00574 
00576   FXFoldingItem* getCurrentItem() const { return currentitem; }
00577 
00579   void setAnchorItem(FXFoldingItem* item);
00580 
00582   FXFoldingItem* getAnchorItem() const { return anchoritem; }
00583 
00585   void sortItems();
00586 
00588   void sortRootItems();
00589 
00591   void sortChildItems(FXFoldingItem* item);
00592 
00594   FXFoldingListSortFunc getSortFunc() const { return sortfunc; }
00595 
00597   void setSortFunc(FXFoldingListSortFunc func){ sortfunc=func; }
00598 
00600   void setFont(FXFont* fnt);
00601 
00603   FXFont* getFont() const { return font; }
00604 
00606   void setIndent(FXint in);
00607 
00609   FXint getIndent() const { return indent; }
00610 
00612   FXColor getTextColor() const { return textColor; }
00613 
00615   void setTextColor(FXColor clr);
00616 
00618   FXColor getSelBackColor() const { return selbackColor; }
00619 
00621   void setSelBackColor(FXColor clr);
00622 
00624   FXColor getSelTextColor() const { return seltextColor; }
00625 
00627   void setSelTextColor(FXColor clr);
00628 
00630   FXColor getLineColor() const { return lineColor; }
00631 
00633   void setLineColor(FXColor clr);
00634 
00636   FXuint getListStyle() const;
00637 
00639   void setListStyle(FXuint style);
00640 
00642   void setHelpText(const FXString& text);
00643 
00645   const FXString& getHelpText() const { return help; }
00646 
00648   virtual void save(FXStream& store) const;
00649 
00651   virtual void load(FXStream& store);
00652 
00654   virtual ~FXFoldingList();
00655   };
00656 
00657 }
00658 
00659 
00660 #endif

Copyright © 1997-2011 Jeroen van der Zijp