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

FXIconList_new.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                         I c o n   L i s t   W i d g e t                       *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1999,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: FXIconList.h,v 1.57 2002/05/02 04:28:04 fox Exp $                        *
00023 ********************************************************************************/
00024 #ifndef FXICONLIST_H
00025 #define FXICONLIST_H
00026 
00027 #ifndef FXSCROLLAREA_H
00028 #include "FXScrollArea.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 /// Icon list styles
00035 enum {
00036   ICONLIST_EXTENDEDSELECT = 0,                /// Extended selection mode
00037   ICONLIST_SINGLESELECT   = 0x00100000,       /// At most one selected item
00038   ICONLIST_BROWSESELECT   = 0x00200000,       /// Always exactly one selected item
00039   ICONLIST_MULTIPLESELECT = 0x00300000,       /// Multiple selection mode
00040   ICONLIST_AUTOSIZE       = 0x00400000,       /// Automatically size item spacing
00041   ICONLIST_DETAILED       = 0,                /// List mode
00042   ICONLIST_MINI_ICONS     = 0x00800000,       /// Mini Icon mode
00043   ICONLIST_BIG_ICONS      = 0x01000000,       /// Big Icon mode
00044   ICONLIST_ROWS           = 0,                /// Row-wise mode
00045   ICONLIST_COLUMNS        = 0x02000000,       /// Column-wise mode
00046   ICONLIST_NORMAL         = ICONLIST_EXTENDEDSELECT
00047   };
00048 
00049 
00050 struct FXTimer;
00051 class FXIcon;
00052 class FXHeader;
00053 class FXFont;
00054 class FXIconList;
00055 class FXFileList;
00056 
00057 
00058 /// Icon item
00059 class FXAPI FXIconItem : public FXObject {
00060   FXDECLARE(FXIconItem)
00061   friend class FXIconList;
00062   friend class FXFileList;
00063 protected:
00064   FXString  label;
00065   FXIcon   *bigIcon;
00066   FXIcon   *miniIcon;
00067   void     *data;
00068   FXuint    state;
00069   FXint     x,y;
00070 protected:
00071   FXIconItem():bigIcon(NULL),miniIcon(NULL),data(NULL),state(0),x(0),y(0){}
00072   virtual void draw(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00073   virtual FXint hitItem(const FXIconList* list,FXint rx,FXint ry,FXint rw=1,FXint rh=1) const;
00074 protected:
00075   virtual void drawBigIcon(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00076   virtual void drawMiniIcon(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00077   virtual void drawDetails(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00078 protected:
00079   enum {
00080     SELECTED      = 1,
00081     FOCUS         = 2,
00082     DISABLED      = 4,
00083     DRAGGABLE     = 8,
00084     BIGICONOWNED  = 16,
00085     MINIICONOWNED = 32
00086     };
00087 public:
00088   FXIconItem(const FXString& text,FXIcon* bi=NULL,FXIcon* mi=NULL,void* ptr=NULL):label(text),bigIcon(bi),miniIcon(mi),data(ptr),state(0),x(0),y(0){}
00089   virtual void setText(const FXString& txt){ label=txt; }
00090   FXString getText() const { return label; }
00091   virtual void setBigIcon(FXIcon* icn){ bigIcon=icn; }
00092   FXIcon* getBigIcon() const { return bigIcon; }
00093   virtual void setMiniIcon(FXIcon* icn){ miniIcon=icn; }
00094   FXIcon* getMiniIcon() const { return miniIcon; }
00095   void setData(void* ptr){ data=ptr; }
00096   void* getData() const { return data; }
00097   virtual void setFocus(FXbool focus);
00098   FXbool hasFocus() const { return (state&FOCUS)!=0; }
00099   virtual void setSelected(FXbool selected);
00100   FXbool isSelected() const { return (state&SELECTED)!=0; }
00101   virtual void setEnabled(FXbool enabled);
00102   FXbool isEnabled() const { return (state&DISABLED)==0; }
00103   virtual void setDraggable(FXbool draggable);
00104   FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
00105   virtual void setIconOwned(FXuint owned=(BIGICONOWNED|MINIICONOWNED));
00106   FXuint isIconOwned() const { return (state&(BIGICONOWNED|MINIICONOWNED)); }
00107   virtual FXint getWidth(const FXIconList* list) const;
00108   virtual FXint getHeight(const FXIconList* list) const;
00109   virtual void create();
00110   virtual void detach();
00111   virtual void destroy();
00112   virtual void save(FXStream& store) const;
00113   virtual void load(FXStream& store);
00114   virtual ~FXIconItem();
00115   };
00116 
00117 
00118 /// Icon item collate function
00119 typedef FXint (*FXIconListSortFunc)(const FXIconItem*,const FXIconItem*);
00120 
00121 
00122 /// Icon List Widget
00123 class FXAPI FXIconList : public FXScrollArea {
00124   FXDECLARE(FXIconList)
00125 protected:
00126   FXHeader          *header;            // Header control
00127   FXIconItem       **items;             // Item list
00128   FXint              nitems;            // Number of items
00129   FXint              anchor;            // Anchor item
00130   FXint              current;           // Current item
00131   FXint              extent;            // Extent item
00132   FXint              cursor;            // Cursor item
00133   FXFont            *font;              // Font
00134   FXIconListSortFunc sortfunc;          // Item sort function
00135   FXColor            textColor;         // Text color
00136   FXColor            selbackColor;      // Selected back color
00137   FXColor            seltextColor;      // Selected text color
00138   FXint              listWidth;         // Width of contents of list
00139   FXint              listHeight;        // Height of contents of list
00140   FXint              itemSpace;         // Maximum space for item
00141   FXint              anchorx;           // Rectangular selection
00142   FXint              anchory;
00143   FXint              currentx;
00144   FXint              currenty;
00145   FXint              grabx;             // Grab point x
00146   FXint              graby;             // Grab point y
00147   FXString           lookup;            // Lookup string
00148   FXTimer           *timer;             // Tip hover timer
00149   FXTimer           *lookuptimer;       // Lookup timer
00150   FXString           help;              // Help text
00151   FXbool             state;             // State of item
00152 protected:
00153   FXIconList();
00154   void drawLasso(FXint x0,FXint y0,FXint x1,FXint y1);
00155   virtual void layout();
00156   void recompute();
00157   virtual FXIconItem *createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr);
00158   void lassoChanged(FXint ox,FXint oy,FXint ow,FXint oh,FXint nx,FXint ny,FXint nw,FXint nh,FXbool notify);
00159 private:
00160   FXIconList(const FXIconList&);
00161   FXIconList &operator=(const FXIconList&);
00162 public:
00163   long onPaint(FXObject*,FXSelector,void*);
00164   long onEnter(FXObject*,FXSelector,void*);
00165   long onLeave(FXObject*,FXSelector,void*);
00166   long onUngrabbed(FXObject*,FXSelector,void*);
00167   long onKeyPress(FXObject*,FXSelector,void*);
00168   long onKeyRelease(FXObject*,FXSelector,void*);
00169   long onLeftBtnPress(FXObject*,FXSelector,void*);
00170   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00171   long onRightBtnPress(FXObject*,FXSelector,void*);
00172   long onRightBtnRelease(FXObject*,FXSelector,void*);
00173   long onMotion(FXObject*,FXSelector,void*);
00174   long onQueryTip(FXObject*,FXSelector,void*);
00175   long onQueryHelp(FXObject*,FXSelector,void*);
00176   long onTipTimer(FXObject*,FXSelector,void*);
00177   long onCmdSelectAll(FXObject*,FXSelector,void*);
00178   long onCmdDeselectAll(FXObject*,FXSelector,void*);
00179   long onCmdSelectInverse(FXObject*,FXSelector,void*);
00180   long onCmdArrangeByRows(FXObject*,FXSelector,void*);
00181   long onUpdArrangeByRows(FXObject*,FXSelector,void*);
00182   long onCmdArrangeByColumns(FXObject*,FXSelector,void*);
00183   long onUpdArrangeByColumns(FXObject*,FXSelector,void*);
00184   long onCmdShowDetails(FXObject*,FXSelector,void*);
00185   long onUpdShowDetails(FXObject*,FXSelector,void*);
00186   long onCmdShowBigIcons(FXObject*,FXSelector,void*);
00187   long onUpdShowBigIcons(FXObject*,FXSelector,void*);
00188   long onCmdShowMiniIcons(FXObject*,FXSelector,void*);
00189   long onUpdShowMiniIcons(FXObject*,FXSelector,void*);
00190   long onHeaderChanged(FXObject*,FXSelector,void*);
00191   long onFocusIn(FXObject*,FXSelector,void*);
00192   long onFocusOut(FXObject*,FXSelector,void*);
00193   long onClicked(FXObject*,FXSelector,void*);
00194   long onDoubleClicked(FXObject*,FXSelector,void*);
00195   long onTripleClicked(FXObject*,FXSelector,void*);
00196   long onCommand(FXObject*,FXSelector,void*);
00197   long onAutoScroll(FXObject*,FXSelector,void*);
00198   long onLookupTimer(FXObject*,FXSelector,void*);
00199   long onCmdSetValue(FXObject*,FXSelector,void*);public:
00200   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00201   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00202 public:
00203   static FXint ascending(const FXIconItem* a,const FXIconItem* b);
00204   static FXint descending(const FXIconItem* a,const FXIconItem* b);
00205 public:
00206   enum {
00207     ID_SHOW_DETAILS=FXScrollArea::ID_LAST,
00208     ID_SHOW_MINI_ICONS,
00209     ID_SHOW_BIG_ICONS,
00210     ID_ARRANGE_BY_ROWS,
00211     ID_ARRANGE_BY_COLUMNS,
00212     ID_HEADER_CHANGE,
00213     ID_TIPTIMER,
00214     ID_LOOKUPTIMER,
00215     ID_SELECT_ALL,
00216     ID_DESELECT_ALL,
00217     ID_SELECT_INVERSE,
00218     ID_LAST
00219     };
00220 public:
00221   /// Construct icon list
00222   FXIconList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=ICONLIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00223 
00224   /// Create server-side resources
00225   virtual void create();
00226 
00227   /// Detach server-side resources
00228   virtual void detach();
00229 
00230   /// Recalculate layout
00231   virtual void recalc();
00232 
00233   /// Compute and return content width
00234   virtual FXint getContentWidth();
00235 
00236   /// Return content height
00237   virtual FXint getContentHeight();
00238 
00239   /// Icon list can receive focus
00240   virtual FXbool canFocus() const;
00241 
00242   /// Move the focus to this window
00243   virtual void setFocus();
00244 
00245   /// Remove the focus from this window
00246   virtual void killFocus();
00247 
00248   /// Return viewport size
00249   virtual FXint getViewportHeight();
00250 
00251   /// Move contents to the specified position
00252   virtual void moveContents(FXint x,FXint y);
00253 
00254   /// Return number of items
00255   FXint getNumItems() const { return nitems; }
00256 
00257   /// Return header control
00258   FXHeader* getHeader() const { return header; }
00259 
00260   /// Append header with given text and optional icon
00261   void appendHeader(const FXString& text,FXIcon *icon=NULL,FXint size=1);
00262 
00263   /// Remove header at index
00264   void removeHeader(FXint index);
00265 
00266   /// Change text of header at index
00267   void setHeaderText(FXint index,const FXString& text);
00268 
00269   /// Return text of header at index
00270   FXString getHeaderText(FXint index) const;
00271 
00272   /// Change icon of header at index
00273   void setHeaderIcon(FXint index,FXIcon *icon);
00274 
00275   /// Return icon of header at index
00276   FXIcon* getHeaderIcon(FXint index) const;
00277 
00278   /// Change size of header at index
00279   void setHeaderSize(FXint index,FXint size);
00280 
00281   /// Return width of header at index
00282   FXint getHeaderSize(FXint index) const;
00283 
00284   /// Return number of headers
00285   FXint getNumHeaders() const;
00286 
00287   /// Return the item at the given index
00288   FXIconItem *retrieveItem(FXint index) const;
00289 
00290   /// Replace the item with a [possibly subclassed] item
00291   FXint replaceItem(FXint index,FXIconItem* item,FXbool notify=FALSE);
00292 
00293   /// Replace items text, icons, and user-data pointer
00294   FXint replaceItem(FXint index,const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE);
00295 
00296   /// Insert a new [possibly subclassed] item at the give index
00297   FXint insertItem(FXint index,FXIconItem* item,FXbool notify=FALSE);
00298 
00299   /// Insert item at index with given text, icons, and user-data pointer
00300   FXint insertItem(FXint index,const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE);
00301 
00302   /// Append a [possibly subclassed] item to the end of the list
00303   FXint appendItem(FXIconItem* item,FXbool notify=FALSE);
00304 
00305   /// Append new item with given text and optional icons, and user-data pointer
00306   FXint appendItem(const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE);
00307 
00308   /// Append a [possibly subclassed] item to the end of the list
00309   FXint prependItem(FXIconItem* item,FXbool notify=FALSE);
00310 
00311   /// Append new item with given text and optional icons, and user-data pointer
00312   FXint prependItem(const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE);
00313 
00314   /// Remove item from list
00315   void removeItem(FXint index,FXbool notify=FALSE);
00316 
00317   /// Remove all items from list
00318   void clearItems(FXbool notify=FALSE);
00319 
00320   /// Return item width
00321   FXint getItemWidth(FXint index) const;
00322 
00323   /// Return item height
00324   FXint getItemHeight(FXint index) const;
00325 
00326   /// Return index of item at x,y, or -1 if none
00327   FXint getItemAt(FXint x,FXint y) const;
00328 
00329   /**
00330   * Search items for item by name, starting from start item; the
00331   * flags argument controls the search direction, and case sensitivity.
00332   */
00333   FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
00334 
00335   /// Scroll to make item at index visible
00336   void makeItemVisible(FXint index);
00337 
00338   /// Change item text
00339   void setItemText(FXint index,const FXString& text);
00340 
00341   /// Return item text
00342   FXString getItemText(FXint index) const;
00343 
00344   /// Change item big icon
00345   void setItemBigIcon(FXint index,FXIcon* icon);
00346 
00347   /// Return big icon of item at index
00348   FXIcon* getItemBigIcon(FXint index) const;
00349 
00350   /// Change item mini icon
00351   void setItemMiniIcon(FXint index,FXIcon* icon);
00352 
00353   /// Return mini icon of item at index
00354   FXIcon* getItemMiniIcon(FXint index) const;
00355 
00356   /// Change item user-data pointer
00357   void setItemData(FXint index,void* ptr);
00358 
00359   /// Return item user-data pointer
00360   void* getItemData(FXint index) const;
00361 
00362   /// Return TRUE if item at index is selected
00363   FXbool isItemSelected(FXint index) const;
00364 
00365   /// Return TRUE if item at index is current
00366   FXbool isItemCurrent(FXint index) const;
00367 
00368   /// Return TRUE if item at index is visible
00369   FXbool isItemVisible(FXint index) const;
00370 
00371   /// Return TRUE if item at index is enabled
00372   FXbool isItemEnabled(FXint index) const;
00373 
00374   /// Return item hit code: 0 outside, 1 icon, 2 text
00375   FXint hitItem(FXint index,FXint x,FXint y,FXint ww=1,FXint hh=1) const;
00376 
00377   /// Repaint item at index
00378   void updateItem(FXint index) const;
00379 
00380   /// Select items in rectangle
00381   FXbool selectInRectangle(FXint x,FXint y,FXint w,FXint h,FXbool notify=FALSE);
00382 
00383   /// Enable item at index
00384   FXbool enableItem(FXint index);
00385 
00386   /// Disable item at index
00387   FXbool disableItem(FXint index);
00388 
00389   /// Select item at index
00390   FXbool selectItem(FXint index,FXbool notify=FALSE);
00391 
00392   /// Deselect item at index
00393   FXbool deselectItem(FXint index,FXbool notify=FALSE);
00394 
00395   /// Toggle item at index
00396   FXbool toggleItem(FXint index,FXbool notify=FALSE);
00397 
00398   /// Change current item index
00399   void setCurrentItem(FXint index,FXbool notify=FALSE);
00400 
00401   /// Return current item index, or -1 if none
00402   FXint getCurrentItem() const { return current; }
00403 
00404   /// Change anchor item index
00405   void setAnchorItem(FXint index);
00406 
00407   /// Return anchor item index, or -1 if none
00408   FXint getAnchorItem() const { return anchor; }
00409 
00410   /// Return index of item under cursor, or -1 if none
00411   FXint getCursorItem() const { return cursor; }
00412 
00413   /// Extend selection from anchor index to index
00414   FXbool extendSelection(FXint index,FXbool notify=FALSE);
00415 
00416   /// Deselect all items
00417   FXbool killSelection(FXbool notify=FALSE);
00418 
00419   /// Sort items
00420   void sortItems();
00421 
00422   /// Change text font
00423   void setFont(FXFont* fnt);
00424 
00425   /// Return text font
00426   FXFont* getFont() const { return font; }
00427 
00428   /// Return normal text color
00429   FXColor getTextColor() const { return textColor; }
00430 
00431   /// Change normal text color
00432   void setTextColor(FXColor clr);
00433 
00434   /// Return selected text background
00435   FXColor getSelBackColor() const { return selbackColor; }
00436 
00437   /// Change selected text background
00438   void setSelBackColor(FXColor clr);
00439 
00440   /// Return selected text color
00441   FXColor getSelTextColor() const { return seltextColor; }
00442 
00443   /// Change selected text color
00444   void setSelTextColor(FXColor clr);
00445 
00446   /// Change maximum item space for each item
00447   void setItemSpace(FXint s);
00448 
00449   /// Return maximum item space
00450   FXint getItemSpace() const { return itemSpace; }
00451 
00452   /// Return sort function
00453   FXIconListSortFunc getSortFunc() const { return sortfunc; }
00454 
00455   /// Change sort function
00456   void setSortFunc(FXIconListSortFunc func){ sortfunc=func; }
00457 
00458   /// Get the current icon list style
00459   FXuint getListStyle() const;
00460 
00461   /// Set the current icon list style.
00462   void setListStyle(FXuint style);
00463 
00464   /// Set the status line help text for this widget
00465   void setHelpText(const FXString& text);
00466 
00467   /// Get the status line help text for this widget
00468   FXString getHelpText() const { return help; }
00469 
00470   /// Save list to a stream
00471   virtual void save(FXStream& store) const;
00472 
00473   /// Load list from a stream
00474   virtual void load(FXStream& store);
00475 
00476   /// Destructor
00477   virtual ~FXIconList();
00478   };
00479 
00480 }
00481 
00482 #endif
00483 
00484 

Copyright © 1997-2004 Jeroen van der Zijp