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

FXFileList.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                        F i l e    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: FXFileList.h,v 1.57 2006/01/22 17:58:01 fox Exp $                        *
00023 ********************************************************************************/
00024 #ifndef FXFILELIST_H
00025 #define FXFILELIST_H
00026 
00027 #ifndef FXICONLIST_H
00028 #include "FXIconList.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 struct FXFileAssoc;
00034 class FXFileDict;
00035 class FXFileList;
00036 class FXIcon;
00037 class FXIconSource;
00038 class FXIconDict;
00039 
00040 
00041 /// File List options
00042 enum {
00043   FILELIST_SHOWHIDDEN   = 0x04000000, /// Show hidden files or directories
00044   FILELIST_SHOWDIRS     = 0x08000000, /// Show only directories
00045   FILELIST_SHOWFILES    = 0x10000000, /// Show only files
00046   FILELIST_SHOWIMAGES   = 0x20000000, /// Show preview of images
00047   FILELIST_NO_OWN_ASSOC = 0x40000000, /// Do not create associations for files
00048   FILELIST_NO_PARENT    = 0x80000000  /// Suppress display of '.' and '..'
00049   };
00050 
00051 
00052 
00053 /// File item
00054 class FXAPI FXFileItem : public FXIconItem {
00055   FXDECLARE(FXFileItem)
00056   friend class FXFileList;
00057 protected:
00058   FXFileAssoc  *assoc;                  // File association record
00059   FXFileItem   *link;                   // Link to next item
00060   FXlong        size;                   // File size
00061   FXTime        date;                   // File time
00062 private:
00063   FXFileItem(const FXFileItem&);
00064   FXFileItem& operator=(const FXFileItem&);
00065 protected:
00066   FXFileItem():assoc(NULL),link(NULL),size(0),date(0){}
00067 protected:
00068   enum{
00069     FOLDER     = 64,                    // Directory item
00070     EXECUTABLE = 128,                   // Executable item
00071     SYMLINK    = 256,                   // Symbolic linked item
00072     CHARDEV    = 512,                   // Character special item
00073     BLOCKDEV   = 1024,                  // Block special item
00074     FIFO       = 2048,                  // FIFO item
00075     SOCK       = 4096,                  // Socket item
00076     SHARE      = 8192                   // Share
00077     };
00078 public:
00079   /// Constructor
00080   FXFileItem(const FXString& text,FXIcon* bi=NULL,FXIcon* mi=NULL,void* ptr=NULL):FXIconItem(text,bi,mi,ptr),assoc(NULL),link(NULL),size(0L),date(0){}
00081 
00082   /// Return true if this is a file item
00083   FXbool isFile() const { return (state&(FOLDER|BLOCKDEV|CHARDEV|FIFO|SOCK|SHARE))==0; }
00084 
00085   /// Return true if this is a directory item
00086   FXbool isDirectory() const { return (state&FOLDER)!=0; }
00087 
00088   /// Return true if this is a share item
00089   FXbool isShare() const { return (state&SHARE)!=0; }
00090 
00091   /// Return true if this is an executable item
00092   FXbool isExecutable() const { return (state&EXECUTABLE)!=0; }
00093 
00094   /// Return true if this is a symbolic link item
00095   FXbool isSymlink() const { return (state&SYMLINK)!=0; }
00096 
00097   /// Return true if this is a character device item
00098   FXbool isChardev() const { return (state&CHARDEV)!=0; }
00099 
00100   /// Return true if this is a block device item
00101   FXbool isBlockdev() const { return (state&BLOCKDEV)!=0; }
00102 
00103   /// Return true if this is an FIFO item
00104   FXbool isFifo() const { return (state&FIFO)!=0; }
00105 
00106   /// Return true if this is a socket
00107   FXbool isSocket() const { return (state&SOCK)!=0; }
00108 
00109   /// Return the file-association object for this item
00110   FXFileAssoc* getAssoc() const { return assoc; }
00111 
00112   /// Return the file size for this item
00113   FXlong getSize() const { return size; }
00114 
00115   /// Return the date for this item
00116   FXTime getDate() const { return date; }
00117   };
00118 
00119 
00120 /**
00121 * A File List widget provides an icon rich view of the file system.
00122 * It automatically updates itself periodically by re-scanning the file system
00123 * for any changes.  As it scans the displayed directory, it automatically
00124 * determines the icons to be displayed by consulting the file associations registry
00125 * settings.  A number of messages can be sent to the File List to control the
00126 * filter pattern, sort category, sorting order, case sensitivity, and hidden file
00127 * display mode.
00128 * The File list widget supports drags and drops of files.
00129 */
00130 class FXAPI FXFileList : public FXIconList {
00131   FXDECLARE(FXFileList)
00132 protected:
00133   FXString      directory;      // Current directory
00134   FXString      orgdirectory;   // Original directory
00135   FXString      dropdirectory;  // Drop directory
00136   FXDragAction  dropaction;     // Drop action
00137   FXString      dragfiles;      // Dragged files
00138   FXFileDict   *associations;   // Association table
00139   FXFileItem   *list;           // File item list
00140   FXString      pattern;        // Pattern of file names
00141   FXuint        matchmode;      // File wildcard match mode
00142   FXuint        counter;        // Refresh counter
00143   FXint         imagesize;      // Image size
00144   FXTime        timestamp;      // Time when last refreshed
00145   FXIcon       *big_folder;     // Big folder icon
00146   FXIcon       *mini_folder;    // Mini folder icon
00147   FXIcon       *big_doc;        // Big document icon
00148   FXIcon       *mini_doc;       // Mini document icon
00149   FXIcon       *big_app;        // Big application icon
00150   FXIcon       *mini_app;       // Mini application icon
00151 protected:
00152   FXFileList();
00153   virtual FXIconItem *createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr);
00154   void listItems(FXbool force);
00155 private:
00156   FXFileList(const FXFileList&);
00157   FXFileList &operator=(const FXFileList&);
00158 public:
00159   long onOpenTimer(FXObject*,FXSelector,void*);
00160   long onRefreshTimer(FXObject*,FXSelector,void*);
00161   long onDNDEnter(FXObject*,FXSelector,void*);
00162   long onDNDLeave(FXObject*,FXSelector,void*);
00163   long onDNDMotion(FXObject*,FXSelector,void*);
00164   long onDNDDrop(FXObject*,FXSelector,void*);
00165   long onDNDRequest(FXObject*,FXSelector,void*);
00166   long onBeginDrag(FXObject*,FXSelector,void*);
00167   long onEndDrag(FXObject*,FXSelector,void*);
00168   long onDragged(FXObject*,FXSelector,void*);
00169   long onCmdSetValue(FXObject*,FXSelector,void*);
00170   long onCmdGetStringValue(FXObject*,FXSelector,void*);
00171   long onCmdSetStringValue(FXObject*,FXSelector,void*);
00172   long onCmdDirectoryUp(FXObject*,FXSelector,void*);
00173   long onUpdDirectoryUp(FXObject*,FXSelector,void*);
00174   long onCmdSortByName(FXObject*,FXSelector,void*);
00175   long onUpdSortByName(FXObject*,FXSelector,void*);
00176   long onCmdSortByType(FXObject*,FXSelector,void*);
00177   long onUpdSortByType(FXObject*,FXSelector,void*);
00178   long onCmdSortBySize(FXObject*,FXSelector,void*);
00179   long onUpdSortBySize(FXObject*,FXSelector,void*);
00180   long onCmdSortByTime(FXObject*,FXSelector,void*);
00181   long onUpdSortByTime(FXObject*,FXSelector,void*);
00182   long onCmdSortByUser(FXObject*,FXSelector,void*);
00183   long onUpdSortByUser(FXObject*,FXSelector,void*);
00184   long onCmdSortByGroup(FXObject*,FXSelector,void*);
00185   long onUpdSortByGroup(FXObject*,FXSelector,void*);
00186   long onCmdSortReverse(FXObject*,FXSelector,void*);
00187   long onUpdSortReverse(FXObject*,FXSelector,void*);
00188   long onCmdSortCase(FXObject*,FXSelector,void*);
00189   long onUpdSortCase(FXObject*,FXSelector,void*);
00190   long onCmdSetPattern(FXObject*,FXSelector,void*);
00191   long onUpdSetPattern(FXObject*,FXSelector,void*);
00192   long onCmdSetDirectory(FXObject*,FXSelector,void*);
00193   long onUpdSetDirectory(FXObject*,FXSelector,void*);
00194   long onCmdToggleHidden(FXObject*,FXSelector,void*);
00195   long onUpdToggleHidden(FXObject*,FXSelector,void*);
00196   long onCmdShowHidden(FXObject*,FXSelector,void*);
00197   long onUpdShowHidden(FXObject*,FXSelector,void*);
00198   long onCmdHideHidden(FXObject*,FXSelector,void*);
00199   long onUpdHideHidden(FXObject*,FXSelector,void*);
00200   long onCmdToggleImages(FXObject*,FXSelector,void*);
00201   long onUpdToggleImages(FXObject*,FXSelector,void*);
00202   long onCmdHeader(FXObject*,FXSelector,void*);
00203   long onUpdHeader(FXObject*,FXSelector,void*);
00204   long onCmdRefresh(FXObject*,FXSelector,void*);
00205 public:
00206   static FXint ascending(const FXIconItem* a,const FXIconItem* b);
00207   static FXint descending(const FXIconItem* a,const FXIconItem* b);
00208   static FXint ascendingCase(const FXIconItem* a,const FXIconItem* b);
00209   static FXint descendingCase(const FXIconItem* a,const FXIconItem* b);
00210   static FXint ascendingType(const FXIconItem* a,const FXIconItem* b);
00211   static FXint descendingType(const FXIconItem* a,const FXIconItem* b);
00212   static FXint ascendingSize(const FXIconItem* a,const FXIconItem* b);
00213   static FXint descendingSize(const FXIconItem* a,const FXIconItem* b);
00214   static FXint ascendingTime(const FXIconItem* a,const FXIconItem* b);
00215   static FXint descendingTime(const FXIconItem* a,const FXIconItem* b);
00216   static FXint ascendingUser(const FXIconItem* a,const FXIconItem* b);
00217   static FXint descendingUser(const FXIconItem* a,const FXIconItem* b);
00218   static FXint ascendingGroup(const FXIconItem* a,const FXIconItem* b);
00219   static FXint descendingGroup(const FXIconItem* a,const FXIconItem* b);
00220 public:
00221   enum {
00222     ID_REFRESHTIMER=FXIconList::ID_LAST,
00223     ID_OPENTIMER,
00224     ID_SORT_BY_NAME,    /// Sort by name
00225     ID_SORT_BY_TYPE,    /// Sort by type
00226     ID_SORT_BY_SIZE,    /// Sort by size
00227     ID_SORT_BY_TIME,    /// Sort by access time
00228     ID_SORT_BY_USER,    /// Sort by owner name
00229     ID_SORT_BY_GROUP,   /// Sort by group name
00230     ID_SORT_REVERSE,    /// Reverse sort order
00231     ID_SORT_CASE,       /// Toggle sort case sensitivity
00232     ID_DIRECTORY_UP,    /// Move up one directory
00233     ID_SET_PATTERN,     /// Set match pattern
00234     ID_SET_DIRECTORY,   /// Set directory
00235     ID_SHOW_HIDDEN,     /// Show hidden files
00236     ID_HIDE_HIDDEN,     /// Hide hidden files
00237     ID_TOGGLE_HIDDEN,   /// Toggle display of hidden files
00238     ID_TOGGLE_IMAGES,   /// Toggle display of images
00239     ID_REFRESH,         /// Refresh immediately
00240     ID_LAST
00241     };
00242 public:
00243 
00244   /// Construct a file list
00245   FXFileList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00246 
00247   /// Create server-side resources
00248   virtual void create();
00249 
00250   /// Detach server-side resources
00251   virtual void detach();
00252 
00253   /// Destroy server-side resources
00254   virtual void destroy();
00255 
00256   /// Scan the current directory and update the items if needed, or if force is TRUE
00257   void scan(FXbool force=TRUE);
00258 
00259   /// Set current file
00260   void setCurrentFile(const FXString& file,FXbool notify=FALSE);
00261 
00262   /// Return current file
00263   FXString getCurrentFile() const;
00264 
00265   /// Set current directory
00266   void setDirectory(const FXString& path);
00267 
00268   /// Return current directory
00269   FXString getDirectory() const { return directory; }
00270 
00271   /// Change wildcard matching pattern
00272   void setPattern(const FXString& ptrn);
00273 
00274   /// Return wildcard pattern
00275   FXString getPattern() const { return pattern; }
00276 
00277   /// Return TRUE if item is a directory
00278   FXbool isItemDirectory(FXint index) const;
00279 
00280   /// Return TRUE if item is a directory
00281   FXbool isItemShare(FXint index) const;
00282 
00283   /// Return TRUE if item is a file
00284   FXbool isItemFile(FXint index) const;
00285 
00286   /// Return TRUE if item is executable
00287   FXbool isItemExecutable(FXint index) const;
00288 
00289   /// Return name of item at index
00290   FXString getItemFilename(FXint index) const;
00291 
00292   /// Return full pathname of item at index
00293   FXString getItemPathname(FXint index) const;
00294 
00295   /// Return file association of item
00296   FXFileAssoc* getItemAssoc(FXint index) const;
00297 
00298   /// Return wildcard matching mode
00299   FXuint getMatchMode() const { return matchmode; }
00300 
00301   /// Change wildcard matching mode
00302   void setMatchMode(FXuint mode);
00303 
00304   /// Return TRUE if showing hidden files
00305   FXbool showHiddenFiles() const;
00306 
00307   /// Show or hide hidden files
00308   void showHiddenFiles(FXbool showing);
00309 
00310   /// Return TRUE if showing directories only
00311   FXbool showOnlyDirectories() const;
00312 
00313   /// Show directories only
00314   void showOnlyDirectories(FXbool shown);
00315 
00316   /// Return TRUE if showing files only
00317   FXbool showOnlyFiles() const;
00318 
00319   /// Show files only
00320   void showOnlyFiles(FXbool shown);
00321 
00322   /// Return TRUE if image preview on
00323   FXbool showImages() const;
00324 
00325   /// Show or hide preview images
00326   void showImages(FXbool showing);
00327 
00328   /// Return images preview size
00329   FXint getImageSize() const { return imagesize; }
00330 
00331   /// Change images preview size
00332   void setImageSize(FXint size);
00333 
00334   /// Return TRUE if showing parent directories
00335   FXbool showParents() const;
00336 
00337   /// Show parent directories
00338   void showParents(FXbool shown);
00339 
00340   /// Change file associations
00341   void setAssociations(FXFileDict* assoc);
00342 
00343   /// Return file associations
00344   FXFileDict* getAssociations() const { return associations; }
00345 
00346   /// Save to stream
00347   virtual void save(FXStream& store) const;
00348 
00349   /// Load from stream
00350   virtual void load(FXStream& store);
00351 
00352   /// Destructor
00353   virtual ~FXFileList();
00354   };
00355 
00356 }
00357 
00358 #endif

Copyright © 1997-2005 Jeroen van der Zijp