Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXTreeList.h
1 /********************************************************************************
2 * *
3 * T r e e L i s t W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXTREELIST_H
22 #define FXTREELIST_H
23 
24 #ifndef FXSCROLLAREA_H
25 #include "FXScrollArea.h"
26 #endif
27 
28 namespace FX {
29 
30 
31 class FXIcon;
32 class FXFont;
33 class FXTreeList;
34 class FXDirList;
35 
36 
38 enum {
39  TREELIST_EXTENDEDSELECT = 0,
40  TREELIST_SINGLESELECT = 0x00100000,
41  TREELIST_BROWSESELECT = 0x00200000,
42  TREELIST_MULTIPLESELECT = 0x00300000,
43  TREELIST_AUTOSELECT = 0x00400000,
44  TREELIST_SHOWS_LINES = 0x00800000,
45  TREELIST_SHOWS_BOXES = 0x01000000,
46  TREELIST_ROOT_BOXES = 0x02000000,
47  TREELIST_NORMAL = TREELIST_EXTENDEDSELECT
48  };
49 
50 
52 class FXAPI FXTreeItem : public FXObject {
53  FXDECLARE(FXTreeItem)
54  friend class FXTreeList;
55  friend class FXDirList;
56 protected:
57  FXTreeItem *parent; // Parent item
58  FXTreeItem *prev; // Previous item
59  FXTreeItem *next; // Next item
60  FXTreeItem *first; // First child item
61  FXTreeItem *last; // Last child item
62  FXString label; // Text of item
63  FXIcon *openIcon; // Icon of item
64  FXIcon *closedIcon; // Icon of item
65  FXptr data; // Item user data pointer
66  FXuint state; // Item state flags
67  FXint x,y;
68 private:
69  FXTreeItem(const FXTreeItem&);
70  FXTreeItem& operator=(const FXTreeItem&);
71 protected:
72  FXTreeItem():parent(nullptr),prev(nullptr),next(nullptr),first(nullptr),last(nullptr),openIcon(nullptr),closedIcon(nullptr),data(nullptr),state(0),x(0),y(0){}
73  virtual void draw(const FXTreeList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
74  virtual FXint hitItem(const FXTreeList* list,FXint x,FXint y) const;
75 public:
76  enum{
77  SELECTED = 1,
78  FOCUS = 2,
79  DISABLED = 4,
80  OPENED = 8,
81  EXPANDED = 16,
82  HASITEMS = 32,
83  DRAGGABLE = 64,
84  OPENICONOWNED = 128,
85  CLOSEDICONOWNED = 256
86  };
87 public:
88 
90  FXTreeItem(const FXString& text,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr):parent(nullptr),prev(nullptr),next(nullptr),first(nullptr),last(nullptr),label(text),openIcon(oi),closedIcon(ci),data(ptr),state(0),x(0),y(0){}
91 
93  FXTreeItem* getParent() const { return parent; }
94 
96  FXTreeItem* getNext() const { return next; }
97 
99  FXTreeItem* getPrev() const { return prev; }
100 
102  FXTreeItem* getFirst() const { return first; }
103 
105  FXTreeItem* getLast() const { return last; }
106 
108  FXTreeItem* getBelow() const;
109 
111  FXTreeItem* getAbove() const;
112 
114  FXint getNumChildren() const;
115 
117  virtual void setText(const FXString& txt);
118 
120  const FXString& getText() const { return label; }
121 
123  virtual void setOpenIcon(FXIcon* icn,FXbool owned=false);
124 
126  FXIcon* getOpenIcon() const { return openIcon; }
127 
129  virtual void setClosedIcon(FXIcon* icn,FXbool owned=false);
130 
132  FXIcon* getClosedIcon() const { return closedIcon; }
133 
135  void setData(FXptr ptr){ data=ptr; }
136 
138  FXptr getData() const { return data; }
139 
141  virtual void setFocus(FXbool focus);
142 
144  FXbool hasFocus() const { return (state&FOCUS)!=0; }
145 
147  virtual void setSelected(FXbool selected);
148 
150  FXbool isSelected() const { return (state&SELECTED)!=0; }
151 
153  virtual void setOpened(FXbool opened);
154 
156  FXbool isOpened() const { return (state&OPENED)!=0; }
157 
159  virtual void setExpanded(FXbool expanded);
160 
162  FXbool isExpanded() const { return (state&EXPANDED)!=0; }
163 
165  virtual void setEnabled(FXbool enabled);
166 
168  FXbool isEnabled() const { return (state&DISABLED)==0; }
169 
171  virtual void setDraggable(FXbool draggable);
172 
174  FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
175 
177  FXbool hasItems() const { return (state&HASITEMS)!=0; }
178 
180  void setHasItems(FXbool flag);
181 
183  FXbool isChildOf(const FXTreeItem* item) const;
184 
186  FXbool isParentOf(const FXTreeItem* item) const;
187 
189  virtual FXString getTipText() const;
190 
192  virtual FXint getWidth(const FXTreeList* list) const;
193 
195  virtual FXint getHeight(const FXTreeList* list) const;
196 
198  virtual void create();
199 
201  virtual void detach();
202 
204  virtual void destroy();
205 
207  virtual void save(FXStream& store) const;
208 
210  virtual void load(FXStream& store);
211 
213  virtual ~FXTreeItem();
214  };
215 
216 
217 
219 typedef FXint (*FXTreeListSortFunc)(const FXTreeItem*,const FXTreeItem*);
220 
221 
222 
243 class FXAPI FXTreeList : public FXScrollArea {
244  FXDECLARE(FXTreeList)
245 protected:
246  FXTreeItem *firstitem; // First root item
247  FXTreeItem *lastitem; // Last root item
248  FXTreeItem *anchoritem; // Selection anchor item
249  FXTreeItem *currentitem; // Current item
250  FXTreeItem *extentitem; // Selection extent
251  FXTreeItem *viewableitem; // Visible item
252  FXFont *font; // Font
253  FXTreeListSortFunc sortfunc; // Item sort function
254  FXColor textColor; // Text color
255  FXColor selbackColor; // Selected background color
256  FXColor seltextColor; // Selected text color
257  FXColor lineColor; // Line color
258  FXint treeWidth; // Tree width
259  FXint treeHeight; // Tree height
260  FXint visible; // Number of visible items
261  FXint indent; // Parent to child indentation
262  FXint grabx; // Grab point x
263  FXint graby; // Grab point y
264  FXString lookup; // Lookup string
265  FXString tip;
266  FXString help; // Help string
267  FXbool state; // State of item
268 protected:
269  FXTreeList();
270  virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,FXptr ptr);
271  void sort(FXTreeItem*& f1,FXTreeItem*& t1,FXTreeItem*& f2,FXTreeItem*& t2,int n);
272  void recompute();
273 private:
274  FXTreeList(const FXTreeList&);
275  FXTreeList& operator=(const FXTreeList&);
276 public:
277  long onPaint(FXObject*,FXSelector,void*);
278  long onEnter(FXObject*,FXSelector,void*);
279  long onLeave(FXObject*,FXSelector,void*);
280  long onUngrabbed(FXObject*,FXSelector,void*);
281  long onMotion(FXObject*,FXSelector,void*);
282  long onKeyPress(FXObject*,FXSelector,void*);
283  long onKeyRelease(FXObject*,FXSelector,void*);
284  long onLeftBtnPress(FXObject*,FXSelector,void*);
285  long onLeftBtnRelease(FXObject*,FXSelector,void*);
286  long onRightBtnPress(FXObject*,FXSelector,void*);
287  long onRightBtnRelease(FXObject*,FXSelector,void*);
288  long onQueryTip(FXObject*,FXSelector,void*);
289  long onQueryHelp(FXObject*,FXSelector,void*);
290  long onTipTimer(FXObject*,FXSelector,void*);
291  long onFocusIn(FXObject*,FXSelector,void*);
292  long onFocusOut(FXObject*,FXSelector,void*);
293  long onAutoScroll(FXObject*,FXSelector,void*);
294  long onClicked(FXObject*,FXSelector,void*);
295  long onDoubleClicked(FXObject*,FXSelector,void*);
296  long onTripleClicked(FXObject*,FXSelector,void*);
297  long onCommand(FXObject*,FXSelector,void*);
298  long onLookupTimer(FXObject*,FXSelector,void*);
299 public:
300  static FXint ascending(const FXTreeItem*,const FXTreeItem*);
301  static FXint descending(const FXTreeItem*,const FXTreeItem*);
302  static FXint ascendingCase(const FXTreeItem*,const FXTreeItem*);
303  static FXint descendingCase(const FXTreeItem*,const FXTreeItem*);
304 public:
305  enum {
306  ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
307  ID_LAST
308  };
309 public:
310 
312  FXTreeList(FXComposite *p,FXObject* tgt=nullptr,FXSelector sel=0,FXuint opts=TREELIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
313 
315  virtual void create();
316 
318  virtual void detach();
319 
321  virtual void layout();
322 
324  virtual FXint getDefaultWidth();
325 
327  virtual FXint getDefaultHeight();
328 
330  virtual FXint getContentWidth();
331 
333  virtual FXint getContentHeight();
334 
336  virtual void recalc();
337 
339  virtual FXbool canFocus() const;
340 
342  virtual void setFocus();
343 
345  virtual void killFocus();
346 
348  FXint getNumItems() const;
349 
351  FXint getNumVisible() const { return visible; }
352 
354  void setNumVisible(FXint nvis);
355 
357  FXTreeItem* getFirstItem() const { return firstitem; }
358 
360  FXTreeItem* getLastItem() const { return lastitem; }
361 
363  FXint fillItems(FXTreeItem* father,const FXchar *const *strings,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
364 
366  FXint fillItems(FXTreeItem* father,const FXString* strings,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
367 
369  FXint fillItems(FXTreeItem* father,const FXString& strings,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
370 
372  FXTreeItem* setItem(FXTreeItem* orig,FXTreeItem* item,FXbool notify=false);
373 
375  FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item,FXbool notify=false);
376 
378  FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,const FXString& text,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
379 
381  FXTreeItem* appendItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=false);
382 
384  FXTreeItem* appendItem(FXTreeItem* father,const FXString& text,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
385 
387  FXTreeItem* prependItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=false);
388 
390  FXTreeItem* prependItem(FXTreeItem* father,const FXString& text,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
391 
393  FXTreeItem *moveItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item);
394 
396  FXTreeItem* extractItem(FXTreeItem* item,FXbool notify=false);
397 
399  void removeItem(FXTreeItem* item,FXbool notify=false);
400 
402  void removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify=false);
403 
405  void clearItems(FXbool notify=false);
406 
408  FXint getItemWidth(const FXTreeItem* item) const { return item->getWidth(this); }
409 
411  FXint getItemHeight(const FXTreeItem* item) const { return item->getHeight(this); }
412 
414  virtual FXTreeItem* getItemAt(FXint x,FXint y) const;
415 
417  FXint hitItem(const FXTreeItem* item,FXint x,FXint y) const;
418 
420  virtual void makeItemVisible(FXTreeItem* item);
421 
432  FXTreeItem* findItem(const FXString& string,FXTreeItem* start=nullptr,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
433 
441  FXTreeItem* findItemByData(FXptr ptr,FXTreeItem* start=nullptr,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
442 
444  void setItemText(FXTreeItem* item,const FXString& text);
445 
447  FXString getItemText(const FXTreeItem* item) const;
448 
450  void setItemOpenIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=false);
451 
453  FXIcon* getItemOpenIcon(const FXTreeItem* item) const;
454 
456  void setItemClosedIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=false);
457 
459  FXIcon* getItemClosedIcon(const FXTreeItem* item) const;
460 
462  void setItemData(FXTreeItem* item,void* ptr) const;
463 
465  void* getItemData(const FXTreeItem* item) const;
466 
468  FXbool isItemSelected(const FXTreeItem* item) const;
469 
471  FXbool isItemCurrent(const FXTreeItem* item) const;
472 
474  FXbool isItemVisible(const FXTreeItem* item) const;
475 
477  FXbool isItemOpened(const FXTreeItem* item) const;
478 
480  FXbool isItemExpanded(const FXTreeItem* item) const;
481 
483  FXbool isItemLeaf(const FXTreeItem* item) const;
484 
486  FXbool isItemEnabled(const FXTreeItem* item) const;
487 
489  void updateItem(FXTreeItem* item) const;
490 
492  virtual FXbool enableItem(FXTreeItem* item);
493 
495  virtual FXbool disableItem(FXTreeItem* item);
496 
498  virtual FXbool selectItem(FXTreeItem* item,FXbool notify=false);
499 
501  virtual FXbool deselectItem(FXTreeItem* item,FXbool notify=false);
502 
504  virtual FXbool toggleItem(FXTreeItem* item,FXbool notify=false);
505 
507  virtual FXbool extendSelection(FXTreeItem* item,FXbool notify=false);
508 
510  virtual FXbool selectAll(FXbool notify=false);
511 
513  virtual FXbool killSelection(FXbool notify=false);
514 
516  virtual FXbool openItem(FXTreeItem* item,FXbool notify=false);
517 
519  virtual FXbool closeItem(FXTreeItem* item,FXbool notify=false);
520 
522  virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=false);
523 
525  virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=false);
526 
528  virtual void setCurrentItem(FXTreeItem* item,FXbool notify=false);
529 
531  FXTreeItem* getCurrentItem() const { return currentitem; }
532 
534  void setAnchorItem(FXTreeItem* item);
535 
537  FXTreeItem* getAnchorItem() const { return anchoritem; }
538 
540  void sortItems();
541 
543  void sortRootItems();
544 
546  void sortChildItems(FXTreeItem* item);
547 
549  FXTreeListSortFunc getSortFunc() const { return sortfunc; }
550 
552  void setSortFunc(FXTreeListSortFunc func){ sortfunc=func; }
553 
555  void setFont(FXFont* fnt);
556 
558  FXFont* getFont() const { return font; }
559 
561  void setIndent(FXint in);
562 
564  FXint getIndent() const { return indent; }
565 
567  FXColor getTextColor() const { return textColor; }
568 
570  void setTextColor(FXColor clr);
571 
573  FXColor getSelBackColor() const { return selbackColor; }
574 
576  void setSelBackColor(FXColor clr);
577 
579  FXColor getSelTextColor() const { return seltextColor; }
580 
582  void setSelTextColor(FXColor clr);
583 
585  FXColor getLineColor() const { return lineColor; }
586 
588  void setLineColor(FXColor clr);
589 
591  FXuint getListStyle() const;
592 
594  void setListStyle(FXuint style);
595 
597  void setHelpText(const FXString& text);
598 
600  const FXString& getHelpText() const { return help; }
601 
603  virtual void save(FXStream& store) const;
604 
606  virtual void load(FXStream& store);
607 
609  virtual ~FXTreeList();
610  };
611 
612 }
613 
614 #endif
FXIcon * getOpenIcon() const
Get open icon.
Definition: FXTreeList.h:126
const FXString & getText() const
Get item label.
Definition: FXTreeList.h:120
FXbool isExpanded() const
Return true if this item is expanded into sub items.
Definition: FXTreeList.h:162
FXTreeItem(const FXString &text, FXIcon *oi=nullptr, FXIcon *ci=nullptr, FXptr ptr=nullptr)
Constructor.
Definition: FXTreeList.h:90
const FXString & getHelpText() const
Get the status line help text for this list.
Definition: FXTreeList.h:600
Tree list Item.
Definition: FXTreeList.h:52
FXTreeListSortFunc getSortFunc() const
Return sort function.
Definition: FXTreeList.h:549
A Tree List Widget organizes items in a hierarchical, tree-like fashion.
Definition: FXTreeList.h:243
FXFont * getFont() const
Return text font.
Definition: FXTreeList.h:558
Base composite.
Definition: FXComposite.h:32
FXTreeItem * getNext() const
Get next sibling item.
Definition: FXTreeList.h:96
FXTreeItem * getFirst() const
Get first child item.
Definition: FXTreeList.h:102
FXint getItemWidth(const FXTreeItem *item) const
Return item width.
Definition: FXTreeList.h:408
FXint getNumVisible() const
Return number of visible items.
Definition: FXTreeList.h:351
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
FXbool isSelected() const
Return true if this item is selected.
Definition: FXTreeList.h:150
FXColor getSelTextColor() const
Return selected text color.
Definition: FXTreeList.h:579
FXTreeItem * getLast() const
Get last child item.
Definition: FXTreeList.h:105
virtual FXint getHeight(const FXTreeList *list) const
Return height of item as drawn in list.
FXTreeItem * getAnchorItem() const
Return anchor item, if any.
Definition: FXTreeList.h:537
Abstract Device Context.
Definition: FXDC.h:153
FXbool isOpened() const
Return true if this item is open.
Definition: FXTreeList.h:156
Definition: FX4Splitter.h:28
An Icon is an image with two additional server-side resources: a shape bitmap, which is used to mask ...
Definition: FXIcon.h:42
The scroll area widget manages a content area and a viewport area through which the content is viewed...
Definition: FXScrollArea.h:69
FXint getIndent() const
Return parent-child indent amount.
Definition: FXTreeList.h:564
FXColor getLineColor() const
Return line color.
Definition: FXTreeList.h:585
FXTreeItem * getPrev() const
Get previous sibling item.
Definition: FXTreeList.h:99
FXTreeItem * getCurrentItem() const
Return current item, if any.
Definition: FXTreeList.h:531
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:134
FXIcon * getClosedIcon() const
Get closed icon.
Definition: FXTreeList.h:132
FXTreeItem * getFirstItem() const
Return first root item.
Definition: FXTreeList.h:357
FXTreeItem * getParent() const
Get parent item.
Definition: FXTreeList.h:93
FXbool hasItems() const
Return true if subitems, real or imagined.
Definition: FXTreeList.h:177
FXColor getTextColor() const
Return normal text color.
Definition: FXTreeList.h:567
void setData(FXptr ptr)
Change item user data.
Definition: FXTreeList.h:135
void setSortFunc(FXTreeListSortFunc func)
Change sort function.
Definition: FXTreeList.h:552
A Directory List widget provides a tree-structured view of the file system.
Definition: FXDirList.h:124
FXbool isEnabled() const
Return true if this item is enabled.
Definition: FXTreeList.h:168
FXbool hasFocus() const
Return true if item has focus.
Definition: FXTreeList.h:144
FXptr getData() const
Get item user data.
Definition: FXTreeList.h:138
Font class.
Definition: FXFont.h:137
FXbool isDraggable() const
Return true if this item is draggable.
Definition: FXTreeList.h:174
FXColor getSelBackColor() const
Return selected text background.
Definition: FXTreeList.h:573
virtual FXint getWidth(const FXTreeList *list) const
Return width of item as drawn in list.
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42
FXTreeItem * getLastItem() const
Return last root item.
Definition: FXTreeList.h:360
FXint getItemHeight(const FXTreeItem *item) const
Return item height.
Definition: FXTreeList.h:411

Copyright © 1997-2022 Jeroen van der Zijp