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
public:
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);
00118
00119
00120 const
FXString& getText()
const {
return label; }
00121
00122
00123
virtual void setOpenIcon(
FXIcon* icn,FXbool owned=FALSE);
00124
00125
00126
FXIcon* getOpenIcon()
const {
return openIcon; }
00127
00128
00129
virtual void setClosedIcon(
FXIcon* icn,FXbool owned=FALSE);
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 FXbool hasItems()
const {
return (state&HASITEMS)!=0; }
00178
00179
00180
void setHasItems(FXbool flag);
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
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
class FXAPI FXTreeList :
public FXScrollArea {
00241 FXDECLARE(FXTreeList)
00242
protected:
00243 FXTreeItem *firstitem;
00244 FXTreeItem *lastitem;
00245 FXTreeItem *anchoritem;
00246 FXTreeItem *currentitem;
00247 FXTreeItem *extentitem;
00248 FXTreeItem *cursoritem;
00249
FXFont *font;
00250 FXTreeListSortFunc sortfunc;
00251 FXColor textColor;
00252 FXColor selbackColor;
00253 FXColor seltextColor;
00254 FXColor lineColor;
00255 FXint treeWidth;
00256 FXint treeHeight;
00257 FXint visible;
00258 FXint indent;
00259 FXint grabx;
00260 FXint graby;
00261
FXString lookup;
00262
FXString tip;
00263
FXString help;
00264 FXbool state;
00265
protected:
00266 FXTreeList();
00267
virtual FXTreeItem* createItem(
const FXString& text,
FXIcon* oi,
FXIcon* ci,
void* ptr);
00268
void sort(FXTreeItem*& f1,FXTreeItem*& t1,FXTreeItem*& f2,FXTreeItem*& t2,
int n);
00269
void recompute();
00270
private:
00271 FXTreeList(
const FXTreeList&);
00272 FXTreeList& operator=(
const FXTreeList&);
00273
public:
00274
long onPaint(
FXObject*,FXSelector,
void*);
00275
long onEnter(
FXObject*,FXSelector,
void*);
00276
long onLeave(
FXObject*,FXSelector,
void*);
00277
long onUngrabbed(
FXObject*,FXSelector,
void*);
00278
long onMotion(
FXObject*,FXSelector,
void*);
00279
long onKeyPress(
FXObject*,FXSelector,
void*);
00280
long onKeyRelease(
FXObject*,FXSelector,
void*);
00281
long onLeftBtnPress(
FXObject*,FXSelector,
void*);
00282
long onLeftBtnRelease(
FXObject*,FXSelector,
void*);
00283
long onRightBtnPress(
FXObject*,FXSelector,
void*);
00284
long onRightBtnRelease(
FXObject*,FXSelector,
void*);
00285
long onQueryTip(
FXObject*,FXSelector,
void*);
00286
long onQueryHelp(
FXObject*,FXSelector,
void*);
00287
long onTipTimer(
FXObject*,FXSelector,
void*);
00288
long onFocusIn(
FXObject*,FXSelector,
void*);
00289
long onFocusOut(
FXObject*,FXSelector,
void*);
00290
long onAutoScroll(
FXObject*,FXSelector,
void*);
00291
long onClicked(
FXObject*,FXSelector,
void*);
00292
long onDoubleClicked(
FXObject*,FXSelector,
void*);
00293
long onTripleClicked(
FXObject*,FXSelector,
void*);
00294
long onCommand(
FXObject*,FXSelector,
void*);
00295
long onLookupTimer(
FXObject*,FXSelector,
void*);
00296
public:
00297
static FXint ascending(
const FXTreeItem*,
const FXTreeItem*);
00298
static FXint descending(
const FXTreeItem*,
const FXTreeItem*);
00299
static FXint ascendingCase(
const FXTreeItem*,
const FXTreeItem*);
00300
static FXint descendingCase(
const FXTreeItem*,
const FXTreeItem*);
00301
public:
00302
enum {
00303 ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
00304 ID_LAST
00305 };
00306
public:
00307
00308
00309 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);
00310
00311
00312
virtual void create();
00313
00314
00315
virtual void detach();
00316
00317
00318
virtual void layout();
00319
00320
00321
virtual FXint getDefaultWidth();
00322
00323
00324
virtual FXint getDefaultHeight();
00325
00326
00327
virtual FXint getContentWidth();
00328
00329
00330
virtual FXint getContentHeight();
00331
00332
00333
virtual void recalc();
00334
00335
00336
virtual FXbool canFocus() const;
00337
00338
00339 virtual
void setFocus();
00340
00341
00342 virtual
void killFocus();
00343
00344
00345 FXint getNumItems() const;
00346
00347
00348 FXint getNumVisible()
const {
return visible; }
00349
00350
00351
void setNumVisible(FXint nvis);
00352
00353
00354 FXTreeItem* getFirstItem()
const {
return firstitem; }
00355
00356
00357 FXTreeItem* getLastItem()
const {
return lastitem; }
00358
00359
00360 FXint fillItems(FXTreeItem* father,
const FXchar** strings,
FXIcon* oi=NULL,
FXIcon* ci=NULL,
void* ptr=NULL,FXbool notify=FALSE);
00361
00362
00363 FXint fillItems(FXTreeItem* father,
const FXString& strings,
FXIcon* oi=NULL,
FXIcon* ci=NULL,
void* ptr=NULL,FXbool notify=FALSE);
00364
00365
00366 FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item,FXbool notify=FALSE);
00367
00368
00369 FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,
const FXString& text,
FXIcon* oi=NULL,
FXIcon* ci=NULL,
void* ptr=NULL,FXbool notify=FALSE);
00370
00371
00372 FXTreeItem* appendItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=FALSE);
00373
00374
00375 FXTreeItem* appendItem(FXTreeItem* father,
const FXString& text,
FXIcon* oi=NULL,
FXIcon* ci=NULL,
void* ptr=NULL,FXbool notify=FALSE);
00376
00377
00378 FXTreeItem* prependItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=FALSE);
00379
00380
00381 FXTreeItem* prependItem(FXTreeItem* father,
const FXString& text,
FXIcon* oi=NULL,
FXIcon* ci=NULL,
void* ptr=NULL,FXbool notify=FALSE);
00382
00383
00384 FXTreeItem *moveItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item);
00385
00386
00387
void removeItem(FXTreeItem* item,FXbool notify=FALSE);
00388
00389
00390
void removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify=FALSE);
00391
00392
00393
void clearItems(FXbool notify=FALSE);
00394
00395
00396 FXint getItemWidth(
const FXTreeItem* item)
const {
return item->
getWidth(
this); }
00397
00398
00399 FXint getItemHeight(
const FXTreeItem* item)
const {
return item->
getHeight(
this); }
00400
00401
00402
virtual FXTreeItem* getItemAt(FXint x,FXint y)
const;
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 FXTreeItem* findItem(
const FXString& name,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP)
const;
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 FXTreeItem* findItemByData(
const void *ptr,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP)
const;
00427
00428
00429
virtual void makeItemVisible(FXTreeItem* item);
00430
00431
00432
void setItemText(FXTreeItem* item,
const FXString& text);
00433
00434
00435 FXString getItemText(
const FXTreeItem* item)
const;
00436
00437
00438
void setItemOpenIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=FALSE);
00439
00440
00441 FXIcon* getItemOpenIcon(
const FXTreeItem* item)
const;
00442
00443
00444
void setItemClosedIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=FALSE);
00445
00446
00447 FXIcon* getItemClosedIcon(
const FXTreeItem* item)
const;
00448
00449
00450
void setItemData(FXTreeItem* item,
void* ptr)
const;
00451
00452
00453
void* getItemData(
const FXTreeItem* item)
const;
00454
00455
00456 FXbool isItemSelected(
const FXTreeItem* item)
const;
00457
00458
00459 FXbool isItemCurrent(
const FXTreeItem* item)
const;
00460
00461
00462 FXbool isItemVisible(
const FXTreeItem* item)
const;
00463
00464
00465 FXbool isItemOpened(
const FXTreeItem* item)
const;
00466
00467
00468 FXbool isItemExpanded(
const FXTreeItem* item)
const;
00469
00470
00471 FXbool isItemLeaf(
const FXTreeItem* item)
const;
00472
00473
00474 FXbool isItemEnabled(
const FXTreeItem* item)
const;
00475
00476
00477 FXint hitItem(
const FXTreeItem* item,FXint x,FXint y)
const;
00478
00479
00480
void updateItem(FXTreeItem* item)
const;
00481
00482
00483
virtual FXbool enableItem(FXTreeItem* item);
00484
00485
00486
virtual FXbool disableItem(FXTreeItem* item);
00487
00488
00489
virtual FXbool selectItem(FXTreeItem* item,FXbool notify=FALSE);
00490
00491
00492
virtual FXbool deselectItem(FXTreeItem* item,FXbool notify=FALSE);
00493
00494
00495
virtual FXbool toggleItem(FXTreeItem* item,FXbool notify=FALSE);
00496
00497
00498
virtual FXbool extendSelection(FXTreeItem* item,FXbool notify=FALSE);
00499
00500
00501
virtual FXbool killSelection(FXbool notify=FALSE);
00502
00503
00504
virtual FXbool openItem(FXTreeItem* item,FXbool notify=FALSE);
00505
00506
00507
virtual FXbool closeItem(FXTreeItem* item,FXbool notify=FALSE);
00508
00509
00510
virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=FALSE);
00511
00512
00513
virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=FALSE);
00514
00515
00516
virtual void setCurrentItem(FXTreeItem* item,FXbool notify=FALSE);
00517
00518
00519 FXTreeItem* getCurrentItem()
const {
return currentitem; }
00520
00521
00522
void setAnchorItem(FXTreeItem* item);
00523
00524
00525 FXTreeItem* getAnchorItem()
const {
return anchoritem; }
00526
00527
00528 FXTreeItem* getCursorItem()
const {
return cursoritem; }
00529
00530
00531
void sortItems();
00532
00533
00534
void sortRootItems();
00535
00536
00537
void sortChildItems(FXTreeItem* item);
00538
00539
00540 FXTreeListSortFunc getSortFunc()
const {
return sortfunc; }
00541
00542
00543
void setSortFunc(FXTreeListSortFunc func){ sortfunc=func; }
00544
00545
00546
void setFont(FXFont* fnt);
00547
00548
00549 FXFont* getFont()
const {
return font; }
00550
00551
00552
void setIndent(FXint in);
00553
00554
00555 FXint getIndent()
const {
return indent; }
00556
00557
00558 FXColor getTextColor()
const {
return textColor; }
00559
00560
00561
void setTextColor(FXColor clr);
00562
00563
00564 FXColor getSelBackColor()
const {
return selbackColor; }
00565
00566
00567
void setSelBackColor(FXColor clr);
00568
00569
00570 FXColor getSelTextColor()
const {
return seltextColor; }
00571
00572
00573
void setSelTextColor(FXColor clr);
00574
00575
00576 FXColor getLineColor()
const {
return lineColor; }
00577
00578
00579
void setLineColor(FXColor clr);
00580
00581
00582 FXuint getListStyle() const;
00583
00584
00585
void setListStyle(FXuint style);
00586
00587
00588
void setHelpText(const FXString& text);
00589
00590
00591 const FXString& getHelpText()
const {
return help; }
00592
00593
00594
virtual void save(FXStream& store)
const;
00595
00596
00597
virtual void load(FXStream& store);
00598
00599
00600
virtual ~FXTreeList();
00601 };
00602
00603 }
00604
00605
#endif