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

FXList.h
1 /********************************************************************************
2 * *
3 * 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 FXLIST_H
22 #define FXLIST_H
23 
24 #ifndef FXSCROLLAREA_H
25 #include "FXScrollArea.h"
26 #endif
27 
28 namespace FX {
29 
30 
32 enum {
33  LIST_EXTENDEDSELECT = 0,
34  LIST_SINGLESELECT = 0x00100000,
35  LIST_BROWSESELECT = 0x00200000,
36  LIST_MULTIPLESELECT = 0x00300000,
37  LIST_AUTOSELECT = 0x00400000,
38  LIST_NORMAL = LIST_EXTENDEDSELECT
39  };
40 
41 
42 class FXIcon;
43 class FXFont;
44 class FXList;
45 
46 
48 class FXAPI FXListItem : public FXObject {
49  FXDECLARE(FXListItem)
50  friend class FXList;
51 protected:
52  FXString label;
53  FXIcon *icon;
54  FXptr data;
55  FXuint state;
56  FXint x,y;
57 private:
58  FXListItem(const FXListItem&);
59  FXListItem& operator=(const FXListItem&);
60 protected:
61  FXListItem():icon(NULL),data(NULL),state(0),x(0),y(0){}
62  virtual void draw(const FXList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
63  virtual FXint hitItem(const FXList* list,FXint x,FXint y) const;
64 public:
65  enum {
66  SELECTED = 1,
67  FOCUS = 2,
68  DISABLED = 4,
69  DRAGGABLE = 8,
70  ICONOWNED = 16
71  };
72 public:
73 
75  FXListItem(const FXString& text,FXIcon* ic=NULL,FXptr ptr=NULL):label(text),icon(ic),data(ptr),state(0),x(0),y(0){}
76 
78  virtual void setText(const FXString& txt);
79 
81  const FXString& getText() const { return label; }
82 
84  virtual void setIcon(FXIcon* icn,FXbool owned=false);
85 
87  FXIcon* getIcon() const { return icon; }
88 
90  void setData(FXptr ptr){ data=ptr; }
91 
93  FXptr getData() const { return data; }
94 
96  virtual void setFocus(FXbool focus);
97 
99  FXbool hasFocus() const { return (state&FOCUS)!=0; }
100 
102  virtual void setSelected(FXbool selected);
103 
105  FXbool isSelected() const { return (state&SELECTED)!=0; }
106 
108  virtual void setEnabled(FXbool enabled);
109 
111  FXbool isEnabled() const { return (state&DISABLED)==0; }
112 
114  virtual void setDraggable(FXbool draggable);
115 
117  FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
118 
120  virtual FXString getTipText() const;
121 
123  virtual FXint getWidth(const FXList* list) const;
124 
126  virtual FXint getHeight(const FXList* list) const;
127 
129  virtual void create();
130 
132  virtual void detach();
133 
135  virtual void destroy();
136 
138  virtual void save(FXStream& store) const;
139 
141  virtual void load(FXStream& store);
142 
144  virtual ~FXListItem();
145  };
146 
147 
149 typedef FXint (*FXListSortFunc)(const FXListItem*,const FXListItem*);
150 
151 
153 //extern template class FXAPI FXObjectListOf<FXListItem>;
154 
156 typedef FXObjectListOf<FXListItem> FXListItemList;
157 
158 
172 class FXAPI FXList : public FXScrollArea {
173  FXDECLARE(FXList)
174 protected:
175  FXListItemList items; // Item list
176  FXint anchor; // Anchor item
177  FXint current; // Current item
178  FXint extent; // Extent item
179  FXint viewable; // Viewable item
180  FXFont *font; // Font
181  FXColor textColor; // Text color
182  FXColor selbackColor; // Selected back color
183  FXColor seltextColor; // Selected text color
184  FXint listWidth; // List width
185  FXint listHeight; // List height
186  FXint visible; // Number of rows high
187  FXString help; // Help text
188  FXListSortFunc sortfunc; // Item sort function
189  FXint grabx; // Grab point x
190  FXint graby; // Grab point y
191  FXString lookup; // Lookup string
192  FXbool state; // State of item
193 protected:
194  FXList();
195  void recompute();
196  virtual FXListItem *createItem(const FXString& text,FXIcon* icon,FXptr ptr);
197 private:
198  FXList(const FXList&);
199  FXList &operator=(const FXList&);
200 public:
201  long onPaint(FXObject*,FXSelector,void*);
202  long onEnter(FXObject*,FXSelector,void*);
203  long onLeave(FXObject*,FXSelector,void*);
204  long onUngrabbed(FXObject*,FXSelector,void*);
205  long onKeyPress(FXObject*,FXSelector,void*);
206  long onKeyRelease(FXObject*,FXSelector,void*);
207  long onLeftBtnPress(FXObject*,FXSelector,void*);
208  long onLeftBtnRelease(FXObject*,FXSelector,void*);
209  long onRightBtnPress(FXObject*,FXSelector,void*);
210  long onRightBtnRelease(FXObject*,FXSelector,void*);
211  long onMotion(FXObject*,FXSelector,void*);
212  long onFocusIn(FXObject*,FXSelector,void*);
213  long onFocusOut(FXObject*,FXSelector,void*);
214  long onAutoScroll(FXObject*,FXSelector,void*);
215  long onClicked(FXObject*,FXSelector,void*);
216  long onDoubleClicked(FXObject*,FXSelector,void*);
217  long onTripleClicked(FXObject*,FXSelector,void*);
218  long onCommand(FXObject*,FXSelector,void*);
219  long onQueryTip(FXObject*,FXSelector,void*);
220  long onQueryHelp(FXObject*,FXSelector,void*);
221  long onTipTimer(FXObject*,FXSelector,void*);
222  long onLookupTimer(FXObject*,FXSelector,void*);
223  long onCmdSetValue(FXObject*,FXSelector,void*);public:
224  long onCmdGetIntValue(FXObject*,FXSelector,void*);
225  long onCmdSetIntValue(FXObject*,FXSelector,void*);
226 public:
227  static FXint ascending(const FXListItem* a,const FXListItem* b);
228  static FXint descending(const FXListItem* a,const FXListItem* b);
229  static FXint ascendingCase(const FXListItem* a,const FXListItem* b);
230  static FXint descendingCase(const FXListItem* a,const FXListItem* b);
231 public:
232  enum {
233  ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
234  ID_LAST
235  };
236 public:
237 
239  FXList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=LIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
240 
242  virtual void create();
243 
245  virtual void detach();
246 
248  virtual void layout();
249 
251  virtual FXint getDefaultWidth();
252 
254  virtual FXint getDefaultHeight();
255 
257  virtual FXint getContentWidth();
258 
260  virtual FXint getContentHeight();
261 
263  virtual void recalc();
264 
266  virtual FXbool canFocus() const;
267 
269  virtual void setFocus();
270 
272  virtual void killFocus();
273 
275  FXint getNumItems() const { return (FXint)items.no(); }
276 
278  FXint getNumVisible() const { return visible; }
279 
281  void setNumVisible(FXint nvis);
282 
284  FXListItem *getItem(FXint index) const;
285 
287  FXint setItem(FXint index,FXListItem* item,FXbool notify=false);
288 
290  FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXptr ptr=NULL,FXbool notify=false);
291 
293  FXint fillItems(const FXchar *const *strings,FXIcon *icon=NULL,FXptr ptr=NULL,FXbool notify=false);
294 
296  FXint fillItems(const FXString* strings,FXIcon *icon=NULL,FXptr ptr=NULL,FXbool notify=false);
297 
299  FXint fillItems(const FXString& strings,FXIcon *icon=NULL,FXptr ptr=NULL,FXbool notify=false);
300 
302  FXint insertItem(FXint index,FXListItem* item,FXbool notify=false);
303 
305  FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXptr ptr=NULL,FXbool notify=false);
306 
308  FXint appendItem(FXListItem* item,FXbool notify=false);
309 
311  FXint appendItem(const FXString& text,FXIcon *icon=NULL,FXptr ptr=NULL,FXbool notify=false);
312 
314  FXint prependItem(FXListItem* item,FXbool notify=false);
315 
317  FXint prependItem(const FXString& text,FXIcon *icon=NULL,FXptr ptr=NULL,FXbool notify=false);
318 
320  FXint moveItem(FXint newindex,FXint oldindex,FXbool notify=false);
321 
323  FXListItem* extractItem(FXint index,FXbool notify=false);
324 
326  void removeItem(FXint index,FXbool notify=false);
327 
329  void clearItems(FXbool notify=false);
330 
332  FXint getItemWidth(FXint index) const;
333 
335  FXint getItemHeight(FXint index) const;
336 
338  virtual FXint getItemAt(FXint x,FXint y) const;
339 
341  FXint hitItem(FXint index,FXint x,FXint y) const;
342 
344  virtual void makeItemVisible(FXint index);
345 
356  FXint findItem(const FXString& string,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
357 
365  FXint findItemByData(FXptr ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
366 
368  void setItemText(FXint index,const FXString& text);
369 
371  FXString getItemText(FXint index) const;
372 
374  void setItemIcon(FXint index,FXIcon* icon,FXbool owned=false);
375 
377  FXIcon* getItemIcon(FXint index) const;
378 
380  void setItemData(FXint index,FXptr ptr);
381 
383  FXptr getItemData(FXint index) const;
384 
386  FXbool isItemSelected(FXint index) const;
387 
389  FXbool isItemCurrent(FXint index) const;
390 
392  FXbool isItemVisible(FXint index) const;
393 
395  FXbool isItemEnabled(FXint index) const;
396 
398  void updateItem(FXint index) const;
399 
401  virtual FXbool enableItem(FXint index);
402 
404  virtual FXbool disableItem(FXint index);
405 
407  virtual FXbool selectItem(FXint index,FXbool notify=false);
408 
410  virtual FXbool deselectItem(FXint index,FXbool notify=false);
411 
413  virtual FXbool toggleItem(FXint index,FXbool notify=false);
414 
416  virtual FXbool extendSelection(FXint index,FXbool notify=false);
417 
419  virtual FXbool selectAll(FXbool notify=false);
420 
422  virtual FXbool killSelection(FXbool notify=false);
423 
425  virtual void setCurrentItem(FXint index,FXbool notify=false);
426 
428  FXint getCurrentItem() const { return current; }
429 
431  void setAnchorItem(FXint index);
432 
434  FXint getAnchorItem() const { return anchor; }
435 
437  void sortItems();
438 
440  FXListSortFunc getSortFunc() const { return sortfunc; }
441 
443  void setSortFunc(FXListSortFunc func){ sortfunc=func; }
444 
446  void setFont(FXFont* fnt);
447 
449  FXFont* getFont() const { return font; }
450 
452  FXColor getTextColor() const { return textColor; }
453 
455  void setTextColor(FXColor clr);
456 
458  FXColor getSelBackColor() const { return selbackColor; }
459 
461  void setSelBackColor(FXColor clr);
462 
464  FXColor getSelTextColor() const { return seltextColor; }
465 
467  void setSelTextColor(FXColor clr);
468 
470  FXuint getListStyle() const;
471 
473  void setListStyle(FXuint style);
474 
476  void setHelpText(const FXString& text);
477 
479  const FXString& getHelpText() const { return help; }
480 
482  virtual void save(FXStream& store) const;
483 
485  virtual void load(FXStream& store);
486 
488  virtual ~FXList();
489  };
490 
491 }
492 
493 #endif

Copyright © 1997-2016 Jeroen van der Zijp