![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
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,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: FXFoldingList.h,v 1.13 2004/02/08 17:17:33 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 00040 /// Folding list styles 00041 enum { 00042 FOLDINGLIST_EXTENDEDSELECT = 0, /// Extended selection mode allows for drag-selection of ranges of items 00043 FOLDINGLIST_SINGLESELECT = 0x00100000, /// Single selection mode allows up to one item to be selected 00044 FOLDINGLIST_BROWSESELECT = 0x00200000, /// Browse selection mode enforces one single item to be selected at all times 00045 FOLDINGLIST_MULTIPLESELECT = 0x00300000, /// Multiple selection mode is used for selection of individual items 00046 FOLDINGLIST_AUTOSELECT = 0x00400000, /// Automatically select under cursor 00047 FOLDINGLIST_SHOWS_LINES = 0x00800000, /// Lines shown 00048 FOLDINGLIST_SHOWS_BOXES = 0x01000000, /// Boxes to expand shown 00049 FOLDINGLIST_ROOT_BOXES = 0x02000000, /// Display root boxes also 00050 FOLDINGLIST_NORMAL = FOLDINGLIST_EXTENDEDSELECT 00051 }; 00052 00053 00054 /// Tree list Item 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 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 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 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 00092 /// Get parent item 00093 FXFoldingItem* getParent() const { return parent; } 00094 00095 /// Get next sibling item 00096 FXFoldingItem* getNext() const { return next; } 00097 00098 /// Get previous sibling item 00099 FXFoldingItem* getPrev() const { return prev; } 00100 00101 /// Get first child item 00102 FXFoldingItem* getFirst() const { return first; } 00103 00104 /// Get las child item 00105 FXFoldingItem* getLast() const { return last; } 00106 00107 /// Get item below this one in list 00108 FXFoldingItem* getBelow() const; 00109 00110 /// Get item above this one in list 00111 FXFoldingItem* 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 virtual 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 FXFoldingItem* item) const; 00184 00185 /// Return true if ancestor of child item 00186 FXbool isParentOf(const FXFoldingItem* item) const; 00187 00188 /// Return width of item as drawn in list 00189 virtual FXint getWidth(const FXFoldingList* list) const; 00190 00191 /// Return height of item as drawn in list 00192 virtual FXint getHeight(const FXFoldingList* 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 ~FXFoldingItem(); 00211 }; 00212 00213 00214 00215 /// Folding item collate function 00216 typedef FXint (*FXFoldingListSortFunc)(const FXFoldingItem*,const FXFoldingItem*); 00217 00218 00219 00220 /// Folding list Widget 00221 class FXAPI FXFoldingList : public FXScrollArea { 00222 FXDECLARE(FXFoldingList) 00223 protected: 00224 FXHeader *header; // Tree header 00225 FXFoldingItem *firstitem; // First root item 00226 FXFoldingItem *lastitem; // Last root item 00227 FXFoldingItem *anchoritem; // Selection anchor item 00228 FXFoldingItem *currentitem; // Current item 00229 FXFoldingItem *extentitem; // Selection extent 00230 FXFoldingItem *cursoritem; // Item under cursor 00231 FXFont *font; // Font 00232 FXFoldingListSortFunc sortfunc; // Item sort function 00233 FXColor textColor; // Text color 00234 FXColor selbackColor; // Selected background color 00235 FXColor seltextColor; // Selected text color 00236 FXColor lineColor; // Line color 00237 FXint treeWidth; // Tree width 00238 FXint treeHeight; // Tree height 00239 FXint visible; // Number of visible items 00240 FXint indent; // Parent to child indentation 00241 FXint grabx; // Grab point x 00242 FXint graby; // Grab point y 00243 FXString lookup; // Lookup string 00244 FXString help; // Help string 00245 FXbool state; // State of item 00246 protected: 00247 FXFoldingList(); 00248 virtual FXFoldingItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr); 00249 virtual void moveContents(FXint x,FXint y); 00250 void sort(FXFoldingItem*& f1,FXFoldingItem*& t1,FXFoldingItem*& f2,FXFoldingItem*& t2,int n); 00251 void mergesort(FXFoldingItem*& list); 00252 void recompute(); 00253 private: 00254 FXFoldingList(const FXFoldingList&); 00255 FXFoldingList& operator=(const FXFoldingList&); 00256 public: 00257 long onPaint(FXObject*,FXSelector,void*); 00258 long onEnter(FXObject*,FXSelector,void*); 00259 long onLeave(FXObject*,FXSelector,void*); 00260 long onUngrabbed(FXObject*,FXSelector,void*); 00261 long onMotion(FXObject*,FXSelector,void*); 00262 long onKeyPress(FXObject*,FXSelector,void*); 00263 long onKeyRelease(FXObject*,FXSelector,void*); 00264 long onLeftBtnPress(FXObject*,FXSelector,void*); 00265 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00266 long onRightBtnPress(FXObject*,FXSelector,void*); 00267 long onRightBtnRelease(FXObject*,FXSelector,void*); 00268 long onHeaderChanged(FXObject*,FXSelector,void*); 00269 long onQueryTip(FXObject*,FXSelector,void*); 00270 long onQueryHelp(FXObject*,FXSelector,void*); 00271 long onTipTimer(FXObject*,FXSelector,void*); 00272 long onFocusIn(FXObject*,FXSelector,void*); 00273 long onFocusOut(FXObject*,FXSelector,void*); 00274 long onAutoScroll(FXObject*,FXSelector,void*); 00275 long onClicked(FXObject*,FXSelector,void*); 00276 long onDoubleClicked(FXObject*,FXSelector,void*); 00277 long onTripleClicked(FXObject*,FXSelector,void*); 00278 long onCommand(FXObject*,FXSelector,void*); 00279 long onLookupTimer(FXObject*,FXSelector,void*); 00280 public: 00281 static FXint ascending(const FXFoldingItem*,const FXFoldingItem*); 00282 static FXint descending(const FXFoldingItem*,const FXFoldingItem*); 00283 static FXint ascendingCase(const FXFoldingItem*,const FXFoldingItem*); 00284 static FXint descendingCase(const FXFoldingItem*,const FXFoldingItem*); 00285 public: 00286 enum { 00287 ID_LOOKUPTIMER=FXScrollArea::ID_LAST, 00288 ID_HEADER_CHANGE, 00289 ID_LAST 00290 }; 00291 public: 00292 00293 /// Construct a folding list with nvis visible items; the folding list is initially empty 00294 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); 00295 00296 /// Create server-side resources 00297 virtual void create(); 00298 00299 /// Detach server-side resources 00300 virtual void detach(); 00301 00302 /// Perform layout 00303 virtual void layout(); 00304 00305 /// Return default width 00306 virtual FXint getDefaultWidth(); 00307 00308 /// Return default height 00309 virtual FXint getDefaultHeight(); 00310 00311 /// Compute and return content width 00312 virtual FXint getContentWidth(); 00313 00314 /// Return content height 00315 virtual FXint getContentHeight(); 00316 00317 /// Recalculate layout 00318 virtual void recalc(); 00319 00320 /// Tree list can receive focus 00321 virtual FXbool canFocus() const; 00322 00323 /// Move the focus to this window 00324 virtual void setFocus(); 00325 00326 /// Remove the focus from this window 00327 virtual void killFocus(); 00328 00329 /// Return header control 00330 FXHeader* getHeader() const { return header; } 00331 00332 /// Append header with given text and optional icon 00333 void appendHeader(const FXString& text,FXIcon *icon=NULL,FXint size=1); 00334 00335 /// Remove header at index 00336 void removeHeader(FXint index); 00337 00338 /// Change text of header at index 00339 void setHeaderText(FXint index,const FXString& text); 00340 00341 /// Return text of header at index 00342 FXString getHeaderText(FXint index) const; 00343 00344 /// Change icon of header at index 00345 void setHeaderIcon(FXint index,FXIcon *icon); 00346 00347 /// Return icon of header at index 00348 FXIcon* getHeaderIcon(FXint index) const; 00349 00350 /// Change size of header at index 00351 void setHeaderSize(FXint index,FXint size); 00352 00353 /// Return width of header at index 00354 FXint getHeaderSize(FXint index) const; 00355 00356 /// Return number of headers 00357 FXint getNumHeaders() const; 00358 00359 /// Return number of items 00360 FXint getNumItems() const; 00361 00362 /// Return number of visible items 00363 FXint getNumVisible() const { return visible; } 00364 00365 /// Change number of visible items 00366 void setNumVisible(FXint nvis); 00367 00368 /// Return first root item 00369 FXFoldingItem* getFirstItem() const { return firstitem; } 00370 00371 /// Return last root item 00372 FXFoldingItem* getLastItem() const { return lastitem; } 00373 00374 /// Prepend new [possibly subclassed] item as first child of p 00375 FXFoldingItem* addItemFirst(FXFoldingItem* p,FXFoldingItem* item,FXbool notify=FALSE); 00376 00377 /// Prepend new item with given text and optional icon, and user-data pointer as first child of p 00378 FXFoldingItem* addItemFirst(FXFoldingItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00379 00380 /// Append new [possibly subclassed] item as last child of p 00381 FXFoldingItem* addItemLast(FXFoldingItem* p,FXFoldingItem* item,FXbool notify=FALSE); 00382 00383 /// Append new item with given text and optional icon, and user-data pointer as last child of p 00384 FXFoldingItem* addItemLast(FXFoldingItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00385 00386 /// Append new [possibly subclassed] item after to other item 00387 FXFoldingItem* addItemAfter(FXFoldingItem* other,FXFoldingItem* item,FXbool notify=FALSE); 00388 00389 /// Append new item with given text and optional icon, and user-data pointer after to other item 00390 FXFoldingItem* addItemAfter(FXFoldingItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00391 00392 /// Prepend new [possibly subclassed] item prior to other item 00393 FXFoldingItem* addItemBefore(FXFoldingItem* other,FXFoldingItem* item,FXbool notify=FALSE); 00394 00395 /// Prepend new item with given text and optional icon, and user-data pointer prior to other item 00396 FXFoldingItem* addItemBefore(FXFoldingItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE); 00397 00398 /// Reparent item under parent p 00399 void reparentItem(FXFoldingItem* item,FXFoldingItem* p); 00400 00401 // Move item before other 00402 FXFoldingItem* moveItemBefore(FXFoldingItem* other,FXFoldingItem* item); 00403 00404 // Move item after other 00405 FXFoldingItem* moveItemAfter(FXFoldingItem* other,FXFoldingItem* item); 00406 00407 /// Remove item 00408 void removeItem(FXFoldingItem* item,FXbool notify=FALSE); 00409 00410 /// Remove items in range [fm, to] inclusively 00411 void removeItems(FXFoldingItem* fm,FXFoldingItem* to,FXbool notify=FALSE); 00412 00413 /// Remove all items from list 00414 void clearItems(FXbool notify=FALSE); 00415 00416 /// Return item width 00417 FXint getItemWidth(const FXFoldingItem* item) const { return item->getWidth(this); } 00418 00419 /// Return item height 00420 FXint getItemHeight(const FXFoldingItem* item) const { return item->getHeight(this); } 00421 00422 /// Get item at x,y, if any 00423 FXFoldingItem* getItemAt(FXint x,FXint y) const; 00424 00425 /** 00426 * Search items for item by name, starting from start item; the 00427 * flags argument controls the search direction, and case sensitivity. 00428 */ 00429 FXFoldingItem* findItem(const FXString& text,FXFoldingItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 00430 00431 /// Scroll to make item visible 00432 void makeItemVisible(FXFoldingItem* item); 00433 00434 /// Change item's text 00435 void setItemText(FXFoldingItem* item,const FXString& text); 00436 00437 /// Return item's text 00438 FXString getItemText(const FXFoldingItem* item) const; 00439 00440 /// Change item's open icon 00441 void setItemOpenIcon(FXFoldingItem* item,FXIcon* icon); 00442 00443 /// Return item's open icon 00444 FXIcon* getItemOpenIcon(const FXFoldingItem* item) const; 00445 00446 /// Chance item's closed icon 00447 void setItemClosedIcon(FXFoldingItem* item,FXIcon* icon); 00448 00449 /// Return item's closed icon 00450 FXIcon* getItemClosedIcon(const FXFoldingItem* item) const; 00451 00452 /// Change item user-data pointer 00453 void setItemData(FXFoldingItem* item,void* ptr) const; 00454 00455 /// Return item user-data pointer 00456 void* getItemData(const FXFoldingItem* item) const; 00457 00458 /// Return TRUE if item is selected 00459 FXbool isItemSelected(const FXFoldingItem* item) const; 00460 00461 /// Return TRUE if item is current 00462 FXbool isItemCurrent(const FXFoldingItem* item) const; 00463 00464 /// Return TRUE if item is visible 00465 FXbool isItemVisible(const FXFoldingItem* item) const; 00466 00467 /// Return TRUE if item opened 00468 FXbool isItemOpened(const FXFoldingItem* item) const; 00469 00470 /// Return TRUE if item expanded 00471 FXbool isItemExpanded(const FXFoldingItem* item) const; 00472 00473 /// Return TRUE if item is a leaf-item, i.e. has no children 00474 FXbool isItemLeaf(const FXFoldingItem* item) const; 00475 00476 /// Return TRUE if item is enabled 00477 FXbool isItemEnabled(const FXFoldingItem* item) const; 00478 00479 /// Return item hit code: 0 outside, 1 icon, 2 text, 3 box 00480 FXint hitItem(const FXFoldingItem* item,FXint x,FXint y) const; 00481 00482 /// Repaint item 00483 void updateItem(FXFoldingItem* item); 00484 00485 /// Enable item 00486 FXbool enableItem(FXFoldingItem* item); 00487 00488 /// Disable item 00489 FXbool disableItem(FXFoldingItem* item); 00490 00491 /// Select item 00492 FXbool selectItem(FXFoldingItem* item,FXbool notify=FALSE); 00493 00494 /// Deselect item 00495 FXbool deselectItem(FXFoldingItem* item,FXbool notify=FALSE); 00496 00497 /// Toggle item selection 00498 FXbool toggleItem(FXFoldingItem* item,FXbool notify=FALSE); 00499 00500 /// Extend selection from anchor item to item 00501 FXbool extendSelection(FXFoldingItem* item,FXbool notify=FALSE); 00502 00503 /// Deselect all items 00504 FXbool killSelection(FXbool notify=FALSE); 00505 00506 /// Open item 00507 FXbool openItem(FXFoldingItem* item,FXbool notify=FALSE); 00508 00509 /// Close item 00510 FXbool closeItem(FXFoldingItem* item,FXbool notify=FALSE); 00511 00512 /// Collapse tree 00513 FXbool collapseTree(FXFoldingItem* tree,FXbool notify=FALSE); 00514 00515 /// Expand tree 00516 FXbool expandTree(FXFoldingItem* tree,FXbool notify=FALSE); 00517 00518 /// Change current item 00519 void setCurrentItem(FXFoldingItem* item,FXbool notify=FALSE); 00520 00521 /// Return current item, if any 00522 FXFoldingItem* getCurrentItem() const { return currentitem; } 00523 00524 /// Change anchor item 00525 void setAnchorItem(FXFoldingItem* item); 00526 00527 /// Return anchor item, if any 00528 FXFoldingItem* getAnchorItem() const { return anchoritem; } 00529 00530 /// Return item under cursor, if any 00531 FXFoldingItem* getCursorItem() const { return cursoritem; } 00532 00533 /// Sort all items recursively 00534 void sortItems(); 00535 00536 /// Sort root items 00537 void sortRootItems(); 00538 00539 /// Sort children of item 00540 void sortChildItems(FXFoldingItem* item); 00541 00542 /// Change text font 00543 void setFont(FXFont* fnt); 00544 00545 /// Return text font 00546 FXFont* getFont() const { return font; } 00547 00548 /// Change parent-child indent amount 00549 void setIndent(FXint in); 00550 00551 /// Return parent-child indent amount 00552 FXint getIndent() const { return indent; } 00553 00554 /// Return normal text color 00555 FXColor getTextColor() const { return textColor; } 00556 00557 /// Change normal text color 00558 void setTextColor(FXColor clr); 00559 00560 /// Return selected text background 00561 FXColor getSelBackColor() const { return selbackColor; } 00562 00563 /// Change selected text background 00564 void setSelBackColor(FXColor clr); 00565 00566 /// Return selected text color 00567 FXColor getSelTextColor() const { return seltextColor; } 00568 00569 /// Change selected text color 00570 void setSelTextColor(FXColor clr); 00571 00572 /// Return line color 00573 FXColor getLineColor() const { return lineColor; } 00574 00575 /// Change line color 00576 void setLineColor(FXColor clr); 00577 00578 /// Return sort function 00579 FXFoldingListSortFunc getSortFunc() const { return sortfunc; } 00580 00581 /// Change sort function 00582 void setSortFunc(FXFoldingListSortFunc func){ sortfunc=func; } 00583 00584 /// Return list style 00585 FXuint getListStyle() const; 00586 00587 /// Change list style 00588 void setListStyle(FXuint style); 00589 00590 /// Set the status line help text for this list 00591 void setHelpText(const FXString& text); 00592 00593 /// Get the status line help text for this list 00594 FXString getHelpText() const { return help; } 00595 00596 /// Save object to a stream 00597 virtual void save(FXStream& store) const; 00598 00599 /// Load object from a stream 00600 virtual void load(FXStream& store); 00601 00602 /// Destructor 00603 virtual ~FXFoldingList(); 00604 }; 00605 00606 } 00607 00608 00609 #endif
![]() |