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 
00035 enum {
00036   LIST_EXTENDEDSELECT    = 0,             
00037   LIST_SINGLESELECT      = 0x00100000,    
00038   LIST_BROWSESELECT      = 0x00200000,    
00039   LIST_MULTIPLESELECT    = 0x00300000,    
00040   LIST_AUTOSELECT        = 0x00400000,    
00041   LIST_NORMAL            = LIST_EXTENDEDSELECT
00042   };
00043 
00044 
00045 class FXIcon;
00046 class FXFont;
00047 class FXList;
00048 
00049 
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,      
00070     FOCUS     = 2,      
00071     DISABLED  = 4,      
00072     DRAGGABLE = 8,      
00073     ICONOWNED = 16      
00074     };
00075 public:
00076 
00078   FXListItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL):label(text),icon(ic),data(ptr),state(0),x(0),y(0){}
00079 
00081   virtual void setText(const FXString& txt);
00082 
00084   const FXString& getText() const { return label; }
00085 
00087   virtual void setIcon(FXIcon* icn,FXbool owned=FALSE);
00088 
00090   FXIcon* getIcon() const { return icon; }
00091 
00093   void setData(void* ptr){ data=ptr; }
00094 
00096   void* getData() const { return data; }
00097 
00099   virtual void setFocus(FXbool focus);
00100 
00102   FXbool hasFocus() const { return (state&FOCUS)!=0; }
00103 
00105   virtual void setSelected(FXbool selected);
00106 
00108   FXbool isSelected() const { return (state&SELECTED)!=0; }
00109 
00111   virtual void setEnabled(FXbool enabled);
00112 
00114   FXbool isEnabled() const { return (state&DISABLED)==0; }
00115 
00117   virtual void setDraggable(FXbool draggable);
00118 
00120   FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
00121 
00123   virtual FXint getWidth(const FXList* list) const;
00124 
00126   virtual FXint getHeight(const FXList* list) const;
00127 
00129   virtual void create();
00130 
00132   virtual void detach();
00133 
00135   virtual void destroy();
00136 
00138   virtual void save(FXStream& store) const;
00139 
00141   virtual void load(FXStream& store);
00142 
00144   virtual ~FXListItem();
00145   };
00146 
00147 
00149 typedef FXint (*FXListSortFunc)(const FXListItem*,const FXListItem*);
00150 
00151 
00153 typedef FXObjectListOf<FXListItem> FXListItemList;
00154 
00155 
00156 #ifdef _MSC_VER
00157 #pragma warning(push)
00158 #pragma warning(disable: 4251)
00159 #endif
00160 
00174 class FXAPI FXList : public FXScrollArea {
00175   FXDECLARE(FXList)
00176 protected:
00177   FXListItemList items;             // Item list
00178   FXint          anchor;            // Anchor item
00179   FXint          current;           // Current item
00180   FXint          extent;            // Extent item
00181   FXint          cursor;            // Cursor item
00182   FXint          viewable;          // Viewable item
00183   FXFont        *font;              // Font
00184   FXColor        textColor;         // Text color
00185   FXColor        selbackColor;      // Selected back color
00186   FXColor        seltextColor;      // Selected text color
00187   FXint          listWidth;         // List width
00188   FXint          listHeight;        // List height
00189   FXint          visible;           // Number of rows high
00190   FXString       help;              // Help text
00191   FXListSortFunc sortfunc;          // Item sort function
00192   FXint          grabx;             // Grab point x
00193   FXint          graby;             // Grab point y
00194   FXString       lookup;            // Lookup string
00195   FXbool         state;             // State of item
00196 protected:
00197   FXList();
00198   void recompute();
00199   virtual FXListItem *createItem(const FXString& text,FXIcon* icon,void* ptr);
00200 private:
00201   FXList(const FXList&);
00202   FXList &operator=(const FXList&);
00203 public:
00204   long onPaint(FXObject*,FXSelector,void*);
00205   long onEnter(FXObject*,FXSelector,void*);
00206   long onLeave(FXObject*,FXSelector,void*);
00207   long onUngrabbed(FXObject*,FXSelector,void*);
00208   long onKeyPress(FXObject*,FXSelector,void*);
00209   long onKeyRelease(FXObject*,FXSelector,void*);
00210   long onLeftBtnPress(FXObject*,FXSelector,void*);
00211   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00212   long onRightBtnPress(FXObject*,FXSelector,void*);
00213   long onRightBtnRelease(FXObject*,FXSelector,void*);
00214   long onMotion(FXObject*,FXSelector,void*);
00215   long onFocusIn(FXObject*,FXSelector,void*);
00216   long onFocusOut(FXObject*,FXSelector,void*);
00217   long onAutoScroll(FXObject*,FXSelector,void*);
00218   long onClicked(FXObject*,FXSelector,void*);
00219   long onDoubleClicked(FXObject*,FXSelector,void*);
00220   long onTripleClicked(FXObject*,FXSelector,void*);
00221   long onCommand(FXObject*,FXSelector,void*);
00222   long onQueryTip(FXObject*,FXSelector,void*);
00223   long onQueryHelp(FXObject*,FXSelector,void*);
00224   long onTipTimer(FXObject*,FXSelector,void*);
00225   long onLookupTimer(FXObject*,FXSelector,void*);
00226   long onCmdSetValue(FXObject*,FXSelector,void*);public:
00227   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00228   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00229 public:
00230   static FXint ascending(const FXListItem* a,const FXListItem* b);
00231   static FXint descending(const FXListItem* a,const FXListItem* b);
00232   static FXint ascendingCase(const FXListItem* a,const FXListItem* b);
00233   static FXint descendingCase(const FXListItem* a,const FXListItem* b);
00234 public:
00235   enum {
00236     ID_LOOKUPTIMER=FXScrollArea::ID_LAST,
00237     ID_LAST
00238     };
00239 public:
00240 
00242   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);
00243 
00245   virtual void create();
00246 
00248   virtual void detach();
00249 
00251   virtual void layout();
00252 
00254   virtual FXint getDefaultWidth();
00255 
00257   virtual FXint getDefaultHeight();
00258 
00260   virtual FXint getContentWidth();
00261 
00263   virtual FXint getContentHeight();
00264 
00266   virtual void recalc();
00267 
00269   virtual bool canFocus() const;
00270 
00272   virtual void setFocus();
00273 
00275   virtual void killFocus();
00276 
00278   FXint getNumItems() const { return items.no(); }
00279 
00281   FXint getNumVisible() const { return visible; }
00282 
00284   void setNumVisible(FXint nvis);
00285 
00287   FXListItem *getItem(FXint index) const;
00288 
00290   FXint setItem(FXint index,FXListItem* item,FXbool notify=FALSE);
00291 
00293   FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00294 
00296   FXint fillItems(const FXchar** strings,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00297 
00299   FXint fillItems(const FXString& strings,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00300 
00302   FXint insertItem(FXint index,FXListItem* item,FXbool notify=FALSE);
00303 
00305   FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00306 
00308   FXint appendItem(FXListItem* item,FXbool notify=FALSE);
00309 
00311   FXint appendItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00312 
00314   FXint prependItem(FXListItem* item,FXbool notify=FALSE);
00315 
00317   FXint prependItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
00318 
00320   FXint moveItem(FXint newindex,FXint oldindex,FXbool notify=FALSE);
00321 
00323   FXListItem* extractItem(FXint index,FXbool notify=FALSE);
00324 
00326   void removeItem(FXint index,FXbool notify=FALSE);
00327 
00329   void clearItems(FXbool notify=FALSE);
00330 
00332   FXint getItemWidth(FXint index) const;
00333 
00335   FXint getItemHeight(FXint index) const;
00336 
00338   virtual FXint getItemAt(FXint x,FXint y) const;
00339 
00341   FXint hitItem(FXint index,FXint x,FXint y) const;
00342 
00353   FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00354 
00362   FXint findItemByData(const void *ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00363 
00365   virtual void makeItemVisible(FXint index);
00366 
00368   void setItemText(FXint index,const FXString& text);
00369 
00371   FXString getItemText(FXint index) const;
00372 
00374   void setItemIcon(FXint index,FXIcon* icon,FXbool owned=FALSE);
00375 
00377   FXIcon* getItemIcon(FXint index) const;
00378 
00380   void setItemData(FXint index,void* ptr);
00381 
00383   void* getItemData(FXint index) const;
00384 
00386   FXbool isItemSelected(FXint index) const;
00387 
00389   FXbool isItemCurrent(FXint index) const;
00390 
00392   FXbool isItemVisible(FXint index) const;
00393 
00395   FXbool isItemEnabled(FXint index) const;
00396 
00398   void updateItem(FXint index) const;
00399 
00401   virtual FXbool enableItem(FXint index);
00402 
00404   virtual FXbool disableItem(FXint index);
00405 
00407   virtual FXbool selectItem(FXint index,FXbool notify=FALSE);
00408 
00410   virtual FXbool deselectItem(FXint index,FXbool notify=FALSE);
00411 
00413   virtual FXbool toggleItem(FXint index,FXbool notify=FALSE);
00414 
00416   virtual FXbool extendSelection(FXint index,FXbool notify=FALSE);
00417 
00419   virtual FXbool killSelection(FXbool notify=FALSE);
00420 
00422   virtual void setCurrentItem(FXint index,FXbool notify=FALSE);
00423 
00425   FXint getCurrentItem() const { return current; }
00426 
00428   void setAnchorItem(FXint index);
00429 
00431   FXint getAnchorItem() const { return anchor; }
00432 
00434   FXint getCursorItem() const { return cursor; }
00435 
00437   void sortItems();
00438 
00440   FXListSortFunc getSortFunc() const { return sortfunc; }
00441 
00443   void setSortFunc(FXListSortFunc func){ sortfunc=func; }
00444 
00446   void setFont(FXFont* fnt);
00447 
00449   FXFont* getFont() const { return font; }
00450 
00452   FXColor getTextColor() const { return textColor; }
00453 
00455   void setTextColor(FXColor clr);
00456 
00458   FXColor getSelBackColor() const { return selbackColor; }
00459 
00461   void setSelBackColor(FXColor clr);
00462 
00464   FXColor getSelTextColor() const { return seltextColor; }
00465 
00467   void setSelTextColor(FXColor clr);
00468 
00470   FXuint getListStyle() const;
00471 
00473   void setListStyle(FXuint style);
00474 
00476   void setHelpText(const FXString& text);
00477 
00479   const FXString& getHelpText() const { return help; }
00480 
00482   virtual void save(FXStream& store) const;
00483 
00485   virtual void load(FXStream& store);
00486 
00488   virtual ~FXList();
00489   };
00490 
00491 #ifdef _MSC_VER
00492 #pragma warning(pop)
00493 #endif
00494 
00495 }
00496 
00497 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:23 2009 for TnFOX by doxygen v1.4.7