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