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

FXDirList.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                     D i r e c t o r y   L i s t   W i d g e t                 *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,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: FXDirList.h,v 1.34 2002/09/12 12:31:28 fox Exp $                         *
00023 ********************************************************************************/
00024 #ifndef FXDIRLIST_H
00025 #define FXDIRLIST_H
00026 
00027 #ifndef FXTREELIST_H
00028 #include "FXTreeList.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 struct FXTimer;
00035 struct FXFileAssoc;
00036 class  FXFileDict;
00037 class  FXIcon;
00038 class FXDirList;
00039 
00040 
00041 /// Directory List options
00042 enum {
00043   DIRLIST_SHOWFILES     = 0x08000000, /// Show files as well as directories
00044   DIRLIST_SHOWHIDDEN    = 0x10000000, /// Show hidden files or directories
00045   DIRLIST_NO_OWN_ASSOC  = 0x20000000  /// Do not create associations for files
00046   };
00047 
00048 
00049 /// Directory item
00050 class FXAPI FXDirItem : public FXTreeItem {
00051   FXDECLARE(FXDirItem)
00052   friend class FXDirList;
00053 protected:
00054   FXDirItem    *iprev;
00055   FXDirItem    *inext;
00056   FXDirItem    *list;
00057   FXFileAssoc  *assoc;
00058   unsigned long size;
00059   FXTime        date;
00060 protected:
00061   FXDirItem():iprev(NULL),inext(NULL),list(NULL),assoc(NULL),date(0){}
00062 protected:
00063   enum {
00064     FOLDER      = 512,                // Directory item
00065     EXECUTABLE  = 1024,               // Executable item
00066     SYMLINK     = 2048,               // Symbolic linked item
00067     CHARDEV     = 4096,               // Character special item
00068     BLOCKDEV    = 8192,               // Block special item
00069     FIFO        = 16384,              // FIFO item
00070     SOCK        = 32768               // Socket item
00071     };
00072 public:
00073 
00074   /// Constructor
00075   FXDirItem(const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL):FXTreeItem(text,oi,ci,ptr),iprev(NULL),inext(NULL),list(NULL),assoc(NULL),size(0),date(0){}
00076 
00077   /// Return true if this is a file item
00078   FXbool isFile() const { return (state&(FOLDER|BLOCKDEV|CHARDEV|FIFO|SOCK))==0; }
00079 
00080   /// Return true if this is a directory item
00081   FXbool isDirectory() const { return (state&FOLDER)!=0; }
00082 
00083   /// Return true if this is an executable item
00084   FXbool isExecutable() const { return (state&EXECUTABLE)!=0; }
00085 
00086   /// Return true if this is a symbolic link item
00087   FXbool isSymlink() const { return (state&SYMLINK)!=0; }
00088 
00089   /// Return true if this is a character device item
00090   FXbool isChardev() const { return (state&CHARDEV)!=0; }
00091 
00092   /// Return true if this is a block device item
00093   FXbool isBlockdev() const { return (state&BLOCKDEV)!=0; }
00094 
00095   /// Return true if this is an FIFO item
00096   FXbool isFifo() const { return (state&FIFO)!=0; }
00097 
00098   /// Return true if this is a socket
00099   FXbool isSocket() const { return (state&SOCK)!=0; }
00100 
00101   /// Return the file-association object for this item
00102   FXFileAssoc* getAssoc() const { return assoc; }
00103 
00104   /// Return the file size for this item
00105   unsigned long getSize() const { return size; }
00106 
00107   /// Return the date for this item
00108   FXTime getDate() const { return date; }
00109   };
00110 
00111 
00112 /// Directory tree List
00113 class FXAPI FXDirList : public FXTreeList {
00114   FXDECLARE(FXDirList)
00115 protected:
00116   FXFileDict   *associations;         // Association table
00117   FXString      dropdirectory;        // Drop directory
00118   FXDragAction  dropaction;           // Drop action
00119   FXString      dragfiles;            // Dragged files
00120   FXString      pattern;              // Pattern of file names
00121   FXuint        matchmode;            // File wildcard match mode
00122   FXTimer      *refresh;              // Refresh timer
00123   FXIcon       *closed_folder;        // Closed folder icon
00124   FXIcon       *open_folder;          // Open folder icon
00125   FXIcon       *mini_doc;             // Document icon
00126   FXIcon       *mini_app;             // Application icon
00127   FXIcon       *cdromicon;
00128   FXIcon       *harddiskicon;
00129   FXIcon       *networkicon;
00130   FXIcon       *floppyicon;
00131   FXIcon       *zipdiskicon;
00132   FXuint        counter;              // Refresh counter
00133 protected:
00134   FXDirList();
00135   virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
00136   FXchar *getpath(const FXTreeItem* item,FXchar* pathname) const;
00137   FXTreeItem* getitem(FXchar* pathname);
00138   FXbool scanRootDir(FXbool relist);
00139   FXbool scanSubDir(FXDirItem *par,FXchar *pathname,FXbool relist);
00140   FXbool listSubDir(FXDirItem *par,FXchar *pathname);
00141   FXbool listRoots();
00142 private:
00143   FXDirList(const FXDirList&);
00144   FXDirList &operator=(const FXDirList&);
00145 public:
00146   long onRefresh(FXObject*,FXSelector,void*);
00147   long onBeginDrag(FXObject*,FXSelector,void*);
00148   long onEndDrag(FXObject*,FXSelector,void*);
00149   long onDragged(FXObject*,FXSelector,void*);
00150   long onDNDEnter(FXObject*,FXSelector,void*);
00151   long onDNDLeave(FXObject*,FXSelector,void*);
00152   long onDNDMotion(FXObject*,FXSelector,void*);
00153   long onDNDDrop(FXObject*,FXSelector,void*);
00154   long onDNDRequest(FXObject*,FXSelector,void*);
00155   long onOpened(FXObject*,FXSelector,void*);
00156   long onClosed(FXObject*,FXSelector,void*);
00157   long onExpanded(FXObject*,FXSelector,void*);
00158   long onCollapsed(FXObject*,FXSelector,void*);
00159   long onCmdSetValue(FXObject*,FXSelector,void*);
00160   long onCmdSetStringValue(FXObject*,FXSelector,void*);
00161   long onCmdGetStringValue(FXObject*,FXSelector,void*);
00162   long onCmdToggleHidden(FXObject*,FXSelector,void*);
00163   long onUpdToggleHidden(FXObject*,FXSelector,void*);
00164   long onCmdShowHidden(FXObject*,FXSelector,void*);
00165   long onUpdShowHidden(FXObject*,FXSelector,void*);
00166   long onCmdHideHidden(FXObject*,FXSelector,void*);
00167   long onUpdHideHidden(FXObject*,FXSelector,void*);
00168   long onCmdToggleFiles(FXObject*,FXSelector,void*);
00169   long onUpdToggleFiles(FXObject*,FXSelector,void*);
00170   long onCmdShowFiles(FXObject*,FXSelector,void*);
00171   long onUpdShowFiles(FXObject*,FXSelector,void*);
00172   long onCmdHideFiles(FXObject*,FXSelector,void*);
00173   long onUpdHideFiles(FXObject*,FXSelector,void*);
00174   long onCmdSetPattern(FXObject*,FXSelector,void*);
00175   long onUpdSetPattern(FXObject*,FXSelector,void*);
00176   long onCmdSortReverse(FXObject*,FXSelector,void*);
00177   long onUpdSortReverse(FXObject*,FXSelector,void*);
00178 public:
00179   static FXint cmpFName(const FXTreeItem* a,const FXTreeItem* b);
00180   static FXint cmpRName(const FXTreeItem* pa,const FXTreeItem* pb);
00181 public:
00182   enum {
00183     ID_REFRESH=FXTreeList::ID_LAST,
00184     ID_SHOW_FILES,
00185     ID_HIDE_FILES,
00186     ID_TOGGLE_FILES,
00187     ID_SHOW_HIDDEN,
00188     ID_HIDE_HIDDEN,
00189     ID_TOGGLE_HIDDEN,
00190     ID_SET_PATTERN,
00191     ID_SORT_REVERSE,
00192     ID_LAST
00193     };
00194 public:
00195 
00196   /// Construct a directory list
00197   FXDirList(FXComposite *p,FXint nvis,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00198 
00199   /// Create server-side resources
00200   virtual void create();
00201 
00202   /// Detach server-side resources
00203   virtual void detach();
00204 
00205   /// Destroy server-side resources
00206   virtual void destroy();
00207 
00208   /// Return TRUE if item is a directory
00209   FXbool isItemDirectory(const FXTreeItem* item) const;
00210 
00211   /// Return TRUE if item is a file
00212   FXbool isItemFile(const FXTreeItem* item) const;
00213 
00214   /// Return TRUE if item is executable
00215   FXbool isItemExecutable(const FXTreeItem* item) const;
00216 
00217   /// Set current file
00218   void setCurrentFile(const FXString& file);
00219 
00220   /// Return current file
00221   FXString getCurrentFile() const;
00222 
00223   /// Set current directory
00224   void setDirectory(const FXString& path);
00225 
00226   /// Return current directory
00227   FXString getDirectory() const;
00228 
00229   /// Return name of item
00230   FXString getItemFilename(const FXTreeItem* item) const;
00231 
00232   /// Return full pathname of item
00233   FXString getItemPathname(const FXTreeItem* item) const;
00234 
00235   /// Change wildcard matching pattern
00236   void setPattern(const FXString& ptrn);
00237 
00238   /// Return wildcard pattern
00239   FXString getPattern() const { return pattern; }
00240 
00241   /// Return wildcard matching mode
00242   FXuint getMatchMode() const { return matchmode; }
00243 
00244   /// Change wildcard matching mode
00245   void setMatchMode(FXuint mode);
00246 
00247   /// Return TRUE if showing files as well as directories
00248   FXbool showFiles() const;
00249 
00250   /// Show or hide normal files
00251   void showFiles(FXbool showing);
00252 
00253   /// Return TRUE if showing hidden files and directories
00254   FXbool showHiddenFiles() const;
00255 
00256   /// Show or hide hidden files and directories
00257   void showHiddenFiles(FXbool showing);
00258 
00259   /// Change file associations
00260   void setAssociations(FXFileDict* assoc);
00261 
00262   /// Return file associations
00263   FXFileDict* getAssociations() const { return associations; }
00264 
00265   /// Save to stream
00266   virtual void save(FXStream& store) const;
00267 
00268   /// Load from stream
00269   virtual void load(FXStream& store);
00270 
00271   /// Destructor
00272   virtual ~FXDirList();
00273   };
00274 
00275 }
00276 
00277 #endif