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,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 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(nullptr),data(nullptr),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=nullptr,FXptr ptr=nullptr):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 typedef FXObjectListOf<FXListItem> FXListItemList;
154 
155 
169 class FXAPI FXList : public FXScrollArea {
170  FXDECLARE(FXList)
171 protected:
172  FXListItemList items; // Item list
173  FXint anchor; // Anchor item
174  FXint current; // Current item
175  FXint extent; // Extent item
176  FXint viewable; // Viewable item
177  FXFont *font; // Font
178  FXColor textColor; // Text color
179  FXColor selbackColor; // Selected back color
180  FXColor seltextColor; // Selected text color
181  FXint listWidth; // List width
182  FXint listHeight; // List height
183  FXint visible; // Number of rows high
184  FXString help; // Help text
185  FXListSortFunc sortfunc; // Item sort function
186  FXint grabx; // Grab point x
187  FXint graby; // Grab point y
188  FXString lookup; // Lookup string
189  FXbool state; // State of item
190 protected:
191  FXList();
192  void recompute();
193  virtual FXListItem *createItem(const FXString& text,FXIcon* icon,FXptr ptr);
194 private:
195  FXList(const FXList&);
196  FXList &operator=(const FXList&);
197 public:
198  long onPaint(FXObject*,FXSelector,void*);
199  long onEnter(FXObject*,FXSelector,void*);
200  long onLeave(FXObject*,FXSelector,void*);
201  long onUngrabbed(FXObject*,FXSelector,void*);
202  long onKeyPress(FXObject*,FXSelector,void*);
203  long onKeyRelease(FXObject*,FXSelector,void*);
204  long onLeftBtnPress(FXObject*,FXSelector,void*);
205  long onLeftBtnRelease(FXObject*,FXSelector,void*);
206  long onRightBtnPress(FXObject*,FXSelector,void*);
207  long onRightBtnRelease(FXObject*,FXSelector,void*);
208  long onMotion(FXObject*,FXSelector,void*);
209  long onFocusIn(FXObject*,FXSelector,void*);
210  long onFocusOut(FXObject*,FXSelector,void*);
211  long onAutoScroll(FXObject*,FXSelector,void*);
212  long onClicked(FXObject*,FXSelector,void*);
213  long onDoubleClicked(FXObject*,FXSelector,void*);
214  long onTripleClicked(FXObject*,FXSelector,void*);
215  long onCommand(FXObject*,FXSelector,void*);
216  long onQueryTip(FXObject*,FXSelector,void*);
217  long onQueryHelp(FXObject*,FXSelector,void*);
218  long onTipTimer(FXObject*,FXSelector,void*);
219  long onLookupTimer(FXObject*,FXSelector,void*);
220  long onCmdSetValue(FXObject*,FXSelector,void*);public:
221  long onCmdGetIntValue(FXObject*,FXSelector,void*);
222  long onCmdSetIntValue(FXObject*,FXSelector,void*);
223 public:
224  static FXint ascending(const FXListItem* a,const FXListItem* b);
225  static FXint descending(const FXListItem* a,const FXListItem* b);
226  static FXint ascendingCase(const FXListItem* a,const FXListItem* b);
227  static FXint descendingCase(const FXListItem* a,const FXListItem* b);
228 public:
229  enum {
230  ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
231  ID_LAST
232  };
233 public:
234 
236  FXList(FXComposite *p,FXObject* tgt=nullptr,FXSelector sel=0,FXuint opts=LIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
237 
239  virtual void create();
240 
242  virtual void detach();
243 
245  virtual void layout();
246 
248  virtual FXint getDefaultWidth();
249 
251  virtual FXint getDefaultHeight();
252 
254  virtual FXint getContentWidth();
255 
257  virtual FXint getContentHeight();
258 
260  virtual void recalc();
261 
263  virtual FXbool canFocus() const;
264 
266  virtual void setFocus();
267 
269  virtual void killFocus();
270 
272  FXint getNumItems() const { return (FXint)items.no(); }
273 
275  FXint getNumVisible() const { return visible; }
276 
278  void setNumVisible(FXint nvis);
279 
281  FXListItem *getItem(FXint index) const;
282 
284  FXint setItem(FXint index,FXListItem* item,FXbool notify=false);
285 
287  FXint setItem(FXint index,const FXString& text,FXIcon *icon=nullptr,FXptr ptr=nullptr,FXbool notify=false);
288 
290  FXint fillItems(const FXchar *const *strings,FXIcon *icon=nullptr,FXptr ptr=nullptr,FXbool notify=false);
291 
293  FXint fillItems(const FXString* strings,FXIcon *icon=nullptr,FXptr ptr=nullptr,FXbool notify=false);
294 
296  FXint fillItems(const FXString& strings,FXIcon *icon=nullptr,FXptr ptr=nullptr,FXbool notify=false);
297 
299  FXint insertItem(FXint index,FXListItem* item,FXbool notify=false);
300 
302  FXint insertItem(FXint index,const FXString& text,FXIcon *icon=nullptr,FXptr ptr=nullptr,FXbool notify=false);
303 
305  FXint appendItem(FXListItem* item,FXbool notify=false);
306 
308  FXint appendItem(const FXString& text,FXIcon *icon=nullptr,FXptr ptr=nullptr,FXbool notify=false);
309 
311  FXint prependItem(FXListItem* item,FXbool notify=false);
312 
314  FXint prependItem(const FXString& text,FXIcon *icon=nullptr,FXptr ptr=nullptr,FXbool notify=false);
315 
317  FXint moveItem(FXint newindex,FXint oldindex,FXbool notify=false);
318 
320  FXListItem* extractItem(FXint index,FXbool notify=false);
321 
323  void removeItem(FXint index,FXbool notify=false);
324 
326  void clearItems(FXbool notify=false);
327 
329  FXint getItemWidth(FXint index) const;
330 
332  FXint getItemHeight(FXint index) const;
333 
335  virtual FXint getItemAt(FXint x,FXint y) const;
336 
338  FXint hitItem(FXint index,FXint x,FXint y) const;
339 
341  virtual void makeItemVisible(FXint index);
342 
353  FXint findItem(const FXString& string,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
354 
362  FXint findItemByData(FXptr ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
363 
365  void setItemText(FXint index,const FXString& text);
366 
368  FXString getItemText(FXint index) const;
369 
371  void setItemIcon(FXint index,FXIcon* icon,FXbool owned=false);
372 
374  FXIcon* getItemIcon(FXint index) const;
375 
377  void setItemData(FXint index,FXptr ptr);
378 
380  FXptr getItemData(FXint index) const;
381 
383  FXbool isItemSelected(FXint index) const;
384 
386  FXbool isItemCurrent(FXint index) const;
387 
389  FXbool isItemVisible(FXint index) const;
390 
392  FXbool isItemEnabled(FXint index) const;
393 
395  void updateItem(FXint index) const;
396 
398  virtual FXbool enableItem(FXint index);
399 
401  virtual FXbool disableItem(FXint index);
402 
404  virtual FXbool selectItem(FXint index,FXbool notify=false);
405 
407  virtual FXbool deselectItem(FXint index,FXbool notify=false);
408 
410  virtual FXbool toggleItem(FXint index,FXbool notify=false);
411 
413  virtual FXbool extendSelection(FXint index,FXbool notify=false);
414 
416  virtual FXbool selectAll(FXbool notify=false);
417 
419  virtual FXbool killSelection(FXbool notify=false);
420 
422  virtual void setCurrentItem(FXint index,FXbool notify=false);
423 
425  FXint getCurrentItem() const { return current; }
426 
428  void setAnchorItem(FXint index);
429 
431  FXint getAnchorItem() const { return anchor; }
432 
434  void sortItems();
435 
437  FXListSortFunc getSortFunc() const { return sortfunc; }
438 
440  void setSortFunc(FXListSortFunc func){ sortfunc=func; }
441 
443  void setFont(FXFont* fnt);
444 
446  FXFont* getFont() const { return font; }
447 
449  FXColor getTextColor() const { return textColor; }
450 
452  void setTextColor(FXColor clr);
453 
455  FXColor getSelBackColor() const { return selbackColor; }
456 
458  void setSelBackColor(FXColor clr);
459 
461  FXColor getSelTextColor() const { return seltextColor; }
462 
464  void setSelTextColor(FXColor clr);
465 
467  FXuint getListStyle() const;
468 
470  void setListStyle(FXuint style);
471 
473  void setHelpText(const FXString& text);
474 
476  const FXString& getHelpText() const { return help; }
477 
479  virtual void save(FXStream& store) const;
480 
482  virtual void load(FXStream& store);
483 
485  virtual ~FXList();
486  };
487 
488 }
489 
490 #endif
FXColor getTextColor() const
Return normal text color.
Definition: FXList.h:449
FXbool isEnabled() const
Return true if this item is enabled.
Definition: FXList.h:111
FXint getAnchorItem() const
Return anchor item, if any.
Definition: FXList.h:431
FXListItem(const FXString &text, FXIcon *ic=nullptr, FXptr ptr=nullptr)
Construct new item with given text, icon, and user-data.
Definition: FXList.h:75
FXColor getSelTextColor() const
Return selected text color.
Definition: FXList.h:461
FXbool isSelected() const
Return true if this item is selected.
Definition: FXList.h:105
FXint getNumItems() const
Return the number of items in the list.
Definition: FXList.h:272
FXptr getData() const
Get item&#39;s user data.
Definition: FXList.h:93
Base composite.
Definition: FXComposite.h:32
void setSortFunc(FXListSortFunc func)
Change sort function.
Definition: FXList.h:440
FXint getCurrentItem() const
Return current item, if any.
Definition: FXList.h:425
FXbool isDraggable() const
Return true if this item is draggable.
Definition: FXList.h:117
FXColor getSelBackColor() const
Return selected text background.
Definition: FXList.h:455
void setData(FXptr ptr)
Change item&#39;s user data.
Definition: FXList.h:90
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
Abstract Device Context.
Definition: FXDC.h:153
FXFont * getFont() const
Return text font.
Definition: FXList.h:446
A List Widget displays a list of items, each with a text and optional icon.
Definition: FXList.h:169
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
FXIcon * getIcon() const
Return item&#39;s icon.
Definition: FXList.h:87
FXival no() const
Return number of objects.
Definition: FXObjectList.h:59
The scroll area widget manages a content area and a viewport area through which the content is viewed...
Definition: FXScrollArea.h:69
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:134
List item.
Definition: FXList.h:48
const FXString & getHelpText() const
Get the status line help text for this list.
Definition: FXList.h:476
FXint getNumVisible() const
Return number of visible items.
Definition: FXList.h:275
const FXString & getText() const
Return item&#39;s text label.
Definition: FXList.h:81
Font class.
Definition: FXFont.h:137
FXbool hasFocus() const
Return true if item has focus.
Definition: FXList.h:99
FXListSortFunc getSortFunc() const
Return sort function.
Definition: FXList.h:437
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp