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

FXList.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                            L i s t   W i d g e t                              *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXList.h,v 1.88.2.2 2006/11/17 16:02:31 fox Exp $                            *
00023 ********************************************************************************/
00024 #ifndef FXLIST_H
00025 #define FXLIST_H
00026 
00027 #ifndef FXSCROLLAREA_H
00028 #include "FXScrollArea.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 /// List styles
00035 enum {
00036   LIST_EXTENDEDSELECT    = 0,             /// Extended selection mode allows for drag-selection of ranges of items
00037   LIST_SINGLESELECT      = 0x00100000,    /// Single selection mode allows up to one item to be selected
00038   LIST_BROWSESELECT      = 0x00200000,    /// Browse selection mode enforces one single item to be selected at all times
00039   LIST_MULTIPLESELECT    = 0x00300000,    /// Multiple selection mode is used for selection of individual items
00040   LIST_AUTOSELECT        = 0x00400000,    /// Automatically select under cursor
00041   LIST_NORMAL            = LIST_EXTENDEDSELECT
00042   };
00043 
00044 
00045 class FXIcon;
00046 class FXFont;
00047 class FXList;
00048 
00049 
00050 /// List item
00051 class FXAPI FXListItem : public FXObject {
00052   FXDECLARE(FXListItem)
00053   friend class FXList;
00054 protected:
00055   FXString  label;
00056   FXIcon   *icon;
00057   void     *data;
00058   FXuint    state;
00059   FXint     x,y;
00060 private:
00061   FXListItem(const FXListItem&);
00062   FXListItem& operator=(const FXListItem&);
00063 protected:
00064   FXListItem():icon(NULL),data(NULL),state(0),x(0),y(0){}
00065   virtual void draw(const FXList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h);
00066   virtual FXint hitItem(const FXList* list,FXint x,FXint y) const;
00067 public:
00068   enum {
00069     SELECTED  = 1,      /// Selected
00070     FOCUS     = 2,      /// Focus
00071     DISABLED  = 4,      /// Disabled
00072     DRAGGABLE = 8,      /// Draggable
00073     ICONOWNED = 16      /// Icon owned by item
00074     };
00075 public:
00076 
00077   /// Construct new item with given text, icon, and user-data
00078   FXListItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL):label(text),icon(ic),data(ptr),state(0),x(0),y(0){}
00079 
00080   /// Change item's text label
00081   virtual void setText(const FXString& txt);
00082 
00083   /// Return item's text label
00084   const FXString& getText() const { return label; }
00085 
00086   /// Change item's icon, deleting the old icon if it was owned
00087   virtual void setIcon(FXIcon* icn,FXbool owned=FALSE);
00088 
00089   /// Return item's icon
00090   FXIcon* getIcon() const { return icon; }
00091 
00092   /// Change item's user data
00093   void setData(void* ptr){ data=ptr; }
00094 
00095   /// Get item's user data
00096   void* getData() const { return data; }
00097 
00098   /// Make item draw as focused
00099   virtual void setFocus(FXbool focus);
00100 
00101   /// Return true if item has focus
00102   FXbool hasFocus() const { return (state&FOCUS)!=0; }
00103 
00104   /// Select item
00105   virtual void setSelected(FXbool selected);
00106 
00107   /// Return true if this item is selected
00108   FXbool isSelected() const { return (state&SELECTED)!=0; }
00109 
00110   /// Enable or disable item
00111   virtual void setEnabled(FXbool enabled);
00112 
00113   /// Return true if this item is enabled
00114   FXbool isEnabled() const { return (state&DISABLED)==0; }
00115 
00116   /// Make item draggable
00117   virtual void setDraggable(FXbool draggable);
00118 
00119   /// Return true if this item is draggable
00120   FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
00121 
00122   /// Return width of item as drawn in list
00123   virtual FXint getWidth(const FXList* list) const;
00124 
00125   /// Return height of item as drawn in list
00126   virtual FXint getHeight(const FXList* list) const;
00127 
00128   /// Create server-side resources
00129   virtual void create();
00130 
00131   /// Detach server-side resources
00132   virtual void detach();
00133 
00134   /// Destroy server-side resources
00135   virtual void destroy();
00136 
00137   /// Save to stream
00138   virtual void save(FXStream& store) const;
00139 
00140   /// Load from stream
00141   virtual void load(FXStream& store);
00142 
00143   /// Destroy item and free icons if owned
00144   virtual ~FXListItem();
00145   };
00146 
00147 
00148 /// List item collate function
00149 typedef FXint (*FXListSortFunc)(const FXListItem*,const FXListItem*);
00150 
00151 
00152 /// List of FXListItem's
00153 typedef FXObjectListOf<FXListItem> FXListItemList;
00154 
00155 
00156 /**
00157 * A List Widget displays a list of items, each with a text and
00158 * optional icon.  When an item's selected state changes, the list sends
00159 * a SEL_SELECTED or SEL_DESELECTED message.  A change of the current
00160 * item is signified by the SEL_CHANGED message.
00161 * The list sends SEL_COMMAND messages when the user clicks on an item,
00162 * and SEL_CLICKED, SEL_DOUBLECLICKED, and SEL_TRIPLECLICKED when the user
00163 * clicks once, twice, or thrice, respectively.
00164 * When items are added, replaced, or removed, the list sends messages of
00165 * the type SEL_INSERTED, SEL_REPLACED, or SEL_DELETED.
00166 * In each of these cases, the index to the item, if any, is passed in the
00167 * 3rd argument of the message.
00168 */
00169 class FXAPI FXList : public FXScrollArea {
00170   FXDECLARE(FXList)
00171 protected:
00172   FXListItemList items;             // Item list
00173   FXint          anchor;            // Anchor item
00174   FXint          current;           // Current item
00175   FXint          extent;            // Extent item
00176   FXint          cursor;            // Cursor item
00177   FXint          viewable;          // Viewable item
00178   FXFont        *font;              // Font
00179   FXColor        textColor;         // Text color
00180   FXColor        selbackColor;      // Selected back color
00181   FXColor        seltextColor;      // Selected text color
00182   FXint          listWidth;         // List width
00183   FXint          listHeight;        // List height
00184   FXint          visible;           // Number of rows high
00185   FXString       help;              // Help text
00186   FXListSortFunc sortfunc;          // Item sort function
00187   FXint          grabx;             // Grab point x
00188   FXint          graby;             // Grab point y
00189   FXString       lookup;            // Lookup string
00190   FXbool         state;             // State of item
00191 protected:
00192   FXList();
00193   void recompute();
00194   virtual FXListItem *createItem(const FXString& text,FXIcon* icon,void* ptr);
00195 private:
00196   FXList(const FXList&);
00197   FXList &operator=(const FXList&);
00198 public:
00199   long onPaint(FXObject*,FXSelector,void*);
00200   long onEnter(FXObject*,FXSelector,void*);
00201   long onLeave(FXObject*,FXSelector,void*);
00202   long onUngrabbed(FXObject*,FXSelector,void*);
00203   long onKeyPress(FXObject*,FXSelector,void*);
00204   long onKeyRelease(FXObject*,FXSelector,void*);
00205   long onLeftBtnPress(FXObject*,FXSelector,void*);
00206   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00207   long onRightBtnPress(FXObject*,FXSelector,void*);
00208   long onRightBtnRelease(FXObject*,FXSelector,void*);
00209   long onMotion(FXObject*,FXSelector,void*);
00210   long onFocusIn(FXObject*,FXSelector,void*);
00211   long onFocusOut(FXObject*,FXSelector,void*);
00212   long onAutoScroll(FXObject*,FXSelector,void*);
00213   long onClicked(FXObject*,FXSelector,void*);
00214   long onDoubleClicked(FXObject*,FXSelector,void*);
00215   long onTripleClicked(FXObject*,FXSelector,void*);
00216   long onCommand(FXObject*,FXSelector,void*);
00217   long onQueryTip(FXObject*,FXSelector,void*);
00218   long onQueryHelp(FXObject*,FXSelector,void*);
00219   long onTipTimer(FXObject*,FXSelector,void*);
00220   long onLookupTimer(FXObject*,FXSelector,void*);
00221   long onCmdSetValue(FXObject*,FXSelector,void*);public:
00222   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00223   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00224 public:
00225   static FXint ascending(const FXListItem* a,const FXListItem* b);
00226   static FXint descending(const FXListItem* a,const FXListItem* b);
00227   static FXint ascendingCase(const FXListItem* a,const FXListItem* b);
00228   static FXint descendingCase(const FXListItem* a,const FXListItem* b);
00229 public:
00230   enum {
00231     ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
00232     ID_LAST
00233     };
00234 public:
00235 
00236   /// Construct a list with initially no items in it
00237   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);
00238 
00239   /// Create server-side resources
00240   virtual void create();
00241 
00242   /// Detach server-side resources
00243   virtual void detach();
00244 
00245   /// Perform layout
00246   virtual void layout();
00247 
00248   /// Return default width
00249   virtual FXint getDefaultWidth();
00250 
00251   /// Return default height
00252   virtual FXint getDefaultHeight();
00253 
00254   /// Compute and return content width
00255   virtual FXint getContentWidth();
00256 
00257   /// Return content height
00258   virtual FXint getContentHeight();
00259 
00260   /// Recalculate layout
00261   virtual void recalc();
00262 
00263   /// List widget can receive focus
00264   virtual bool canFocus() const;
00265 
00266   /// Move the focus to this window
00267   virtual void setFocus();
00268 
00269   /// Remove the focus from this window
00270   virtual void killFocus();
00271 
00272   /// Return the number of items in the list
00273   FXint getNumItems() const { return items.no(); }
00274 
00275   /// Return number of visible items
00276   FXint getNumVisible() const { return visible; }
00277 
00278   /// Change the number of visible items
00279   void setNumVisible(FXint nvis);
00280 
00281   /// Return the item at the given index
00282   FXListItem *getItem(FXint index) const;
00283 
00284   /// Replace the item with a [possibly subclassed] item
00285   FXint setItem(FXint index,FXListItem* item,FXbool notify=FALSE);
00286 
00287   /// Replace items text, icon, and user-data pointer
00288   FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00289 
00290   /// Fill list by appending items from array of strings
00291   FXint fillItems(const FXchar** strings,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00292 
00293   /// Fill list by appending items from newline separated strings
00294   FXint fillItems(const FXString& strings,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00295 
00296   /// Insert a new [possibly subclassed] item at the give index
00297   FXint insertItem(FXint index,FXListItem* item,FXbool notify=FALSE);
00298 
00299   /// Insert item at index with given text, icon, and user-data pointer
00300   FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00301 
00302   /// Append a [possibly subclassed] item to the list
00303   FXint appendItem(FXListItem* item,FXbool notify=FALSE);
00304 
00305   /// Append new item with given text and optional icon, and user-data pointer
00306   FXint appendItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00307 
00308   /// Prepend a [possibly subclassed] item to the list
00309   FXint prependItem(FXListItem* item,FXbool notify=FALSE);
00310 
00311   /// Prepend new item with given text and optional icon, and user-data pointer
00312   FXint prependItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00313 
00314   /// Move item from oldindex to newindex
00315   FXint moveItem(FXint newindex,FXint oldindex,FXbool notify=FALSE);
00316 
00317   /// Extract item from list
00318   FXListItem* extractItem(FXint index,FXbool notify=FALSE);
00319 
00320   /// Remove item from list
00321   void removeItem(FXint index,FXbool notify=FALSE);
00322 
00323   /// Remove all items from list
00324   void clearItems(FXbool notify=FALSE);
00325 
00326   /// Return item width
00327   FXint getItemWidth(FXint index) const;
00328 
00329   /// Return item height
00330   FXint getItemHeight(FXint index) const;
00331 
00332   /// Return index of item at x,y, if any
00333   virtual FXint getItemAt(FXint x,FXint y) const;
00334 
00335   /// Return item hit code: 0 no hit; 1 hit the icon; 2 hit the text
00336   FXint hitItem(FXint index,FXint x,FXint y) const;
00337 
00338   /**
00339   * Search items by name, beginning from item start.  If the start
00340   * item is -1 the search will start at the first item in the list.
00341   * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the
00342   * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
00343   * to control whether the search wraps at the start or end of the list.
00344   * The option SEARCH_IGNORECASE causes a case-insensitive match.  Finally,
00345   * passing SEARCH_PREFIX causes searching for a prefix of the item name.
00346   * Return -1 if no matching item is found.
00347   */
00348   FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00349 
00350   /**
00351   * Search items by associated user data, beginning from item start. If the
00352   * start item is -1 the search will start at the first item in the list.
00353   * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the
00354   * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
00355   * to control whether the search wraps at the start or end of the list.
00356   */
00357   FXint findItemByData(const void *ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00358 
00359   /// Scroll to bring item into view
00360   virtual void makeItemVisible(FXint index);
00361 
00362   /// Change item text
00363   void setItemText(FXint index,const FXString& text);
00364 
00365   /// Return item text
00366   FXString getItemText(FXint index) const;
00367 
00368   /// Change item icon, deleting the old icon if it was owned
00369   void setItemIcon(FXint index,FXIcon* icon,FXbool owned=FALSE);
00370 
00371   /// Return item icon, if any
00372   FXIcon* getItemIcon(FXint index) const;
00373 
00374   /// Change item user-data pointer
00375   void setItemData(FXint index,void* ptr);
00376 
00377   /// Return item user-data pointer
00378   void* getItemData(FXint index) const;
00379 
00380   /// Return TRUE if item is selected
00381   FXbool isItemSelected(FXint index) const;
00382 
00383   /// Return TRUE if item is current
00384   FXbool isItemCurrent(FXint index) const;
00385 
00386   /// Return TRUE if item is visible
00387   FXbool isItemVisible(FXint index) const;
00388 
00389   /// Return TRUE if item is enabled
00390   FXbool isItemEnabled(FXint index) const;
00391 
00392   /// Repaint item
00393   void updateItem(FXint index) const;
00394 
00395   /// Enable item
00396   virtual FXbool enableItem(FXint index);
00397 
00398   /// Disable item
00399   virtual FXbool disableItem(FXint index);
00400 
00401   /// Select item
00402   virtual FXbool selectItem(FXint index,FXbool notify=FALSE);
00403 
00404   /// Deselect item
00405   virtual FXbool deselectItem(FXint index,FXbool notify=FALSE);
00406 
00407   /// Toggle item selection state
00408   virtual FXbool toggleItem(FXint index,FXbool notify=FALSE);
00409 
00410   /// Extend selection from anchor item to index
00411   virtual FXbool extendSelection(FXint index,FXbool notify=FALSE);
00412 
00413   /// Deselect all items
00414   virtual FXbool killSelection(FXbool notify=FALSE);
00415 
00416   /// Change current item
00417   virtual void setCurrentItem(FXint index,FXbool notify=FALSE);
00418 
00419   /// Return current item, if any
00420   FXint getCurrentItem() const { return current; }
00421 
00422   /// Change anchor item
00423   void setAnchorItem(FXint index);
00424 
00425   /// Return anchor item, if any
00426   FXint getAnchorItem() const { return anchor; }
00427 
00428   /// Get item under the cursor, if any
00429   FXint getCursorItem() const { return cursor; }
00430 
00431   /// Sort items using current sort function
00432   void sortItems();
00433 
00434   /// Return sort function
00435   FXListSortFunc getSortFunc() const { return sortfunc; }
00436 
00437   /// Change sort function
00438   void setSortFunc(FXListSortFunc func){ sortfunc=func; }
00439 
00440   /// Change text font
00441   void setFont(FXFont* fnt);
00442 
00443   /// Return text font
00444   FXFont* getFont() const { return font; }
00445 
00446   /// Return normal text color
00447   FXColor getTextColor() const { return textColor; }
00448 
00449   /// Change normal text color
00450   void setTextColor(FXColor clr);
00451 
00452   /// Return selected text background
00453   FXColor getSelBackColor() const { return selbackColor; }
00454 
00455   /// Change selected text background
00456   void setSelBackColor(FXColor clr);
00457 
00458   /// Return selected text color
00459   FXColor getSelTextColor() const { return seltextColor; }
00460 
00461   /// Change selected text color
00462   void setSelTextColor(FXColor clr);
00463 
00464   /// Return list style
00465   FXuint getListStyle() const;
00466 
00467   /// Change list style
00468   void setListStyle(FXuint style);
00469 
00470   /// Set the status line help text for this list
00471   void setHelpText(const FXString& text);
00472 
00473   /// Get the status line help text for this list
00474   const FXString& getHelpText() const { return help; }
00475 
00476   /// Save list to a stream
00477   virtual void save(FXStream& store) const;
00478 
00479   /// Load list from a stream
00480   virtual void load(FXStream& store);
00481 
00482   /// Destructor
00483   virtual ~FXList();
00484   };
00485 
00486 }
00487 
00488 #endif

Copyright © 1997-2005 Jeroen van der Zijp