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