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

FXFileList.h
1 /********************************************************************************
2 * *
3 * F i l e L i s t W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (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 *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXFILELIST_H
22 #define FXFILELIST_H
23 
24 #ifndef FXICONLIST_H
25 #include "FXIconList.h"
26 #endif
27 
28 namespace FX {
29 
30 
31 struct FXFileAssoc;
32 class FXFileList;
33 class FXIconSource;
34 class FXFileAssociations;
35 
36 
38 enum {
39  FILELIST_SHOWHIDDEN = 0x04000000,
40  FILELIST_SHOWDIRS = 0x08000000,
41  FILELIST_SHOWFILES = 0x10000000,
42  FILELIST_SHOWIMAGES = 0x20000000,
43  FILELIST_NO_OWN_ASSOC = 0x40000000,
44  FILELIST_NO_PARENT = 0x80000000
45  };
46 
47 
49 class FXAPI FXFileItem : public FXIconItem {
50  FXDECLARE(FXFileItem)
51  friend class FXFileList;
52 protected:
53  FXFileAssoc *assoc; // File association record
54  FXFileItem *link; // Link to next item
55  FXlong size; // File size
56  FXTime date; // File time
57  FXuint mode; // Mode flags
58 private:
59  FXFileItem(const FXFileItem&);
60  FXFileItem& operator=(const FXFileItem&);
61 protected:
62  FXFileItem():assoc(nullptr),link(nullptr),size(0),date(0){}
63 public:
64 
66  FXFileItem(const FXString& text,FXIcon* bi=nullptr,FXIcon* mi=nullptr,void* ptr=nullptr):FXIconItem(text,bi,mi,ptr),assoc(nullptr),link(nullptr),size(0L),date(0L),mode(0){}
67 
69  FXbool isFile() const { return (mode&(FXIO::File))!=0; }
70 
72  FXbool isDirectory() const { return (mode&FXIO::Directory)!=0; }
73 
75  FXbool isExecutable() const { return (mode&FXIO::File)!=0 && (mode&FXIO::AllExec)!=0; }
76 
78  FXbool isSymlink() const { return (mode&FXIO::SymLink)!=0; }
79 
81  FXbool isChardev() const { return (mode&FXIO::Character)!=0; }
82 
84  FXbool isBlockdev() const { return (mode&FXIO::Block)!=0; }
85 
87  FXbool isFifo() const { return (mode&FXIO::Fifo)!=0; }
88 
90  FXbool isSocket() const { return (mode&FXIO::Socket)!=0; }
91 
93  FXbool isNavigational() const { return (label[0]=='.' && (label[1]=='\t' || (label[1]=='.' && label[2]=='\t'))); }
94 
96  void setAssoc(FXFileAssoc* a){ assoc=a; }
97 
99  FXFileAssoc* getAssoc() const { return assoc; }
100 
102  void setSize(FXlong s){ size=s; }
103 
105  FXlong getSize() const { return size; }
106 
108  void setDate(FXTime d){ date=d; }
109 
111  FXTime getDate() const { return date; }
112 
114  void setMode(FXuint m){ mode=m; }
115 
117  FXuint getMode() const { return mode; }
118  };
119 
120 
131 class FXAPI FXFileList : public FXIconList {
132  FXDECLARE(FXFileList)
133 protected:
134  FXFileAssociations *associations; // Association table
135  FXIconSource *iconloader; // Icon loader
136  FXFileItem *list; // File item list
137  FXIcon *big_folder; // Big folder icon
138  FXIcon *mini_folder; // Mini folder icon
139  FXIcon *big_doc; // Big document icon
140  FXIcon *mini_doc; // Mini document icon
141  FXIcon *big_app; // Big application icon
142  FXIcon *mini_app; // Mini application icon
143  FXString directory; // Current directory
144  FXString pattern; // Pattern of file names
145  FXString timeformat; // File time formatting
146  FXString startdirectory; // Start directory
147  FXString dropdirectory; // Drop directory
148  FXString clipfiles; // Clipped files
149  FXString dragfiles; // Dragged files
150  FXString dropfiles; // Dropped files
151  FXDragAction dropaction; // Drop action
152  FXuint matchmode; // File wildcard match mode
153  FXint imagesize; // Image size
154  FXTime timestamp; // Time when last refreshed
155  FXuint counter; // Refresh counter
156  FXbool clipcut; // Cut or copy
157  FXbool draggable; // Dragable files
158 protected:
159  FXFileList();
160  FXbool listItems(FXbool force,FXbool notify);
161  FXString getSelectedFiles() const;
162  virtual FXIconItem *createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr);
163  void delete_files(const FXString& files);
164  void copy_files(const FXString& directory,const FXString& files);
165  void move_files(const FXString& directory,const FXString& files);
166  static FXint compareSectionNatural(const FXchar* s1,const FXchar* s2,FXint s,FXbool ci=false);
167 private:
168  FXFileList(const FXFileList&);
169  FXFileList &operator=(const FXFileList&);
170 public:
171  long onOpenTimer(FXObject*,FXSelector,void*);
172  long onRefreshTimer(FXObject*,FXSelector,void*);
173  long onPreviewChore(FXObject*,FXSelector,void*);
174  long onDNDEnter(FXObject*,FXSelector,void*);
175  long onDNDLeave(FXObject*,FXSelector,void*);
176  long onDNDMotion(FXObject*,FXSelector,void*);
177  long onDNDDrop(FXObject*,FXSelector,void*);
178  long onDNDRequest(FXObject*,FXSelector,void*);
179  long onBeginDrag(FXObject*,FXSelector,void*);
180  long onEndDrag(FXObject*,FXSelector,void*);
181  long onDragged(FXObject*,FXSelector,void*);
182  long onClipboardLost(FXObject*,FXSelector,void*);
183  long onClipboardRequest(FXObject*,FXSelector,void*);
184  long onCmdSetValue(FXObject*,FXSelector,void*);
185  long onCmdGetStringValue(FXObject*,FXSelector,void*);
186  long onCmdSetStringValue(FXObject*,FXSelector,void*);
187  long onCmdDirectoryUp(FXObject*,FXSelector,void*);
188  long onUpdDirectoryUp(FXObject*,FXSelector,void*);
189  long onCmdSortByName(FXObject*,FXSelector,void*);
190  long onUpdSortByName(FXObject*,FXSelector,void*);
191  long onCmdSortByType(FXObject*,FXSelector,void*);
192  long onUpdSortByType(FXObject*,FXSelector,void*);
193  long onCmdSortBySize(FXObject*,FXSelector,void*);
194  long onUpdSortBySize(FXObject*,FXSelector,void*);
195  long onCmdSortByTime(FXObject*,FXSelector,void*);
196  long onUpdSortByTime(FXObject*,FXSelector,void*);
197  long onCmdSortByUser(FXObject*,FXSelector,void*);
198  long onUpdSortByUser(FXObject*,FXSelector,void*);
199  long onCmdSortByGroup(FXObject*,FXSelector,void*);
200  long onUpdSortByGroup(FXObject*,FXSelector,void*);
201  long onCmdSortReverse(FXObject*,FXSelector,void*);
202  long onUpdSortReverse(FXObject*,FXSelector,void*);
203  long onCmdSortCase(FXObject*,FXSelector,void*);
204  long onUpdSortCase(FXObject*,FXSelector,void*);
205  long onCmdSetPattern(FXObject*,FXSelector,void*);
206  long onUpdSetPattern(FXObject*,FXSelector,void*);
207  long onCmdSetDirectory(FXObject*,FXSelector,void*);
208  long onUpdSetDirectory(FXObject*,FXSelector,void*);
209  long onCmdToggleHidden(FXObject*,FXSelector,void*);
210  long onUpdToggleHidden(FXObject*,FXSelector,void*);
211  long onCmdShowHidden(FXObject*,FXSelector,void*);
212  long onUpdShowHidden(FXObject*,FXSelector,void*);
213  long onCmdHideHidden(FXObject*,FXSelector,void*);
214  long onUpdHideHidden(FXObject*,FXSelector,void*);
215  long onCmdToggleImages(FXObject*,FXSelector,void*);
216  long onUpdToggleImages(FXObject*,FXSelector,void*);
217  long onCmdHeader(FXObject*,FXSelector,void*);
218  long onUpdHeader(FXObject*,FXSelector,void*);
219  long onCmdRefresh(FXObject*,FXSelector,void*);
220  long onUpdHaveSel(FXObject*,FXSelector,void*);
221  long onCmdCutSel(FXObject*,FXSelector,void*);
222  long onCmdCopySel(FXObject*,FXSelector,void*);
223  long onCmdPasteSel(FXObject*,FXSelector,void*);
224  long onCmdDeleteSel(FXObject*,FXSelector,void*);
225  long onCmdDropAsk(FXObject*,FXSelector,void*);
226  long onCmdDropCopy(FXObject*,FXSelector,void*);
227  long onCmdDropMove(FXObject*,FXSelector,void*);
228  long onCmdDropLink(FXObject*,FXSelector,void*);
229 public:
230  static FXint ascending(const FXIconItem* a,const FXIconItem* b);
231  static FXint descending(const FXIconItem* a,const FXIconItem* b);
232  static FXint ascendingCase(const FXIconItem* a,const FXIconItem* b);
233  static FXint descendingCase(const FXIconItem* a,const FXIconItem* b);
234  static FXint ascendingType(const FXIconItem* a,const FXIconItem* b);
235  static FXint descendingType(const FXIconItem* a,const FXIconItem* b);
236  static FXint ascendingSize(const FXIconItem* a,const FXIconItem* b);
237  static FXint descendingSize(const FXIconItem* a,const FXIconItem* b);
238  static FXint ascendingTime(const FXIconItem* a,const FXIconItem* b);
239  static FXint descendingTime(const FXIconItem* a,const FXIconItem* b);
240  static FXint ascendingUser(const FXIconItem* a,const FXIconItem* b);
241  static FXint descendingUser(const FXIconItem* a,const FXIconItem* b);
242  static FXint ascendingGroup(const FXIconItem* a,const FXIconItem* b);
243  static FXint descendingGroup(const FXIconItem* a,const FXIconItem* b);
244 public:
245  enum {
246  ID_OPENTIMER=FXIconList::ID_LAST,
247  ID_REFRESHTIMER,
248  ID_DROPASK,
249  ID_DROPCOPY,
250  ID_DROPMOVE,
251  ID_DROPLINK,
252  ID_PREVIEWCHORE,
253  ID_SORT_BY_NAME,
273  ID_LAST
274  };
275 public:
276 
278  FXFileList(FXComposite *p,FXObject* tgt=nullptr,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
279 
281  virtual void create();
282 
284  virtual void detach();
285 
287  virtual void destroy();
288 
290  FXbool setCurrentFile(const FXString& file,FXbool notify=false);
291 
293  FXString getCurrentFile() const;
294 
296  FXbool setDirectory(const FXString& path,FXbool notify=false);
297 
299  FXString getDirectory() const { return directory; }
300 
302  FXString getItemFilename(FXint index) const;
303 
305  FXString getItemPathname(FXint index) const;
306 
308  FXbool isItemFile(FXint index) const;
309 
311  FXbool isItemDirectory(FXint index) const;
312 
314  FXbool isItemExecutable(FXint index) const;
315 
317  FXbool isItemSymlink(FXint index) const;
318 
320  FXbool isItemNavigational(FXint index) const;
321 
323  FXFileAssoc* getItemAssoc(FXint index) const;
324 
326  FXlong getItemSize(FXint index) const;
327 
329  FXTime getItemDate(FXint index) const;
330 
332  FXuint getItemMode(FXint index) const;
333 
335  FXbool selectMatching(const FXString& ptrn="*",FXuint mode=FXPath::PathName|FXPath::NoEscape,FXbool notify=false);
336 
338  void setPattern(const FXString& ptrn="*",FXbool notify=false);
339 
341  FXString getPattern() const { return pattern; }
342 
344  void setMatchMode(FXuint mode=FXPath::PathName|FXPath::NoEscape,FXbool notify=false);
345 
347  FXuint getMatchMode() const { return matchmode; }
348 
350  void showHiddenFiles(FXbool flag,FXbool notify=false);
351 
353  FXbool showHiddenFiles() const;
354 
356  void showOnlyDirectories(FXbool flag,FXbool notify=false);
357 
359  FXbool showOnlyDirectories() const;
360 
362  void showOnlyFiles(FXbool flag,FXbool notify=false);
363 
365  FXbool showOnlyFiles() const;
366 
368  void showParents(FXbool flag,FXbool notify=false);
369 
371  FXbool showParents() const;
372 
374  void showImages(FXbool flag,FXbool notify=false);
375 
377  FXbool showImages() const;
378 
380  void setImageSize(FXint size,FXbool notify=false);
381 
383  FXint getImageSize() const { return imagesize; }
384 
386  void setDraggableFiles(FXbool flag,FXbool notify=false);
387 
389  FXbool getDraggableFiles() const { return draggable; }
390 
392  void setTimeFormat(const FXString& fmt,FXbool notify=false);
393 
395  const FXString& getTimeFormat() const { return timeformat; }
396 
398  void setAssociations(FXFileAssociations* assoc,FXbool owned=false,FXbool notify=false);
399 
401  FXFileAssociations* getAssociations() const { return associations; }
402 
404  void setIconSource(FXIconSource* src){ iconloader=src; }
405 
407  FXIconSource* getIconSource() const { return iconloader; }
408 
410  virtual void save(FXStream& store) const;
411 
413  virtual void load(FXStream& store);
414 
416  virtual ~FXFileList();
417  };
418 
419 }
420 
421 #endif
Sticky bit.
Definition: FXIO.h:107
FXbool isBlockdev() const
Return true if this is a block device item.
Definition: FXFileList.h:84
Is directory.
Definition: FXIO.h:98
Write permisson for all.
Definition: FXIO.h:91
FXbool isFifo() const
Return true if this is an FIFO item.
Definition: FXFileList.h:87
FXString getPattern() const
Return wildcard pattern.
Definition: FXFileList.h:341
Is regular file.
Definition: FXIO.h:99
FXint getImageSize() const
Return images preview size.
Definition: FXFileList.h:383
Registers stuff to know about the extension.
Definition: FXFileAssociations.h:36
Delete selected files.
Definition: FXFileList.h:272
void setIconSource(FXIconSource *src)
Change icon loader.
Definition: FXFileList.h:404
Show hidden files.
Definition: FXFileList.h:265
FXbool isSocket() const
Return true if this is a socket.
Definition: FXFileList.h:90
A File List widget provides an icon rich view of the file system.
Definition: FXFileList.h:131
An icon source is a class that loads an icon of any type.
Definition: FXIconSource.h:47
Sort by group name.
Definition: FXFileList.h:259
Refresh immediately.
Definition: FXFileList.h:269
Toggle sort case sensitivity.
Definition: FXFileList.h:261
Reverse sort order.
Definition: FXFileList.h:260
FXIconSource * getIconSource() const
Return icon loader.
Definition: FXFileList.h:407
Base composite.
Definition: FXComposite.h:32
const FXString & getTimeFormat() const
Return file time format.
Definition: FXFileList.h:395
File item.
Definition: FXFileList.h:49
FXTime getDate() const
Return the date for this item, in nanoseconds.
Definition: FXFileList.h:111
Sort by name.
Definition: FXFileList.h:254
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
FXuint getMode() const
Return file mode bits.
Definition: FXFileList.h:117
FXFileAssoc * getAssoc() const
Return the file-association object for this item.
Definition: FXFileList.h:99
Copy selected files to clipboard.
Definition: FXFileList.h:271
Toggle display of hidden files.
Definition: FXFileList.h:267
FXbool isDirectory() const
Return true if this is a directory item.
Definition: FXFileList.h:72
FXFileAssociations * getAssociations() const
Return file associations.
Definition: FXFileList.h:401
FXString getDirectory() const
Return current directory.
Definition: FXFileList.h:299
void setDate(FXTime d)
Set the date for this item, in nanoseconds.
Definition: FXFileList.h:108
Definition: FX4Splitter.h:28
An Icon is an image with two additional server-side resources: a shape bitmap, which is used to mask ...
Definition: FXIcon.h:42
Sort by size.
Definition: FXFileList.h:256
Icon item.
Definition: FXIconList.h:55
Move up one directory.
Definition: FXFileList.h:262
FXlong getSize() const
Return the file size for this item.
Definition: FXFileList.h:105
Sort by owner name.
Definition: FXFileList.h:258
Set directory.
Definition: FXFileList.h:264
FXbool isExecutable() const
Return true if this is an executable item.
Definition: FXFileList.h:75
FXFileItem(const FXString &text, FXIcon *bi=nullptr, FXIcon *mi=nullptr, void *ptr=nullptr)
Constructor.
Definition: FXFileList.h:66
FXuint getMatchMode() const
Return wildcard matching mode.
Definition: FXFileList.h:347
FXbool isChardev() const
Return true if this is a character device item.
Definition: FXFileList.h:81
void setAssoc(FXFileAssoc *a)
Set the file-association object for this item.
Definition: FXFileList.h:96
The FileAssociations object manages file associations between a file extension and a FileAssoc record...
Definition: FXFileAssociations.h:101
void setSize(FXlong s)
Set the file size for this item.
Definition: FXFileList.h:102
void setMode(FXuint m)
Set file mode bits.
Definition: FXFileList.h:114
A Icon List Widget displays a list of items, each with a text and optional icon.
Definition: FXIconList.h:200
Block device.
Definition: FXIO.h:109
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:138
FXbool getDraggableFiles() const
Are draggable files.
Definition: FXFileList.h:389
Hidden file.
Definition: FXIO.h:97
FXbool isSymlink() const
Return true if this is a symbolic link item.
Definition: FXFileList.h:78
Socket device.
Definition: FXIO.h:110
Character device.
Definition: FXIO.h:108
Toggle display of images.
Definition: FXFileList.h:268
Hide hidden files.
Definition: FXFileList.h:266
Set match pattern.
Definition: FXFileList.h:263
FXbool isNavigational() const
Return true if item is a special navigational item like &#39;.&#39; or &#39;..&#39;.
Definition: FXFileList.h:93
Cut selected files to clipboard.
Definition: FXFileList.h:270
Sort by type.
Definition: FXFileList.h:255
Sort by access time.
Definition: FXFileList.h:257
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42
FXbool isFile() const
Return true if this is a file item.
Definition: FXFileList.h:69

Copyright © 1997-2022 Jeroen van der Zijp