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 private:
00072 FXTreeItem(const FXTreeItem&);
00073 FXTreeItem& operator=(const FXTreeItem&);
00074 protected:
00075 FXTreeItem():parent(NULL),prev(NULL),next(NULL),first(NULL),last(NULL),openIcon(NULL),closedIcon(NULL),data(NULL),state(0),x(0),y(0){}
00076 virtual void draw(const FXTreeList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00077 virtual FXint hitItem(const FXTreeList* list,FXint x,FXint y) const;
00078 public:
00079 enum{
00080 SELECTED = 1,
00081 FOCUS = 2,
00082 DISABLED = 4,
00083 OPENED = 8,
00084 EXPANDED = 16,
00085 HASITEMS = 32,
00086 DRAGGABLE = 64,
00087 OPENICONOWNED = 128,
00088 CLOSEDICONOWNED = 256
00089 };
00090 public:
00091
00092
00093 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){}
00094
00095
00096 FXTreeItem* getParent() const { return parent; }
00097
00098
00099 FXTreeItem* getNext() const { return next; }
00100
00101
00102 FXTreeItem* getPrev() const { return prev; }
00103
00104
00105 FXTreeItem* getFirst() const { return first; }
00106
00107
00108 FXTreeItem* getLast() const { return last; }
00109
00110
00111 FXTreeItem* getBelow() const;
00112
00113
00114 FXTreeItem* getAbove() const;
00115
00116
00117 FXint getNumChildren() const;
00118
00119
00120 virtual void setText(const FXString& txt);
00121
00122
00123 const FXString& getText() const { return label; }
00124
00125
00126 virtual void setOpenIcon(FXIcon* icn,FXbool owned=FALSE);
00127
00128
00129 FXIcon* getOpenIcon() const { return openIcon; }
00130
00131
00132 virtual void setClosedIcon(FXIcon* icn,FXbool owned=FALSE);
00133
00134
00135 FXIcon* getClosedIcon() const { return closedIcon; }
00136
00137
00138 void setData(void* ptr){ data=ptr; }
00139
00140
00141 void* getData() const { return data; }
00142
00143
00144 virtual void setFocus(FXbool focus);
00145
00146
00147 FXbool hasFocus() const { return (state&FOCUS)!=0; }
00148
00149
00150 virtual void setSelected(FXbool selected);
00151
00152
00153 FXbool isSelected() const { return (state&SELECTED)!=0; }
00154
00155
00156 virtual void setOpened(FXbool opened);
00157
00158
00159 FXbool isOpened() const { return (state&OPENED)!=0; }
00160
00161
00162 virtual void setExpanded(FXbool expanded);
00163
00164
00165 FXbool isExpanded() const { return (state&EXPANDED)!=0; }
00166
00167
00168 virtual void setEnabled(FXbool enabled);
00169
00170
00171 FXbool isEnabled() const { return (state&DISABLED)==0; }
00172
00173
00174 virtual void setDraggable(FXbool draggable);
00175
00176
00177 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
00178
00179
00180 FXbool hasItems() const { return (state&HASITEMS)!=0; }
00181
00182
00183 void setHasItems(FXbool flag);
00184
00185
00186 FXbool isChildOf(const FXTreeItem* item) const;
00187
00188
00189 FXbool isParentOf(const FXTreeItem* item) const;
00190
00191
00192 virtual FXint getWidth(const FXTreeList* list) const;
00193
00194
00195 virtual FXint getHeight(const FXTreeList* list) const;
00196
00197
00198 virtual void create();
00199
00200
00201 virtual void detach();
00202
00203
00204 virtual void destroy();
00205
00206
00207 virtual void save(FXStream& store) const;
00208
00209
00210 virtual void load(FXStream& store);
00211
00212
00213 virtual ~FXTreeItem();
00214 };
00215
00216
00217
00218
00219 typedef FXint (*FXTreeListSortFunc)(const FXTreeItem*,const FXTreeItem*);
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 class FXAPI FXTreeList : public FXScrollArea {
00244 FXDECLARE(FXTreeList)
00245 protected:
00246 FXTreeItem *firstitem;
00247 FXTreeItem *lastitem;
00248 FXTreeItem *anchoritem;
00249 FXTreeItem *currentitem;
00250 FXTreeItem *extentitem;
00251 FXTreeItem *cursoritem;
00252 FXTreeItem *viewableitem;
00253 FXFont *font;
00254 FXTreeListSortFunc sortfunc;
00255 FXColor textColor;
00256 FXColor selbackColor;
00257 FXColor seltextColor;
00258 FXColor lineColor;
00259 FXint treeWidth;
00260 FXint treeHeight;
00261 FXint visible;
00262 FXint indent;
00263 FXint grabx;
00264 FXint graby;
00265 FXString lookup;
00266 FXString tip;
00267 FXString help;
00268 FXbool state;
00269 protected:
00270 FXTreeList();
00271 virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
00272 void sort(FXTreeItem*& f1,FXTreeItem*& t1,FXTreeItem*& f2,FXTreeItem*& t2,int n);
00273 void recompute();
00274 private:
00275 FXTreeList(const FXTreeList&);
00276 FXTreeList& operator=(const FXTreeList&);
00277 public:
00278 long onPaint(FXObject*,FXSelector,void*);
00279 long onEnter(FXObject*,FXSelector,void*);
00280 long onLeave(FXObject*,FXSelector,void*);
00281 long onUngrabbed(FXObject*,FXSelector,void*);
00282 long onMotion(FXObject*,FXSelector,void*);
00283 long onKeyPress(FXObject*,FXSelector,void*);
00284 long onKeyRelease(FXObject*,FXSelector,void*);
00285 long onLeftBtnPress(FXObject*,FXSelector,void*);
00286 long onLeftBtnRelease(FXObject*,FXSelector,void*);
00287 long onRightBtnPress(FXObject*,FXSelector,void*);
00288 long onRightBtnRelease(FXObject*,FXSelector,void*);
00289 long onQueryTip(FXObject*,FXSelector,void*);
00290 long onQueryHelp(FXObject*,FXSelector,void*);
00291 long onTipTimer(FXObject*,FXSelector,void*);
00292 long onFocusIn(FXObject*,FXSelector,void*);
00293 long onFocusOut(FXObject*,FXSelector,void*);
00294 long onAutoScroll(FXObject*,FXSelector,void*);
00295 long onClicked(FXObject*,FXSelector,void*);
00296 long onDoubleClicked(FXObject*,FXSelector,void*);
00297 long onTripleClicked(FXObject*,FXSelector,void*);
00298 long onCommand(FXObject*,FXSelector,void*);
00299 long onLookupTimer(FXObject*,FXSelector,void*);
00300 public:
00301 static FXint ascending(const FXTreeItem*,const FXTreeItem*);
00302 static FXint descending(const FXTreeItem*,const FXTreeItem*);
00303 static FXint ascendingCase(const FXTreeItem*,const FXTreeItem*);
00304 static FXint descendingCase(const FXTreeItem*,const FXTreeItem*);
00305 public:
00306 enum {
00307 ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
00308 ID_LAST
00309 };
00310 public:
00311
00312
00313 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);
00314
00315
00316 virtual void create();
00317
00318
00319 virtual void detach();
00320
00321
00322 virtual void layout();
00323
00324
00325 virtual FXint getDefaultWidth();
00326
00327
00328 virtual FXint getDefaultHeight();
00329
00330
00331 virtual FXint getContentWidth();
00332
00333
00334 virtual FXint getContentHeight();
00335
00336
00337 virtual void recalc();
00338
00339
00340 virtual bool canFocus() const;
00341
00342
00343 virtual void setFocus();
00344
00345
00346 virtual void killFocus();
00347
00348
00349 FXint getNumItems() const;
00350
00351
00352 FXint getNumVisible() const { return visible; }
00353
00354
00355 void setNumVisible(FXint nvis);
00356
00357
00358 FXTreeItem* getFirstItem() const { return firstitem; }
00359
00360
00361 FXTreeItem* getLastItem() const { return lastitem; }
00362
00363
00364 FXint fillItems(FXTreeItem* father,const FXchar** strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00365
00366
00367 FXint fillItems(FXTreeItem* father,const FXString& strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00368
00369
00370 FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item,FXbool notify=FALSE);
00371
00372
00373 FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00374
00375
00376 FXTreeItem* appendItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=FALSE);
00377
00378
00379 FXTreeItem* appendItem(FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00380
00381
00382 FXTreeItem* prependItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=FALSE);
00383
00384
00385 FXTreeItem* prependItem(FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL,FXbool notify=FALSE);
00386
00387
00388 FXTreeItem *moveItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item);
00389
00390
00391 FXTreeItem* extractItem(FXTreeItem* item,FXbool notify=FALSE);
00392
00393
00394 void removeItem(FXTreeItem* item,FXbool notify=FALSE);
00395
00396
00397 void removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify=FALSE);
00398
00399
00400 void clearItems(FXbool notify=FALSE);
00401
00402
00403 FXint getItemWidth(const FXTreeItem* item) const { return item->getWidth(this); }
00404
00405
00406 FXint getItemHeight(const FXTreeItem* item) const { return item->getHeight(this); }
00407
00408
00409 virtual FXTreeItem* getItemAt(FXint x,FXint y) const;
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 FXTreeItem* findItem(const FXString& name,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00422
00423
00424
00425
00426
00427
00428
00429
00430 FXTreeItem* findItemByData(const void *ptr,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00431
00432
00433 virtual void makeItemVisible(FXTreeItem* item);
00434
00435
00436 void setItemText(FXTreeItem* item,const FXString& text);
00437
00438
00439 FXString getItemText(const FXTreeItem* item) const;
00440
00441
00442 void setItemOpenIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=FALSE);
00443
00444
00445 FXIcon* getItemOpenIcon(const FXTreeItem* item) const;
00446
00447
00448 void setItemClosedIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=FALSE);
00449
00450
00451 FXIcon* getItemClosedIcon(const FXTreeItem* item) const;
00452
00453
00454 void setItemData(FXTreeItem* item,void* ptr) const;
00455
00456
00457 void* getItemData(const FXTreeItem* item) const;
00458
00459
00460 FXbool isItemSelected(const FXTreeItem* item) const;
00461
00462
00463 FXbool isItemCurrent(const FXTreeItem* item) const;
00464
00465
00466 FXbool isItemVisible(const FXTreeItem* item) const;
00467
00468
00469 FXbool isItemOpened(const FXTreeItem* item) const;
00470
00471
00472 FXbool isItemExpanded(const FXTreeItem* item) const;
00473
00474
00475 FXbool isItemLeaf(const FXTreeItem* item) const;
00476
00477
00478 FXbool isItemEnabled(const FXTreeItem* item) const;
00479
00480
00481 FXint hitItem(const FXTreeItem* item,FXint x,FXint y) const;
00482
00483
00484 void updateItem(FXTreeItem* item) const;
00485
00486
00487 virtual FXbool enableItem(FXTreeItem* item);
00488
00489
00490 virtual FXbool disableItem(FXTreeItem* item);
00491
00492
00493 virtual FXbool selectItem(FXTreeItem* item,FXbool notify=FALSE);
00494
00495
00496 virtual FXbool deselectItem(FXTreeItem* item,FXbool notify=FALSE);
00497
00498
00499 virtual FXbool toggleItem(FXTreeItem* item,FXbool notify=FALSE);
00500
00501
00502 virtual FXbool extendSelection(FXTreeItem* item,FXbool notify=FALSE);
00503
00504
00505 virtual FXbool killSelection(FXbool notify=FALSE);
00506
00507
00508 virtual FXbool openItem(FXTreeItem* item,FXbool notify=FALSE);
00509
00510
00511 virtual FXbool closeItem(FXTreeItem* item,FXbool notify=FALSE);
00512
00513
00514 virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=FALSE);
00515
00516
00517 virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=FALSE);
00518
00519
00520 virtual void setCurrentItem(FXTreeItem* item,FXbool notify=FALSE);
00521
00522
00523 FXTreeItem* getCurrentItem() const { return currentitem; }
00524
00525
00526 void setAnchorItem(FXTreeItem* item);
00527
00528
00529 FXTreeItem* getAnchorItem() const { return anchoritem; }
00530
00531
00532 FXTreeItem* getCursorItem() const { return cursoritem; }
00533
00534
00535 void sortItems();
00536
00537
00538 void sortRootItems();
00539
00540
00541 void sortChildItems(FXTreeItem* item);
00542
00543
00544 FXTreeListSortFunc getSortFunc() const { return sortfunc; }
00545
00546
00547 void setSortFunc(FXTreeListSortFunc func){ sortfunc=func; }
00548
00549
00550 void setFont(FXFont* fnt);
00551
00552
00553 FXFont* getFont() const { return font; }
00554
00555
00556 void setIndent(FXint in);
00557
00558
00559 FXint getIndent() const { return indent; }
00560
00561
00562 FXColor getTextColor() const { return textColor; }
00563
00564
00565 void setTextColor(FXColor clr);
00566
00567
00568 FXColor getSelBackColor() const { return selbackColor; }
00569
00570
00571 void setSelBackColor(FXColor clr);
00572
00573
00574 FXColor getSelTextColor() const { return seltextColor; }
00575
00576
00577 void setSelTextColor(FXColor clr);
00578
00579
00580 FXColor getLineColor() const { return lineColor; }
00581
00582
00583 void setLineColor(FXColor clr);
00584
00585
00586 FXuint getListStyle() const;
00587
00588
00589 void setListStyle(FXuint style);
00590
00591
00592 void setHelpText(const FXString& text);
00593
00594
00595 const FXString& getHelpText() const { return help; }
00596
00597
00598 virtual void save(FXStream& store) const;
00599
00600
00601 virtual void load(FXStream& store);
00602
00603
00604 virtual ~FXTreeList();
00605 };
00606
00607 }
00608
00609 #endif