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,2004 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.59 2004/02/08 17:17:33 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 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   FXFileAssoc  *assoc;                // File association
00054   FXDirItem    *link;                 // Link to next item
00055   FXDirItem    *list;                 // List of child items
00056   unsigned long size;                 // File size (if a file)
00057   FXTime        date;                 // Time of item
00058 protected:
00059   FXDirItem():assoc(NULL),link(NULL),list(NULL),size(0),date(0){}
00060 protected:
00061   enum {
00062     FOLDER      = 512,                // Directory item
00063     EXECUTABLE  = 1024,               // Executable item
00064     SYMLINK     = 2048,               // Symbolic linked item
00065     CHARDEV     = 4096,               // Character special item
00066     BLOCKDEV    = 8192,               // Block special item
00067     FIFO        = 16384,              // FIFO item
00068     SOCK        = 32768               // Socket item
00069     };
00070 public:
00071 
00072   /// Constructor
00073   FXDirItem(const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL):FXTreeItem(text,oi,ci,ptr),assoc(NULL),link(NULL),list(NULL),size(0),date(0){state=HASITEMS;}
00074 
00075   /// Return true if this is a file item
00076   FXbool isFile() const { return (state&(FOLDER|BLOCKDEV|CHARDEV|FIFO|SOCK))==0; }
00077 
00078   /// Return true if this is a directory item
00079   FXbool isDirectory() const { return (state&FOLDER)!=0; }
00080 
00081   /// Return true if this is an executable item
00082   FXbool isExecutable() const { return (state&EXECUTABLE)!=0; }
00083 
00084   /// Return true if this is a symbolic link item
00085   FXbool isSymlink() const { return (state&SYMLINK)!=0; }
00086 
00087   /// Return true if this is a character device item
00088   FXbool isChardev() const { return (state&CHARDEV)!=0; }
00089 
00090   /// Return true if this is a block device item
00091   FXbool isBlockdev() const { return (state&BLOCKDEV)!=0; }
00092 
00093   /// Return true if this is an FIFO item
00094   FXbool isFifo() const { return (state&FIFO)!=0; }
00095 
00096   /// Return true if this is a socket
00097   FXbool isSocket() const { return (state&SOCK)!=0; }
00098 
00099   /// Return the file-association object for this item
00100   FXFileAssoc* getAssoc() const { return assoc; }
00101 
00102   /// Return the file size for this item
00103   unsigned long getSize() const { return size; }
00104 
00105   /// Return the date for this item
00106   FXTime getDate() const { return date; }
00107   };
00108 
00109 
00110 /// Directory tree List
00111 class FXAPI FXDirList : public FXTreeList {
00112   FXDECLARE(FXDirList)
00113 protected:
00114   FXFileDict   *associations;         // Association table
00115   FXDirItem    *list;                 // Root item list
00116   FXString      dropdirectory;        // Drop directory
00117   FXDragAction  dropaction;           // Drop action
00118   FXString      dragfiles;            // Dragged files
00119   FXString      pattern;              // Pattern of file names
00120   FXuint        matchmode;            // File wildcard match mode
00121   FXuint        counter;              // Refresh counter
00122   FXIcon       *open_folder;          // Open folder icon
00123   FXIcon       *closed_folder;        // Closed folder icon
00124   FXIcon       *mini_doc;             // Document icon
00125   FXIcon       *mini_app;             // Application icon
00126   FXIcon       *cdromicon;
00127   FXIcon       *harddiskicon;
00128   FXIcon       *networkicon;
00129   FXIcon       *floppyicon;
00130   FXIcon       *zipdiskicon;
00131 protected:
00132   FXDirList();
00133   void listRootItems();
00134   void listChildItems(FXDirItem *par);
00135   virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
00136 private:
00137   FXDirList(const FXDirList&);
00138   FXDirList &operator=(const FXDirList&);
00139 public:
00140   long onRefreshTimer(FXObject*,FXSelector,void*);
00141   long onBeginDrag(FXObject*,FXSelector,void*);
00142   long onEndDrag(FXObject*,FXSelector,void*);
00143   long onDragged(FXObject*,FXSelector,void*);
00144   long onDNDEnter(FXObject*,FXSelector,void*);
00145   long onDNDLeave(FXObject*,FXSelector,void*);
00146   long onDNDMotion(FXObject*,FXSelector,void*);
00147   long onDNDDrop(FXObject*,FXSelector,void*);
00148   long onDNDRequest(FXObject*,FXSelector,void*);
00149   long onCmdSetValue(FXObject*,FXSelector,void*);
00150   long onCmdSetStringValue(FXObject*,FXSelector,void*);
00151   long onCmdGetStringValue(FXObject*,FXSelector,void*);
00152   long onCmdToggleHidden(FXObject*,FXSelector,void*);
00153   long onUpdToggleHidden(FXObject*,FXSelector,void*);
00154   long onCmdShowHidden(FXObject*,FXSelector,void*);
00155   long onUpdShowHidden(FXObject*,FXSelector,void*);
00156   long onCmdHideHidden(FXObject*,FXSelector,void*);
00157   long onUpdHideHidden(FXObject*,FXSelector,void*);
00158   long onCmdToggleFiles(FXObject*,FXSelector,void*);
00159   long onUpdToggleFiles(FXObject*,FXSelector,void*);
00160   long onCmdShowFiles(FXObject*,FXSelector,void*);
00161   long onUpdShowFiles(FXObject*,FXSelector,void*);
00162   long onCmdHideFiles(FXObject*,FXSelector,void*);
00163   long onUpdHideFiles(FXObject*,FXSelector,void*);
00164   long onCmdSetPattern(FXObject*,FXSelector,void*);
00165   long onUpdSetPattern(FXObject*,FXSelector,void*);
00166   long onCmdSortReverse(FXObject*,FXSelector,void*);
00167   long onUpdSortReverse(FXObject*,FXSelector,void*);
00168   long onCmdSortCase(FXObject*,FXSelector,void*);
00169   long onUpdSortCase(FXObject*,FXSelector,void*);
00170   long onCmdRefresh(FXObject*,FXSelector,void*);
00171 public:
00172   static FXint ascending(const FXTreeItem* a,const FXTreeItem* b);
00173   static FXint descending(const FXTreeItem* a,const FXTreeItem* b);
00174   static FXint ascendingCase(const FXTreeItem* a,const FXTreeItem* b);
00175   static FXint descendingCase(const FXTreeItem* a,const FXTreeItem* b);
00176 public:
00177   enum {
00178     ID_REFRESHTIMER=FXTreeList::ID_LAST,
00179     ID_SHOW_FILES,
00180     ID_HIDE_FILES,
00181     ID_TOGGLE_FILES,
00182     ID_SHOW_HIDDEN,
00183     ID_HIDE_HIDDEN,
00184     ID_TOGGLE_HIDDEN,
00185     ID_SET_PATTERN,
00186     ID_SORT_REVERSE,
00187     ID_SORT_CASE,
00188     ID_REFRESH,
00189     ID_LAST
00190     };
00191 public:
00192 
00193   /// Construct a directory list
00194   FXDirList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00195 
00196   /// Create server-side resources
00197   virtual void create();
00198 
00199   /// Detach server-side resources
00200   virtual void detach();
00201 
00202   /// Destroy server-side resources
00203   virtual void destroy();
00204 
00205   /// Scan the directories and update the items if needed, or if force is TRUE
00206   void scan(FXbool force=TRUE);
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   /// Collapse tree
00218   virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=FALSE);
00219 
00220   /// Expand tree
00221   virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=FALSE);
00222 
00223   /// Set current file
00224   void setCurrentFile(const FXString& file,FXbool notify=FALSE);
00225 
00226   /// Return current file
00227   FXString getCurrentFile() const;
00228 
00229   /// Set current directory
00230   void setDirectory(const FXString& path,FXbool notify=FALSE);
00231 
00232   /// Return current directory
00233   FXString getDirectory() const;
00234 
00235   /// Return absolute pathname of item
00236   FXString getItemPathname(const FXTreeItem* item) const;
00237 
00238   /// Return the item from the absolute pathname
00239   FXTreeItem* getPathnameItem(const FXString& path);
00240 
00241   /// Change wildcard matching pattern
00242   void setPattern(const FXString& ptrn);
00243 
00244   /// Return wildcard pattern
00245   FXString getPattern() const { return pattern; }
00246 
00247   /// Return wildcard matching mode
00248   FXuint getMatchMode() const { return matchmode; }
00249 
00250   /// Change wildcard matching mode
00251   void setMatchMode(FXuint mode);
00252 
00253   /// Return TRUE if showing files as well as directories
00254   FXbool showFiles() const;
00255 
00256   /// Show or hide normal files
00257   void showFiles(FXbool showing);
00258 
00259   /// Return TRUE if showing hidden files and directories
00260   FXbool showHiddenFiles() const;
00261 
00262   /// Show or hide hidden files and directories
00263   void showHiddenFiles(FXbool showing);
00264 
00265   /// Change file associations
00266   void setAssociations(FXFileDict* assoc);
00267 
00268   /// Return file associations
00269   FXFileDict* getAssociations() const { return associations; }
00270 
00271   /// Save to stream
00272   virtual void save(FXStream& store) const;
00273 
00274   /// Load from stream
00275   virtual void load(FXStream& store);
00276 
00277   /// Destructor
00278   virtual ~FXDirList();
00279   };
00280 
00281 }
00282 
00283 #endif

Copyright © 1997-2004 Jeroen van der Zijp