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

FXList.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                            L i s t   W i d g e t                              *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2002 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.56 2002/09/30 13:06:56 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 struct FXTimer;
00049 
00050 
00051 /// List item
00052 class FXAPI FXListItem : public FXObject {
00053   FXDECLARE(FXListItem)
00054   friend class FXList;
00055 protected:
00056   FXString  label;
00057   FXIcon   *icon;
00058   void     *data;
00059   FXuint    state;
00060   FXint     x,y;
00061 protected:
00062   FXListItem():icon(NULL),data(NULL),state(0),x(0),y(0){}
00063   virtual void draw(const FXList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h);
00064   virtual FXint hitItem(const FXList* list,FXint x,FXint y) const;
00065 protected:
00066   enum {
00067     SELECTED  = 1,
00068     FOCUS     = 2,
00069     DISABLED  = 4,
00070     DRAGGABLE = 8,
00071     ICONOWNED = 16
00072     };
00073 public:
00074   FXListItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL):label(text),icon(ic),data(ptr),state(0),x(0),y(0){}
00075   virtual void setText(const FXString& txt){ label=txt; }
00076   const FXString& getText() const { return label; }
00077   virtual void setIcon(FXIcon* icn){ icon=icn; }
00078   FXIcon* getIcon() const { return icon; }
00079   void setData(void* ptr){ data=ptr; }
00080   void* getData() const { return data; }
00081   virtual void setFocus(FXbool focus);
00082   FXbool hasFocus() const { return (state&FOCUS)!=0; }
00083   virtual void setSelected(FXbool selected);
00084   FXbool isSelected() const { return (state&SELECTED)!=0; }
00085   virtual void setEnabled(FXbool enabled);
00086   FXbool isEnabled() const { return (state&DISABLED)==0; }
00087   virtual void setDraggable(FXbool draggable);
00088   FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
00089   virtual void setIconOwned(FXuint owned=ICONOWNED);
00090   FXuint isIconOwned() const { return (state&ICONOWNED); }
00091   virtual FXint getWidth(const FXList* list) const;
00092   virtual FXint getHeight(const FXList* list) const;
00093   virtual void create();
00094   virtual void detach();
00095   virtual void destroy();
00096   virtual void save(FXStream& store) const;
00097   virtual void load(FXStream& store);
00098   virtual ~FXListItem();
00099   };
00100 
00101 
00102 /// List item collate function
00103 typedef FXint (*FXListSortFunc)(const FXListItem*,const FXListItem*);
00104 
00105 
00106 /// List Widget
00107 class FXAPI FXList : public FXScrollArea {
00108   FXDECLARE(FXList)
00109 protected:
00110   FXListItem   **items;             // Item list
00111   FXint          nitems;            // Number of items
00112   FXint          anchor;            // Anchor item
00113   FXint          current;           // Current item
00114   FXint          extent;            // Extent item
00115   FXint          cursor;            // Cursor item
00116   FXFont        *font;              // Font
00117   FXColor        textColor;         // Text color
00118   FXColor        selbackColor;      // Selected back color
00119   FXColor        seltextColor;      // Selected text color
00120   FXint          listWidth;         // List width
00121   FXint          listHeight;        // List height
00122   FXint          visible;           // Number of rows high
00123   FXString       help;              // Help text
00124   FXListSortFunc sortfunc;          // Item sort function
00125   FXint          grabx;             // Grab point x
00126   FXint          graby;             // Grab point y
00127   FXString       lookup;            // Lookup string
00128   FXTimer       *timer;             // Tip hover timer
00129   FXTimer       *lookuptimer;       // Lookup timer
00130   FXbool         state;             // State of item
00131 protected:
00132   FXList();
00133   virtual void layout();
00134   void recompute();
00135   virtual FXListItem *createItem(const FXString& text,FXIcon* icon,void* ptr);
00136 private:
00137   FXList(const FXList&);
00138   FXList &operator=(const FXList&);
00139 public:
00140   long onPaint(FXObject*,FXSelector,void*);
00141   long onEnter(FXObject*,FXSelector,void*);
00142   long onLeave(FXObject*,FXSelector,void*);
00143   long onUngrabbed(FXObject*,FXSelector,void*);
00144   long onKeyPress(FXObject*,FXSelector,void*);
00145   long onKeyRelease(FXObject*,FXSelector,void*);
00146   long onLeftBtnPress(FXObject*,FXSelector,void*);
00147   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00148   long onRightBtnPress(FXObject*,FXSelector,void*);
00149   long onRightBtnRelease(FXObject*,FXSelector,void*);
00150   long onMotion(FXObject*,FXSelector,void*);
00151   long onFocusIn(FXObject*,FXSelector,void*);
00152   long onFocusOut(FXObject*,FXSelector,void*);
00153   long onAutoScroll(FXObject*,FXSelector,void*);
00154   long onClicked(FXObject*,FXSelector,void*);
00155   long onDoubleClicked(FXObject*,FXSelector,void*);
00156   long onTripleClicked(FXObject*,FXSelector,void*);
00157   long onCommand(FXObject*,FXSelector,void*);
00158   long onQueryTip(FXObject*,FXSelector,void*);
00159   long onQueryHelp(FXObject*,FXSelector,void*);
00160   long onTipTimer(FXObject*,FXSelector,void*);
00161   long onLookupTimer(FXObject*,FXSelector,void*);
00162   long onCmdSetValue(FXObject*,FXSelector,void*);public:
00163   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00164   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00165 public:
00166   static FXint ascending(const FXListItem* a,const FXListItem* b);
00167   static FXint descending(const FXListItem* a,const FXListItem* b);
00168 public:
00169   enum {
00170     ID_TIPTIMER=FXScrollArea::ID_LAST,
00171     ID_LOOKUPTIMER,
00172     ID_LAST
00173     };
00174 public:
00175 
00176   /// Construct a list with nvis visible items; the list is initially empty
00177   FXList(FXComposite *p,FXint nvis,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=LIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00178 
00179   /// Create server-side resources
00180   virtual void create();
00181 
00182   /// Detach server-side resources
00183   virtual void detach();
00184 
00185   /// Return default width
00186   virtual FXint getDefaultWidth();
00187 
00188   /// Return default height
00189   virtual FXint getDefaultHeight();
00190 
00191   /// Compute and return content width
00192   virtual FXint getContentWidth();
00193 
00194   /// Return content height
00195   virtual FXint getContentHeight();
00196 
00197   /// Recalculate layout
00198   virtual void recalc();
00199 
00200   /// List widget can receive focus
00201   virtual FXbool canFocus() const;
00202 
00203   /// Move the focus to this window
00204   virtual void setFocus();
00205 
00206   /// Remove the focus from this window
00207   virtual void killFocus();
00208 
00209   /// Return the number of items in the list
00210   FXint getNumItems() const { return nitems; }
00211 
00212   /// Return number of visible items
00213   FXint getNumVisible() const { return visible; }
00214 
00215   /// Change the number of visible items
00216   void setNumVisible(FXint nvis);
00217 
00218   /// Return the item at the given index
00219   FXListItem *getItem(FXint index) const;
00220 
00221   /// Replace the item with a [possibly subclassed] item
00222   FXint setItem(FXint index,FXListItem* item,FXbool notify=FALSE);
00223 
00224   /// Replace items text, icon, and user-data pointer
00225   FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00226 
00227   /// Insert a new [possibly subclassed] item at the give index
00228   FXint insertItem(FXint index,FXListItem* item,FXbool notify=FALSE);
00229 
00230   /// Insert item at index with given text, icon, and user-data pointer
00231   FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00232 
00233   /// Append a [possibly subclassed] item to the list
00234   FXint appendItem(FXListItem* item,FXbool notify=FALSE);
00235 
00236   /// Append new item with given text and optional icon, and user-data pointer
00237   FXint appendItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00238 
00239   /// Prepend a [possibly subclassed] item to the list
00240   FXint prependItem(FXListItem* item,FXbool notify=FALSE);
00241 
00242   /// Prepend new item with given text and optional icon, and user-data pointer
00243   FXint prependItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00244 
00245   /// Remove item from list
00246   void removeItem(FXint index,FXbool notify=FALSE);
00247 
00248   /// Remove all items from list
00249   void clearItems(FXbool notify=FALSE);
00250 
00251   /// Return item width
00252   FXint getItemWidth(FXint index) const;
00253 
00254   /// Return item height
00255   FXint getItemHeight(FXint index) const;
00256 
00257   /// Return index of item at x,y, if any
00258   FXint getItemAt(FXint x,FXint y) const;
00259 
00260   /// Return item hit code: 0 no hit; 1 hit the icon; 2 hit the text
00261   FXint hitItem(FXint index,FXint x,FXint y) const;
00262 
00263   /**
00264   * Search items for item by name, starting from start item; the
00265   * flags argument controls the search direction, and case sensitivity.
00266   */
00267   FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00268 
00269   /// Scroll to bring item into view
00270   void makeItemVisible(FXint index);
00271 
00272   /// Change item text
00273   void setItemText(FXint index,const FXString& text);
00274 
00275   /// Return item text
00276   FXString getItemText(FXint index) const;
00277 
00278   /// Change item icon
00279   void setItemIcon(FXint index,FXIcon* icon);
00280 
00281   /// Return item icon, if any
00282   FXIcon* getItemIcon(FXint index) const;
00283 
00284   /// Change item user-data pointer
00285   void setItemData(FXint index,void* ptr);
00286 
00287   /// Return item user-data pointer
00288   void* getItemData(FXint index) const;
00289 
00290   /// Return TRUE if item is selected
00291   FXbool isItemSelected(FXint index) const;
00292 
00293   /// Return TRUE if item is current
00294   FXbool isItemCurrent(FXint index) const;
00295 
00296   /// Return TRUE if item is visible
00297   FXbool isItemVisible(FXint index) const;
00298 
00299   /// Return TRUE if item is enabled
00300   FXbool isItemEnabled(FXint index) const;
00301 
00302   /// Repaint item
00303   void updateItem(FXint index) const;
00304 
00305   /// Enable item
00306   FXbool enableItem(FXint index);
00307 
00308   /// Disable item
00309   FXbool disableItem(FXint index);
00310 
00311   /// Select item
00312   FXbool selectItem(FXint index,FXbool notify=FALSE);
00313 
00314   /// Deselect item
00315   FXbool deselectItem(FXint index,FXbool notify=FALSE);
00316 
00317   /// Toggle item selection state
00318   FXbool toggleItem(FXint index,FXbool notify=FALSE);
00319 
00320   /// Change current item
00321   void setCurrentItem(FXint index,FXbool notify=FALSE);
00322 
00323   /// Return current item, if any
00324   FXint getCurrentItem() const { return current; }
00325 
00326   /// Change anchor item
00327   void setAnchorItem(FXint index);
00328 
00329   /// Return anchor item, if any
00330   FXint getAnchorItem() const { return anchor; }
00331 
00332   /// Get item under the cursor, if any
00333   FXint getCursorItem() const { return cursor; }
00334 
00335   /// Extend selection from anchor item to index
00336   FXbool extendSelection(FXint index,FXbool notify=FALSE);
00337 
00338   /// Deselect all items
00339   FXbool killSelection(FXbool notify=FALSE);
00340 
00341   /// Sort items using current sort function
00342   void sortItems();
00343 
00344   /// Change text font
00345   void setFont(FXFont* fnt);
00346 
00347   /// Return text font
00348   FXFont* getFont() const { return font; }
00349 
00350   /// Return normal text color
00351   FXColor getTextColor() const { return textColor; }
00352 
00353   /// Change normal text color
00354   void setTextColor(FXColor clr);
00355 
00356   /// Return selected text background
00357   FXColor getSelBackColor() const { return selbackColor; }
00358 
00359   /// Change selected text background
00360   void setSelBackColor(FXColor clr);
00361 
00362   /// Return selected text color
00363   FXColor getSelTextColor() const { return seltextColor; }
00364 
00365   /// Change selected text color
00366   void setSelTextColor(FXColor clr);
00367 
00368   /// Return sort function
00369   FXListSortFunc getSortFunc() const { return sortfunc; }
00370 
00371   /// Change sort function
00372   void setSortFunc(FXListSortFunc func){ sortfunc=func; }
00373 
00374   /// Return list style
00375   FXuint getListStyle() const;
00376 
00377   /// Change list style
00378   void setListStyle(FXuint style);
00379 
00380   /// Set the status line help text for this list
00381   void setHelpText(const FXString& text);
00382 
00383   /// Get the status line help text for this list
00384   const FXString& getHelpText() const { return help; }
00385 
00386   /// Save list to a stream
00387   virtual void save(FXStream& store) const;
00388 
00389   /// Load list from a stream
00390   virtual void load(FXStream& store);
00391 
00392   /// Destructor
00393   virtual ~FXList();
00394   };
00395 
00396 }
00397 
00398 #endif