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

FXDirList.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * D i r e c t o r y L i s t W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXDirList.h,v 1.70 2006/01/22 17:58:00 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXDIRLIST_H
25 #define FXDIRLIST_H
26 
27 #ifndef FXTREELIST_H
28 #include "FXTreeList.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 struct FXFileAssoc;
35 class FXFileDict;
36 class FXIcon;
37 class FXDirList;
38 
39 
40 /// Directory List options
41 enum {
42  DIRLIST_SHOWFILES = 0x08000000, /// Show files as well as directories
43  DIRLIST_SHOWHIDDEN = 0x10000000, /// Show hidden files or directories
44  DIRLIST_NO_OWN_ASSOC = 0x20000000 /// Do not create associations for files
45  };
46 
47 
48 /// Directory item
49 class FXAPI FXDirItem : public FXTreeItem {
51  friend class FXDirList;
52 protected:
53  FXFileAssoc *assoc; // File association
54  FXDirItem *link; // Link to next item
55  FXDirItem *list; // List of child items
56  FXlong size; // File size (if a file)
57  FXTime date; // Time of item
58 private:
60  FXDirItem& operator=(const FXDirItem&);
61 protected:
62  FXDirItem():assoc(NULL),link(NULL),list(NULL),size(0L),date(0){}
63 public:
64  enum {
65  FOLDER = 512, /// Directory item
66  EXECUTABLE = 1024, /// Executable item
67  SYMLINK = 2048, /// Symbolic linked item
68  CHARDEV = 4096, /// Character special item
69  BLOCKDEV = 8192, /// Block special item
70  FIFO = 16384, /// FIFO item
71  SOCK = 32768 /// Socket item
72  };
73 public:
74 
75  /// Constructor
76  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;}
77 
78  /// Return true if this is a file item
79  FXbool isFile() const { return (state&(FOLDER|BLOCKDEV|CHARDEV|FIFO|SOCK))==0; }
80 
81  /// Return true if this is a directory item
82  FXbool isDirectory() const { return (state&FOLDER)!=0; }
83 
84  /// Return true if this is an executable item
85  FXbool isExecutable() const { return (state&EXECUTABLE)!=0; }
86 
87  /// Return true if this is a symbolic link item
88  FXbool isSymlink() const { return (state&SYMLINK)!=0; }
89 
90  /// Return true if this is a character device item
91  FXbool isChardev() const { return (state&CHARDEV)!=0; }
92 
93  /// Return true if this is a block device item
94  FXbool isBlockdev() const { return (state&BLOCKDEV)!=0; }
95 
96  /// Return true if this is an FIFO item
97  FXbool isFifo() const { return (state&FIFO)!=0; }
98 
99  /// Return true if this is a socket
100  FXbool isSocket() const { return (state&SOCK)!=0; }
101 
102  /// Return the file-association object for this item
103  FXFileAssoc* getAssoc() const { return assoc; }
104 
105  /// Return the file size for this item
106  FXlong getSize() const { return size; }
107 
108  /// Return the date for this item
109  FXTime getDate() const { return date; }
110  };
111 
112 
113 /**
114 * A Directory List widget provides a tree-structured view of the file system.
115 * It automatically updates itself periodically by re-scanning the file system
116 * for any changes. As it scans the displayed directories and files, it automatically
117 * determines the icons to be displayed by consulting the file-associations registry
118 * settings. A number of messages can be sent to the Directory List to control the
119 * filter pattern, sorting order, case sensitivity, and hidden file display mode.
120 * The Directory list widget supports drags and drops of files.
121 */
122 class FXAPI FXDirList : public FXTreeList {
124 protected:
125  FXFileDict *associations; // Association table
126  FXDirItem *list; // Root item list
127  FXString dropdirectory; // Drop directory
128  FXDragAction dropaction; // Drop action
129  FXString dragfiles; // Dragged files
130  FXString pattern; // Pattern of file names
131  FXuint matchmode; // File wildcard match mode
132  FXuint counter; // Refresh counter
133  FXIcon *open_folder; // Open folder icon
134  FXIcon *closed_folder; // Closed folder icon
135  FXIcon *mini_doc; // Document icon
136  FXIcon *mini_app; // Application icon
137  FXIcon *cdromicon;
138  FXIcon *harddiskicon;
139  FXIcon *networkicon;
140  FXIcon *floppyicon;
141  FXIcon *zipdiskicon;
142 protected:
143  FXDirList();
144  void listRootItems();
145  void listChildItems(FXDirItem *par);
146  virtual FXTreeItem* createItem(const FXString& text,FXIcon* oi,FXIcon* ci,void* ptr);
147 private:
148  FXDirList(const FXDirList&);
149  FXDirList &operator=(const FXDirList&);
150 public:
151  long onRefreshTimer(FXObject*,FXSelector,void*);
152  long onBeginDrag(FXObject*,FXSelector,void*);
153  long onEndDrag(FXObject*,FXSelector,void*);
154  long onDragged(FXObject*,FXSelector,void*);
155  long onDNDEnter(FXObject*,FXSelector,void*);
156  long onDNDLeave(FXObject*,FXSelector,void*);
157  long onDNDMotion(FXObject*,FXSelector,void*);
158  long onDNDDrop(FXObject*,FXSelector,void*);
159  long onDNDRequest(FXObject*,FXSelector,void*);
160  long onCmdSetValue(FXObject*,FXSelector,void*);
161  long onCmdSetStringValue(FXObject*,FXSelector,void*);
162  long onCmdGetStringValue(FXObject*,FXSelector,void*);
163  long onCmdToggleHidden(FXObject*,FXSelector,void*);
164  long onUpdToggleHidden(FXObject*,FXSelector,void*);
165  long onCmdShowHidden(FXObject*,FXSelector,void*);
166  long onUpdShowHidden(FXObject*,FXSelector,void*);
167  long onCmdHideHidden(FXObject*,FXSelector,void*);
168  long onUpdHideHidden(FXObject*,FXSelector,void*);
169  long onCmdToggleFiles(FXObject*,FXSelector,void*);
170  long onUpdToggleFiles(FXObject*,FXSelector,void*);
171  long onCmdShowFiles(FXObject*,FXSelector,void*);
172  long onUpdShowFiles(FXObject*,FXSelector,void*);
173  long onCmdHideFiles(FXObject*,FXSelector,void*);
174  long onUpdHideFiles(FXObject*,FXSelector,void*);
175  long onCmdSetPattern(FXObject*,FXSelector,void*);
176  long onUpdSetPattern(FXObject*,FXSelector,void*);
177  long onCmdSortReverse(FXObject*,FXSelector,void*);
178  long onUpdSortReverse(FXObject*,FXSelector,void*);
179  long onCmdSortCase(FXObject*,FXSelector,void*);
180  long onUpdSortCase(FXObject*,FXSelector,void*);
181  long onCmdRefresh(FXObject*,FXSelector,void*);
182 public:
183  static FXint ascending(const FXTreeItem* a,const FXTreeItem* b);
184  static FXint descending(const FXTreeItem* a,const FXTreeItem* b);
185  static FXint ascendingCase(const FXTreeItem* a,const FXTreeItem* b);
186  static FXint descendingCase(const FXTreeItem* a,const FXTreeItem* b);
187 public:
188  enum {
189  ID_REFRESHTIMER=FXTreeList::ID_LAST,
190  ID_SHOW_FILES,
191  ID_HIDE_FILES,
192  ID_TOGGLE_FILES,
193  ID_SHOW_HIDDEN,
194  ID_HIDE_HIDDEN,
195  ID_TOGGLE_HIDDEN,
196  ID_SET_PATTERN,
197  ID_SORT_REVERSE,
198  ID_SORT_CASE,
199  ID_REFRESH,
200  ID_LAST
201  };
202 public:
203 
204  /// Construct a directory list
205  FXDirList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
206 
207  /// Create server-side resources
208  virtual void create();
209 
210  /// Detach server-side resources
211  virtual void detach();
212 
213  /// Destroy server-side resources
214  virtual void destroy();
215 
216  /// Scan the directories and update the items if needed, or if force is TRUE
217  void scan(FXbool force=TRUE);
218 
219  /// Return TRUE if item is a directory
220  FXbool isItemDirectory(const FXTreeItem* item) const;
221 
222  /// Return TRUE if item is a file
223  FXbool isItemFile(const FXTreeItem* item) const;
224 
225  /// Return TRUE if item is executable
226  FXbool isItemExecutable(const FXTreeItem* item) const;
227 
228  /// Collapse tree
229  virtual FXbool collapseTree(FXTreeItem* tree,FXbool notify=FALSE);
230 
231  /// Expand tree
232  virtual FXbool expandTree(FXTreeItem* tree,FXbool notify=FALSE);
233 
234  /// Set current file
235  void setCurrentFile(const FXString& file,FXbool notify=FALSE);
236 
237  /// Return current file
238  FXString getCurrentFile() const;
239 
240  /// Set current directory
241  void setDirectory(const FXString& path,FXbool notify=FALSE);
242 
243  /// Return current directory
244  FXString getDirectory() const;
245 
246  /// Return absolute pathname of item
247  FXString getItemPathname(const FXTreeItem* item) const;
248 
249  /// Return the item from the absolute pathname
250  FXTreeItem* getPathnameItem(const FXString& path);
251 
252  /// Change wildcard matching pattern
253  void setPattern(const FXString& ptrn);
254 
255  /// Return wildcard pattern
256  FXString getPattern() const { return pattern; }
257 
258  /// Return wildcard matching mode
259  FXuint getMatchMode() const { return matchmode; }
260 
261  /// Change wildcard matching mode
262  void setMatchMode(FXuint mode);
263 
264  /// Return TRUE if showing files as well as directories
265  FXbool showFiles() const;
266 
267  /// Show or hide normal files
268  void showFiles(FXbool showing);
269 
270  /// Return TRUE if showing hidden files and directories
271  FXbool showHiddenFiles() const;
272 
273  /// Show or hide hidden files and directories
274  void showHiddenFiles(FXbool showing);
275 
276  /// Change file associations
277  void setAssociations(FXFileDict* assoc);
278 
279  /// Return file associations
280  FXFileDict* getAssociations() const { return associations; }
281 
282  /// Save to stream
283  virtual void save(FXStream& store) const;
284 
285  /// Load from stream
286  virtual void load(FXStream& store);
287 
288  /// Destructor
289  virtual ~FXDirList();
290  };
291 
292 }
293 
294 #endif
FXDragAction
Drag and drop actions.
Definition: fxdefs.h:330
Tree list Item.
Definition: FXTreeList.h:63
Registers stuff to know about the extension.
Definition: FXFileDict.h:38
#define TRUE
Definition: fxdefs.h:32
Definition: FXWindow.h:241
unsigned int FXuint
Definition: fxdefs.h:396
Do not create associations for files.
Definition: FXDirList.h:47
FXuint FXSelector
Association key.
Definition: FXObject.h:53
A Tree List Widget organizes items in a hierarchical, tree-like fashion.
Definition: FXTreeList.h:235
#define FXAPI
Definition: fxdefs.h:122
FXuchar FXbool
Definition: fxdefs.h:393
Base composite.
Definition: FXComposite.h:35
#define NULL
Definition: fxdefs.h:41
The File Association dictionary associates a file extension with a File Association record which cont...
Definition: FXFileDict.h:85
Show hidden files or directories.
Definition: FXDirList.h:46
long FXTime
Definition: fxdefs.h:448
int FXint
Definition: fxdefs.h:397
An Icon is an image with two additional server-side resources: a shape bitmap, which is used to mask ...
Definition: FXIcon.h:45
Directory item.
Definition: FXDirList.h:57
#define FALSE
Definition: fxdefs.h:35
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
A Directory List widget provides a tree-structured view of the file system.
Definition: FXDirList.h:122
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
Show files as well as directories.
Definition: FXDirList.h:45
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp