00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00041 enum {
00042 TREELIST_EXTENDEDSELECT = 0,
00043 TREELIST_SINGLESELECT = 0x00100000,
00044 TREELIST_BROWSESELECT = 0x00200000,
00045 TREELIST_MULTIPLESELECT = 0x00300000,
00046 TREELIST_AUTOSELECT = 0x00400000,
00047 TREELIST_SHOWS_LINES = 0x00800000,
00048 TREELIST_SHOWS_BOXES = 0x01000000,
00049 TREELIST_ROOT_BOXES = 0x02000000,
00050 TREELIST_NORMAL = TREELIST_EXTENDEDSELECT
00051 };
00052
00053
00054
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
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
00093 FXTreeItem* getParent() const { return parent; }
00094
00095
00096 FXTreeItem* getNext() const { return next; }
00097
00098
00099 FXTreeItem* getPrev() const { return prev; }
00100
00101
00102 FXTreeItem* getFirst() const { return first; }
00103
00104
00105 FXTreeItem* getLast() const { return last; }
00106
00107
00108 FXTreeItem* getBelow() const;
00109
00110
00111 FXTreeItem* getAbove() const;
00112
00113
00114 FXint getNumChildren() const;
00115
00116
00117 virtual void setText(const FXString& txt){ label=txt; }
00118
00119
00120 const FXString& getText() const { return label; }
00121
00122
00123 virtual void setOpenIcon(FXIcon* icn){ openIcon=icn; }
00124
00125
00126 FXIcon* getOpenIcon() const { return openIcon; }
00127
00128
00129 virtual void setClosedIcon(FXIcon* icn){ closedIcon=icn; }
00130
00131
00132 FXIcon* getClosedIcon() const { return closedIcon; }
00133
00134
00135 void setData(void* ptr){ data=ptr; }
00136
00137
00138 void* getData() const { return data; }
00139
00140
00141 virtual void setFocus(FXbool focus);
00142
00143
00144 FXbool hasFocus() const { return (state&FOCUS)!=0; }
00145
00146
00147 virtual void setSelected(FXbool selected);
00148
00149
00150 FXbool isSelected() const { return (state&SELECTED)!=0; }
00151
00152
00153 virtual void setOpened(FXbool opened);
00154
00155
00156 FXbool isOpened() const { return (state&OPENED)!=0; }
00157
00158
00159 virtual void setExpanded(FXbool expanded);
00160
00161
00162 FXbool isExpanded() const { return (state&EXPANDED)!=0; }
00163
00164
00165 virtual void setEnabled(FXbool enabled);
00166
00167
00168 FXbool isEnabled() const { return (state&DISABLED)==0; }
00169
00170
00171 virtual void setDraggable(FXbool draggable);
00172
00173
00174 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
00175
00176
00177 void setIconOwned(FXuint owned=(OPENICONOWNED|CLOSEDICONOWNED));
00178
00179
00180 FXuint isIconOwned() const { return (state&(OPENICONOWNED|CLOSEDICONOWNED)); }
00181
00182
00183 FXbool isChildOf(const FXTreeItem* item) const;
00184
00185
00186 FXbool isParentOf(const FXTreeItem* item) const;
00187
00188
00189 virtual FXint getWidth(const FXTreeList* list) const;
00190
00191
00192 virtual FXint getHeight(const FXTreeList* list) const;
00193
00194
00195 virtual void create();
00196
00197
00198 virtual void detach();
00199
00200
00201 virtual void destroy();
00202
00203
00204 virtual void save(FXStream& store) const;
00205
00206
00207 virtual void load(FXStream& store);
00208
00209
00210 virtual ~FXTreeItem();
00211 };
00212
00213
00214
00215
00216 typedef FXint (*FXTreeListSortFunc)(const FXTreeItem*,const FXTreeItem*);
00217
00218
00219
00220
00221 class FXAPI FXTreeList : public FXScrollArea {
00222 FXDECLARE(FXTreeList)
00223 protected:
00224 FXTreeItem *firstitem;
00225 FXTreeItem *lastitem;
00226 FXTreeItem *anchoritem;
00227 FXTreeItem *currentitem;
00228 FXTreeItem *extentitem;
00229 FXTreeItem *cursoritem;
00230 FXFont *font;
00231 FXTreeListSortFunc sortfunc;
00232 FXColor textColor;
00233 FXColor selbackColor;
00234 FXColor seltextColor;
00235 FXColor lineColor;
00236 FXint treeWidth;
00237 FXint treeHeight;
00238 FXint visible;
00239 FXint indent;
00240 FXint grabx;
00241 FXint graby;
00242 FXString lookup;
00243 FXString help;
00244 FXbool state;
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
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
00292 virtual void create();
00293
00294
00295 virtual void detach();
00296
00297
00298 virtual void layout();
00299
00300
00301 virtual FXint getDefaultWidth();
00302
00303
00304 virtual FXint getDefaultHeight();
00305
00306
00307 virtual FXint getContentWidth();
00308
00309
00310 virtual FXint getContentHeight();
00311
00312
00313 virtual void recalc();
00314
00315
00316 virtual FXbool canFocus() const;
00317
00318
00319 virtual void setFocus();
00320
00321
00322 virtual void killFocus();
00323
00324
00325 FXint getNumItems() const;
00326
00327
00328 FXint getNumVisible() const { return visible; }
00329
00330
00331 void setNumVisible(FXint nvis);
00332
00333
00334 FXTreeItem* getFirstItem() const { return firstitem; }
00335
00336
00337 FXTreeItem* getLastItem() const { return lastitem; }
00338
00339
00340 FXTreeItem* addItemFirst(FXTreeItem* p,FXTreeItem* item,FXbool notify=FALSE);
00341
00342
00343 FXTreeItem* addItemFirst(FXTreeItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00344
00345
00346 FXTreeItem* addItemLast(FXTreeItem* p,FXTreeItem* item,FXbool notify=FALSE);
00347
00348
00349 FXTreeItem* addItemLast(FXTreeItem* p,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00350
00351
00352 FXTreeItem* addItemAfter(FXTreeItem* other,FXTreeItem* item,FXbool notify=FALSE);
00353
00354
00355 FXTreeItem* addItemAfter(FXTreeItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00356
00357
00358 FXTreeItem* addItemBefore(FXTreeItem* other,FXTreeItem* item,FXbool notify=FALSE);
00359
00360
00361 FXTreeItem* addItemBefore(FXTreeItem* other,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00362
00363
00364 void reparentItem(FXTreeItem* item,FXTreeItem* p);
00365
00366
00367 FXTreeItem* moveItemBefore(FXTreeItem* other,FXTreeItem* item);
00368
00369
00370 FXTreeItem* moveItemAfter(FXTreeItem* other,FXTreeItem* item);
00371
00372
00373 void removeItem(FXTreeItem* item,FXbool notify=FALSE);
00374
00375
00376 void removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify=FALSE);
00377
00378
00379 void clearItems(FXbool notify=FALSE);
00380
00381
00382 FXint getItemWidth(const FXTreeItem* item) const { return item->getWidth(this); }
00383
00384
00385 FXint getItemHeight(const FXTreeItem* item) const { return item->getHeight(this); }
00386
00387
00388 FXTreeItem* getItemAt(FXint x,FXint y) const;
00389
00390
00391
00392
00393
00394 FXTreeItem* findItem(const FXString& text,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00395
00396
00397 void makeItemVisible(FXTreeItem* item);
00398
00399
00400 void setItemText(FXTreeItem* item,const FXString& text);
00401
00402
00403 FXString getItemText(const FXTreeItem* item) const;
00404
00405
00406 void setItemOpenIcon(FXTreeItem* item,FXIcon* icon);
00407
00408
00409 FXIcon* getItemOpenIcon(const FXTreeItem* item) const;
00410
00411
00412 void setItemClosedIcon(FXTreeItem* item,FXIcon* icon);
00413
00414
00415 FXIcon* getItemClosedIcon(const FXTreeItem* item) const;
00416
00417
00418 void setItemData(FXTreeItem* item,void* ptr) const;
00419
00420
00421 void* getItemData(const FXTreeItem* item) const;
00422
00423
00424 FXbool isItemSelected(const FXTreeItem* item) const;
00425
00426
00427 FXbool isItemCurrent(const FXTreeItem* item) const;
00428
00429
00430 FXbool isItemVisible(const FXTreeItem* item) const;
00431
00432
00433 FXbool isItemOpened(const FXTreeItem* item) const;
00434
00435
00436 FXbool isItemExpanded(const FXTreeItem* item) const;
00437
00438
00439 FXbool isItemLeaf(const FXTreeItem* item) const;
00440
00441
00442 FXbool isItemEnabled(const FXTreeItem* item) const;
00443
00444
00445 FXint hitItem(const FXTreeItem* item,FXint x,FXint y) const;
00446
00447
00448 void updateItem(FXTreeItem* item) const;
00449
00450
00451 FXbool enableItem(FXTreeItem* item);
00452
00453
00454 FXbool disableItem(FXTreeItem* item);
00455
00456
00457 virtual FXbool selectItem(FXTreeItem* item,FXbool notify=FALSE);
00458
00459
00460 virtual FXbool deselectItem(FXTreeItem* item,FXbool notify=FALSE);
00461
00462
00463 virtual FXbool toggleItem(FXTreeItem* item,FXbool notify=FALSE);
00464
00465
00466 virtual FXbool extendSelection(FXTreeItem* item,FXbool notify=FALSE);
00467
00468
00469 virtual FXbool killSelection(FXbool notify=FALSE);
00470
00471
00472 virtual FXbool openItem(FXTreeItem* item,FXbool notify=FALSE);
00473
00474
00475 virtual FXbool closeItem(FXTreeItem* item,FXbool notify=FALSE);
00476
00477
00478 virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=FALSE);
00479
00480
00481 virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=FALSE);
00482
00483
00484 virtual void setCurrentItem(FXTreeItem* item,FXbool notify=FALSE);
00485
00486
00487 FXTreeItem* getCurrentItem() const { return currentitem; }
00488
00489
00490 void setAnchorItem(FXTreeItem* item);
00491
00492
00493 FXTreeItem* getAnchorItem() const { return anchoritem; }
00494
00495
00496 FXTreeItem* getCursorItem() const { return cursoritem; }
00497
00498
00499 void sortItems();
00500
00501
00502 void sortRootItems();
00503
00504
00505 void sortChildItems(FXTreeItem* item);
00506
00507
00508 void setFont(FXFont* fnt);
00509
00510
00511 FXFont* getFont() const { return font; }
00512
00513
00514 void setIndent(FXint in);
00515
00516
00517 FXint getIndent() const { return indent; }
00518
00519
00520 FXColor getTextColor() const { return textColor; }
00521
00522
00523 void setTextColor(FXColor clr);
00524
00525
00526 FXColor getSelBackColor() const { return selbackColor; }
00527
00528
00529 void setSelBackColor(FXColor clr);
00530
00531
00532 FXColor getSelTextColor() const { return seltextColor; }
00533
00534
00535 void setSelTextColor(FXColor clr);
00536
00537
00538 FXColor getLineColor() const { return lineColor; }
00539
00540
00541 void setLineColor(FXColor clr);
00542
00543
00544 FXTreeListSortFunc getSortFunc() const { return sortfunc; }
00545
00546
00547 void setSortFunc(FXTreeListSortFunc func){ sortfunc=func; }
00548
00549
00550 FXuint getListStyle() const;
00551
00552
00553 void setListStyle(FXuint style);
00554
00555
00556 void setHelpText(const FXString& text);
00557
00558
00559 FXString getHelpText() const { return help; }
00560
00561
00562 virtual void save(FXStream& store) const;
00563
00564
00565 virtual void load(FXStream& store);
00566
00567
00568 virtual ~FXTreeList();
00569 };
00570
00571 }
00572
00573 #endif