![]() |
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 #ifndef FXCHECKTREELIST_H 00023 #define FXCHECKTREELIST_H 00024 00025 #ifndef FXSCROLLAREA_H 00026 #include <fox/FXScrollArea.h> 00027 using namespace FX; 00028 #endif 00029 namespace FXEX { 00030 00031 /// CheckTreeList styles 00032 enum { 00033 CHECKTREELIST_EXTENDEDSELECT= 0, /// Extended selection mode allows for drag-selection of ranges of items 00034 CHECKTREELIST_SINGLESELECT = 0x00100000, /// Single selection mode allows up to one item to be selected 00035 CHECKTREELIST_BROWSESELECT = 0x00200000, /// Browse selection mode enforces one single item to be selected at all times 00036 CHECKTREELIST_MULTIPLESELECT= 0x00300000, /// Multiple selection mode is used for selection of individual items 00037 CHECKTREELIST_AUTOSELECT = 0x00400000, /// Automatically select under cursor 00038 CHECKTREELIST_SHOWS_LINES = 0x00800000, /// Lines shown 00039 CHECKTREELIST_SHOWS_BOXES = 0x01000000, /// Boxes to expand shown 00040 CHECKTREELIST_ROOT_BOXES = 0x02000000, /// Display root boxes also 00041 CHECKTREELIST_NORMAL = CHECKTREELIST_EXTENDEDSELECT 00042 }; 00043 00044 00045 /// Tree list Item 00046 class FXAPI FXCheckTreeItem : public FXObject { 00047 FXDECLARE(FXCheckTreeItem) 00048 friend class FXCheckTreeList; 00049 friend class FXDirList; 00050 00051 protected: 00052 FXCheckTreeItem *prev; 00053 FXCheckTreeItem *next; 00054 FXCheckTreeItem *parent; 00055 FXCheckTreeItem *first; 00056 FXCheckTreeItem *last; 00057 FXString label; 00058 FXIcon *openIcon; 00059 FXIcon *closedIcon; 00060 void *data; 00061 FXuint state; 00062 FXint x,y; 00063 00064 protected: 00065 FXCheckTreeItem():prev(NULL),next(NULL),parent(NULL),first(NULL),last(NULL),openIcon(NULL),closedIcon(NULL),data(NULL),state(0),x(0),y(0){} 00066 virtual void draw(const FXCheckTreeList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 00067 void drawFocus(const FXCheckTreeList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 00068 virtual FXint hitItem(const FXCheckTreeList* list,FXint x,FXint y) const; 00069 00070 protected: 00071 enum{ 00072 SELECTED = 1, 00073 FOCUS = 2, 00074 DISABLED = 4, 00075 OPENED = 8, 00076 EXPANDED = 16, 00077 HASITEMS = 32, 00078 DRAGGABLE = 64, 00079 OPENICONOWNED = 128, 00080 CLOSEDICONOWNED = 256, 00081 CHECKED = 512 00082 }; 00083 00084 public: 00085 /// Check tree item 00086 FXCheckTreeItem(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){} 00087 00088 /// get parent item 00089 FXCheckTreeItem* getParent() const { return parent; } 00090 00091 /// get next item 00092 FXCheckTreeItem* getNext() const { return next; } 00093 00094 /// get previous item 00095 FXCheckTreeItem* getPrev() const { return prev; } 00096 00097 /// get first item in branch 00098 FXCheckTreeItem* getFirst() const { return first; } 00099 00100 /// get last item in branch 00101 FXCheckTreeItem* getLast() const { return last; } 00102 00103 /// get item below this item 00104 FXCheckTreeItem* getBelow() const; 00105 00106 /// get item above this item 00107 FXCheckTreeItem* getAbove() const; 00108 00109 /// get the number of children that belong to this item 00110 FXint getNumChildren() const; 00111 00112 /// set item text 00113 virtual void setText(const FXString& txt){ label=txt; } 00114 00115 /// get item text 00116 FXString getText() const { return label; } 00117 00118 /// set open icon 00119 virtual void setOpenIcon(FXIcon* icn){ openIcon=icn; } 00120 00121 /// get open icon 00122 FXIcon* getOpenIcon() const { return openIcon; } 00123 00124 /// set closed icon 00125 virtual void setClosedIcon(FXIcon* icn){ closedIcon=icn; } 00126 00127 /// get closed icon 00128 FXIcon* getClosedIcon() const { return closedIcon; } 00129 00130 /// set item specific data 00131 void setData(void* ptr){ data=ptr; } 00132 00133 /// get item specific data 00134 void* getData() const { return data; } 00135 00136 /// set focus on item 00137 virtual void setFocus(FXbool focus); 00138 00139 /// item has focus 00140 FXbool hasFocus() const { return (state&FOCUS)!=0; } 00141 00142 /// make item selected 00143 virtual void setSelected(FXbool selected); 00144 00145 /// is item selected 00146 FXbool isSelected() const { return (state&SELECTED)!=0; } 00147 00148 /// make item checked 00149 virtual void setChecked(FXbool checked); 00150 00151 /// is item checked 00152 FXbool isChecked() const { return (state&CHECKED)!=0; } 00153 00154 /// set item opened 00155 virtual void setOpened(FXbool opened); 00156 00157 /// is item opened 00158 FXbool isOpened() const { return (state&OPENED)!=0; } 00159 00160 /// expand item 00161 virtual void setExpanded(FXbool expanded); 00162 00163 /// is item expaned 00164 FXbool isExpanded() const { return (state&EXPANDED)!=0; } 00165 00166 /// enable item 00167 virtual void setEnabled(FXbool enabled); 00168 00169 /// is item enabled 00170 FXbool isEnabled() const { return (state&DISABLED)==0; } 00171 00172 /// make item draggable 00173 virtual void setDraggable(FXbool draggable); 00174 00175 /// is item draggable 00176 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; } 00177 00178 /// set ownership of icon 00179 virtual void setIconOwned(FXuint owned=(OPENICONOWNED|CLOSEDICONOWNED)); 00180 00181 /// get ownership of icon 00182 FXuint isIconOwned() const { return (state&(OPENICONOWNED|CLOSEDICONOWNED)); } 00183 00184 /// get width 00185 virtual FXint getWidth(const FXCheckTreeList* list) const; 00186 00187 /// get height 00188 virtual FXint getHeight(const FXCheckTreeList* list) const; 00189 00190 /// create resources 00191 virtual void create(); 00192 00193 /// detach resources 00194 virtual void detach(); 00195 00196 /// destroy resources 00197 virtual void destroy(); 00198 00199 /// save to stream 00200 virtual void save(FXStream& store) const; 00201 00202 /// load from stream 00203 virtual void load(FXStream& store); 00204 00205 /// dtor 00206 virtual ~FXCheckTreeItem(); 00207 }; 00208 00209 00210 00211 /// Tree item collate function 00212 typedef FXint (*FXCheckTreeListSortFunc)(const FXCheckTreeItem*,const FXCheckTreeItem*); 00213 00214 00215 00216 /// Tree list Widget 00217 class FXAPI FXCheckTreeList : public FXScrollArea { 00218 FXDECLARE(FXCheckTreeList) 00219 00220 protected: 00221 FXCheckTreeItem *firstitem; // First root item 00222 FXCheckTreeItem *lastitem; // Last root item 00223 FXCheckTreeItem *anchoritem; // Selection anchor item 00224 FXCheckTreeItem *currentitem; // Current item 00225 FXCheckTreeItem *extentitem; // Selection extent 00226 FXCheckTreeItem *cursoritem; // Item under cursor 00227 FXFont *font; // Font 00228 FXCheckTreeListSortFunc sortfunc; // Item sort function 00229 FXColor textColor; // Text color 00230 FXColor selbackColor; // Selected background color 00231 FXColor seltextColor; // Selected text color 00232 FXColor lineColor; // Line color 00233 FXint treeWidth; // Tree width 00234 FXint treeHeight; // Tree height 00235 FXint visible; // Number of visible items 00236 FXint indent; // Parent to child indentation 00237 FXint grabx; // Grab point x 00238 FXint graby; // Grab point y 00239 FXString lookup; // Lookup string 00240 FXString help; // Help string 00241 FXbool state; // State of item 00242 00243 protected: 00244 /// serialisation 00245 FXCheckTreeList(); 00246 00247 /// calculate layout 00248 virtual void layout(); 00249 00250 /// create instance of item 00251 virtual FXCheckTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr); 00252 00253 /// sort items 00254 void sort(FXCheckTreeItem*& f1,FXCheckTreeItem*& t1,FXCheckTreeItem*& f2,FXCheckTreeItem*& t2,int n); 00255 void recompute(); 00256 00257 private: 00258 FXCheckTreeList(const FXCheckTreeList&); 00259 FXCheckTreeList& operator=(const FXCheckTreeList&); 00260 00261 public: 00262 long onPaint(FXObject*,FXSelector,void*); 00263 long onEnter(FXObject*,FXSelector,void*); 00264 long onLeave(FXObject*,FXSelector,void*); 00265 long onUngrabbed(FXObject*,FXSelector,void*); 00266 long onMotion(FXObject*,FXSelector,void*); 00267 long onKeyPress(FXObject*,FXSelector,void*); 00268 long onKeyRelease(FXObject*,FXSelector,void*); 00269 long onLeftBtnPress(FXObject*,FXSelector,void*); 00270 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00271 long onRightBtnPress(FXObject*,FXSelector,void*); 00272 long onRightBtnRelease(FXObject*,FXSelector,void*); 00273 long onQueryTip(FXObject*,FXSelector,void*); 00274 long onQueryHelp(FXObject*,FXSelector,void*); 00275 long onTipTimer(FXObject*,FXSelector,void*); 00276 long onFocusIn(FXObject*,FXSelector,void*); 00277 long onFocusOut(FXObject*,FXSelector,void*); 00278 long onAutoScroll(FXObject*,FXSelector,void*); 00279 long onClicked(FXObject*,FXSelector,void*); 00280 long onDoubleClicked(FXObject*,FXSelector,void*); 00281 long onTripleClicked(FXObject*,FXSelector,void*); 00282 long onCommand(FXObject*,FXSelector,void*); 00283 long onSelected(FXObject*,FXSelector,void*); 00284 long onDeselected(FXObject*,FXSelector,void*); 00285 long onOpened(FXObject*,FXSelector,void*); 00286 long onClosed(FXObject*,FXSelector,void*); 00287 long onExpanded(FXObject*,FXSelector,void*); 00288 long onCollapsed(FXObject*,FXSelector,void*); 00289 long onLookupTimer(FXObject*,FXSelector,void*); 00290 00291 public: 00292 /// sort ascending 00293 static FXint ascending(const FXCheckTreeItem* a,const FXCheckTreeItem* b); 00294 00295 /// sort descending 00296 static FXint descending(const FXCheckTreeItem* a,const FXCheckTreeItem* b); 00297 00298 public: 00299 enum { 00300 ID_TIPTIMER=FXScrollArea::ID_LAST, 00301 ID_LOOKUPTIMER, 00302 ID_LAST 00303 }; 00304 00305 public: 00306 /// Construct a tree list with nvis visible items; the tree list is initially empty 00307 FXCheckTreeList(FXComposite *p,FXint nvis,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=CHECKTREELIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0); 00308 00309 /// Create server-side resources 00310 virtual void create(); 00311 00312 /// Detach server-side resources 00313 virtual void detach(); 00314 00315 /// Return default width 00316 virtual FXint getDefaultWidth(); 00317 00318 /// Return default height 00319 virtual FXint getDefaultHeight(); 00320 00321 /// Compute and return content width 00322 virtual FXint getContentWidth(); 00323 00324 /// Return content height 00325 virtual FXint getContentHeight(); 00326 00327 /// Recalculate layout 00328 virtual void recalc(); 00329 00330 /// Tree list can receive focus 00331 virtual FXbool canFocus() const; 00332 00333 /// Return number of items 00334 FXint getNumItems() const; 00335 00336 /// Return number of visible items 00337 FXint getNumVisible() const { return visible; } 00338 00339 /// Change number of visible items 00340 void setNumVisible(FXint nvis); 00341 00342 /// REturn first root item 00343 FXCheckTreeItem* getFirstItem() const { return firstitem; } 00344 00345 /// Return last root item 00346 FXCheckTreeItem* getLastItem() const { return lastitem; } 00347 00348 /// Prepend new [possibly subclassed] item as first child of p 00349 FXCheckTreeItem* addItemFirst(FXCheckTreeItem* p,FXCheckTreeItem* item,FXbool notify=FALSE); 00350 00351 /// Prepend new item with given text and optional icon, and user-data pointer as first child of p 00352 FXCheckTreeItem* addItemFirst(FXCheckTreeItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00353 00354 /// Append new [possibly subclassed] item as last child of p 00355 FXCheckTreeItem* addItemLast(FXCheckTreeItem* p,FXCheckTreeItem* item,FXbool notify=FALSE); 00356 00357 /// Append new item with given text and optional icon, and user-data pointer as last child of p 00358 FXCheckTreeItem* addItemLast(FXCheckTreeItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00359 00360 /// Append new [possibly subclassed] item after to other item 00361 FXCheckTreeItem* addItemAfter(FXCheckTreeItem* other,FXCheckTreeItem* item,FXbool notify=FALSE); 00362 00363 /// Append new item with given text and optional icon, and user-data pointer after to other item 00364 FXCheckTreeItem* addItemAfter(FXCheckTreeItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00365 00366 /// Prepend new [possibly subclassed] item prior to other item 00367 FXCheckTreeItem* addItemBefore(FXCheckTreeItem* other,FXCheckTreeItem* item,FXbool notify=FALSE); 00368 00369 /// Prepend new item with given text and optional icon, and user-data pointer prior to other item 00370 FXCheckTreeItem* addItemBefore(FXCheckTreeItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00371 00372 /// Remove item 00373 void removeItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00374 00375 /// Remove items in range [fm, to] inclusively 00376 void removeItems(FXCheckTreeItem* fm,FXCheckTreeItem* 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 FXCheckTreeItem* item) const { return item->getWidth(this); } 00383 00384 /// Return item height 00385 FXint getItemHeight(const FXCheckTreeItem* item) const { return item->getHeight(this); } 00386 00387 /// Get item at x,y, if any 00388 virtual FXCheckTreeItem* 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 FXCheckTreeItem* findItem(const FXString& text,FXCheckTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 00395 00396 /// Scroll to make item visible 00397 void makeItemVisible(FXCheckTreeItem* item); 00398 00399 /// Change item's text 00400 void setItemText(FXCheckTreeItem* item,const FXString& text); 00401 00402 /// Return item's text 00403 FXString getItemText(const FXCheckTreeItem* item) const; 00404 00405 /// Change item's open icon 00406 void setItemOpenIcon(FXCheckTreeItem* item,FXIcon* icon); 00407 00408 /// Return item's open icon 00409 FXIcon* getItemOpenIcon(const FXCheckTreeItem* item) const; 00410 00411 /// Chance item's closed icon 00412 void setItemClosedIcon(FXCheckTreeItem* item,FXIcon* icon); 00413 00414 /// Return item's closed icon 00415 FXIcon* getItemClosedIcon(const FXCheckTreeItem* item) const; 00416 00417 /// Change item user-data pointer 00418 void setItemData(FXCheckTreeItem* item,void* ptr) const; 00419 00420 /// Return item user-data pointer 00421 void* getItemData(const FXCheckTreeItem* item) const; 00422 00423 /// Return TRUE if item is selected 00424 FXbool isItemSelected(const FXCheckTreeItem* item) const; 00425 00426 /// Return TRUE if item is checked 00427 FXbool isItemChecked(const FXCheckTreeItem* item) const; 00428 00429 /// Return TRUE if item is current 00430 FXbool isItemCurrent(const FXCheckTreeItem* item) const; 00431 00432 /// Return TRUE if item is visible 00433 FXbool isItemVisible(const FXCheckTreeItem* item) const; 00434 00435 /// Return TRUE if item opened 00436 FXbool isItemOpened(const FXCheckTreeItem* item) const; 00437 00438 /// Return TRUE if item expanded 00439 FXbool isItemExpanded(const FXCheckTreeItem* item) const; 00440 00441 /// Return TRUE if item is a leaf-item, i.e. has no children 00442 FXbool isItemLeaf(const FXCheckTreeItem* item) const; 00443 00444 /// Return TRUE if item is enabled 00445 FXbool isItemEnabled(const FXCheckTreeItem* item) const; 00446 00447 /// Return item hit code: 0 outside, 1 icon, 2 text, 3 box 00448 /// 4 hit the check 00449 FXint hitItem(const FXCheckTreeItem* item,FXint x,FXint y) const; 00450 00451 /// Repaint item 00452 void updateItem(FXCheckTreeItem* item); 00453 00454 /// Enable item 00455 FXbool enableItem(FXCheckTreeItem* item); 00456 00457 /// Disable item 00458 FXbool disableItem(FXCheckTreeItem* item); 00459 00460 /// Select item 00461 FXbool selectItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00462 00463 /// Deselect item 00464 FXbool deselectItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00465 00466 /// Toggle item selection 00467 FXbool toggleItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00468 00469 /// check item 00470 FXbool checkItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00471 00472 /// uncheck item 00473 FXbool uncheckItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00474 00475 /// Toggle item check state 00476 FXbool toggleCheckItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00477 00478 /// Open item 00479 FXbool openItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00480 00481 /// Close item 00482 FXbool closeItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00483 00484 /// Collapse tree 00485 FXbool collapseTree(FXCheckTreeItem* tree,FXbool notify=FALSE); 00486 00487 /// Expand tree 00488 FXbool expandTree(FXCheckTreeItem* tree,FXbool notify=FALSE); 00489 00490 /// Reparent item under parent p 00491 void reparentItem(FXCheckTreeItem* item,FXCheckTreeItem* p); 00492 00493 /// Change current item 00494 void setCurrentItem(FXCheckTreeItem* item,FXbool notify=FALSE); 00495 00496 /// Return current item, if any 00497 FXCheckTreeItem* getCurrentItem() const { return currentitem; } 00498 00499 /// Change anchor item 00500 void setAnchorItem(FXCheckTreeItem* item); 00501 00502 /// Return anchor item, if any 00503 FXCheckTreeItem* getAnchorItem() const { return anchoritem; } 00504 00505 /// Return item under cursor, if any 00506 FXCheckTreeItem* getCursorItem() const { return cursoritem; } 00507 00508 /// Extend selection from anchor item to item 00509 FXbool extendSelection(FXCheckTreeItem* item,FXbool notify=FALSE); 00510 00511 /// Deselect all items 00512 FXbool killSelection(FXbool notify=FALSE); 00513 00514 /// Sort root items 00515 void sortItems(); 00516 00517 /// Sort children of item 00518 void sortChildItems(FXCheckTreeItem* item); 00519 00520 /// Change text font 00521 void setFont(FXFont* fnt); 00522 00523 /// Return text font 00524 FXFont* getFont() const { return font; } 00525 00526 /// Change parent-child indent amount 00527 void setIndent(FXint in); 00528 00529 /// Return parent-child indent amount 00530 FXint getIndent() const { return indent; } 00531 00532 /// Return normal text color 00533 FXColor getTextColor() const { return textColor; } 00534 00535 /// Change normal text color 00536 void setTextColor(FXColor clr); 00537 00538 /// Return selected text background 00539 FXColor getSelBackColor() const { return selbackColor; } 00540 00541 /// Change selected text background 00542 void setSelBackColor(FXColor clr); 00543 00544 /// Return selected text color 00545 FXColor getSelTextColor() const { return seltextColor; } 00546 00547 /// Change selected text color 00548 void setSelTextColor(FXColor clr); 00549 00550 /// Return line color 00551 FXColor getLineColor() const { return lineColor; } 00552 00553 /// Change line color 00554 void setLineColor(FXColor clr); 00555 00556 /// Return sort function 00557 FXCheckTreeListSortFunc getSortFunc() const { return sortfunc; } 00558 00559 /// Change sort function 00560 void setSortFunc(FXCheckTreeListSortFunc func){ sortfunc=func; } 00561 00562 /// Return list style 00563 FXuint getListStyle() const; 00564 00565 /// Change list style 00566 void setListStyle(FXuint style); 00567 00568 /// Set the status line help text for this list 00569 void setHelpText(const FXString& text); 00570 00571 /// Get the status line help text for this list 00572 FXString getHelpText() const { return help; } 00573 00574 /// Save object to a stream 00575 virtual void save(FXStream& store) const; 00576 00577 /// Load object from a stream 00578 virtual void load(FXStream& store); 00579 00580 /// Destructor 00581 virtual ~FXCheckTreeList(); 00582 }; 00583 00584 } // namespace FXEX 00585 #endif // FXCHECKTREE_LIST_H 00586