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

FXFileList.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * F i l e L i s t W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,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: FXFileList.h,v 1.57 2006/01/22 17:58:01 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXFILELIST_H
25 #define FXFILELIST_H
26 
27 #ifndef FXICONLIST_H
28 #include "FXIconList.h"
29 #endif
30 
31 namespace FX {
32 
33 struct FXFileAssoc;
34 class FXFileDict;
35 class FXFileList;
36 class FXIcon;
37 class FXIconSource;
38 class FXIconDict;
39 
40 
41 /// File List options
42 enum {
43  FILELIST_SHOWHIDDEN = 0x04000000, /// Show hidden files or directories
44  FILELIST_SHOWDIRS = 0x08000000, /// Show only directories
45  FILELIST_SHOWFILES = 0x10000000, /// Show only files
46  FILELIST_SHOWIMAGES = 0x20000000, /// Show preview of images
47  FILELIST_NO_OWN_ASSOC = 0x40000000, /// Do not create associations for files
48  FILELIST_NO_PARENT = 0x80000000 /// Suppress display of '.' and '..'
49  };
50 
51 
52 
53 /// File item
54 class FXAPI FXFileItem : public FXIconItem {
56  friend class FXFileList;
57 protected:
58  FXFileAssoc *assoc; // File association record
59  FXFileItem *link; // Link to next item
60  FXlong size; // File size
61  FXTime date; // File time
62 private:
63  FXFileItem(const FXFileItem&);
64  FXFileItem& operator=(const FXFileItem&);
65 protected:
66  FXFileItem():assoc(NULL),link(NULL),size(0),date(0){}
67 protected:
68  enum{
69  FOLDER = 64, // Directory item
70  EXECUTABLE = 128, // Executable item
71  SYMLINK = 256, // Symbolic linked item
72  CHARDEV = 512, // Character special item
73  BLOCKDEV = 1024, // Block special item
74  FIFO = 2048, // FIFO item
75  SOCK = 4096, // Socket item
76  SHARE = 8192 // Share
77  };
78 public:
79  /// Constructor
80  FXFileItem(const FXString& text,FXIcon* bi=NULL,FXIcon* mi=NULL,void* ptr=NULL):FXIconItem(text,bi,mi,ptr),assoc(NULL),link(NULL),size(0L),date(0){}
81 
82  /// Return true if this is a file item
83  FXbool isFile() const { return (state&(FOLDER|BLOCKDEV|CHARDEV|FIFO|SOCK|SHARE))==0; }
84 
85  /// Return true if this is a directory item
86  FXbool isDirectory() const { return (state&FOLDER)!=0; }
87 
88  /// Return true if this is a share item
89  FXbool isShare() const { return (state&SHARE)!=0; }
90 
91  /// Return true if this is an executable item
92  FXbool isExecutable() const { return (state&EXECUTABLE)!=0; }
93 
94  /// Return true if this is a symbolic link item
95  FXbool isSymlink() const { return (state&SYMLINK)!=0; }
96 
97  /// Return true if this is a character device item
98  FXbool isChardev() const { return (state&CHARDEV)!=0; }
99 
100  /// Return true if this is a block device item
101  FXbool isBlockdev() const { return (state&BLOCKDEV)!=0; }
102 
103  /// Return true if this is an FIFO item
104  FXbool isFifo() const { return (state&FIFO)!=0; }
105 
106  /// Return true if this is a socket
107  FXbool isSocket() const { return (state&SOCK)!=0; }
108 
109  /// Return the file-association object for this item
110  FXFileAssoc* getAssoc() const { return assoc; }
111 
112  /// Return the file size for this item
113  FXlong getSize() const { return size; }
114 
115  /// Return the date for this item
116  FXTime getDate() const { return date; }
117  };
118 
119 
120 /**
121 * A File List widget provides an icon rich view of the file system.
122 * It automatically updates itself periodically by re-scanning the file system
123 * for any changes. As it scans the displayed directory, it automatically
124 * determines the icons to be displayed by consulting the file associations registry
125 * settings. A number of messages can be sent to the File List to control the
126 * filter pattern, sort category, sorting order, case sensitivity, and hidden file
127 * display mode.
128 * The File list widget supports drags and drops of files.
129 */
130 class FXAPI FXFileList : public FXIconList {
132 protected:
133  FXString directory; // Current directory
134  FXString orgdirectory; // Original directory
135  FXString dropdirectory; // Drop directory
136  FXDragAction dropaction; // Drop action
137  FXString dragfiles; // Dragged files
138  FXFileDict *associations; // Association table
139  FXFileItem *list; // File item list
140  FXString pattern; // Pattern of file names
141  FXuint matchmode; // File wildcard match mode
142  FXuint counter; // Refresh counter
143  FXint imagesize; // Image size
144  FXTime timestamp; // Time when last refreshed
145  FXIcon *big_folder; // Big folder icon
146  FXIcon *mini_folder; // Mini folder icon
147  FXIcon *big_doc; // Big document icon
148  FXIcon *mini_doc; // Mini document icon
149  FXIcon *big_app; // Big application icon
150  FXIcon *mini_app; // Mini application icon
151 protected:
152  FXFileList();
153  virtual FXIconItem *createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr);
154  void listItems(FXbool force);
155 private:
156  FXFileList(const FXFileList&);
157  FXFileList &operator=(const FXFileList&);
158 public:
159  long onOpenTimer(FXObject*,FXSelector,void*);
160  long onRefreshTimer(FXObject*,FXSelector,void*);
161  long onDNDEnter(FXObject*,FXSelector,void*);
162  long onDNDLeave(FXObject*,FXSelector,void*);
163  long onDNDMotion(FXObject*,FXSelector,void*);
164  long onDNDDrop(FXObject*,FXSelector,void*);
165  long onDNDRequest(FXObject*,FXSelector,void*);
166  long onBeginDrag(FXObject*,FXSelector,void*);
167  long onEndDrag(FXObject*,FXSelector,void*);
168  long onDragged(FXObject*,FXSelector,void*);
169  long onCmdSetValue(FXObject*,FXSelector,void*);
170  long onCmdGetStringValue(FXObject*,FXSelector,void*);
171  long onCmdSetStringValue(FXObject*,FXSelector,void*);
172  long onCmdDirectoryUp(FXObject*,FXSelector,void*);
173  long onUpdDirectoryUp(FXObject*,FXSelector,void*);
174  long onCmdSortByName(FXObject*,FXSelector,void*);
175  long onUpdSortByName(FXObject*,FXSelector,void*);
176  long onCmdSortByType(FXObject*,FXSelector,void*);
177  long onUpdSortByType(FXObject*,FXSelector,void*);
178  long onCmdSortBySize(FXObject*,FXSelector,void*);
179  long onUpdSortBySize(FXObject*,FXSelector,void*);
180  long onCmdSortByTime(FXObject*,FXSelector,void*);
181  long onUpdSortByTime(FXObject*,FXSelector,void*);
182  long onCmdSortByUser(FXObject*,FXSelector,void*);
183  long onUpdSortByUser(FXObject*,FXSelector,void*);
184  long onCmdSortByGroup(FXObject*,FXSelector,void*);
185  long onUpdSortByGroup(FXObject*,FXSelector,void*);
186  long onCmdSortReverse(FXObject*,FXSelector,void*);
187  long onUpdSortReverse(FXObject*,FXSelector,void*);
188  long onCmdSortCase(FXObject*,FXSelector,void*);
189  long onUpdSortCase(FXObject*,FXSelector,void*);
190  long onCmdSetPattern(FXObject*,FXSelector,void*);
191  long onUpdSetPattern(FXObject*,FXSelector,void*);
192  long onCmdSetDirectory(FXObject*,FXSelector,void*);
193  long onUpdSetDirectory(FXObject*,FXSelector,void*);
194  long onCmdToggleHidden(FXObject*,FXSelector,void*);
195  long onUpdToggleHidden(FXObject*,FXSelector,void*);
196  long onCmdShowHidden(FXObject*,FXSelector,void*);
197  long onUpdShowHidden(FXObject*,FXSelector,void*);
198  long onCmdHideHidden(FXObject*,FXSelector,void*);
199  long onUpdHideHidden(FXObject*,FXSelector,void*);
200  long onCmdToggleImages(FXObject*,FXSelector,void*);
201  long onUpdToggleImages(FXObject*,FXSelector,void*);
202  long onCmdHeader(FXObject*,FXSelector,void*);
203  long onUpdHeader(FXObject*,FXSelector,void*);
204  long onCmdRefresh(FXObject*,FXSelector,void*);
205 public:
206  static FXint ascending(const FXIconItem* a,const FXIconItem* b);
207  static FXint descending(const FXIconItem* a,const FXIconItem* b);
208  static FXint ascendingCase(const FXIconItem* a,const FXIconItem* b);
209  static FXint descendingCase(const FXIconItem* a,const FXIconItem* b);
210  static FXint ascendingType(const FXIconItem* a,const FXIconItem* b);
211  static FXint descendingType(const FXIconItem* a,const FXIconItem* b);
212  static FXint ascendingSize(const FXIconItem* a,const FXIconItem* b);
213  static FXint descendingSize(const FXIconItem* a,const FXIconItem* b);
214  static FXint ascendingTime(const FXIconItem* a,const FXIconItem* b);
215  static FXint descendingTime(const FXIconItem* a,const FXIconItem* b);
216  static FXint ascendingUser(const FXIconItem* a,const FXIconItem* b);
217  static FXint descendingUser(const FXIconItem* a,const FXIconItem* b);
218  static FXint ascendingGroup(const FXIconItem* a,const FXIconItem* b);
219  static FXint descendingGroup(const FXIconItem* a,const FXIconItem* b);
220 public:
221  enum {
222  ID_REFRESHTIMER=FXIconList::ID_LAST,
223  ID_OPENTIMER,
224  ID_SORT_BY_NAME, /// Sort by name
225  ID_SORT_BY_TYPE, /// Sort by type
226  ID_SORT_BY_SIZE, /// Sort by size
227  ID_SORT_BY_TIME, /// Sort by access time
228  ID_SORT_BY_USER, /// Sort by owner name
229  ID_SORT_BY_GROUP, /// Sort by group name
230  ID_SORT_REVERSE, /// Reverse sort order
231  ID_SORT_CASE, /// Toggle sort case sensitivity
232  ID_DIRECTORY_UP, /// Move up one directory
233  ID_SET_PATTERN, /// Set match pattern
234  ID_SET_DIRECTORY, /// Set directory
235  ID_SHOW_HIDDEN, /// Show hidden files
236  ID_HIDE_HIDDEN, /// Hide hidden files
237  ID_TOGGLE_HIDDEN, /// Toggle display of hidden files
238  ID_TOGGLE_IMAGES, /// Toggle display of images
239  ID_REFRESH, /// Refresh immediately
240  ID_LAST
241  };
242 public:
243 
244  /// Construct a file list
245  FXFileList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
246 
247  /// Create server-side resources
248  virtual void create();
249 
250  /// Detach server-side resources
251  virtual void detach();
252 
253  /// Destroy server-side resources
254  virtual void destroy();
255 
256  /// Scan the current directory and update the items if needed, or if force is TRUE
257  void scan(FXbool force=TRUE);
258 
259  /// Set current file
260  void setCurrentFile(const FXString& file,FXbool notify=FALSE);
261 
262  /// Return current file
263  FXString getCurrentFile() const;
264 
265  /// Set current directory
266  void setDirectory(const FXString& path);
267 
268  /// Return current directory
269  FXString getDirectory() const { return directory; }
270 
271  /// Change wildcard matching pattern
272  void setPattern(const FXString& ptrn);
273 
274  /// Return wildcard pattern
275  FXString getPattern() const { return pattern; }
276 
277  /// Return TRUE if item is a directory
278  FXbool isItemDirectory(FXint index) const;
279 
280  /// Return TRUE if item is a directory
281  FXbool isItemShare(FXint index) const;
282 
283  /// Return TRUE if item is a file
284  FXbool isItemFile(FXint index) const;
285 
286  /// Return TRUE if item is executable
287  FXbool isItemExecutable(FXint index) const;
288 
289  /// Return name of item at index
290  FXString getItemFilename(FXint index) const;
291 
292  /// Return full pathname of item at index
293  FXString getItemPathname(FXint index) const;
294 
295  /// Return file association of item
296  FXFileAssoc* getItemAssoc(FXint index) const;
297 
298  /// Return wildcard matching mode
299  FXuint getMatchMode() const { return matchmode; }
300 
301  /// Change wildcard matching mode
302  void setMatchMode(FXuint mode);
303 
304  /// Return TRUE if showing hidden files
305  FXbool showHiddenFiles() const;
306 
307  /// Show or hide hidden files
308  void showHiddenFiles(FXbool showing);
309 
310  /// Return TRUE if showing directories only
311  FXbool showOnlyDirectories() const;
312 
313  /// Show directories only
314  void showOnlyDirectories(FXbool shown);
315 
316  /// Return TRUE if showing files only
317  FXbool showOnlyFiles() const;
318 
319  /// Show files only
320  void showOnlyFiles(FXbool shown);
321 
322  /// Return TRUE if image preview on
323  FXbool showImages() const;
324 
325  /// Show or hide preview images
326  void showImages(FXbool showing);
327 
328  /// Return images preview size
329  FXint getImageSize() const { return imagesize; }
330 
331  /// Change images preview size
332  void setImageSize(FXint size);
333 
334  /// Return TRUE if showing parent directories
335  FXbool showParents() const;
336 
337  /// Show parent directories
338  void showParents(FXbool shown);
339 
340  /// Change file associations
341  void setAssociations(FXFileDict* assoc);
342 
343  /// Return file associations
344  FXFileDict* getAssociations() const { return associations; }
345 
346  /// Save to stream
347  virtual void save(FXStream& store) const;
348 
349  /// Load from stream
350  virtual void load(FXStream& store);
351 
352  /// Destructor
353  virtual ~FXFileList();
354  };
355 
356 }
357 
358 #endif
bool isShare(const FXString &file)
Return true if input path is a file share.
FXDragAction
Drag and drop actions.
Definition: fxdefs.h:330
Registers stuff to know about the extension.
Definition: FXFileDict.h:38
#define TRUE
Definition: fxdefs.h:32
Suppress display of '.' and '..'.
Definition: FXFileList.h:51
Definition: FXWindow.h:241
unsigned int FXuint
Definition: fxdefs.h:396
FXuint FXSelector
Association key.
Definition: FXObject.h:53
A File List widget provides an icon rich view of the file system.
Definition: FXFileList.h:120
#define FXAPI
Definition: fxdefs.h:122
FXuchar FXbool
Definition: fxdefs.h:393
Do not create associations for files.
Definition: FXFileList.h:50
Base composite.
Definition: FXComposite.h:35
File item.
Definition: FXFileList.h:62
#define NULL
Definition: fxdefs.h:41
Show only files.
Definition: FXFileList.h:48
Show hidden files or directories.
Definition: FXFileList.h:46
The File Association dictionary associates a file extension with a File Association record which cont...
Definition: FXFileDict.h:85
long FXTime
Definition: fxdefs.h:448
Definition: FX4Splitter.h:31
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
Icon item.
Definition: FXIconList.h:66
#define FALSE
Definition: fxdefs.h:35
A Icon List Widget displays a list of items, each with a text and optional icon.
Definition: FXIconList.h:189
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
Show only directories.
Definition: FXFileList.h:47
FXString directory(const FXString &file)
Return the directory part of the path name.
Show preview of images.
Definition: FXFileList.h:49
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp