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