]> git.saurik.com Git - wxWidgets.git/blame - interface/filefn.h
added test of focusing/selecting another item
[wxWidgets.git] / interface / filefn.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: filefn.h
e54c96f1 3// Purpose: interface of wxPathList
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxPathList
11 @wxheader{filefn.h}
7c913512 12
23324ae1
FM
13 The path list is a convenient way of storing a number of directories, and
14 when presented with a filename without a directory, searching for an existing
15 file
16 in those directories.
7c913512 17
23324ae1
FM
18 Be sure to look also at wxStandardPaths if you only
19 want to search files in some standard paths.
7c913512 20
23324ae1
FM
21 @library{wxbase}
22 @category{file}
7c913512 23
e54c96f1 24 @see wxArrayString, wxStandardPaths, wxFileName
23324ae1
FM
25*/
26class wxPathList : public wxArrayString
27{
28public:
29 //@{
30 /**
31 Constructs the object calling the Add() function.
32 */
33 wxPathList();
7c913512 34 wxPathList(const wxArrayString& arr);
23324ae1
FM
35 //@}
36
37 //@{
38 /**
39 The first form adds the given directory to the path list, if the path is not
40 already in the list.
41 If the path cannot be normalized for some reason, it returns @false.
23324ae1 42 The second form just calls the first form on all elements of the given array.
4cc4bfaf 43 The @a path is always considered a directory but no existence checks will be
23324ae1
FM
44 done on it
45 (because if it doesn't exist, it could be created later and thus result a valid
46 path when
47 FindValidPath() is called).
23324ae1
FM
48 @b Note: if the given path is relative, it won't be made absolute before adding
49 it
50 (this is why FindValidPath() may return relative paths).
51 */
52 bool Add(const wxString& path);
7c913512 53 void Add(const wxArrayString& arr);
23324ae1
FM
54 //@}
55
56 /**
57 Finds the value of the given environment variable, and adds all paths
58 to the path list. Useful for finding files in the @c PATH variable, for
59 example.
60 */
61 void AddEnvList(const wxString& env_variable);
62
63 /**
64 Given a full filename (with path), calls Add() with the path
65 of the file.
66 */
67 bool EnsureFileAccessible(const wxString& filename);
68
69 /**
70 Like FindValidPath() but this function always
71 returns an absolute path (eventually prepending the current working directory
72 to the value returned wxPathList::FindValidPath) or an
73 empty string.
74 */
328f5751 75 wxString FindAbsoluteValidPath(const wxString& file) const;
23324ae1
FM
76
77 /**
78 Searches the given file in all paths stored in this class.
79 The first path which concatenated to the given string points to an existing
80 file (see @ref wxFile::exists wxFileExists) is returned.
23324ae1
FM
81 If the file wasn't found in any of the stored paths, an empty string is
82 returned.
23324ae1
FM
83 The given string must be a file name, eventually with a path prefix (if the path
84 prefix is absolute, only its name will be searched); i.e. it must not end with
85 a directory separator (see wxFileName::GetPathSeparator)
86 otherwise an assertion will fail.
23324ae1
FM
87 The returned path may be relative to the current working directory.
88 Note in fact that wxPathList can be used to store both relative and absolute
89 paths so that
90 if you Added() relative paths, then the current working directory
e54c96f1 91 (see wxGetCwd() and wxSetWorkingDirectory())
23324ae1
FM
92 may affect the value returned by this function!
93 */
328f5751 94 wxString FindValidPath(const wxString& file) const;
23324ae1
FM
95};
96
97
e54c96f1 98
23324ae1
FM
99// ============================================================================
100// Global functions/macros
101// ============================================================================
102
103/**
104 This function returns the total number of bytes and number of free bytes on
4cc4bfaf
FM
105 the disk containing the directory @a path (it should exist). Both
106 @a total and @a free parameters may be @NULL if the corresponding
23324ae1
FM
107 information is not needed.
108*/
109bool wxGetDiskSpace(const wxString& path,
4cc4bfaf
FM
110 wxLongLong total = NULL,
111 wxLongLong free = NULL);
23324ae1
FM
112
113/**
114 Returns the Windows directory under Windows; on other platforms returns the
115 empty string.
116*/
117wxString wxGetOSDirectory();
118
119/**
120 Parses the @e wildCard, returning the number of filters.
121 Returns 0 if none or if there's a problem.
122 The arrays will contain an equal number of items found before the error.
123 On platforms where native dialogs handle only one filter per entry,
124 entries in arrays are automatically adjusted.
4cc4bfaf 125 @a wildCard is in the form:
7c913512 126
23324ae1
FM
127 @code
128 "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
129 @endcode
130*/
131int wxParseCommonDialogsFilter(const wxString& wildCard,
132 wxArrayString& descriptions,
133 wxArrayString& filters);
134
135/**
136 This function is deprecated, use wxFileName instead.
23324ae1
FM
137 Converts a Unix to a DOS filename by replacing forward
138 slashes with backslashes.
139*/
4cc4bfaf 140void wxUnix2DosFilename(wxChar* s);
23324ae1
FM
141
142/**
4cc4bfaf 143 Returns @true if @a dirname exists and is a directory.
23324ae1
FM
144*/
145bool wxDirExists(const wxString& dirname);
146
147/**
148 @b NB: This function is obsolete, please use
149 wxFileName::SplitPath instead.
23324ae1
FM
150 This function splits a full file name into components: the path (including
151 possible disk/drive
152 specification under Windows), the base name and the extension. Any of the
153 output parameters
4cc4bfaf 154 (@e path, @a name or @e ext) may be @NULL if you are not interested in the value
23324ae1
FM
155 of
156 a particular component.
23324ae1
FM
157 wxSplitPath() will correctly handle filenames with both DOS and Unix path
158 separators under
159 Windows, however it will not consider backslashes as path separators under Unix
160 (where backslash
161 is a valid character in a filename).
4cc4bfaf
FM
162 On entry, @a fullname should be non-@NULL (it may be empty though).
163 On return, @a path contains the file path (without the trailing separator), @e
23324ae1 164 name
4cc4bfaf 165 contains the file name and @a ext contains the file extension without leading
23324ae1
FM
166 dot. All
167 three of them may be empty if the corresponding component is. The old contents
168 of the
169 strings pointed to by these parameters will be overwritten in any case (if the
170 pointers
171 are not @NULL).
172*/
4cc4bfaf
FM
173void wxSplitPath(const wxString& fullname, wxString* path,
174 wxString* name,
175 wxString* ext);
23324ae1
FM
176
177/**
178 Under Unix this macro changes the current process umask to the given value,
179 unless it is equal to -1 in which case nothing is done, and restores it to
180 the original value on scope exit. It works by declaring a variable which sets
4cc4bfaf 181 umask to @a mask in its constructor and restores it in its destructor.
23324ae1
FM
182 Under other platforms this macro expands to nothing.
183*/
184#define wxCHANGE_UMASK(int mask) /* implementation is private */
185
186/**
187 Returns time of last modification of given file.
23324ae1
FM
188 The function returns @c (time_t)-1 if an error occurred (e.g. file not
189 found).
190*/
191time_t wxFileModificationTime(const wxString& filename);
192
193//@{
194/**
195 @b NB: This function is obsolete, please use
196 wxFileName::SplitPath instead.
23324ae1
FM
197 Returns the filename for a full path. The second form returns a pointer to
198 temporary storage that should not be deallocated.
199*/
200wxString wxFileNameFromPath(const wxString& path);
4cc4bfaf 201char* wxFileNameFromPath(char* path);
23324ae1
FM
202//@}
203
204/**
4cc4bfaf
FM
205 Renames @a file1 to @e file2, returning @true if successful.
206 If @a overwrite parameter is @true (default), the destination file is
207 overwritten if it exists, but if @a overwrite is @false, the functions fails
23324ae1
FM
208 in this case.
209*/
210bool wxRenameFile(const wxString& file1, const wxString& file2,
4cc4bfaf 211 bool overwrite = true);
23324ae1
FM
212
213/**
4cc4bfaf
FM
214 Copies @a file1 to @e file2, returning @true if successful. If
215 @a overwrite parameter is @true (default), the destination file is overwritten
216 if it exists, but if @a overwrite is @false, the functions fails in this
23324ae1 217 case.
23324ae1
FM
218 This function supports resources forks under Mac OS.
219*/
220bool wxCopyFile(const wxString& file1, const wxString& file2,
4cc4bfaf 221 bool overwrite = true);
23324ae1
FM
222
223/**
224 Returns @true if the file exists and is a plain file.
225*/
226bool wxFileExists(const wxString& filename);
227
228/**
4cc4bfaf 229 Returns @true if the @a pattern matches the @e text; if @a dot_special is @true,
23324ae1 230 filenames beginning with a dot are not matched
e54c96f1 231 with wildcard characters. See wxIsWild().
23324ae1
FM
232*/
233bool wxMatchWild(const wxString& pattern, const wxString& text,
234 bool dot_special);
235
236/**
e54c96f1 237 @b NB: This function is deprecated: use wxGetCwd() instead.
23324ae1
FM
238 Copies the current working directory into the buffer if supplied, or
239 copies the working directory into new storage (which you must delete
240 yourself) if the buffer is @NULL.
4cc4bfaf 241 @a sz is the size of the buffer if supplied.
23324ae1 242*/
4cc4bfaf 243wxString wxGetWorkingDirectory(char* buf = NULL, int sz = 1000);
23324ae1
FM
244
245/**
246 Returns the directory part of the filename.
247*/
248wxString wxPathOnly(const wxString& path);
249
250/**
e54c96f1 251 Returns @true if the pattern contains wildcards. See wxMatchWild().
23324ae1
FM
252*/
253bool wxIsWild(const wxString& pattern);
254
255/**
256 Returns a string containing the current (or working) directory.
257*/
258wxString wxGetCwd();
259
260/**
261 Converts a DOS to a Unix filename by replacing backslashes with forward
262 slashes.
263*/
4cc4bfaf 264void wxDos2UnixFilename(wxChar* s);
23324ae1
FM
265
266/**
4cc4bfaf 267 Concatenates @a file1 and @a file2 to @e file3, returning
23324ae1
FM
268 @true if successful.
269*/
270bool wxConcatFiles(const wxString& file1, const wxString& file2,
271 const wxString& file3);
272
273/**
274 Removes @e file, returning @true if successful.
275*/
276bool wxRemoveFile(const wxString& file);
277
278/**
279 Sets the current working directory, returning @true if the operation succeeded.
4cc4bfaf 280 Under MS Windows, the current drive is also changed if @a dir contains a drive
23324ae1
FM
281 specification.
282*/
283bool wxSetWorkingDirectory(const wxString& dir);
284
285/**
286 Makes the directory @e dir, returning @true if successful.
4cc4bfaf 287 @a perm is the access mask for the directory for the systems on which it is
23324ae1
FM
288 supported (Unix) and doesn't have any effect on the other ones.
289*/
290bool wxMkdir(const wxString& dir, int perm = 0777);
291
292/**
293 Returns @true if the argument is an absolute filename, i.e. with a slash
294 or drive name at the beginning.
295*/
296bool wxIsAbsolutePath(const wxString& filename);
297
298/**
e54c96f1
FM
299 Returns the next file that matches the path passed to wxFindFirstFile().
300 See wxFindFirstFile() for an example.
23324ae1
FM
301*/
302wxString wxFindNextFile();
303
304/**
305 This function does directory searching; returns the first file
e54c96f1 306 that matches the path @e spec, or the empty string. Use wxFindNextFile() to
23324ae1
FM
307 get the next matching file. Neither will report the current directory "." or the
308 parent directory "..".
309*/
310wxString wxFindFirstFile(const wxString& spec, int flags = 0);
311
312//@{
313/**
314 Returns the type of an open file. Possible return values are:
4cc4bfaf 315
23324ae1
FM
316 @code
317 enum wxFileKind
318 {
319 wxFILE_KIND_UNKNOWN,
320 wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets
321 wxFILE_KIND_TERMINAL, // a tty
322 wxFILE_KIND_PIPE // a pipe
323 };
324 @endcode
325*/
326wxFileKind wxGetFileKind(int fd);
4cc4bfaf 327wxFileKind wxGetFileKind(FILE* fp);
23324ae1
FM
328//@}
329
330//@{
331/**
332 @b NB: These functions are obsolete, please use
333 wxFileName::CreateTempFileName
334 instead.
335*/
4cc4bfaf 336char* wxGetTempFileName(const wxString& prefix, char* buf = NULL);
7c913512 337bool wxGetTempFileName(const wxString& prefix, wxString& buf);
23324ae1
FM
338//@}
339
340/**
341 Removes the directory @e dir, returning @true if successful. Does not work under
342 VMS.
4cc4bfaf 343 The @a flags parameter is reserved for future use.
23324ae1
FM
344 Please notice that there is also a wxRmDir() function which simply wraps the
345 standard POSIX rmdir() function and so return an integer error code instead of
346 a boolean value (but otherwise is currently identical to wxRmdir), don't
347 confuse these two functions.
348*/
4cc4bfaf 349bool wxRmdir(const wxString& dir, int flags = 0);
23324ae1 350