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