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

FXDirList.h

Go to the documentation of this file.
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,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (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                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXDirList.h,v 1.85 2009/01/06 13:07:23 fox Exp $                         *
00022 ********************************************************************************/
00023 #ifndef FXDIRLIST_H
00024 #define FXDIRLIST_H
00025 
00026 #ifndef FXTREELIST_H
00027 #include "FXTreeList.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 
00033 struct FXFileAssoc;
00034 class  FXFileDict;
00035 class  FXIcon;
00036 class  FXDirList;
00037 
00038 
00039 /// Directory List options
00040 enum {
00041   DIRLIST_SHOWFILES     = 0x08000000, /// Show files as well as directories
00042   DIRLIST_SHOWHIDDEN    = 0x10000000, /// Show hidden files or directories
00043   DIRLIST_NO_OWN_ASSOC  = 0x20000000  /// Do not create associations for files
00044   };
00045 
00046 
00047 /// Directory item
00048 class FXAPI FXDirItem : public FXTreeItem {
00049   FXDECLARE(FXDirItem)
00050   friend class FXDirList;
00051 protected:
00052   FXFileAssoc *assoc;           // File association
00053   FXDirItem   *link;            // Link to next item
00054   FXDirItem   *list;            // List of child items
00055   FXlong       size;            // File size (if a file)
00056   FXTime       date;            // Time of item
00057 private:
00058   FXDirItem(const FXDirItem&);
00059   FXDirItem& operator=(const FXDirItem&);
00060 protected:
00061   FXDirItem():assoc(NULL),link(NULL),list(NULL),size(0L),date(0){}
00062 public:
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),assoc(NULL),link(NULL),list(NULL),size(0),date(0){state=HASITEMS;}
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   FXlong getSize() const { return size; }
00106 
00107   /// Return the date for this item, in nanoseconds
00108   FXTime getDate() const { return date; }
00109   };
00110 
00111 
00112 /**
00113 * A Directory List widget provides a tree-structured view of the file system.
00114 * It automatically updates itself periodically by re-scanning the file system
00115 * for any changes.  As it scans the displayed directories and files, it automatically
00116 * determines the icons to be displayed by consulting the file-associations registry
00117 * settings.  A number of messages can be sent to the Directory List to control the
00118 * filter pattern, sorting order, case sensitivity, and hidden file display mode.
00119 * The Directory list widget supports drags and drops of files.
00120 */
00121 class FXAPI FXDirList : public FXTreeList {
00122   FXDECLARE(FXDirList)
00123 protected:
00124   FXFileDict   *associations;           // Association table
00125   FXDirItem    *list;                   // Root item list
00126   FXIcon       *opendiricon;            // Open folder icon
00127   FXIcon       *closeddiricon;          // Closed folder icon
00128   FXIcon       *documenticon;           // Document icon
00129   FXIcon       *applicationicon;        // Application icon
00130   FXIcon       *cdromicon;              // CDROM icon
00131   FXIcon       *harddiskicon;           // Hard drive icon
00132   FXIcon       *networkicon;            // Network icon
00133   FXIcon       *floppyicon;             // Floppy icon
00134   FXIcon       *zipdiskicon;            // Zip disk icon
00135   FXString      pattern;                // Pattern of file names
00136   FXString      dropdirectory;          // Drop directory
00137   FXString      dragfiles;              // Dragged file names
00138   FXString      dropfiles;              // Dropped file names
00139   FXDragAction  dropaction;             // Drop action
00140   FXuint        matchmode;              // File wildcard match mode
00141   FXuint        counter;                // Refresh counter
00142   FXbool        draggable;              // Dragable files
00143 protected:
00144   FXDirList();
00145   void listRootItems();
00146   void listChildItems(FXDirItem *par);
00147   FXString getSelectedFiles() const;
00148   virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
00149 private:
00150   FXDirList(const FXDirList&);
00151   FXDirList &operator=(const FXDirList&);
00152 public:
00153   long onRefreshTimer(FXObject*,FXSelector,void*);
00154   long onBeginDrag(FXObject*,FXSelector,void*);
00155   long onEndDrag(FXObject*,FXSelector,void*);
00156   long onDragged(FXObject*,FXSelector,void*);
00157   long onDNDEnter(FXObject*,FXSelector,void*);
00158   long onDNDLeave(FXObject*,FXSelector,void*);
00159   long onDNDMotion(FXObject*,FXSelector,void*);
00160   long onDNDDrop(FXObject*,FXSelector,void*);
00161   long onDNDRequest(FXObject*,FXSelector,void*);
00162   long onCmdSetValue(FXObject*,FXSelector,void*);
00163   long onCmdSetStringValue(FXObject*,FXSelector,void*);
00164   long onCmdGetStringValue(FXObject*,FXSelector,void*);
00165   long onCmdToggleHidden(FXObject*,FXSelector,void*);
00166   long onUpdToggleHidden(FXObject*,FXSelector,void*);
00167   long onCmdShowHidden(FXObject*,FXSelector,void*);
00168   long onUpdShowHidden(FXObject*,FXSelector,void*);
00169   long onCmdHideHidden(FXObject*,FXSelector,void*);
00170   long onUpdHideHidden(FXObject*,FXSelector,void*);
00171   long onCmdToggleFiles(FXObject*,FXSelector,void*);
00172   long onUpdToggleFiles(FXObject*,FXSelector,void*);
00173   long onCmdShowFiles(FXObject*,FXSelector,void*);
00174   long onUpdShowFiles(FXObject*,FXSelector,void*);
00175   long onCmdHideFiles(FXObject*,FXSelector,void*);
00176   long onUpdHideFiles(FXObject*,FXSelector,void*);
00177   long onCmdSetPattern(FXObject*,FXSelector,void*);
00178   long onUpdSetPattern(FXObject*,FXSelector,void*);
00179   long onCmdSortReverse(FXObject*,FXSelector,void*);
00180   long onUpdSortReverse(FXObject*,FXSelector,void*);
00181   long onCmdSortCase(FXObject*,FXSelector,void*);
00182   long onUpdSortCase(FXObject*,FXSelector,void*);
00183   long onCmdRefresh(FXObject*,FXSelector,void*);
00184   long onCmdDropAsk(FXObject*,FXSelector,void*);
00185   long onCmdDropCopy(FXObject*,FXSelector,void*);
00186   long onCmdDropMove(FXObject*,FXSelector,void*);
00187   long onCmdDropLink(FXObject*,FXSelector,void*);
00188 public:
00189   static FXint ascending(const FXTreeItem* a,const FXTreeItem* b);
00190   static FXint descending(const FXTreeItem* a,const FXTreeItem* b);
00191   static FXint ascendingCase(const FXTreeItem* a,const FXTreeItem* b);
00192   static FXint descendingCase(const FXTreeItem* a,const FXTreeItem* b);
00193 public:
00194   enum {
00195     ID_REFRESHTIMER=FXTreeList::ID_LAST,
00196     ID_DROPASK,
00197     ID_DROPCOPY,
00198     ID_DROPMOVE,
00199     ID_DROPLINK,
00200     ID_SHOW_FILES,
00201     ID_HIDE_FILES,
00202     ID_TOGGLE_FILES,
00203     ID_SHOW_HIDDEN,
00204     ID_HIDE_HIDDEN,
00205     ID_TOGGLE_HIDDEN,
00206     ID_SET_PATTERN,
00207     ID_SORT_REVERSE,
00208     ID_SORT_CASE,
00209     ID_REFRESH,
00210     ID_LAST
00211     };
00212 public:
00213 
00214   /// Construct a directory list
00215   FXDirList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00216 
00217   /// Create server-side resources
00218   virtual void create();
00219 
00220   /// Detach server-side resources
00221   virtual void detach();
00222 
00223   /// Destroy server-side resources
00224   virtual void destroy();
00225 
00226   /// Scan the directories and update the items if needed, or if force is true
00227   void scan(FXbool force=true);
00228 
00229   /// Return true if item is a directory
00230   FXbool isItemDirectory(const FXTreeItem* item) const;
00231 
00232   /// Return true if item is a file
00233   FXbool isItemFile(const FXTreeItem* item) const;
00234 
00235   /// Return true if item is executable
00236   FXbool isItemExecutable(const FXTreeItem* item) const;
00237 
00238   /// Collapse tree
00239   virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=false);
00240 
00241   /// Expand tree
00242   virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=false);
00243 
00244   /// Set current file
00245   void setCurrentFile(const FXString& file,FXbool notify=false);
00246 
00247   /// Return current file
00248   FXString getCurrentFile() const;
00249 
00250   /// Set current directory
00251   void setDirectory(const FXString& path,FXbool notify=false);
00252 
00253   /// Return current directory
00254   FXString getDirectory() const;
00255 
00256   /// Return absolute pathname of item
00257   FXString getItemPathname(const FXTreeItem* item) const;
00258 
00259   /// Return the item from the absolute pathname
00260   FXTreeItem* getPathnameItem(const FXString& path);
00261 
00262   /// Change wildcard matching pattern
00263   void setPattern(const FXString& ptrn);
00264 
00265   /// Return wildcard pattern
00266   FXString getPattern() const { return pattern; }
00267 
00268   /// Return wildcard matching mode
00269   FXuint getMatchMode() const { return matchmode; }
00270 
00271   /// Change wildcard matching mode
00272   void setMatchMode(FXuint mode);
00273 
00274   /// Return true if showing files as well as directories
00275   FXbool showFiles() const;
00276 
00277   /// Show or hide normal files
00278   void showFiles(FXbool flag);
00279 
00280   /// Return true if showing hidden files and directories
00281   FXbool showHiddenFiles() const;
00282 
00283   /// Show or hide hidden files and directories
00284   void showHiddenFiles(FXbool flag);
00285 
00286   /// Change file associations; delete the old one unless it was shared
00287   void setAssociations(FXFileDict* assoc,FXbool owned=false);
00288 
00289   /// Return file associations
00290   FXFileDict* getAssociations() const { return associations; }
00291 
00292   /// Set draggable files
00293   void setDraggableFiles(FXbool flag);
00294 
00295   /// Are files draggable
00296   FXbool getDraggableFiles() const { return draggable; }
00297 
00298   /// Save to stream
00299   virtual void save(FXStream& store) const;
00300 
00301   /// Load from stream
00302   virtual void load(FXStream& store);
00303 
00304   /// Destructor
00305   virtual ~FXDirList();
00306   };
00307 
00308 }
00309 
00310 #endif

Copyright © 1997-2009 Jeroen van der Zijp