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

FXExplorer.h

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