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