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

FXFoldingList.h
1 /********************************************************************************
2 * *
3 * F o l d i n g L i s t W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2017 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 FXFOLDINGLIST_H
22 #define FXFOLDINGLIST_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 FXHeader;
34 class FXFoldingList;
35 
36 
38 enum {
39  FOLDINGLIST_EXTENDEDSELECT = 0,
40  FOLDINGLIST_SINGLESELECT = 0x00100000,
41  FOLDINGLIST_BROWSESELECT = 0x00200000,
42  FOLDINGLIST_MULTIPLESELECT = 0x00300000,
43  FOLDINGLIST_AUTOSELECT = 0x00400000,
44  FOLDINGLIST_SHOWS_LINES = 0x00800000,
45  FOLDINGLIST_SHOWS_BOXES = 0x01000000,
46  FOLDINGLIST_ROOT_BOXES = 0x02000000,
47  FOLDINGLIST_NORMAL = FOLDINGLIST_EXTENDEDSELECT
48  };
49 
50 
52 class FXAPI FXFoldingItem : public FXObject {
53  FXDECLARE(FXFoldingItem)
54  friend class FXFoldingList;
55  friend class FXDirList;
56 protected:
57  FXFoldingItem *parent;
58  FXFoldingItem *prev;
59  FXFoldingItem *next;
60  FXFoldingItem *first;
61  FXFoldingItem *last;
62  FXString label;
63  FXIcon *openIcon;
64  FXIcon *closedIcon;
65  FXptr data;
66  FXuint state;
67  FXint x,y;
68 private:
70  FXFoldingItem& operator=(const FXFoldingItem&);
71 protected:
72  FXFoldingItem():parent(NULL),prev(NULL),next(NULL),first(NULL),last(NULL),openIcon(NULL),closedIcon(NULL),data(NULL),state(0),x(0),y(0){}
73  virtual void draw(const FXFoldingList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
74  virtual FXint hitItem(const FXFoldingList* 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  FXFoldingItem(const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,FXptr 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){}
91 
93  FXFoldingItem* getParent() const { return parent; }
94 
96  FXFoldingItem* getNext() const { return next; }
97 
99  FXFoldingItem* getPrev() const { return prev; }
100 
102  FXFoldingItem* getFirst() const { return first; }
103 
105  FXFoldingItem* getLast() const { return last; }
106 
108  FXFoldingItem* getBelow() const;
109 
111  FXFoldingItem* 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 FXFoldingItem* item) const;
184 
186  FXbool isParentOf(const FXFoldingItem* item) const;
187 
189  virtual FXString getTipText() const;
190 
192  virtual FXint getWidth(const FXFoldingList* list) const;
193 
195  virtual FXint getHeight(const FXFoldingList* 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 ~FXFoldingItem();
214  };
215 
216 
217 
219 typedef FXint (*FXFoldingListSortFunc)(const FXFoldingItem*,const FXFoldingItem*);
220 
221 
222 
249 class FXAPI FXFoldingList : public FXScrollArea {
250  FXDECLARE(FXFoldingList)
251 protected:
252  FXHeader *header; // Tree header
253  FXFoldingItem *firstitem; // First root item
254  FXFoldingItem *lastitem; // Last root item
255  FXFoldingItem *anchoritem; // Selection anchor item
256  FXFoldingItem *currentitem; // Current item
257  FXFoldingItem *extentitem; // Selection extent
258  FXFoldingItem *viewableitem; // Viewable item
259  FXFont *font; // Font
260  FXFoldingListSortFunc sortfunc; // Item sort function
261  FXColor textColor; // Text color
262  FXColor selbackColor; // Selected background color
263  FXColor seltextColor; // Selected text color
264  FXColor lineColor; // Line color
265  FXint treeWidth; // Tree width
266  FXint treeHeight; // Tree height
267  FXint visible; // Number of visible items
268  FXint indent; // Parent to child indentation
269  FXint grabx; // Grab point x
270  FXint graby; // Grab point y
271  FXString lookup; // Lookup string
272  FXString help; // Help string
273  FXbool state; // State of item
274 protected:
275  FXFoldingList();
276  void recompute();
277  void mergesort(FXFoldingItem*& list);
278  void sort(FXFoldingItem*& f1,FXFoldingItem*& t1,FXFoldingItem*& f2,FXFoldingItem*& t2,int n);
279  virtual void moveContents(FXint x,FXint y);
280  virtual FXFoldingItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,FXptr ptr);
281  static FXint compareSection(const FXchar *p,const FXchar* q,FXint s);
282  static FXint compareSectionCase(const FXchar *p,const FXchar* q,FXint s);
283 private:
285  FXFoldingList& operator=(const FXFoldingList&);
286 public:
287  long onPaint(FXObject*,FXSelector,void*);
288  long onEnter(FXObject*,FXSelector,void*);
289  long onLeave(FXObject*,FXSelector,void*);
290  long onUngrabbed(FXObject*,FXSelector,void*);
291  long onMotion(FXObject*,FXSelector,void*);
292  long onKeyPress(FXObject*,FXSelector,void*);
293  long onKeyRelease(FXObject*,FXSelector,void*);
294  long onLeftBtnPress(FXObject*,FXSelector,void*);
295  long onLeftBtnRelease(FXObject*,FXSelector,void*);
296  long onRightBtnPress(FXObject*,FXSelector,void*);
297  long onRightBtnRelease(FXObject*,FXSelector,void*);
298  long onChgHeader(FXObject*,FXSelector,void*);
299  long onQueryTip(FXObject*,FXSelector,void*);
300  long onQueryHelp(FXObject*,FXSelector,void*);
301  long onTipTimer(FXObject*,FXSelector,void*);
302  long onFocusIn(FXObject*,FXSelector,void*);
303  long onFocusOut(FXObject*,FXSelector,void*);
304  long onAutoScroll(FXObject*,FXSelector,void*);
305  long onClicked(FXObject*,FXSelector,void*);
306  long onDoubleClicked(FXObject*,FXSelector,void*);
307  long onTripleClicked(FXObject*,FXSelector,void*);
308  long onCommand(FXObject*,FXSelector,void*);
309  long onLookupTimer(FXObject*,FXSelector,void*);
310 public:
311  static FXint ascending(const FXFoldingItem*,const FXFoldingItem*);
312  static FXint descending(const FXFoldingItem*,const FXFoldingItem*);
313  static FXint ascendingCase(const FXFoldingItem*,const FXFoldingItem*);
314  static FXint descendingCase(const FXFoldingItem*,const FXFoldingItem*);
315 public:
316  enum {
317  ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
318  ID_HEADER,
319  ID_LAST
320  };
321 public:
322 
324  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);
325 
327  virtual void create();
328 
330  virtual void detach();
331 
333  virtual void layout();
334 
336  virtual FXint getDefaultWidth();
337 
339  virtual FXint getDefaultHeight();
340 
342  virtual FXint getVisibleY() const;
343 
345  virtual FXint getVisibleHeight() const;
346 
348  virtual FXint getContentWidth();
349 
351  virtual FXint getContentHeight();
352 
354  virtual void recalc();
355 
357  virtual FXbool canFocus() const;
358 
360  virtual void setFocus();
361 
363  virtual void killFocus();
364 
366  FXHeader* getHeader() const { return header; }
367 
369  void setHeaders(const FXchar *const *strings,FXint size=1);
370 
372  void setHeaders(const FXString* strings,FXint size=1);
373 
375  void setHeaders(const FXString& strings,FXint size=1);
376 
378  void appendHeader(const FXString& text,FXIcon *icon=NULL,FXint size=1);
379 
381  void removeHeader(FXint index);
382 
384  void setHeaderText(FXint index,const FXString& text);
385 
387  FXString getHeaderText(FXint index) const;
388 
390  void setHeaderIcon(FXint index,FXIcon *icon);
391 
393  FXIcon* getHeaderIcon(FXint index) const;
394 
396  void setHeaderSize(FXint index,FXint size);
397 
399  FXint getHeaderSize(FXint index) const;
400 
402  FXint getNumHeaders() const;
403 
405  FXint getNumItems() const;
406 
408  FXint getNumVisible() const { return visible; }
409 
411  void setNumVisible(FXint nvis);
412 
414  FXFoldingItem* getFirstItem() const { return firstitem; }
415 
417  FXFoldingItem* getLastItem() const { return lastitem; }
418 
420  FXint fillItems(FXFoldingItem* father,const FXchar *const *strings,FXIcon* oi=NULL,FXIcon* ci=NULL,FXptr ptr=NULL,FXbool notify=false);
421 
423  FXint fillItems(FXFoldingItem* father,const FXString* strings,FXIcon* oi=NULL,FXIcon* ci=NULL,FXptr ptr=NULL,FXbool notify=false);
424 
426  FXint fillItems(FXFoldingItem* father,const FXString& strings,FXIcon* oi=NULL,FXIcon* ci=NULL,FXptr ptr=NULL,FXbool notify=false);
427 
429  FXFoldingItem* setItem(FXFoldingItem* orig,FXFoldingItem* item,FXbool notify=false);
430 
432  FXFoldingItem* insertItem(FXFoldingItem* other,FXFoldingItem* father,FXFoldingItem* item,FXbool notify=false);
433 
435  FXFoldingItem* insertItem(FXFoldingItem* other,FXFoldingItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,FXptr ptr=NULL,FXbool notify=false);
436 
438  FXFoldingItem* appendItem(FXFoldingItem* father,FXFoldingItem* item,FXbool notify=false);
439 
441  FXFoldingItem* appendItem(FXFoldingItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,FXptr ptr=NULL,FXbool notify=false);
442 
444  FXFoldingItem* prependItem(FXFoldingItem* father,FXFoldingItem* item,FXbool notify=false);
445 
447  FXFoldingItem* prependItem(FXFoldingItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,FXptr ptr=NULL,FXbool notify=false);
448 
450  FXFoldingItem *moveItem(FXFoldingItem* other,FXFoldingItem* father,FXFoldingItem* item);
451 
453  FXFoldingItem* extractItem(FXFoldingItem* item,FXbool notify=false);
454 
456  void removeItem(FXFoldingItem* item,FXbool notify=false);
457 
459  void removeItems(FXFoldingItem* fm,FXFoldingItem* to,FXbool notify=false);
460 
462  void clearItems(FXbool notify=false);
463 
465  FXint getItemWidth(const FXFoldingItem* item) const { return item->getWidth(this); }
466 
468  FXint getItemHeight(const FXFoldingItem* item) const { return item->getHeight(this); }
469 
471  virtual FXFoldingItem* getItemAt(FXint x,FXint y) const;
472 
474  FXint hitItem(const FXFoldingItem* item,FXint x,FXint y) const;
475 
477  virtual void makeItemVisible(FXFoldingItem* item);
478 
489  FXFoldingItem* findItem(const FXString& text,FXFoldingItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
490 
498  FXFoldingItem* findItemByData(FXptr ptr,FXFoldingItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
499 
501  void setItemText(FXFoldingItem* item,const FXString& text);
502 
504  FXString getItemText(const FXFoldingItem* item) const;
505 
507  void setItemOpenIcon(FXFoldingItem* item,FXIcon* icon,FXbool owned=false);
508 
510  FXIcon* getItemOpenIcon(const FXFoldingItem* item) const;
511 
513  void setItemClosedIcon(FXFoldingItem* item,FXIcon* icon,FXbool owned=false);
514 
516  FXIcon* getItemClosedIcon(const FXFoldingItem* item) const;
517 
519  void setItemData(FXFoldingItem* item,FXptr ptr) const;
520 
522  FXptr getItemData(const FXFoldingItem* item) const;
523 
525  FXbool isItemSelected(const FXFoldingItem* item) const;
526 
528  FXbool isItemCurrent(const FXFoldingItem* item) const;
529 
531  FXbool isItemVisible(const FXFoldingItem* item) const;
532 
534  FXbool isItemOpened(const FXFoldingItem* item) const;
535 
537  FXbool isItemExpanded(const FXFoldingItem* item) const;
538 
540  FXbool isItemLeaf(const FXFoldingItem* item) const;
541 
543  FXbool isItemEnabled(const FXFoldingItem* item) const;
544 
546  void updateItem(FXFoldingItem* item);
547 
549  virtual FXbool enableItem(FXFoldingItem* item);
550 
552  virtual FXbool disableItem(FXFoldingItem* item);
553 
555  virtual FXbool selectItem(FXFoldingItem* item,FXbool notify=false);
556 
558  virtual FXbool deselectItem(FXFoldingItem* item,FXbool notify=false);
559 
561  virtual FXbool toggleItem(FXFoldingItem* item,FXbool notify=false);
562 
564  virtual FXbool extendSelection(FXFoldingItem* item,FXbool notify=false);
565 
567  virtual FXbool selectAll(FXbool notify=false);
568 
570  virtual FXbool killSelection(FXbool notify=false);
571 
573  virtual FXbool openItem(FXFoldingItem* item,FXbool notify=false);
574 
576  virtual FXbool closeItem(FXFoldingItem* item,FXbool notify=false);
577 
579  virtual FXbool collapseTree(FXFoldingItem* tree,FXbool notify=false);
580 
582  virtual FXbool expandTree(FXFoldingItem* tree,FXbool notify=false);
583 
585  virtual void setCurrentItem(FXFoldingItem* item,FXbool notify=false);
586 
588  FXFoldingItem* getCurrentItem() const { return currentitem; }
589 
591  void setAnchorItem(FXFoldingItem* item);
592 
594  FXFoldingItem* getAnchorItem() const { return anchoritem; }
595 
597  void sortItems();
598 
600  void sortRootItems();
601 
603  void sortChildItems(FXFoldingItem* item);
604 
606  FXFoldingListSortFunc getSortFunc() const { return sortfunc; }
607 
609  void setSortFunc(FXFoldingListSortFunc func){ sortfunc=func; }
610 
612  void setFont(FXFont* fnt);
613 
615  FXFont* getFont() const { return font; }
616 
618  void setIndent(FXint in);
619 
621  FXint getIndent() const { return indent; }
622 
624  FXColor getTextColor() const { return textColor; }
625 
627  void setTextColor(FXColor clr);
628 
630  FXColor getSelBackColor() const { return selbackColor; }
631 
633  void setSelBackColor(FXColor clr);
634 
636  FXColor getSelTextColor() const { return seltextColor; }
637 
639  void setSelTextColor(FXColor clr);
640 
642  FXColor getLineColor() const { return lineColor; }
643 
645  void setLineColor(FXColor clr);
646 
648  FXuint getListStyle() const;
649 
651  void setListStyle(FXuint style);
652 
654  void setHelpText(const FXString& text);
655 
657  const FXString& getHelpText() const { return help; }
658 
660  virtual void save(FXStream& store) const;
661 
663  virtual void load(FXStream& store);
664 
666  virtual ~FXFoldingList();
667  };
668 
669 }
670 
671 
672 #endif

Copyright © 1997-2016 Jeroen van der Zijp