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,2006 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.70 2006/01/22 17:58:00 fox Exp $                         *
00023 ********************************************************************************/
00024 #ifndef FX_DISABLEFILEDIRDIALOGS
00025 
00026 #ifndef FXDIRLIST_H
00027 #define FXDIRLIST_H
00028 
00029 #ifndef FXTREELIST_H
00030 #include "FXTreeList.h"
00031 #endif
00032 
00033 namespace FX {
00034 
00035 
00036 struct FXFileAssoc;
00037 class  FXFileDict;
00038 class  FXIcon;
00039 class  FXDirList;
00040 
00041 
00043 enum {
00044   DIRLIST_SHOWFILES     = 0x08000000, 
00045   DIRLIST_SHOWHIDDEN    = 0x10000000, 
00046   DIRLIST_NO_OWN_ASSOC  = 0x20000000  
00047   };
00048 
00049 
00051 class FXAPI FXDirItem : public FXTreeItem {
00052   FXDECLARE(FXDirItem)
00053   friend class FXDirList;
00054 protected:
00055   FXFileAssoc  *assoc;                // File association
00056   FXDirItem    *link;                 // Link to next item
00057   FXDirItem    *list;                 // List of child items
00058   FXlong        size;                 // File size (if a file)
00059   FXTime        date;                 // Time of item
00060 private:
00061   FXDirItem(const FXDirItem&);
00062   FXDirItem& operator=(const FXDirItem&);
00063 protected:
00064   FXDirItem():assoc(NULL),link(NULL),list(NULL),size(0L),date(0){}
00065 public:
00066   enum {
00067     FOLDER      = 512,          
00068     EXECUTABLE  = 1024,         
00069     SYMLINK     = 2048,         
00070     CHARDEV     = 4096,         
00071     BLOCKDEV    = 8192,         
00072     FIFO        = 16384,        
00073     SOCK        = 32768         
00074     };
00075 public:
00076 
00078   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;}
00079 
00081   FXbool isFile() const { return (state&(FOLDER|BLOCKDEV|CHARDEV|FIFO|SOCK))==0; }
00082 
00084   FXbool isDirectory() const { return (state&FOLDER)!=0; }
00085 
00087   FXbool isExecutable() const { return (state&EXECUTABLE)!=0; }
00088 
00090   FXbool isSymlink() const { return (state&SYMLINK)!=0; }
00091 
00093   FXbool isChardev() const { return (state&CHARDEV)!=0; }
00094 
00096   FXbool isBlockdev() const { return (state&BLOCKDEV)!=0; }
00097 
00099   FXbool isFifo() const { return (state&FIFO)!=0; }
00100 
00102   FXbool isSocket() const { return (state&SOCK)!=0; }
00103 
00105   FXFileAssoc* getAssoc() const { return assoc; }
00106 
00108   FXlong getSize() const { return size; }
00109 
00111   FXTime getDate() const { return date; }
00112   };
00113 
00114 
00124 class FXAPI FXDirList : public FXTreeList {
00125   FXDECLARE(FXDirList)
00126 protected:
00127   FXFileDict   *associations;         // Association table
00128   FXDirItem    *list;                 // Root item list
00129   FXString      dropdirectory;        // Drop directory
00130   FXDragAction  dropaction;           // Drop action
00131   FXString      dragfiles;            // Dragged files
00132   FXString      pattern;              // Pattern of file names
00133   FXuint        matchmode;            // File wildcard match mode
00134   FXuint        counter;              // Refresh counter
00135   FXIcon       *open_folder;          // Open folder icon
00136   FXIcon       *closed_folder;        // Closed folder icon
00137   FXIcon       *mini_doc;             // Document icon
00138   FXIcon       *mini_app;             // Application icon
00139   FXIcon       *cdromicon;
00140   FXIcon       *harddiskicon;
00141   FXIcon       *networkicon;
00142   FXIcon       *floppyicon;
00143   FXIcon       *zipdiskicon;
00144 protected:
00145   FXDirList();
00146   void listRootItems();
00147   void listChildItems(FXDirItem *par);
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 public:
00185   static FXint ascending(const FXTreeItem* a,const FXTreeItem* b);
00186   static FXint descending(const FXTreeItem* a,const FXTreeItem* b);
00187   static FXint ascendingCase(const FXTreeItem* a,const FXTreeItem* b);
00188   static FXint descendingCase(const FXTreeItem* a,const FXTreeItem* b);
00189 public:
00190   enum {
00191     ID_REFRESHTIMER=FXTreeList::ID_LAST,
00192     ID_SHOW_FILES,
00193     ID_HIDE_FILES,
00194     ID_TOGGLE_FILES,
00195     ID_SHOW_HIDDEN,
00196     ID_HIDE_HIDDEN,
00197     ID_TOGGLE_HIDDEN,
00198     ID_SET_PATTERN,
00199     ID_SORT_REVERSE,
00200     ID_SORT_CASE,
00201     ID_REFRESH,
00202     ID_LAST
00203     };
00204 public:
00205 
00207   FXDirList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00208 
00210   virtual void create();
00211 
00213   virtual void detach();
00214 
00216   virtual void destroy();
00217 
00219   void scan(FXbool force=TRUE);
00220 
00222   FXbool isItemDirectory(const FXTreeItem* item) const;
00223 
00225   FXbool isItemFile(const FXTreeItem* item) const;
00226 
00228   FXbool isItemExecutable(const FXTreeItem* item) const;
00229 
00231   virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=FALSE);
00232 
00234   virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=FALSE);
00235 
00237   void setCurrentFile(const FXString& file,FXbool notify=FALSE);
00238 
00240   FXString getCurrentFile() const;
00241 
00243   void setDirectory(const FXString& path,FXbool notify=FALSE);
00244 
00246   FXString getDirectory() const;
00247 
00249   FXString getItemPathname(const FXTreeItem* item) const;
00250 
00252   FXTreeItem* getPathnameItem(const FXString& path);
00253 
00255   void setPattern(const FXString& ptrn);
00256 
00258   FXString getPattern() const { return pattern; }
00259 
00261   FXuint getMatchMode() const { return matchmode; }
00262 
00264   void setMatchMode(FXuint mode);
00265 
00267   FXbool showFiles() const;
00268 
00270   void showFiles(FXbool showing);
00271 
00273   FXbool showHiddenFiles() const;
00274 
00276   void showHiddenFiles(FXbool showing);
00277 
00279   void setAssociations(FXFileDict* assoc);
00280 
00282   FXFileDict* getAssociations() const { return associations; }
00283 
00285   virtual void save(FXStream& store) const;
00286 
00288   virtual void load(FXStream& store);
00289 
00291   virtual ~FXDirList();
00292   };
00293 
00294 }
00295 
00296 #endif
00297 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:20 2009 for TnFOX by doxygen v1.4.7