![]() |
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,2004 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.75 2004/02/08 17:17:34 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 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 *parent; 00061 FXTreeItem *prev; 00062 FXTreeItem *next; 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():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 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 00089 /// Constructor 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 00092 /// Get parent item 00093 FXTreeItem* getParent() const { return parent; } 00094 00095 /// Get next sibling item 00096 FXTreeItem* getNext() const { return next; } 00097 00098 /// Get previous sibling item 00099 FXTreeItem* getPrev() const { return prev; } 00100 00101 /// Get first child item 00102 FXTreeItem* getFirst() const { return first; } 00103 00104 /// Get las child item 00105 FXTreeItem* getLast() const { return last; } 00106 00107 /// Get item below this one in list 00108 FXTreeItem* getBelow() const; 00109 00110 /// Get item above this one in list 00111 FXTreeItem* getAbove() const; 00112 00113 /// Get number of children of item 00114 FXint getNumChildren() const; 00115 00116 /// Change item label 00117 virtual void setText(const FXString& txt){ label=txt; } 00118 00119 /// Get item label 00120 const FXString& getText() const { return label; } 00121 00122 /// Change open icon 00123 virtual void setOpenIcon(FXIcon* icn){ openIcon=icn; } 00124 00125 /// Get open icon 00126 FXIcon* getOpenIcon() const { return openIcon; } 00127 00128 /// Change closed icon 00129 virtual void setClosedIcon(FXIcon* icn){ closedIcon=icn; } 00130 00131 /// Get closed icon 00132 FXIcon* getClosedIcon() const { return closedIcon; } 00133 00134 /// Change item user data 00135 void setData(void* ptr){ data=ptr; } 00136 00137 /// Get item user data 00138 void* getData() const { return data; } 00139 00140 /// Make item draw as focused 00141 virtual void setFocus(FXbool focus); 00142 00143 /// Return true if item has focus 00144 FXbool hasFocus() const { return (state&FOCUS)!=0; } 00145 00146 /// Select item 00147 virtual void setSelected(FXbool selected); 00148 00149 /// Return true if this item is selected 00150 FXbool isSelected() const { return (state&SELECTED)!=0; } 00151 00152 /// Make item show as open 00153 virtual void setOpened(FXbool opened); 00154 00155 /// Return true if this item is open 00156 FXbool isOpened() const { return (state&OPENED)!=0; } 00157 00158 /// Expand or collapse item 00159 virtual void setExpanded(FXbool expanded); 00160 00161 /// Return true if this item is expanded into sub items 00162 FXbool isExpanded() const { return (state&EXPANDED)!=0; } 00163 00164 /// Enable or disable item 00165 virtual void setEnabled(FXbool enabled); 00166 00167 /// Return true if this item is enabled 00168 FXbool isEnabled() const { return (state&DISABLED)==0; } 00169 00170 /// Make item draggable 00171 virtual void setDraggable(FXbool draggable); 00172 00173 /// Return true if this item is draggable 00174 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; } 00175 00176 /// Make open and or icon owned by the item 00177 void setIconOwned(FXuint owned=(OPENICONOWNED|CLOSEDICONOWNED)); 00178 00179 /// Return open icon and closed icon ownership status 00180 FXuint isIconOwned() const { return (state&(OPENICONOWNED|CLOSEDICONOWNED)); } 00181 00182 /// Return true if descendent of parent item 00183 FXbool isChildOf(const FXTreeItem* item) const; 00184 00185 /// Return true if ancestor of child item 00186 FXbool isParentOf(const FXTreeItem* item) const; 00187 00188 /// Return width of item as drawn in list 00189 virtual FXint getWidth(const FXTreeList* list) const; 00190 00191 /// Return height of item as drawn in list 00192 virtual FXint getHeight(const FXTreeList* list) const; 00193 00194 /// Create server-side resources 00195 virtual void create(); 00196 00197 /// Detach server-side resources 00198 virtual void detach(); 00199 00200 /// Destroy server-side resources 00201 virtual void destroy(); 00202 00203 /// Save to stream 00204 virtual void save(FXStream& store) const; 00205 00206 /// Load from stream 00207 virtual void load(FXStream& store); 00208 00209 /// Destroy item and free icons if owned 00210 virtual ~FXTreeItem(); 00211 }; 00212 00213 00214 00215 /// Tree item collate function 00216 typedef FXint (*FXTreeListSortFunc)(const FXTreeItem*,const FXTreeItem*); 00217 00218 00219 00220 /// Tree list Widget 00221 class FXAPI FXTreeList : public FXScrollArea { 00222 FXDECLARE(FXTreeList) 00223 protected: 00224 FXTreeItem *firstitem; // First root item 00225 FXTreeItem *lastitem; // Last root item 00226 FXTreeItem *anchoritem; // Selection anchor item 00227 FXTreeItem *currentitem; // Current item 00228 FXTreeItem *extentitem; // Selection extent 00229 FXTreeItem *cursoritem; // Item under cursor 00230 FXFont *font; // Font 00231 FXTreeListSortFunc sortfunc; // Item sort function 00232 FXColor textColor; // Text color 00233 FXColor selbackColor; // Selected background color 00234 FXColor seltextColor; // Selected text color 00235 FXColor lineColor; // Line color 00236 FXint treeWidth; // Tree width 00237 FXint treeHeight; // Tree height 00238 FXint visible; // Number of visible items 00239 FXint indent; // Parent to child indentation 00240 FXint grabx; // Grab point x 00241 FXint graby; // Grab point y 00242 FXString lookup; // Lookup string 00243 FXString help; // Help string 00244 FXbool state; // State of item 00245 protected: 00246 FXTreeList(); 00247 virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr); 00248 void sort(FXTreeItem*& f1,FXTreeItem*& t1,FXTreeItem*& f2,FXTreeItem*& t2,int n); 00249 void recompute(); 00250 private: 00251 FXTreeList(const FXTreeList&); 00252 FXTreeList& operator=(const FXTreeList&); 00253 public: 00254 long onPaint(FXObject*,FXSelector,void*); 00255 long onEnter(FXObject*,FXSelector,void*); 00256 long onLeave(FXObject*,FXSelector,void*); 00257 long onUngrabbed(FXObject*,FXSelector,void*); 00258 long onMotion(FXObject*,FXSelector,void*); 00259 long onKeyPress(FXObject*,FXSelector,void*); 00260 long onKeyRelease(FXObject*,FXSelector,void*); 00261 long onLeftBtnPress(FXObject*,FXSelector,void*); 00262 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00263 long onRightBtnPress(FXObject*,FXSelector,void*); 00264 long onRightBtnRelease(FXObject*,FXSelector,void*); 00265 long onQueryTip(FXObject*,FXSelector,void*); 00266 long onQueryHelp(FXObject*,FXSelector,void*); 00267 long onTipTimer(FXObject*,FXSelector,void*); 00268 long onFocusIn(FXObject*,FXSelector,void*); 00269 long onFocusOut(FXObject*,FXSelector,void*); 00270 long onAutoScroll(FXObject*,FXSelector,void*); 00271 long onClicked(FXObject*,FXSelector,void*); 00272 long onDoubleClicked(FXObject*,FXSelector,void*); 00273 long onTripleClicked(FXObject*,FXSelector,void*); 00274 long onCommand(FXObject*,FXSelector,void*); 00275 long onLookupTimer(FXObject*,FXSelector,void*); 00276 public: 00277 static FXint ascending(const FXTreeItem*,const FXTreeItem*); 00278 static FXint descending(const FXTreeItem*,const FXTreeItem*); 00279 static FXint ascendingCase(const FXTreeItem*,const FXTreeItem*); 00280 static FXint descendingCase(const FXTreeItem*,const FXTreeItem*); 00281 public: 00282 enum { 00283 ID_LOOKUPTIMER=FXScrollArea::ID_LAST, 00284 ID_LAST 00285 }; 00286 public: 00287 00288 /// Construct a tree list with nvis visible items; the tree list is initially empty 00289 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); 00290 00291 /// Create server-side resources 00292 virtual void create(); 00293 00294 /// Detach server-side resources 00295 virtual void detach(); 00296 00297 /// Perform layout 00298 virtual void layout(); 00299 00300 /// Return default width 00301 virtual FXint getDefaultWidth(); 00302 00303 /// Return default height 00304 virtual FXint getDefaultHeight(); 00305 00306 /// Compute and return content width 00307 virtual FXint getContentWidth(); 00308 00309 /// Return content height 00310 virtual FXint getContentHeight(); 00311 00312 /// Recalculate layout 00313 virtual void recalc(); 00314 00315 /// Tree list can receive focus 00316 virtual FXbool canFocus() const; 00317 00318 /// Move the focus to this window 00319 virtual void setFocus(); 00320 00321 /// Remove the focus from this window 00322 virtual void killFocus(); 00323 00324 /// Return number of items 00325 FXint getNumItems() const; 00326 00327 /// Return number of visible items 00328 FXint getNumVisible() const { return visible; } 00329 00330 /// Change number of visible items 00331 void setNumVisible(FXint nvis); 00332 00333 /// Return first root item 00334 FXTreeItem* getFirstItem() const { return firstitem; } 00335 00336 /// Return last root item 00337 FXTreeItem* getLastItem() const { return lastitem; } 00338 00339 /// Prepend new [possibly subclassed] item as first child of p 00340 FXTreeItem* addItemFirst(FXTreeItem* p,FXTreeItem* item,FXbool notify=FALSE); 00341 00342 /// Prepend new item with given text and optional icon, and user-data pointer as first child of p 00343 FXTreeItem* addItemFirst(FXTreeItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00344 00345 /// Append new [possibly subclassed] item as last child of p 00346 FXTreeItem* addItemLast(FXTreeItem* p,FXTreeItem* item,FXbool notify=FALSE); 00347 00348 /// Append new item with given text and optional icon, and user-data pointer as last child of p 00349 FXTreeItem* addItemLast(FXTreeItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00350 00351 /// Append new [possibly subclassed] item after to other item 00352 FXTreeItem* addItemAfter(FXTreeItem* other,FXTreeItem* item,FXbool notify=FALSE); 00353 00354 /// Append new item with given text and optional icon, and user-data pointer after to other item 00355 FXTreeItem* addItemAfter(FXTreeItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00356 00357 /// Prepend new [possibly subclassed] item prior to other item 00358 FXTreeItem* addItemBefore(FXTreeItem* other,FXTreeItem* item,FXbool notify=FALSE); 00359 00360 /// Prepend new item with given text and optional icon, and user-data pointer prior to other item 00361 FXTreeItem* addItemBefore(FXTreeItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00362 00363 /// Reparent item under parent p 00364 void reparentItem(FXTreeItem* item,FXTreeItem* p); 00365 00366 // Move item before other 00367 FXTreeItem* moveItemBefore(FXTreeItem* other,FXTreeItem* item); 00368 00369 // Move item after other 00370 FXTreeItem* moveItemAfter(FXTreeItem* other,FXTreeItem* item); 00371 00372 /// Remove item 00373 void removeItem(FXTreeItem* item,FXbool notify=FALSE); 00374 00375 /// Remove items in range [fm, to] inclusively 00376 void removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify=FALSE); 00377 00378 /// Remove all items from list 00379 void clearItems(FXbool notify=FALSE); 00380 00381 /// Return item width 00382 FXint getItemWidth(const FXTreeItem* item) const { return item->getWidth(this); } 00383 00384 /// Return item height 00385 FXint getItemHeight(const FXTreeItem* item) const { return item->getHeight(this); } 00386 00387 /// Get item at x,y, if any 00388 FXTreeItem* getItemAt(FXint x,FXint y) const; 00389 00390 /** 00391 * Search items for item by name, starting from start item; the 00392 * flags argument controls the search direction, and case sensitivity. 00393 */ 00394 FXTreeItem* findItem(const FXString& text,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 00395 00396 /// Scroll to make item visible 00397 void makeItemVisible(FXTreeItem* item); 00398 00399 /// Change item's text 00400 void setItemText(FXTreeItem* item,const FXString& text); 00401 00402 /// Return item's text 00403 FXString getItemText(const FXTreeItem* item) const; 00404 00405 /// Change item's open icon 00406 void setItemOpenIcon(FXTreeItem* item,FXIcon* icon); 00407 00408 /// Return item's open icon 00409 FXIcon* getItemOpenIcon(const FXTreeItem* item) const; 00410 00411 /// Chance item's closed icon 00412 void setItemClosedIcon(FXTreeItem* item,FXIcon* icon); 00413 00414 /// Return item's closed icon 00415 FXIcon* getItemClosedIcon(const FXTreeItem* item) const; 00416 00417 /// Change item user-data pointer 00418 void setItemData(FXTreeItem* item,void* ptr) const; 00419 00420 /// Return item user-data pointer 00421 void* getItemData(const FXTreeItem* item) const; 00422 00423 /// Return TRUE if item is selected 00424 FXbool isItemSelected(const FXTreeItem* item) const; 00425 00426 /// Return TRUE if item is current 00427 FXbool isItemCurrent(const FXTreeItem* item) const; 00428 00429 /// Return TRUE if item is visible 00430 FXbool isItemVisible(const FXTreeItem* item) const; 00431 00432 /// Return TRUE if item opened 00433 FXbool isItemOpened(const FXTreeItem* item) const; 00434 00435 /// Return TRUE if item expanded 00436 FXbool isItemExpanded(const FXTreeItem* item) const; 00437 00438 /// Return TRUE if item is a leaf-item, i.e. has no children 00439 FXbool isItemLeaf(const FXTreeItem* item) const; 00440 00441 /// Return TRUE if item is enabled 00442 FXbool isItemEnabled(const FXTreeItem* item) const; 00443 00444 /// Return item hit code: 0 outside, 1 icon, 2 text, 3 box 00445 FXint hitItem(const FXTreeItem* item,FXint x,FXint y) const; 00446 00447 /// Repaint item 00448 void updateItem(FXTreeItem* item) const; 00449 00450 /// Enable item 00451 FXbool enableItem(FXTreeItem* item); 00452 00453 /// Disable item 00454 FXbool disableItem(FXTreeItem* item); 00455 00456 /// Select item 00457 virtual FXbool selectItem(FXTreeItem* item,FXbool notify=FALSE); 00458 00459 /// Deselect item 00460 virtual FXbool deselectItem(FXTreeItem* item,FXbool notify=FALSE); 00461 00462 /// Toggle item selection 00463 virtual FXbool toggleItem(FXTreeItem* item,FXbool notify=FALSE); 00464 00465 /// Extend selection from anchor item to item 00466 virtual FXbool extendSelection(FXTreeItem* item,FXbool notify=FALSE); 00467 00468 /// Deselect all items 00469 virtual FXbool killSelection(FXbool notify=FALSE); 00470 00471 /// Open item 00472 virtual FXbool openItem(FXTreeItem* item,FXbool notify=FALSE); 00473 00474 /// Close item 00475 virtual FXbool closeItem(FXTreeItem* item,FXbool notify=FALSE); 00476 00477 /// Collapse tree 00478 virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=FALSE); 00479 00480 /// Expand tree 00481 virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=FALSE); 00482 00483 /// Change current item 00484 virtual void setCurrentItem(FXTreeItem* item,FXbool notify=FALSE); 00485 00486 /// Return current item, if any 00487 FXTreeItem* getCurrentItem() const { return currentitem; } 00488 00489 /// Change anchor item 00490 void setAnchorItem(FXTreeItem* item); 00491 00492 /// Return anchor item, if any 00493 FXTreeItem* getAnchorItem() const { return anchoritem; } 00494 00495 /// Return item under cursor, if any 00496 FXTreeItem* getCursorItem() const { return cursoritem; } 00497 00498 /// Sort all items recursively 00499 void sortItems(); 00500 00501 /// Sort root items 00502 void sortRootItems(); 00503 00504 /// Sort children of item 00505 void sortChildItems(FXTreeItem* item); 00506 00507 /// Change text font 00508 void setFont(FXFont* fnt); 00509 00510 /// Return text font 00511 FXFont* getFont() const { return font; } 00512 00513 /// Change parent-child indent amount 00514 void setIndent(FXint in); 00515 00516 /// Return parent-child indent amount 00517 FXint getIndent() const { return indent; } 00518 00519 /// Return normal text color 00520 FXColor getTextColor() const { return textColor; } 00521 00522 /// Change normal text color 00523 void setTextColor(FXColor clr); 00524 00525 /// Return selected text background 00526 FXColor getSelBackColor() const { return selbackColor; } 00527 00528 /// Change selected text background 00529 void setSelBackColor(FXColor clr); 00530 00531 /// Return selected text color 00532 FXColor getSelTextColor() const { return seltextColor; } 00533 00534 /// Change selected text color 00535 void setSelTextColor(FXColor clr); 00536 00537 /// Return line color 00538 FXColor getLineColor() const { return lineColor; } 00539 00540 /// Change line color 00541 void setLineColor(FXColor clr); 00542 00543 /// Return sort function 00544 FXTreeListSortFunc getSortFunc() const { return sortfunc; } 00545 00546 /// Change sort function 00547 void setSortFunc(FXTreeListSortFunc func){ sortfunc=func; } 00548 00549 /// Return list style 00550 FXuint getListStyle() const; 00551 00552 /// Change list style 00553 void setListStyle(FXuint style); 00554 00555 /// Set the status line help text for this list 00556 void setHelpText(const FXString& text); 00557 00558 /// Get the status line help text for this list 00559 FXString getHelpText() const { return help; } 00560 00561 /// Save object to a stream 00562 virtual void save(FXStream& store) const; 00563 00564 /// Load object from a stream 00565 virtual void load(FXStream& store); 00566 00567 /// Destructor 00568 virtual ~FXTreeList(); 00569 }; 00570 00571 } 00572 00573 #endif
![]() |