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

FXFileList.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                        F i l e    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: FXFileList.h,v 1.35 2002/03/12 07:11:30 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 FXTimer;
00034 struct FXFileAssoc;
00035 class FXFileDict;
00036 class FXFileList;
00037 class FXIcon;
00038 
00039 
00040 // File List options
00041 enum {
00042   FILELIST_SHOWHIDDEN   = 0x04000000, /// Show hidden files or directories
00043   FILELIST_SHOWDIRS     = 0x08000000, /// Show only directories
00044   FILELIST_NO_OWN_ASSOC = 0x10000000  /// Do not create associations for files
00045   };
00046 
00047 
00048 
00049 /// File item
00050 class FXAPI FXFileItem : public FXIconItem {
00051   FXDECLARE(FXFileItem)
00052   friend class FXFileList;
00053 protected:
00054   FXFileAssoc  *assoc;                      /// File association record
00055   unsigned long size;                       /// File size
00056   FXTime        date;                       /// File time
00057 protected:
00058   FXFileItem():assoc(NULL),size(0),date(0){}
00059 protected:
00060   enum{
00061     FOLDER     = 64,                        /// Directory item
00062     EXECUTABLE = 128,                       /// Executable item
00063     SYMLINK    = 256,                       /// Symbolic linked item
00064     CHARDEV    = 512,                       /// Character special item
00065     BLOCKDEV   = 1024,                      /// Block special item
00066     FIFO       = 2048,                      /// FIFO item
00067     SOCK       = 4096                       /// Socket item
00068     };
00069 public:
00070   /// Constructor
00071   FXFileItem(const FXString& text,FXIcon* bi=NULL,FXIcon* mi=NULL,void* ptr=NULL):FXIconItem(text,bi,mi,ptr),assoc(NULL),size(0),date(0){}
00072 
00073   /// Return true if this is a file item
00074   FXbool isFile() const { return (state&(FOLDER|BLOCKDEV|CHARDEV|FIFO|SOCK))==0; }
00075 
00076   /// Return true if this is a directory item
00077   FXbool isDirectory() const { return (state&FOLDER)!=0; }
00078 
00079   /// Return true if this is an executable item
00080   FXbool isExecutable() const { return (state&EXECUTABLE)!=0; }
00081 
00082   /// Return true if this is a symbolic link item
00083   FXbool isSymlink() const { return (state&SYMLINK)!=0; }
00084 
00085   /// Return true if this is a character device item
00086   FXbool isChardev() const { return (state&CHARDEV)!=0; }
00087 
00088   /// Return true if this is a block device item
00089   FXbool isBlockdev() const { return (state&BLOCKDEV)!=0; }
00090 
00091   /// Return true if this is an FIFO item
00092   FXbool isFifo() const { return (state&FIFO)!=0; }
00093 
00094   /// Return true if this is a socket
00095   FXbool isSocket() const { return (state&SOCK)!=0; }
00096 
00097   /// Return the file-association object for this item
00098   FXFileAssoc* getAssoc() const { return assoc; }
00099 
00100   /// Return the file size for this item
00101   unsigned long getSize() const { return size; }
00102 
00103   /// Return the date for this item
00104   FXTime getDate() const { return date; }
00105   };
00106 
00107 
00108 /// File List object
00109 class FXAPI FXFileList : public FXIconList {
00110   FXDECLARE(FXFileList)
00111 protected:
00112   FXString     directory;             // Current directory
00113   FXString     orgdirectory;          // Original directory
00114   FXString     dropdirectory;         // Drop directory
00115   FXDragAction dropaction;            // Drop action
00116   FXString     dragfiles;             // Dragged files
00117   FXFileDict  *associations;          // Association table
00118   FXString     pattern;               // Pattern of file names
00119   FXuint       matchmode;             // File wildcard match mode
00120   FXTime       timestamp;             // Time when last refreshed
00121   FXTimer     *refreshtimer;          // Refresh timer
00122   FXTimer     *opentimer;             // Open up folder when hovering
00123   FXIcon      *big_folder;            // Big folder icon
00124   FXIcon      *mini_folder;           // Mini folder icon
00125   FXIcon      *big_doc;               // Big document icon
00126   FXIcon      *mini_doc;              // Mini document icon
00127   FXIcon      *big_app;               // Big application icon
00128   FXIcon      *mini_app;              // Mini application icon
00129 protected:
00130   FXFileList();
00131   virtual FXIconItem *createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr);
00132   void listDirectory();
00133 private:
00134   FXFileList(const FXFileList&);
00135   FXFileList &operator=(const FXFileList&);
00136 public:
00137   long onRefreshTimer(FXObject*,FXSelector,void*);
00138   long onOpenTimer(FXObject*,FXSelector,void*);
00139   long onDNDEnter(FXObject*,FXSelector,void*);
00140   long onDNDLeave(FXObject*,FXSelector,void*);
00141   long onDNDMotion(FXObject*,FXSelector,void*);
00142   long onDNDDrop(FXObject*,FXSelector,void*);
00143   long onDNDRequest(FXObject*,FXSelector,void*);
00144   long onBeginDrag(FXObject*,FXSelector,void*);
00145   long onEndDrag(FXObject*,FXSelector,void*);
00146   long onDragged(FXObject*,FXSelector,void*);
00147   long onCmdSetValue(FXObject*,FXSelector,void*);
00148   long onCmdGetStringValue(FXObject*,FXSelector,void*);
00149   long onCmdSetStringValue(FXObject*,FXSelector,void*);
00150   long onCmdDirectoryUp(FXObject*,FXSelector,void*);
00151   long onUpdDirectoryUp(FXObject*,FXSelector,void*);
00152   long onCmdSortByName(FXObject*,FXSelector,void*);
00153   long onUpdSortByName(FXObject*,FXSelector,void*);
00154   long onCmdSortByType(FXObject*,FXSelector,void*);
00155   long onUpdSortByType(FXObject*,FXSelector,void*);
00156   long onCmdSortBySize(FXObject*,FXSelector,void*);
00157   long onUpdSortBySize(FXObject*,FXSelector,void*);
00158   long onCmdSortByTime(FXObject*,FXSelector,void*);
00159   long onUpdSortByTime(FXObject*,FXSelector,void*);
00160   long onCmdSortByUser(FXObject*,FXSelector,void*);
00161   long onUpdSortByUser(FXObject*,FXSelector,void*);
00162   long onCmdSortByGroup(FXObject*,FXSelector,void*);
00163   long onUpdSortByGroup(FXObject*,FXSelector,void*);
00164   long onCmdSortReverse(FXObject*,FXSelector,void*);
00165   long onUpdSortReverse(FXObject*,FXSelector,void*);
00166   long onCmdSetPattern(FXObject*,FXSelector,void*);
00167   long onUpdSetPattern(FXObject*,FXSelector,void*);
00168   long onCmdSetDirectory(FXObject*,FXSelector,void*);
00169   long onUpdSetDirectory(FXObject*,FXSelector,void*);
00170   long onCmdToggleHidden(FXObject*,FXSelector,void*);
00171   long onUpdToggleHidden(FXObject*,FXSelector,void*);
00172   long onCmdShowHidden(FXObject*,FXSelector,void*);
00173   long onUpdShowHidden(FXObject*,FXSelector,void*);
00174   long onCmdHideHidden(FXObject*,FXSelector,void*);
00175   long onUpdHideHidden(FXObject*,FXSelector,void*);
00176   long onCmdHeader(FXObject*,FXSelector,void*);
00177   long onUpdHeader(FXObject*,FXSelector,void*);
00178 public:
00179   static FXint cmpFName(const FXIconItem* pa,const FXIconItem* pb);
00180   static FXint cmpRName(const FXIconItem* pa,const FXIconItem* pb);
00181   static FXint cmpFType(const FXIconItem* pa,const FXIconItem* pb);
00182   static FXint cmpRType(const FXIconItem* pa,const FXIconItem* pb);
00183   static FXint cmpFSize(const FXIconItem* pa,const FXIconItem* pb);
00184   static FXint cmpRSize(const FXIconItem* pa,const FXIconItem* pb);
00185   static FXint cmpFTime(const FXIconItem* pa,const FXIconItem* pb);
00186   static FXint cmpRTime(const FXIconItem* pa,const FXIconItem* pb);
00187   static FXint cmpFUser(const FXIconItem* pa,const FXIconItem* pb);
00188   static FXint cmpRUser(const FXIconItem* pa,const FXIconItem* pb);
00189   static FXint cmpFGroup(const FXIconItem* pa,const FXIconItem* pb);
00190   static FXint cmpRGroup(const FXIconItem* pa,const FXIconItem* pb);
00191 public:
00192   enum {
00193     ID_SORT_BY_NAME=FXIconList::ID_LAST,
00194     ID_SORT_BY_TYPE,
00195     ID_SORT_BY_SIZE,
00196     ID_SORT_BY_TIME,
00197     ID_SORT_BY_USER,
00198     ID_SORT_BY_GROUP,
00199     ID_SORT_REVERSE,
00200     ID_DIRECTORY_UP,
00201     ID_SET_PATTERN,
00202     ID_SET_DIRECTORY,
00203     ID_SHOW_HIDDEN,
00204     ID_HIDE_HIDDEN,
00205     ID_TOGGLE_HIDDEN,
00206     ID_REFRESHTIMER,
00207     ID_OPENTIMER,
00208     ID_LAST
00209     };
00210 public:
00211 
00212   /// Construct a file list
00213   FXFileList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00214 
00215   /// Create server-side resources
00216   virtual void create();
00217 
00218   /// Detach server-side resources
00219   virtual void detach();
00220 
00221   /// Destroy server-side resources
00222   virtual void destroy();
00223 
00224   /// Set current file
00225   void setCurrentFile(const FXString& file);
00226 
00227   /// Return current file
00228   FXString getCurrentFile() const;
00229 
00230   /// Set current directory
00231   void setDirectory(const FXString& path);
00232 
00233   /// Return current directory
00234   FXString getDirectory() const { return directory; }
00235 
00236   /// Change wildcard matching pattern
00237   void setPattern(const FXString& ptrn);
00238 
00239   /// Return wildcard pattern
00240   FXString getPattern() const { return pattern; }
00241 
00242   /// Return TRUE if item is a directory
00243   FXbool isItemDirectory(FXint index) const;
00244 
00245   /// Return TRUE if item is a file
00246   FXbool isItemFile(FXint index) const;
00247 
00248   /// Return TRUE if item is executable
00249   FXbool isItemExecutable(FXint index) const;
00250 
00251   /// Return name of item at index
00252   FXString getItemFilename(FXint index) const;
00253 
00254   /// Return full pathname of item at index
00255   FXString getItemPathname(FXint index) const;
00256 
00257   /// Return file association of item
00258   FXFileAssoc* getItemAssoc(FXint index) const;
00259 
00260   /// Return wildcard matching mode
00261   FXuint getMatchMode() const { return matchmode; }
00262 
00263   /// Change wildcard matching mode
00264   void setMatchMode(FXuint mode);
00265 
00266   /// Return TRUE if showing hidden files
00267   FXbool showHiddenFiles() const;
00268 
00269   /// Show or hide hidden files
00270   void showHiddenFiles(FXbool showing);
00271 
00272   /// Return TRUE if showing directories only
00273   FXbool showOnlyDirectories() const;
00274 
00275   /// Show directories only
00276   void showOnlyDirectories(FXbool shown);
00277 
00278   /// Change file associations
00279   void setAssociations(FXFileDict* assoc);
00280 
00281   /// Return file associations
00282   FXFileDict* getAssociations() const { return associations; }
00283 
00284   /// Save to stream
00285   virtual void save(FXStream& store) const;
00286 
00287   /// Load from stream
00288   virtual void load(FXStream& store);
00289 
00290   /// Destructor
00291   virtual ~FXFileList();
00292   };
00293 
00294 }
00295 
00296 #endif