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

FXList.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * L i s t W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (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 GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXList.h,v 1.88.2.2 2006/11/17 16:02:31 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXLIST_H
25 #define FXLIST_H
26 
27 #ifndef FXSCROLLAREA_H
28 #include "FXScrollArea.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /// List styles
35 enum {
36  LIST_EXTENDEDSELECT = 0, /// Extended selection mode allows for drag-selection of ranges of items
37  LIST_SINGLESELECT = 0x00100000, /// Single selection mode allows up to one item to be selected
38  LIST_BROWSESELECT = 0x00200000, /// Browse selection mode enforces one single item to be selected at all times
39  LIST_MULTIPLESELECT = 0x00300000, /// Multiple selection mode is used for selection of individual items
40  LIST_AUTOSELECT = 0x00400000, /// Automatically select under cursor
42  };
43 
44 
45 class FXIcon;
46 class FXFont;
47 class FXList;
48 
49 
50 /// List item
51 class FXAPI FXListItem : public FXObject {
53  friend class FXList;
54 protected:
55  FXString label;
56  FXIcon *icon;
57  void *data;
58  FXuint state;
59  FXint x,y;
60 private:
62  FXListItem& operator=(const FXListItem&);
63 protected:
64  FXListItem():icon(NULL),data(NULL),state(0),x(0),y(0){}
65  virtual void draw(const FXList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h);
66  virtual FXint hitItem(const FXList* list,FXint x,FXint y) const;
67 public:
68  enum {
69  SELECTED = 1, /// Selected
70  FOCUS = 2, /// Focus
71  DISABLED = 4, /// Disabled
72  DRAGGABLE = 8, /// Draggable
73  ICONOWNED = 16 /// Icon owned by item
74  };
75 public:
76 
77  /// Construct new item with given text, icon, and user-data
78  FXListItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL):label(text),icon(ic),data(ptr),state(0),x(0),y(0){}
79 
80  /// Change item's text label
81  virtual void setText(const FXString& txt);
82 
83  /// Return item's text label
84  const FXString& getText() const { return label; }
85 
86  /// Change item's icon, deleting the old icon if it was owned
87  virtual void setIcon(FXIcon* icn,FXbool owned=FALSE);
88 
89  /// Return item's icon
90  FXIcon* getIcon() const { return icon; }
91 
92  /// Change item's user data
93  void setData(void* ptr){ data=ptr; }
94 
95  /// Get item's user data
96  void* getData() const { return data; }
97 
98  /// Make item draw as focused
99  virtual void setFocus(FXbool focus);
100 
101  /// Return true if item has focus
102  FXbool hasFocus() const { return (state&FOCUS)!=0; }
104  /// Select item
105  virtual void setSelected(FXbool selected);
106 
107  /// Return true if this item is selected
108  FXbool isSelected() const { return (state&SELECTED)!=0; }
110  /// Enable or disable item
111  virtual void setEnabled(FXbool enabled);
112 
113  /// Return true if this item is enabled
114  FXbool isEnabled() const { return (state&DISABLED)==0; }
116  /// Make item draggable
117  virtual void setDraggable(FXbool draggable);
118 
119  /// Return true if this item is draggable
120  FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
121 
122  /// Return width of item as drawn in list
123  virtual FXint getWidth(const FXList* list) const;
124 
125  /// Return height of item as drawn in list
126  virtual FXint getHeight(const FXList* list) const;
127 
128  /// Create server-side resources
129  virtual void create();
130 
131  /// Detach server-side resources
132  virtual void detach();
133 
134  /// Destroy server-side resources
135  virtual void destroy();
136 
137  /// Save to stream
138  virtual void save(FXStream& store) const;
139 
140  /// Load from stream
141  virtual void load(FXStream& store);
142 
143  /// Destroy item and free icons if owned
144  virtual ~FXListItem();
145  };
146 
147 
148 /// List item collate function
149 typedef FXint (*FXListSortFunc)(const FXListItem*,const FXListItem*);
150 
151 
152 /// List of FXListItem's
154 
155 
156 /**
157 * A List Widget displays a list of items, each with a text and
158 * optional icon. When an item's selected state changes, the list sends
159 * a SEL_SELECTED or SEL_DESELECTED message. A change of the current
160 * item is signified by the SEL_CHANGED message.
161 * The list sends SEL_COMMAND messages when the user clicks on an item,
162 * and SEL_CLICKED, SEL_DOUBLECLICKED, and SEL_TRIPLECLICKED when the user
163 * clicks once, twice, or thrice, respectively.
164 * When items are added, replaced, or removed, the list sends messages of
165 * the type SEL_INSERTED, SEL_REPLACED, or SEL_DELETED.
166 * In each of these cases, the index to the item, if any, is passed in the
167 * 3rd argument of the message.
168 */
169 class FXAPI FXList : public FXScrollArea {
171 protected:
172  FXListItemList items; // Item list
173  FXint anchor; // Anchor item
174  FXint current; // Current item
175  FXint extent; // Extent item
176  FXint cursor; // Cursor item
177  FXint viewable; // Viewable item
178  FXFont *font; // Font
179  FXColor textColor; // Text color
180  FXColor selbackColor; // Selected back color
181  FXColor seltextColor; // Selected text color
182  FXint listWidth; // List width
183  FXint listHeight; // List height
184  FXint visible; // Number of rows high
185  FXString help; // Help text
186  FXListSortFunc sortfunc; // Item sort function
187  FXint grabx; // Grab point x
188  FXint graby; // Grab point y
189  FXString lookup; // Lookup string
190  FXbool state; // State of item
191 protected:
192  FXList();
193  void recompute();
194  virtual FXListItem *createItem(const FXString& text,FXIcon* icon,void* ptr);
195 private:
196  FXList(const FXList&);
197  FXList &operator=(const FXList&);
198 public:
199  long onPaint(FXObject*,FXSelector,void*);
200  long onEnter(FXObject*,FXSelector,void*);
201  long onLeave(FXObject*,FXSelector,void*);
202  long onUngrabbed(FXObject*,FXSelector,void*);
203  long onKeyPress(FXObject*,FXSelector,void*);
204  long onKeyRelease(FXObject*,FXSelector,void*);
205  long onLeftBtnPress(FXObject*,FXSelector,void*);
206  long onLeftBtnRelease(FXObject*,FXSelector,void*);
207  long onRightBtnPress(FXObject*,FXSelector,void*);
208  long onRightBtnRelease(FXObject*,FXSelector,void*);
209  long onMotion(FXObject*,FXSelector,void*);
210  long onFocusIn(FXObject*,FXSelector,void*);
211  long onFocusOut(FXObject*,FXSelector,void*);
212  long onAutoScroll(FXObject*,FXSelector,void*);
213  long onClicked(FXObject*,FXSelector,void*);
214  long onDoubleClicked(FXObject*,FXSelector,void*);
215  long onTripleClicked(FXObject*,FXSelector,void*);
216  long onCommand(FXObject*,FXSelector,void*);
217  long onQueryTip(FXObject*,FXSelector,void*);
218  long onQueryHelp(FXObject*,FXSelector,void*);
219  long onTipTimer(FXObject*,FXSelector,void*);
220  long onLookupTimer(FXObject*,FXSelector,void*);
221  long onCmdSetValue(FXObject*,FXSelector,void*);public:
222  long onCmdGetIntValue(FXObject*,FXSelector,void*);
223  long onCmdSetIntValue(FXObject*,FXSelector,void*);
224 public:
225  static FXint ascending(const FXListItem* a,const FXListItem* b);
226  static FXint descending(const FXListItem* a,const FXListItem* b);
227  static FXint ascendingCase(const FXListItem* a,const FXListItem* b);
228  static FXint descendingCase(const FXListItem* a,const FXListItem* b);
229 public:
230  enum {
231  ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
232  ID_LAST
233  };
234 public:
235 
236  /// Construct a list with initially no items in it
237  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);
238 
239  /// Create server-side resources
240  virtual void create();
241 
242  /// Detach server-side resources
243  virtual void detach();
244 
245  /// Perform layout
246  virtual void layout();
247 
248  /// Return default width
249  virtual FXint getDefaultWidth();
250 
251  /// Return default height
252  virtual FXint getDefaultHeight();
253 
254  /// Compute and return content width
255  virtual FXint getContentWidth();
256 
257  /// Return content height
258  virtual FXint getContentHeight();
259 
260  /// Recalculate layout
261  virtual void recalc();
262 
263  /// List widget can receive focus
264  virtual bool canFocus() const;
265 
266  /// Move the focus to this window
267  virtual void setFocus();
268 
269  /// Remove the focus from this window
270  virtual void killFocus();
271 
272  /// Return the number of items in the list
273  FXint getNumItems() const { return items.no(); }
274 
275  /// Return number of visible items
276  FXint getNumVisible() const { return visible; }
277 
278  /// Change the number of visible items
279  void setNumVisible(FXint nvis);
280 
281  /// Return the item at the given index
282  FXListItem *getItem(FXint index) const;
283 
284  /// Replace the item with a [possibly subclassed] item
285  FXint setItem(FXint index,FXListItem* item,FXbool notify=FALSE);
286 
287  /// Replace items text, icon, and user-data pointer
288  FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
289 
290  /// Fill list by appending items from array of strings
291  FXint fillItems(const FXchar** strings,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
292 
293  /// Fill list by appending items from newline separated strings
294  FXint fillItems(const FXString& strings,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
295 
296  /// Insert a new [possibly subclassed] item at the give index
297  FXint insertItem(FXint index,FXListItem* item,FXbool notify=FALSE);
298 
299  /// Insert item at index with given text, icon, and user-data pointer
300  FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
301 
302  /// Append a [possibly subclassed] item to the list
303  FXint appendItem(FXListItem* item,FXbool notify=FALSE);
304 
305  /// Append new item with given text and optional icon, and user-data pointer
306  FXint appendItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
307 
308  /// Prepend a [possibly subclassed] item to the list
309  FXint prependItem(FXListItem* item,FXbool notify=FALSE);
310 
311  /// Prepend new item with given text and optional icon, and user-data pointer
312  FXint prependItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
313 
314  /// Move item from oldindex to newindex
315  FXint moveItem(FXint newindex,FXint oldindex,FXbool notify=FALSE);
316 
317  /// Extract item from list
318  FXListItem* extractItem(FXint index,FXbool notify=FALSE);
319 
320  /// Remove item from list
321  void removeItem(FXint index,FXbool notify=FALSE);
322 
323  /// Remove all items from list
324  void clearItems(FXbool notify=FALSE);
325 
326  /// Return item width
327  FXint getItemWidth(FXint index) const;
328 
329  /// Return item height
330  FXint getItemHeight(FXint index) const;
331 
332  /// Return index of item at x,y, if any
333  virtual FXint getItemAt(FXint x,FXint y) const;
334 
335  /// Return item hit code: 0 no hit; 1 hit the icon; 2 hit the text
336  FXint hitItem(FXint index,FXint x,FXint y) const;
337 
338  /**
339  * Search items by name, beginning from item start. If the start
340  * item is -1 the search will start at the first item in the list.
341  * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the
342  * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
343  * to control whether the search wraps at the start or end of the list.
344  * The option SEARCH_IGNORECASE causes a case-insensitive match. Finally,
345  * passing SEARCH_PREFIX causes searching for a prefix of the item name.
346  * Return -1 if no matching item is found.
347  */
348  FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
349 
350  /**
351  * Search items by associated user data, beginning from item start. If the
352  * start item is -1 the search will start at the first item in the list.
353  * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the
354  * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
355  * to control whether the search wraps at the start or end of the list.
356  */
357  FXint findItemByData(const void *ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
358 
359  /// Scroll to bring item into view
360  virtual void makeItemVisible(FXint index);
361 
362  /// Change item text
363  void setItemText(FXint index,const FXString& text);
364 
365  /// Return item text
366  FXString getItemText(FXint index) const;
367 
368  /// Change item icon, deleting the old icon if it was owned
369  void setItemIcon(FXint index,FXIcon* icon,FXbool owned=FALSE);
370 
371  /// Return item icon, if any
372  FXIcon* getItemIcon(FXint index) const;
373 
374  /// Change item user-data pointer
375  void setItemData(FXint index,void* ptr);
376 
377  /// Return item user-data pointer
378  void* getItemData(FXint index) const;
379 
380  /// Return TRUE if item is selected
381  FXbool isItemSelected(FXint index) const;
382 
383  /// Return TRUE if item is current
384  FXbool isItemCurrent(FXint index) const;
385 
386  /// Return TRUE if item is visible
387  FXbool isItemVisible(FXint index) const;
388 
389  /// Return TRUE if item is enabled
390  FXbool isItemEnabled(FXint index) const;
391 
392  /// Repaint item
393  void updateItem(FXint index) const;
394 
395  /// Enable item
396  virtual FXbool enableItem(FXint index);
397 
398  /// Disable item
399  virtual FXbool disableItem(FXint index);
400 
401  /// Select item
402  virtual FXbool selectItem(FXint index,FXbool notify=FALSE);
403 
404  /// Deselect item
405  virtual FXbool deselectItem(FXint index,FXbool notify=FALSE);
406 
407  /// Toggle item selection state
408  virtual FXbool toggleItem(FXint index,FXbool notify=FALSE);
409 
410  /// Extend selection from anchor item to index
411  virtual FXbool extendSelection(FXint index,FXbool notify=FALSE);
412 
413  /// Deselect all items
414  virtual FXbool killSelection(FXbool notify=FALSE);
415 
416  /// Change current item
417  virtual void setCurrentItem(FXint index,FXbool notify=FALSE);
418 
419  /// Return current item, if any
420  FXint getCurrentItem() const { return current; }
421 
422  /// Change anchor item
423  void setAnchorItem(FXint index);
424 
425  /// Return anchor item, if any
426  FXint getAnchorItem() const { return anchor; }
427 
428  /// Get item under the cursor, if any
429  FXint getCursorItem() const { return cursor; }
430 
431  /// Sort items using current sort function
432  void sortItems();
433 
434  /// Return sort function
435  FXListSortFunc getSortFunc() const { return sortfunc; }
436 
437  /// Change sort function
438  void setSortFunc(FXListSortFunc func){ sortfunc=func; }
439 
440  /// Change text font
441  void setFont(FXFont* fnt);
442 
443  /// Return text font
444  FXFont* getFont() const { return font; }
445 
446  /// Return normal text color
447  FXColor getTextColor() const { return textColor; }
448 
449  /// Change normal text color
450  void setTextColor(FXColor clr);
451 
452  /// Return selected text background
453  FXColor getSelBackColor() const { return selbackColor; }
454 
455  /// Change selected text background
456  void setSelBackColor(FXColor clr);
457 
458  /// Return selected text color
459  FXColor getSelTextColor() const { return seltextColor; }
460 
461  /// Change selected text color
462  void setSelTextColor(FXColor clr);
463 
464  /// Return list style
465  FXuint getListStyle() const;
466 
467  /// Change list style
468  void setListStyle(FXuint style);
469 
470  /// Set the status line help text for this list
471  void setHelpText(const FXString& text);
472 
473  /// Get the status line help text for this list
474  const FXString& getHelpText() const { return help; }
475 
476  /// Save list to a stream
477  virtual void save(FXStream& store) const;
478 
479  /// Load list from a stream
480  virtual void load(FXStream& store);
481 
482  /// Destructor
483  virtual ~FXList();
484  };
485 
486 }
487 
488 #endif
Search forward (default)
Definition: fxdefs.h:363
char FXchar
Definition: fxdefs.h:380
FXint no() const
Return number of objects.
Definition: FXObjectList.h:53
Definition: FXWindow.h:241
unsigned int FXuint
Definition: fxdefs.h:389
FXuint FXSelector
Association key.
Definition: FXObject.h:53
#define FXAPI
Definition: fxdefs.h:122
FXuchar FXbool
Definition: fxdefs.h:386
Base composite.
Definition: FXComposite.h:35
#define NULL
Definition: fxdefs.h:41
FXuint FXColor
Definition: fxdefs.h:447
Multiple selection mode is used for selection of individual items.
Definition: FXList.h:42
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
Abstract Device Context.
Definition: FXDC.h:191
Browse selection mode enforces one single item to be selected at all times.
Definition: FXList.h:41
A List Widget displays a list of items, each with a text and optional icon.
Definition: FXList.h:167
Single selection mode allows up to one item to be selected.
Definition: FXList.h:40
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:390
An Icon is an image with two additional server-side resources: a shape bitmap, which is used to mask ...
Definition: FXIcon.h:45
Definition: FXList.h:44
Extended selection mode allows for drag-selection of ranges of items.
Definition: FXList.h:39
The scroll area widget manages a content area and a viewport area through which the content is viewed...
Definition: FXScrollArea.h:75
#define FALSE
Definition: fxdefs.h:35
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
FXint(* FXListSortFunc)(const FXListItem *, const FXListItem *)
List item collate function.
Definition: FXList.h:144
List item.
Definition: FXList.h:59
Wrap around to start.
Definition: fxdefs.h:366
Specialize list to pointers to TYPE.
Definition: FXObjectList.h:145
Font class.
Definition: FXFont.h:142
FXObjectListOf< FXListItem > FXListItemList
List of FXListItem's.
Definition: FXList.h:148
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33
Automatically select under cursor.
Definition: FXList.h:43

Copyright © 1997-2005 Jeroen van der Zijp