FXFoldingList.h

Go to the documentation of this file.
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,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: FXFoldingList.h,v 1.34 2006/01/22 17:58:02 fox Exp $                     *
00023 ********************************************************************************/
00024 #ifndef FXFOLDINGLIST_H
00025 #define FXFOLDINGLIST_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 FXHeader;
00037 class FXFoldingList;
00038 
00039 
00041 enum {
00042   FOLDINGLIST_EXTENDEDSELECT = 0,            
00043   FOLDINGLIST_SINGLESELECT   = 0x00100000,   
00044   FOLDINGLIST_BROWSESELECT   = 0x00200000,   
00045   FOLDINGLIST_MULTIPLESELECT = 0x00300000,   
00046   FOLDINGLIST_AUTOSELECT     = 0x00400000,   
00047   FOLDINGLIST_SHOWS_LINES    = 0x00800000,   
00048   FOLDINGLIST_SHOWS_BOXES    = 0x01000000,   
00049   FOLDINGLIST_ROOT_BOXES     = 0x02000000,   
00050   FOLDINGLIST_NORMAL         = FOLDINGLIST_EXTENDEDSELECT
00051   };
00052 
00053 
00055 class FXAPI FXFoldingItem : public FXObject {
00056   FXDECLARE(FXFoldingItem)
00057   friend class FXFoldingList;
00058   friend class FXDirList;
00059 protected:
00060   FXFoldingItem *parent;
00061   FXFoldingItem *prev;
00062   FXFoldingItem *next;
00063   FXFoldingItem *first;
00064   FXFoldingItem *last;
00065   FXString       label;
00066   FXIcon        *openIcon;
00067   FXIcon        *closedIcon;
00068   void          *data;
00069   FXuint         state;
00070   FXint          x,y;
00071 private:
00072   FXFoldingItem(const FXFoldingItem&);
00073   FXFoldingItem& operator=(const FXFoldingItem&);
00074 protected:
00075   FXFoldingItem():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 FXFoldingList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00077   virtual FXint hitItem(const FXFoldingList* 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   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){}
00094 
00096   FXFoldingItem* getParent() const { return parent; }
00097 
00099   FXFoldingItem* getNext() const { return next; }
00100 
00102   FXFoldingItem* getPrev() const { return prev; }
00103 
00105   FXFoldingItem* getFirst() const { return first; }
00106 
00108   FXFoldingItem* getLast() const { return last; }
00109 
00111   FXFoldingItem* getBelow() const;
00112 
00114   FXFoldingItem* 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 FXFoldingItem* item) const;
00187 
00189   FXbool isParentOf(const FXFoldingItem* item) 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 
00244 class FXAPI FXFoldingList : public FXScrollArea {
00245   FXDECLARE(FXFoldingList)
00246 protected:
00247   FXHeader          *header;            // Tree header
00248   FXFoldingItem     *firstitem;         // First root item
00249   FXFoldingItem     *lastitem;          // Last root item
00250   FXFoldingItem     *anchoritem;        // Selection anchor item
00251   FXFoldingItem     *currentitem;       // Current item
00252   FXFoldingItem     *extentitem;        // Selection extent
00253   FXFoldingItem     *cursoritem;        // Item under cursor
00254   FXFoldingItem     *viewableitem;      // Viewable item
00255   FXFont            *font;              // Font
00256   FXFoldingListSortFunc sortfunc;       // Item sort function
00257   FXColor            textColor;         // Text color
00258   FXColor            selbackColor;      // Selected background color
00259   FXColor            seltextColor;      // Selected text color
00260   FXColor            lineColor;         // Line color
00261   FXint              treeWidth;         // Tree width
00262   FXint              treeHeight;        // Tree height
00263   FXint              visible;           // Number of visible items
00264   FXint              indent;            // Parent to child indentation
00265   FXint              grabx;             // Grab point x
00266   FXint              graby;             // Grab point y
00267   FXString           lookup;            // Lookup string
00268   FXString           help;              // Help string
00269   FXbool             state;             // State of item
00270 protected:
00271   FXFoldingList();
00272   void recompute();
00273   void mergesort(FXFoldingItem*& list);
00274   void sort(FXFoldingItem*& f1,FXFoldingItem*& t1,FXFoldingItem*& f2,FXFoldingItem*& t2,int n);
00275   virtual void moveContents(FXint x,FXint y);
00276   virtual FXFoldingItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
00277   static FXint compareSection(const FXchar *p,const FXchar* q,FXint s);
00278   static FXint compareSectionCase(const FXchar *p,const FXchar* q,FXint s);
00279 private:
00280   FXFoldingList(const FXFoldingList&);
00281   FXFoldingList& operator=(const FXFoldingList&);
00282 public:
00283   long onPaint(FXObject*,FXSelector,void*);
00284   long onEnter(FXObject*,FXSelector,void*);
00285   long onLeave(FXObject*,FXSelector,void*);
00286   long onUngrabbed(FXObject*,FXSelector,void*);
00287   long onMotion(FXObject*,FXSelector,void*);
00288   long onKeyPress(FXObject*,FXSelector,void*);
00289   long onKeyRelease(FXObject*,FXSelector,void*);
00290   long onLeftBtnPress(FXObject*,FXSelector,void*);
00291   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00292   long onRightBtnPress(FXObject*,FXSelector,void*);
00293   long onRightBtnRelease(FXObject*,FXSelector,void*);
00294   long onHeaderChanged(FXObject*,FXSelector,void*);
00295   long onQueryTip(FXObject*,FXSelector,void*);
00296   long onQueryHelp(FXObject*,FXSelector,void*);
00297   long onTipTimer(FXObject*,FXSelector,void*);
00298   long onFocusIn(FXObject*,FXSelector,void*);
00299   long onFocusOut(FXObject*,FXSelector,void*);
00300   long onAutoScroll(FXObject*,FXSelector,void*);
00301   long onClicked(FXObject*,FXSelector,void*);
00302   long onDoubleClicked(FXObject*,FXSelector,void*);
00303   long onTripleClicked(FXObject*,FXSelector,void*);
00304   long onCommand(FXObject*,FXSelector,void*);
00305   long onLookupTimer(FXObject*,FXSelector,void*);
00306 public:
00307   static FXint ascending(const FXFoldingItem*,const FXFoldingItem*);
00308   static FXint descending(const FXFoldingItem*,const FXFoldingItem*);
00309   static FXint ascendingCase(const FXFoldingItem*,const FXFoldingItem*);
00310   static FXint descendingCase(const FXFoldingItem*,const FXFoldingItem*);
00311 public:
00312   enum {
00313     ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
00314     ID_HEADER_CHANGE,
00315     ID_LAST
00316     };
00317 public:
00318 
00320   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);
00321 
00323   virtual void create();
00324 
00326   virtual void detach();
00327 
00329   virtual void layout();
00330 
00332   virtual FXint getDefaultWidth();
00333 
00335   virtual FXint getDefaultHeight();
00336 
00338   virtual FXint getContentWidth();
00339 
00341   virtual FXint getContentHeight();
00342 
00344   virtual void recalc();
00345 
00347   virtual bool canFocus() const;
00348 
00350   virtual void setFocus();
00351 
00353   virtual void killFocus();
00354 
00356   FXHeader* getHeader() const { return header; }
00357 
00359   void setHeaders(const FXchar** strings,FXint size=1);
00360 
00362   void setHeaders(const FXString& strings,FXint size=1);
00363 
00365   void appendHeader(const FXString& text,FXIcon *icon=NULL,FXint size=1);
00366 
00368   void removeHeader(FXint index);
00369 
00371   void setHeaderText(FXint index,const FXString& text);
00372 
00374   FXString getHeaderText(FXint index) const;
00375 
00377   void setHeaderIcon(FXint index,FXIcon *icon);
00378 
00380   FXIcon* getHeaderIcon(FXint index) const;
00381 
00383   void setHeaderSize(FXint index,FXint size);
00384 
00386   FXint getHeaderSize(FXint index) const;
00387 
00389   FXint getNumHeaders() const;
00390 
00392   FXint getNumItems() const;
00393 
00395   FXint getNumVisible() const { return visible; }
00396 
00398   void setNumVisible(FXint nvis);
00399 
00401   FXFoldingItem* getFirstItem() const { return firstitem; }
00402 
00404   FXFoldingItem* getLastItem() const { return lastitem; }
00405 
00407   FXint fillItems(FXFoldingItem* father,const FXchar** strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00408 
00410   FXint fillItems(FXFoldingItem* father,const FXString& strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00411 
00413   FXFoldingItem* insertItem(FXFoldingItem* other,FXFoldingItem* father,FXFoldingItem* item,FXbool notify=FALSE);
00414 
00416   FXFoldingItem* insertItem(FXFoldingItem* other,FXFoldingItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00417 
00419   FXFoldingItem* appendItem(FXFoldingItem* father,FXFoldingItem* item,FXbool notify=FALSE);
00420 
00422   FXFoldingItem* appendItem(FXFoldingItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00423 
00425   FXFoldingItem* prependItem(FXFoldingItem* father,FXFoldingItem* item,FXbool notify=FALSE);
00426 
00428   FXFoldingItem* prependItem(FXFoldingItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00429 
00431   FXFoldingItem *moveItem(FXFoldingItem* other,FXFoldingItem* father,FXFoldingItem* item);
00432 
00434   FXFoldingItem* extractItem(FXFoldingItem* item,FXbool notify=FALSE);
00435 
00437   void removeItem(FXFoldingItem* item,FXbool notify=FALSE);
00438 
00440   void removeItems(FXFoldingItem* fm,FXFoldingItem* to,FXbool notify=FALSE);
00441 
00443   void clearItems(FXbool notify=FALSE);
00444 
00446   FXint getItemWidth(const FXFoldingItem* item) const { return item->getWidth(this); }
00447 
00449   FXint getItemHeight(const FXFoldingItem* item) const { return item->getHeight(this); }
00450 
00452   virtual FXFoldingItem* getItemAt(FXint x,FXint y) const;
00453 
00464   FXFoldingItem* findItem(const FXString& text,FXFoldingItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00465 
00473   FXFoldingItem* findItemByData(const void *ptr,FXFoldingItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00474 
00476   virtual void makeItemVisible(FXFoldingItem* item);
00477 
00479   void setItemText(FXFoldingItem* item,const FXString& text);
00480 
00482   FXString getItemText(const FXFoldingItem* item) const;
00483 
00485   void setItemOpenIcon(FXFoldingItem* item,FXIcon* icon,FXbool owned=FALSE);
00486 
00488   FXIcon* getItemOpenIcon(const FXFoldingItem* item) const;
00489 
00491   void setItemClosedIcon(FXFoldingItem* item,FXIcon* icon,FXbool owned=FALSE);
00492 
00494   FXIcon* getItemClosedIcon(const FXFoldingItem* item) const;
00495 
00497   void setItemData(FXFoldingItem* item,void* ptr) const;
00498 
00500   void* getItemData(const FXFoldingItem* item) const;
00501 
00503   FXbool isItemSelected(const FXFoldingItem* item) const;
00504 
00506   FXbool isItemCurrent(const FXFoldingItem* item) const;
00507 
00509   FXbool isItemVisible(const FXFoldingItem* item) const;
00510 
00512   FXbool isItemOpened(const FXFoldingItem* item) const;
00513 
00515   FXbool isItemExpanded(const FXFoldingItem* item) const;
00516 
00518   FXbool isItemLeaf(const FXFoldingItem* item) const;
00519 
00521   FXbool isItemEnabled(const FXFoldingItem* item) const;
00522 
00524   FXint hitItem(const FXFoldingItem* item,FXint x,FXint y) const;
00525 
00527   void updateItem(FXFoldingItem* item);
00528 
00530   virtual FXbool enableItem(FXFoldingItem* item);
00531 
00533   virtual FXbool disableItem(FXFoldingItem* item);
00534 
00536   virtual FXbool selectItem(FXFoldingItem* item,FXbool notify=FALSE);
00537 
00539   virtual FXbool deselectItem(FXFoldingItem* item,FXbool notify=FALSE);
00540 
00542   virtual FXbool toggleItem(FXFoldingItem* item,FXbool notify=FALSE);
00543 
00545   virtual FXbool extendSelection(FXFoldingItem* item,FXbool notify=FALSE);
00546 
00548   virtual FXbool killSelection(FXbool notify=FALSE);
00549 
00551   virtual FXbool openItem(FXFoldingItem* item,FXbool notify=FALSE);
00552 
00554   virtual FXbool closeItem(FXFoldingItem* item,FXbool notify=FALSE);
00555 
00557   virtual FXbool collapseTree(FXFoldingItem* tree,FXbool notify=FALSE);
00558 
00560   virtual FXbool expandTree(FXFoldingItem* tree,FXbool notify=FALSE);
00561 
00563   virtual void setCurrentItem(FXFoldingItem* item,FXbool notify=FALSE);
00564 
00566   FXFoldingItem* getCurrentItem() const { return currentitem; }
00567 
00569   void setAnchorItem(FXFoldingItem* item);
00570 
00572   FXFoldingItem* getAnchorItem() const { return anchoritem; }
00573 
00575   FXFoldingItem* getCursorItem() const { return cursoritem; }
00576 
00578   void sortItems();
00579 
00581   void sortRootItems();
00582 
00584   void sortChildItems(FXFoldingItem* item);
00585 
00587   FXFoldingListSortFunc getSortFunc() const { return sortfunc; }
00588 
00590   void setSortFunc(FXFoldingListSortFunc func){ sortfunc=func; }
00591 
00593   void setFont(FXFont* fnt);
00594 
00596   FXFont* getFont() const { return font; }
00597 
00599   void setIndent(FXint in);
00600 
00602   FXint getIndent() const { return indent; }
00603 
00605   FXColor getTextColor() const { return textColor; }
00606 
00608   void setTextColor(FXColor clr);
00609 
00611   FXColor getSelBackColor() const { return selbackColor; }
00612 
00614   void setSelBackColor(FXColor clr);
00615 
00617   FXColor getSelTextColor() const { return seltextColor; }
00618 
00620   void setSelTextColor(FXColor clr);
00621 
00623   FXColor getLineColor() const { return lineColor; }
00624 
00626   void setLineColor(FXColor clr);
00627 
00629   FXuint getListStyle() const;
00630 
00632   void setListStyle(FXuint style);
00633 
00635   void setHelpText(const FXString& text);
00636 
00638   const FXString& getHelpText() const { return help; }
00639 
00641   virtual void save(FXStream& store) const;
00642 
00644   virtual void load(FXStream& store);
00645 
00647   virtual ~FXFoldingList();
00648   };
00649 
00650 }
00651 
00652 
00653 #endif

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