1 #ifndef DIRLIST_H
2 #define DIRLIST_H
3 
4 struct FileAssoc;
5 class FileDict;
6 class DirList;
7 
8 // Tree item
9 class FXAPI TreeItem : public FXTreeItem
10 {
FXDECLARE(TreeItem)11     FXDECLARE(TreeItem)
12     friend class DirList;
13 protected:
14     TreeItem()
15     {}
16 public:
17     // Constructor
FXTreeItem(text,oi,ci,ptr)18     TreeItem(const FXString& text, FXIcon* oi = NULL, FXIcon* ci = NULL, void* ptr = NULL) : FXTreeItem(text, oi, ci, ptr)
19     {}
20 };
21 
22 // Directory item
23 class FXAPI DirItem : public FXTreeItem
24 {
25     FXDECLARE(DirItem)
26     friend class DirList;
27 protected:
28     FileAssoc* assoc;               // File association
29     DirItem*   link;                // Link to next item
30     DirItem*   list;                // List of child items
31     FXulong    size;                // File size (if a file)
32     FXTime     date;                // Time of item
33     FXString   tdata;               // Tooltip data
34 protected:
DirItem()35     DirItem() : assoc(NULL), link(NULL), list(NULL), size(0L), date(0)
36     {}
37 protected:
38     enum
39     {
40         FOLDER      = 512,                // Directory item
41         EXECUTABLE  = 1024,               // Executable item
42         SYMLINK     = 2048,               // Symbolic linked item
43         CHARDEV     = 4096,               // Character special item
44         BLOCKDEV    = 8192,               // Block special item
45         FIFO        = 16384,              // FIFO item
46         SOCK        = 32768               // Socket item
47     };
48 public:
49     // Constructor
FXTreeItem(text,oi,ci,ptr)50     DirItem(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)
51     {
52         state = HASITEMS;
53         tdata = "";
54     }
55 
isDirectory()56     FXbool isDirectory() const
57     {
58         return((state&FOLDER) != 0);
59     }
60 
isExecutable()61     FXbool isExecutable() const
62     {
63         return((state&EXECUTABLE) != 0);
64     }
65 
isSymlink()66     FXbool isSymlink() const
67     {
68         return((state&SYMLINK) != 0);
69     }
70 
isChardev()71     FXbool isChardev() const
72     {
73         return((state&CHARDEV) != 0);
74     }
75 
isBlockdev()76     FXbool isBlockdev() const
77     {
78         return((state&BLOCKDEV) != 0);
79     }
80 
isFifo()81     FXbool isFifo() const
82     {
83         return((state&FIFO) != 0);
84     }
85 
isSocket()86     FXbool isSocket() const
87     {
88         return((state&SOCK) != 0);
89     }
90 
getAssoc()91     FileAssoc* getAssoc() const
92     {
93         return(assoc);
94     }
95 
getSize()96     FXulong getSize() const
97     {
98         return(size);
99     }
100 
getDate()101     FXTime getDate() const
102     {
103         return(date);
104     }
105 
getTooltipData()106     FXString getTooltipData() const
107     {
108         if (getData() != NULL)
109         {
110             return(tdata);
111         }
112         else
113         {
114             return("");
115         }
116     }
117 };
118 
119 
120 // Directory tree List
121 class FXAPI DirList : public FXTreeList
122 {
123     FXDECLARE(DirList)
124 protected:
125     TreeItem*    prevSelItem;
126     DirItem*     list;                      // Root item list
127     FileDict*    associations;              // Association table
128     FXString     dropdirectory;             // Drop directory
129     FXDragAction dropaction;                // Drop action
130     FXString     dragfiles;                 // Dragged files
131     FXString     pattern;                   // Pattern of file names
132     FXuint       matchmode;                 // File wildcard match mode
133     FXuint       counter;                   // Refresh counter
134     FXString     trashfileslocation;        // Location of the trash files directory
135     FXString     trashinfolocation;         // Location of the trash info directory
136     FXWindow*    focuswindow;               // Window used to test focus
137 protected:
DirList()138     DirList() : prevSelItem(NULL), list(NULL), associations(NULL), dropaction(DRAG_MOVE), matchmode(0), counter(0), focuswindow(NULL)
139     {}
140     virtual TreeItem* createItem(const FXString& text, FXIcon* oi, FXIcon* ci, void* ptr);
141     TreeItem* getitem(char* pathname);
142     void listRootItems();
143     void listChildItems(DirItem* par);
144 
145 private:
146     DirList(const DirList&);
147     DirList& operator=(const DirList&);
148 
149 public:
150     long onCmdRefresh(FXObject*, FXSelector, void*);
151     long onCmdRefreshTimer(FXObject*, FXSelector, void*);
152 #if defined(linux)
153     long onMtdevicesRefresh(FXObject*, FXSelector, void*);
154     long onUpdevicesRefresh(FXObject*, FXSelector, void*);
155 #endif
156     long onExpandTimer(FXObject*, FXSelector, void*);
157     long onBeginDrag(FXObject*, FXSelector, void*);
158     long onEndDrag(FXObject*, FXSelector, void*);
159     long onDragged(FXObject*, FXSelector, void*);
160     long onDNDEnter(FXObject*, FXSelector, void*);
161     long onDNDLeave(FXObject*, FXSelector, void*);
162     long onDNDMotion(FXObject*, FXSelector, void*);
163     long onDNDDrop(FXObject*, FXSelector, void*);
164     long onDNDRequest(FXObject*, FXSelector, void*);
165     long onOpened(FXObject*, FXSelector, void*);
166     long onClosed(FXObject*, FXSelector, void*);
167     long onExpanded(FXObject*, FXSelector, void*);
168     long onCollapsed(FXObject*, FXSelector, void*);
169     long onCmdToggleHidden(FXObject*, FXSelector, void*);
170     long onUpdToggleHidden(FXObject*, FXSelector, void*);
171     long onCmdShowHidden(FXObject*, FXSelector, void*);
172     long onUpdShowHidden(FXObject*, FXSelector, void*);
173     long onCmdHideHidden(FXObject*, FXSelector, void*);
174     long onUpdHideHidden(FXObject*, FXSelector, void*);
175     long onCmdToggleFiles(FXObject*, FXSelector, void*);
176     long onUpdToggleFiles(FXObject*, FXSelector, void*);
177     long onCmdShowFiles(FXObject*, FXSelector, void*);
178     long onUpdShowFiles(FXObject*, FXSelector, void*);
179     long onCmdHideFiles(FXObject*, FXSelector, void*);
180     long onUpdHideFiles(FXObject*, FXSelector, void*);
181     long onCmdSetPattern(FXObject*, FXSelector, void*);
182     long onUpdSetPattern(FXObject*, FXSelector, void*);
183     long onCmdSortReverse(FXObject*, FXSelector, void*);
184     long onUpdSortReverse(FXObject*, FXSelector, void*);
185     long onCmdSortCase(FXObject*, FXSelector, void*);
186     long onUpdSortCase(FXObject*, FXSelector, void*);
187     long onCmdDragCopy(FXObject* sender, FXSelector, void*);
188     long onCmdDragMove(FXObject* sender, FXSelector, void*);
189     long onCmdDragLink(FXObject* sender, FXSelector, void*);
190     long onCmdDragReject(FXObject* sender, FXSelector, void*);
191     long onUpdRefreshTimers(FXObject*, FXSelector, void*);
192 public:
193     static int compareItem(const FXTreeItem*, const FXTreeItem*, FXbool, FXbool);
194     static int ascending(const FXTreeItem*, const FXTreeItem*);
195     static int descending(const FXTreeItem*, const FXTreeItem*);
196     static int ascendingCase(const FXTreeItem*, const FXTreeItem*);
197     static int descendingCase(const FXTreeItem*, const FXTreeItem*);
198 
199 public:
200     enum
201     {
202         ID_REFRESH_TIMER=FXTreeList::ID_LAST,
203         ID_SHOW_FILES,
204         ID_HIDE_FILES,
205         ID_TOGGLE_FILES,
206         ID_SHOW_HIDDEN,
207         ID_HIDE_HIDDEN,
208         ID_TOGGLE_HIDDEN,
209         ID_SET_PATTERN,
210         ID_SORT_REVERSE,
211         ID_SORT_CASE,
212         ID_EXPAND_TIMER,
213 #if defined(linux)
214         ID_UPDEVICES_REFRESH,
215         ID_MTDEVICES_REFRESH,
216 #endif
217         ID_DRAG_COPY,
218         ID_DRAG_MOVE,
219         ID_DRAG_LINK,
220         ID_DRAG_REJECT,
221         ID_REFRESH,
222         ID_LAST
223     };
224 public:
225 
226     // Construct a directory list
227     DirList(FXWindow* focuswin, FXComposite* p, FXObject* tgt = NULL, FXSelector sel = 0, FXuint opts = 0, int x = 0, int y = 0, int w = 0, int h = 0);
228 
229     // Create server-side resources
230     virtual void create();
231 
232     // Scan the directories and update the items if needed, or if force is true
233     void scan(FXbool force = true);
234 
235     // Return true if item is a directory
236     FXbool isItemDirectory(const TreeItem* item) const;
237 
238     // Return true if item is a file
239     FXbool isItemFile(const TreeItem* item) const;
240 
241     // Return true if item is executable
242     FXbool isItemExecutable(const TreeItem* item) const;
243 
244     // Collapse tree
245     virtual FXbool collapseTree(TreeItem* tree, FXbool notify = false);
246 
247     // Expand tree
248     virtual FXbool expandTree(TreeItem* tree, FXbool notify = false);
249 
250     // Set current file
251     void setCurrentFile(const FXString& file, FXbool notify = false);
252 
253     // Return current file
254     FXString getCurrentFile() const;
255 
256     // Set current directory
257     void setDirectory(const FXString& pathname, FXbool notify);
258 
259     // Return current directory
260     FXString getDirectory() const;
261 
262     // Return name of item
263     FXString getItemFilename(const TreeItem* item) const;
264 
265     // Return absolute pathname of item
266     FXString getItemPathname(const TreeItem* item) const;
267 
268     // Return the item from the absolute pathname
269     TreeItem* getPathnameItem(const FXString& path);
270 
271     // Change wildcard matching pattern
272     void setPattern(const FXString& ptrn);
273 
274     // Return wildcard pattern
getPattern()275     FXString getPattern() const
276     {
277         return(pattern);
278     }
279 
280     // Return wildcard matching mode
getMatchMode()281     FXuint getMatchMode() const
282     {
283         return(matchmode);
284     }
285 
286     // Change wildcard matching mode
287     void setMatchMode(FXuint mode);
288 
289     // Return true if showing files as well as directories
290     FXbool showFiles() const;
291 
292     // Show or hide normal files
293     void showFiles(FXbool showing);
294 
295     // Return true if showing hidden files and directories
296     FXbool shownHiddenFiles() const;
297 
298     // Show or hide hidden files and directories
299     void showHiddenFiles(FXbool showing);
300 
301     // Change file associations
302     void setAssociations(FileDict* assoc);
303 
304     // Return file associations
getAssociations()305     FileDict* getAssociations() const
306     {
307         return(associations);
308     }
309 
310     // Destructor
311     virtual ~DirList();
312 };
313 
314 
315 #endif
316