1 /********************************************************************************
2 *                                                                               *
3 *                  F i l e   S e l e c t i o n   W i d g e t                    *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1998,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: FXFileSelector.h,v 1.55.2.1 2005/02/11 13:33:39 fox Exp $                    *
23 ********************************************************************************/
24 #ifndef FXFILESELECTOR_H
25 #define FXFILESELECTOR_H
26 
27 #ifndef FXPACKER_H
28 #include "FXPacker.h"
29 #endif
30 
31 namespace FX {
32 
33 class FXFileList;
34 class FXTextField;
35 class FXComboBox;
36 class FXDirBox;
37 class FXButton;
38 class FXIcon;
39 class FXMenuPane;
40 class FXCheckButton;
41 class FXMatrix;
42 class FXHorizontalFrame;
43 
44 
45 /// File selection modes
46 enum {
47   SELECTFILE_ANY,             /// A single file, existing or not (to save to)
48   SELECTFILE_EXISTING,        /// An existing file (to load)
49   SELECTFILE_MULTIPLE,        /// Multiple existing files
50   SELECTFILE_MULTIPLE_ALL,    /// Multiple existing files or directories, but not '.' and '..'
51   SELECTFILE_DIRECTORY        /// Existing directory, including '.' or '..'
52   };
53 
54 
55 /// File selection widget
56 class FXAPI FXFileSelector : public FXPacker {
57   FXDECLARE(FXFileSelector)
58 protected:
59   FXFileList        *filebox;           // File list widget
60   FXTextField       *filename;          // File name entry field
61   FXComboBox        *filefilter;        // Combobox for pattern list
62   FXMenuPane        *bookmarkmenu;      // Menu for bookmarks
63   FXHorizontalFrame *navbuttons;        // Navigation buttons
64   FXHorizontalFrame *fileboxframe;      // Frame around file list
65   FXMatrix          *entryblock;        // Entry block
66   FXCheckButton     *readonly;          // Open file as read only
67   FXDirBox          *dirbox;            // Directory hierarchy list
68   FXButton          *accept;            // Accept button
69   FXButton          *cancel;            // Cancel button
70   FXIcon            *updiricon;         // Up directory icon
71   FXIcon            *listicon;          // List mode icon
72   FXIcon            *detailicon;        // Detail mode icon
73   FXIcon            *iconsicon;         // Icon mode icon
74   FXIcon            *homeicon;          // Go home icon
75   FXIcon            *workicon;          // Go home icon
76   FXIcon            *shownicon;         // Files shown icon
77   FXIcon            *hiddenicon;        // Files hidden icon
78   FXIcon            *markicon;          // Book mark icon
79   FXIcon            *clearicon;         // Book clear icon
80   FXIcon            *newicon;           // New directory icon
81   FXIcon            *deleteicon;        // Delete file icon
82   FXIcon            *moveicon;          // Rename file icon
83   FXIcon            *copyicon;          // Copy file icon
84   FXIcon            *linkicon;          // Link file icon
85   FXRecentFiles      bookmarks;         // Bookmarked places
86   FXuint             selectmode;        // Select mode
87 protected:
FXFileSelector()88   FXFileSelector(){}
89   FXString *getSelectedFiles() const;
90   FXString *getSelectedFilesOnly() const;
91 private:
92   FXFileSelector(const FXFileSelector&);
93   FXFileSelector &operator=(const FXFileSelector&);
94 public:
95   long onCmdAccept(FXObject*,FXSelector,void*);
96   long onCmdFilter(FXObject*,FXSelector,void*);
97   long onCmdItemDblClicked(FXObject*,FXSelector,void*);
98   long onCmdItemSelected(FXObject*,FXSelector,void*);
99   long onCmdItemDeselected(FXObject*,FXSelector,void*);
100   long onCmdDirectoryUp(FXObject*,FXSelector,void*);
101   long onUpdDirectoryUp(FXObject*,FXSelector,void*);
102   long onCmdDirTree(FXObject*,FXSelector,void*);
103   long onCmdHome(FXObject*,FXSelector,void*);
104   long onCmdWork(FXObject*,FXSelector,void*);
105   long onCmdBookmark(FXObject*,FXSelector,void*);
106   long onCmdVisit(FXObject*,FXSelector,void*);
107   long onCmdNew(FXObject*,FXSelector,void*);
108   long onUpdNew(FXObject*,FXSelector,void*);
109   long onCmdMove(FXObject*,FXSelector,void*);
110   long onCmdCopy(FXObject*,FXSelector,void*);
111   long onCmdLink(FXObject*,FXSelector,void*);
112   long onCmdDelete(FXObject*,FXSelector,void*);
113   long onUpdSelected(FXObject*,FXSelector,void*);
114   long onPopupMenu(FXObject*,FXSelector,void*);
115   long onCmdImageSize(FXObject*,FXSelector,void*);
116   long onUpdImageSize(FXObject*,FXSelector,void*);
117 public:
118   enum {
119     ID_FILEFILTER=FXPacker::ID_LAST,
120     ID_ACCEPT,
121     ID_FILELIST,
122     ID_DIRECTORY_UP,
123     ID_DIRTREE,
124     ID_NORMAL_SIZE,
125     ID_MEDIUM_SIZE,
126     ID_GIANT_SIZE,
127     ID_HOME,
128     ID_WORK,
129     ID_BOOKMARK,
130     ID_VISIT,
131     ID_NEW,
132     ID_DELETE,
133     ID_MOVE,
134     ID_COPY,
135     ID_LINK,
136     ID_LAST
137     };
138 public:
139 
140   /// Constructor
141   FXFileSelector(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
142 
143   /// Return a pointer to the "Accept" button
acceptButton()144   FXButton *acceptButton() const { return accept; }
145 
146   /// Return a pointer to the "Cancel" button
cancelButton()147   FXButton *cancelButton() const { return cancel; }
148 
149   /// Change file name
150   void setFilename(const FXString& path);
151 
152   /// Return file name, if any
153   FXString getFilename() const;
154 
155   /**
156   * Return array of strings containing the selected file names, terminated
157   * by an empty string.  This string array must be freed using delete [].
158   * If no files were selected, a NULL is returned.
159   */
160   FXString* getFilenames() const;
161 
162   /// Change file pattern
163   void setPattern(const FXString& ptrn);
164 
165   /// Return file pattern
166   FXString getPattern() const;
167 
168   /**
169   * Change the list of file patterns shown in the file dialog.
170   * Each pattern comprises an optional name, followed by a pattern in
171   * parentheses.  The patterns are separated by newlines.
172   * For example,
173   *
174   *  "*\n*.cpp,*.cc\n*.hpp,*.hh,*.h"
175   *
176   * and
177   *
178   *  "All Files (*)\nC++ Sources (*.cpp,*.cc)\nC++ Headers (*.hpp,*.hh,*.h)"
179   *
180   * will set the same three patterns, but the former shows no pattern names.
181   */
182   void setPatternList(const FXString& patterns);
183 
184   /// Return list of patterns
185   FXString getPatternList() const;
186 
187   /**
188   * After setting the list of patterns, this call will
189   * initially select pattern n as the active one.
190   */
191   void setCurrentPattern(FXint n);
192 
193   /// Return current pattern number
194   FXint getCurrentPattern() const;
195 
196   /// Get pattern text for given pattern number
197   FXString getPatternText(FXint patno) const;
198 
199   /// Change pattern text for pattern number
200   void setPatternText(FXint patno,const FXString& text);
201 
202   /// Allow pattern entry
203   void allowPatternEntry(FXbool allow);
204 
205   /// Return TRUE if pattern entry is allowed
206   FXbool allowPatternEntry() const;
207 
208   /**
209   * Given filename pattern of the form "GIF Format (*.gif)",
210   * returns the pattern only, i.e. "*.gif" in this case.
211   * If the parentheses are not found then returns the entire
212   * input pattern.
213   */
214   static FXString patternFromText(const FXString& pattern);
215 
216   /**
217   * Given a pattern of the form "*.gif,*.GIF", return
218   * the first extension of the pattern, i.e. "gif" in this
219   * example. Returns empty string if it doesn't work out.
220   */
221   static FXString extensionFromPattern(const FXString& pattern);
222 
223   /// Change directory
224   void setDirectory(const FXString& path);
225 
226   /// Return directory
227   FXString getDirectory() const;
228 
229   /// Set the inter-item spacing (in pixels)
230   void setItemSpace(FXint s);
231 
232   /// Return the inter-item spacing (in pixels)
233   FXint getItemSpace() const;
234 
235   /// Change file list style
236   void setFileBoxStyle(FXuint style);
237 
238   /// Return file list style
239   FXuint getFileBoxStyle() const;
240 
241   /// Change file selection mode
242   void setSelectMode(FXuint mode);
243 
244   /// Return file selection mode
getSelectMode()245   FXuint getSelectMode() const { return selectmode; }
246 
247   /// Change wildcard matching mode
248   void setMatchMode(FXuint mode);
249 
250   /// Return wildcard matching mode
251   FXuint getMatchMode() const;
252 
253   /// Return TRUE if showing hidden files
254   FXbool showHiddenFiles() const;
255 
256   /// Show or hide hidden files
257   void showHiddenFiles(FXbool showing);
258 
259   /// Return TRUE if image preview on
260   FXbool showImages() const;
261 
262   /// Show or hide preview images
263   void showImages(FXbool showing);
264 
265   /// Return images preview size
266   FXint getImageSize() const;
267 
268   /// Change images preview size
269   void setImageSize(FXint size);
270 
271   /// Show readonly button
272   void showReadOnly(FXbool show);
273 
274   /// Return TRUE if readonly is shown
275   FXbool shownReadOnly() const;
276 
277   /// Set initial state of readonly button
278   void setReadOnly(FXbool state);
279 
280   /// Get readonly state
281   FXbool getReadOnly() const;
282 
283   /// Save object to a stream
284   virtual void save(FXStream& store) const;
285 
286   /// Load object from a stream
287   virtual void load(FXStream& store);
288 
289   /// Destructor
290   virtual ~FXFileSelector();
291   };
292 
293 }
294 
295 #endif
296