![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * T r e e L i s t W i d g e t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2002 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.50 2002/01/18 22:42:55 jeroen Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXTREELIST_H 00025 #define FXTREELIST_H 00026 00027 #ifndef FXSCROLLAREA_H 00028 #include "FXScrollArea.h" 00029 #endif 00030 00031 00032 00033 struct FXTimer; 00034 class FXIcon; 00035 class FXFont; 00036 class FXTreeList; 00037 class FXDirList; 00038 00039 00040 /// Tree list styles 00041 enum { 00042 TREELIST_EXTENDEDSELECT = 0, /// Extended selection mode allows for drag-selection of ranges of items 00043 TREELIST_SINGLESELECT = 0x00100000, /// Single selection mode allows up to one item to be selected 00044 TREELIST_BROWSESELECT = 0x00200000, /// Browse selection mode enforces one single item to be selected at all times 00045 TREELIST_MULTIPLESELECT = 0x00300000, /// Multiple selection mode is used for selection of individual items 00046 TREELIST_AUTOSELECT = 0x00400000, /// Automatically select under cursor 00047 TREELIST_SHOWS_LINES = 0x00800000, /// Lines shown 00048 TREELIST_SHOWS_BOXES = 0x01000000, /// Boxes to expand shown 00049 TREELIST_ROOT_BOXES = 0x02000000, /// Display root boxes also 00050 TREELIST_NORMAL = TREELIST_EXTENDEDSELECT 00051 }; 00052 00053 00054 /// Tree list Item 00055 class FXAPI FXTreeItem : public FXObject { 00056 FXDECLARE(FXTreeItem) 00057 friend class FXTreeList; 00058 friend class FXDirList; 00059 protected: 00060 FXTreeItem *prev; 00061 FXTreeItem *next; 00062 FXTreeItem *parent; 00063 FXTreeItem *first; 00064 FXTreeItem *last; 00065 FXString label; 00066 FXIcon *openIcon; 00067 FXIcon *closedIcon; 00068 void *data; 00069 FXuint state; 00070 FXint x,y; 00071 protected: 00072 FXTreeItem():prev(NULL),next(NULL),parent(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 protected: 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 FXTreeItem(const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL):prev(NULL),next(NULL),parent(NULL),first(NULL),last(NULL),label(text),openIcon(oi),closedIcon(ci),data(ptr),state(0),x(0),y(0){} 00089 FXTreeItem* getParent() const { return parent; } 00090 FXTreeItem* getNext() const { return next; } 00091 FXTreeItem* getPrev() const { return prev; } 00092 FXTreeItem* getFirst() const { return first; } 00093 FXTreeItem* getLast() const { return last; } 00094 FXTreeItem* getBelow() const; 00095 FXTreeItem* getAbove() const; 00096 FXint getNumChildren() const; 00097 virtual void setText(const FXString& txt){ label=txt; } 00098 FXString getText() const { return label; } 00099 virtual void setOpenIcon(FXIcon* icn){ openIcon=icn; } 00100 FXIcon* getOpenIcon() const { return openIcon; } 00101 virtual void setClosedIcon(FXIcon* icn){ closedIcon=icn; } 00102 FXIcon* getClosedIcon() const { return closedIcon; } 00103 void setData(void* ptr){ data=ptr; } 00104 void* getData() const { return data; } 00105 virtual void setFocus(FXbool focus); 00106 FXbool hasFocus() const { return (state&FOCUS)!=0; } 00107 virtual void setSelected(FXbool selected); 00108 FXbool isSelected() const { return (state&SELECTED)!=0; } 00109 virtual void setOpened(FXbool opened); 00110 FXbool isOpened() const { return (state&OPENED)!=0; } 00111 virtual void setExpanded(FXbool expanded); 00112 FXbool isExpanded() const { return (state&EXPANDED)!=0; } 00113 virtual void setEnabled(FXbool enabled); 00114 FXbool isEnabled() const { return (state&DISABLED)==0; } 00115 virtual void setDraggable(FXbool draggable); 00116 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; } 00117 virtual void setIconOwned(FXuint owned=(OPENICONOWNED|CLOSEDICONOWNED)); 00118 FXuint isIconOwned() const { return (state&(OPENICONOWNED|CLOSEDICONOWNED)); } 00119 virtual FXint getWidth(const FXTreeList* list) const; 00120 virtual FXint getHeight(const FXTreeList* list) const; 00121 virtual void create(); 00122 virtual void detach(); 00123 virtual void destroy(); 00124 virtual void save(FXStream& store) const; 00125 virtual void load(FXStream& store); 00126 virtual ~FXTreeItem(); 00127 }; 00128 00129 00130 00131 /// Tree item collate function 00132 typedef FXint (*FXTreeListSortFunc)(const FXTreeItem*,const FXTreeItem*); 00133 00134 00135 00136 /// Tree list Widget 00137 class FXAPI FXTreeList : public FXScrollArea { 00138 FXDECLARE(FXTreeList) 00139 protected: 00140 FXTreeItem *firstitem; // First root item 00141 FXTreeItem *lastitem; // Last root item 00142 FXTreeItem *anchoritem; // Selection anchor item 00143 FXTreeItem *currentitem; // Current item 00144 FXTreeItem *extentitem; // Selection extent 00145 FXTreeItem *cursoritem; // Item under cursor 00146 FXFont *font; // Font 00147 FXTreeListSortFunc sortfunc; // Item sort function 00148 FXColor textColor; // Text color 00149 FXColor selbackColor; // Selected background color 00150 FXColor seltextColor; // Selected text color 00151 FXColor lineColor; // Line color 00152 FXint treeWidth; // Tree width 00153 FXint treeHeight; // Tree height 00154 FXint visible; // Number of visible items 00155 FXint indent; // Parent to child indentation 00156 FXint grabx; // Grab point x 00157 FXint graby; // Grab point y 00158 FXString lookup; // Lookup string 00159 FXTimer *timer; // Tip timer 00160 FXTimer *lookuptimer; // Lookup timer 00161 FXString help; // Help string 00162 FXbool state; // State of item 00163 protected: 00164 FXTreeList(); 00165 virtual void layout(); 00166 virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr); 00167 void sort(FXTreeItem*& f1,FXTreeItem*& t1,FXTreeItem*& f2,FXTreeItem*& t2,int n); 00168 void recompute(); 00169 private: 00170 FXTreeList(const FXTreeList&); 00171 FXTreeList& operator=(const FXTreeList&); 00172 public: 00173 long onPaint(FXObject*,FXSelector,void*); 00174 long onEnter(FXObject*,FXSelector,void*); 00175 long onLeave(FXObject*,FXSelector,void*); 00176 long onUngrabbed(FXObject*,FXSelector,void*); 00177 long onMotion(FXObject*,FXSelector,void*); 00178 long onKeyPress(FXObject*,FXSelector,void*); 00179 long onKeyRelease(FXObject*,FXSelector,void*); 00180 long onLeftBtnPress(FXObject*,FXSelector,void*); 00181 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00182 long onRightBtnPress(FXObject*,FXSelector,void*); 00183 long onRightBtnRelease(FXObject*,FXSelector,void*); 00184 long onQueryTip(FXObject*,FXSelector,void*); 00185 long onQueryHelp(FXObject*,FXSelector,void*); 00186 long onTipTimer(FXObject*,FXSelector,void*); 00187 long onFocusIn(FXObject*,FXSelector,void*); 00188 long onFocusOut(FXObject*,FXSelector,void*); 00189 long onAutoScroll(FXObject*,FXSelector,void*); 00190 long onClicked(FXObject*,FXSelector,void*); 00191 long onDoubleClicked(FXObject*,FXSelector,void*); 00192 long onTripleClicked(FXObject*,FXSelector,void*); 00193 long onCommand(FXObject*,FXSelector,void*); 00194 long onSelected(FXObject*,FXSelector,void*); 00195 long onDeselected(FXObject*,FXSelector,void*); 00196 long onOpened(FXObject*,FXSelector,void*); 00197 long onClosed(FXObject*,FXSelector,void*); 00198 long onExpanded(FXObject*,FXSelector,void*); 00199 long onCollapsed(FXObject*,FXSelector,void*); 00200 long onLookupTimer(FXObject*,FXSelector,void*); 00201 public: 00202 static FXint ascending(const FXTreeItem* a,const FXTreeItem* b); 00203 static FXint descending(const FXTreeItem* a,const FXTreeItem* b); 00204 public: 00205 enum { 00206 ID_TIPTIMER=FXScrollArea::ID_LAST, 00207 ID_LOOKUPTIMER, 00208 ID_LAST 00209 }; 00210 public: 00211 00212 /// Construct a tree list with nvis visible items; the tree list is initially empty 00213 FXTreeList(FXComposite *p,FXint nvis,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=TREELIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0); 00214 00215 /// Create server-side resources 00216 virtual void create(); 00217 00218 /// Detach server-side resources 00219 virtual void detach(); 00220 00221 /// Return default width 00222 virtual FXint getDefaultWidth(); 00223 00224 /// Return default height 00225 virtual FXint getDefaultHeight(); 00226 00227 /// Compute and return content width 00228 virtual FXint getContentWidth(); 00229 00230 /// Return content height 00231 virtual FXint getContentHeight(); 00232 00233 /// Recalculate layout 00234 virtual void recalc(); 00235 00236 /// Tree list can receive focus 00237 virtual FXbool canFocus() const; 00238 00239 /// Move the focus to this window 00240 virtual void setFocus(); 00241 00242 /// Remove the focus from this window 00243 virtual void killFocus(); 00244 00245 /// Return number of items 00246 FXint getNumItems() const; 00247 00248 /// Return number of visible items 00249 FXint getNumVisible() const { return visible; } 00250 00251 /// Change number of visible items 00252 void setNumVisible(FXint nvis); 00253 00254 /// REturn first root item 00255 FXTreeItem* getFirstItem() const { return firstitem; } 00256 00257 /// Return last root item 00258 FXTreeItem* getLastItem() const { return lastitem; } 00259 00260 /// Prepend new [possibly subclassed] item as first child of p 00261 FXTreeItem* addItemFirst(FXTreeItem* p,FXTreeItem* item,FXbool notify=FALSE); 00262 00263 /// Prepend new item with given text and optional icon, and user-data pointer as first child of p 00264 FXTreeItem* addItemFirst(FXTreeItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00265 00266 /// Append new [possibly subclassed] item as last child of p 00267 FXTreeItem* addItemLast(FXTreeItem* p,FXTreeItem* item,FXbool notify=FALSE); 00268 00269 /// Append new item with given text and optional icon, and user-data pointer as last child of p 00270 FXTreeItem* addItemLast(FXTreeItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00271 00272 /// Append new [possibly subclassed] item after to other item 00273 FXTreeItem* addItemAfter(FXTreeItem* other,FXTreeItem* item,FXbool notify=FALSE); 00274 00275 /// Append new item with given text and optional icon, and user-data pointer after to other item 00276 FXTreeItem* addItemAfter(FXTreeItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00277 00278 /// Prepend new [possibly subclassed] item prior to other item 00279 FXTreeItem* addItemBefore(FXTreeItem* other,FXTreeItem* item,FXbool notify=FALSE); 00280 00281 /// Prepend new item with given text and optional icon, and user-data pointer prior to other item 00282 FXTreeItem* addItemBefore(FXTreeItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00283 00284 /// Remove item 00285 void removeItem(FXTreeItem* item,FXbool notify=FALSE); 00286 00287 /// Remove items in range [fm, to] inclusively 00288 void removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify=FALSE); 00289 00290 /// Remove all items from list 00291 void clearItems(FXbool notify=FALSE); 00292 00293 /// Return item width 00294 FXint getItemWidth(const FXTreeItem* item) const; 00295 00296 /// Return item height 00297 FXint getItemHeight(const FXTreeItem* item) const; 00298 00299 /// Get item at x,y, if any 00300 virtual FXTreeItem* getItemAt(FXint x,FXint y) const; 00301 00302 /** 00303 * Search items for item by name, starting from start item; the 00304 * flags argument controls the search direction, and case sensitivity. 00305 */ 00306 FXTreeItem* findItem(const FXString& text,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 00307 00308 /// Scroll to make item visible 00309 void makeItemVisible(FXTreeItem* item); 00310 00311 /// Change item's text 00312 void setItemText(FXTreeItem* item,const FXString& text); 00313 00314 /// Return item's text 00315 FXString getItemText(const FXTreeItem* item) const; 00316 00317 /// Change item's open icon 00318 void setItemOpenIcon(FXTreeItem* item,FXIcon* icon); 00319 00320 /// Return item's open icon 00321 FXIcon* getItemOpenIcon(const FXTreeItem* item) const; 00322 00323 /// Chance item's closed icon 00324 void setItemClosedIcon(FXTreeItem* item,FXIcon* icon); 00325 00326 /// Return item's closed icon 00327 FXIcon* getItemClosedIcon(const FXTreeItem* item) const; 00328 00329 /// Change item user-data pointer 00330 void setItemData(FXTreeItem* item,void* ptr) const; 00331 00332 /// Return item user-data pointer 00333 void* getItemData(const FXTreeItem* item) const; 00334 00335 /// Return TRUE if item is selected 00336 FXbool isItemSelected(const FXTreeItem* item) const; 00337 00338 /// Return TRUE if item is current 00339 FXbool isItemCurrent(const FXTreeItem* item) const; 00340 00341 /// Return TRUE if item is visible 00342 FXbool isItemVisible(const FXTreeItem* item) const; 00343 00344 /// Return TRUE if item opened 00345 FXbool isItemOpened(const FXTreeItem* item) const; 00346 00347 /// Return TRUE if item expanded 00348 FXbool isItemExpanded(const FXTreeItem* item) const; 00349 00350 /// Return TRUE if item is a leaf-item, i.e. has no children 00351 FXbool isItemLeaf(const FXTreeItem* item) const; 00352 00353 /// Return TRUE if item is enabled 00354 FXbool isItemEnabled(const FXTreeItem* item) const; 00355 00356 /// Return item hit code: 0 outside, 1 icon, 2 text, 3 box 00357 FXint hitItem(const FXTreeItem* item,FXint x,FXint y) const; 00358 00359 /// Repaint item 00360 void updateItem(FXTreeItem* item); 00361 00362 /// Enable item 00363 FXbool enableItem(FXTreeItem* item); 00364 00365 /// Disable item 00366 FXbool disableItem(FXTreeItem* item); 00367 00368 /// Select item 00369 FXbool selectItem(FXTreeItem* item,FXbool notify=FALSE); 00370 00371 /// Deselect item 00372 FXbool deselectItem(FXTreeItem* item,FXbool notify=FALSE); 00373 00374 /// Toggle item selection 00375 FXbool toggleItem(FXTreeItem* item,FXbool notify=FALSE); 00376 00377 /// Open item 00378 FXbool openItem(FXTreeItem* item,FXbool notify=FALSE); 00379 00380 /// Close item 00381 FXbool closeItem(FXTreeItem* item,FXbool notify=FALSE); 00382 00383 /// Collapse tree 00384 FXbool collapseTree(FXTreeItem* tree,FXbool notify=FALSE); 00385 00386 /// Expand tree 00387 FXbool expandTree(FXTreeItem* tree,FXbool notify=FALSE); 00388 00389 /// Reparent item under parent p 00390 void reparentItem(FXTreeItem* item,FXTreeItem* p); 00391 00392 /// Change current item 00393 void setCurrentItem(FXTreeItem* item,FXbool notify=FALSE); 00394 00395 /// Return current item, if any 00396 FXTreeItem* getCurrentItem() const { return currentitem; } 00397 00398 /// Change anchor item 00399 void setAnchorItem(FXTreeItem* item); 00400 00401 /// Return anchor item, if any 00402 FXTreeItem* getAnchorItem() const { return anchoritem; } 00403 00404 /// Return item under cursor, if any 00405 FXTreeItem* getCursorItem() const { return cursoritem; } 00406 00407 /// Extend selection from anchor item to item 00408 FXbool extendSelection(FXTreeItem* item,FXbool notify=FALSE); 00409 00410 /// Deselect all items 00411 FXbool killSelection(FXbool notify=FALSE); 00412 00413 /// Sort root items 00414 void sortItems(); 00415 00416 /// Sort children of item 00417 void sortChildItems(FXTreeItem* item); 00418 00419 /// Change text font 00420 void setFont(FXFont* fnt); 00421 00422 /// Return text font 00423 FXFont* getFont() const { return font; } 00424 00425 /// Change parent-child indent amount 00426 void setIndent(FXint in); 00427 00428 /// Return parent-child indent amount 00429 FXint getIndent() const { return indent; } 00430 00431 /// Return normal text color 00432 FXColor getTextColor() const { return textColor; } 00433 00434 /// Change normal text color 00435 void setTextColor(FXColor clr); 00436 00437 /// Return selected text background 00438 FXColor getSelBackColor() const { return selbackColor; } 00439 00440 /// Change selected text background 00441 void setSelBackColor(FXColor clr); 00442 00443 /// Return selected text color 00444 FXColor getSelTextColor() const { return seltextColor; } 00445 00446 /// Change selected text color 00447 void setSelTextColor(FXColor clr); 00448 00449 /// Return line color 00450 FXColor getLineColor() const { return lineColor; } 00451 00452 /// Change line color 00453 void setLineColor(FXColor clr); 00454 00455 /// Return sort function 00456 FXTreeListSortFunc getSortFunc() const { return sortfunc; } 00457 00458 /// Change sort function 00459 void setSortFunc(FXTreeListSortFunc func){ sortfunc=func; } 00460 00461 /// Return list style 00462 FXuint getListStyle() const; 00463 00464 /// Change list style 00465 void setListStyle(FXuint style); 00466 00467 /// Set the status line help text for this list 00468 void setHelpText(const FXString& text); 00469 00470 /// Get the status line help text for this list 00471 FXString getHelpText() const { return help; } 00472 00473 /// Save object to a stream 00474 virtual void save(FXStream& store) const; 00475 00476 /// Load object from a stream 00477 virtual void load(FXStream& store); 00478 00479 /// Destructor 00480 virtual ~FXTreeList(); 00481 }; 00482 00483 00484 #endif