]> git.saurik.com Git - wxWidgets.git/blame - interface/filedlg.h
first raw revision
[wxWidgets.git] / interface / filedlg.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: filedlg.h
e54c96f1 3// Purpose: interface of wxFileDialog
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxFileDialog
11 @wxheader{filedlg.h}
7c913512 12
23324ae1 13 This class represents the file chooser dialog.
7c913512 14
0ce6d6c8
FM
15 It pops up a file selector box (native for Windows and GTK2.4+).
16
17 The path and filename are distinct elements of a full file pathname.
18 If path is "", the current directory will be used. If filename is "", no default
19 filename will be supplied. The wildcard determines what files are displayed in the
20 file selector, and file extension supplies a type extension for the required filename.
21
22 @remarks
23 All implementations of the wxFileDialog provide a wildcard filter. Typing a filename
24 containing wildcards (*, ?) in the filename text item, and clicking on Ok, will
25 result in only those files matching the pattern being displayed.
26 The wildcard may be a specification for multiple types of file with a description
27 for each, such as:
28 "BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png"
29 It must be noted that wildcard support in the native Motif file dialog is quite
30 limited: only one alternative is supported, and it is displayed without the
31 descriptive test; "BMP files (*.bmp)|*.bmp" is displayed as "*.bmp", and both
32 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif" and "Image files|*.bmp;*.gif"
33 are errors.
34
23324ae1
FM
35 @beginStyleTable
36 @style{wxFD_DEFAULT_STYLE}:
37 Equivalent to wxFD_OPEN.
38 @style{wxFD_OPEN}:
39 This is an open dialog; usually this means that the default
0ce6d6c8 40 button's label of the dialog is "Open". Cannot be combined with wxFD_SAVE.
23324ae1
FM
41 @style{wxFD_SAVE}:
42 This is a save dialog; usually this means that the default button's
43 label of the dialog is "Save". Cannot be combined with wxFD_OPEN.
44 @style{wxFD_OVERWRITE_PROMPT}:
45 For save dialog only: prompt for a confirmation if a file will be
46 overwritten.
47 @style{wxFD_FILE_MUST_EXIST}:
0ce6d6c8 48 For open dialog only: the user may only select files that actually exist.
23324ae1
FM
49 @style{wxFD_MULTIPLE}:
50 For open dialog only: allows selecting multiple files.
51 @style{wxFD_CHANGE_DIR}:
52 Change the current working directory to the directory where the
53 file(s) chosen by the user are.
54 @style{wxFD_PREVIEW}:
55 Show the preview of the selected files (currently only supported by
56 wxGTK using GTK+ 2.4 or later).
57 @endStyleTable
7c913512 58
23324ae1
FM
59 @library{wxcore}
60 @category{cmndlg}
7c913512 61
0ce6d6c8 62 @see @ref overview_wxfiledialog, ::wxFileSelector()
23324ae1
FM
63*/
64class wxFileDialog : public wxDialog
65{
66public:
67 /**
68 Constructor. Use ShowModal() to show the dialog.
3c4f71cc 69
7c913512 70 @param parent
4cc4bfaf 71 Parent window.
7c913512 72 @param message
4cc4bfaf 73 Message to show on the dialog.
7c913512 74 @param defaultDir
4cc4bfaf 75 The default directory, or the empty string.
7c913512 76 @param defaultFile
4cc4bfaf 77 The default filename, or the empty string.
7c913512 78 @param wildcard
0ce6d6c8 79 A wildcard, such as "*.*" or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
4cc4bfaf
FM
80 Note that the native Motif dialog has some limitations with respect to
81 wildcards; see the Remarks section above.
7c913512 82 @param style
4cc4bfaf 83 A dialog style. See wxFD_* styles for more info.
7c913512 84 @param pos
4cc4bfaf 85 Dialog position. Not implemented.
7c913512 86 @param size
4cc4bfaf 87 Dialog size. Not implemented.
7c913512 88 @param name
4cc4bfaf 89 Dialog name. Not implemented.
23324ae1
FM
90 */
91 wxFileDialog(wxWindow* parent,
92 const wxString& message = "Choose a file",
93 const wxString& defaultDir = "",
94 const wxString& defaultFile = "",
95 const wxString& wildcard = ".",
96 long style = wxFD_DEFAULT_STYLE,
97 const wxPoint& pos = wxDefaultPosition,
98 const wxSize& sz = wxDefaultSize,
99 const wxString& name = "filedlg");
100
101 /**
102 Destructor.
103 */
104 ~wxFileDialog();
105
106 /**
107 Returns the default directory.
108 */
328f5751 109 wxString GetDirectory() const;
23324ae1
FM
110
111 /**
0ce6d6c8 112 If functions SetExtraControlCreator() and ShowModal() were called,
23324ae1
FM
113 returns the extra window. Otherwise returns @NULL.
114 */
328f5751 115 wxWindow* GetExtraControl() const;
23324ae1
FM
116
117 /**
118 Returns the default filename.
119 */
328f5751 120 wxString GetFilename() const;
23324ae1
FM
121
122 /**
0ce6d6c8
FM
123 Fills the array @a filenames with the names of the files chosen.
124
125 This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
23324ae1 126 use GetFilename() for the others.
0ce6d6c8 127
23324ae1
FM
128 Note that under Windows, if the user selects shortcuts, the filenames
129 include paths, since the application cannot determine the full path
130 of each referenced file by appending the directory containing the shortcuts
131 to the filename.
132 */
328f5751 133 void GetFilenames(wxArrayString& filenames) const;
23324ae1
FM
134
135 /**
136 Returns the index into the list of filters supplied, optionally, in the
137 wildcard parameter.
0ce6d6c8 138
23324ae1
FM
139 Before the dialog is shown, this is the index which will be used when the
140 dialog is first displayed.
0ce6d6c8 141
23324ae1
FM
142 After the dialog is shown, this is the index selected by the user.
143 */
328f5751 144 int GetFilterIndex() const;
23324ae1
FM
145
146 /**
147 Returns the message that will be displayed on the dialog.
148 */
328f5751 149 wxString GetMessage() const;
23324ae1
FM
150
151 /**
152 Returns the full path (directory and filename) of the selected file.
153 */
328f5751 154 wxString GetPath() const;
23324ae1
FM
155
156 /**
0ce6d6c8
FM
157 Fills the array @a paths with the full paths of the files chosen.
158
159 This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
23324ae1
FM
160 use GetPath() for the others.
161 */
328f5751 162 void GetPaths(wxArrayString& paths) const;
23324ae1
FM
163
164 /**
165 Returns the file dialog wildcard.
166 */
328f5751 167 wxString GetWildcard() const;
23324ae1
FM
168
169 /**
170 Sets the default directory.
171 */
172 void SetDirectory(const wxString& directory);
173
174 /**
175 Customize file dialog by adding extra window, which is typically placed
176 below the list of files and above the buttons.
0ce6d6c8
FM
177
178 SetExtraControlCreator() can be called only once, before calling ShowModal().
179
23324ae1
FM
180 The @c creator function should take pointer to parent window (file dialog)
181 and should return a window allocated with operator new.
0ce6d6c8 182
23324ae1
FM
183 Supported platforms: wxGTK, wxUniv.
184 */
185 bool SetExtraControlCreator(t_extraControlCreator creator);
186
187 /**
188 Sets the default filename.
189 */
190 void SetFilename(const wxString& setfilename);
191
192 /**
193 Sets the default filter index, starting from zero.
194 */
195 void SetFilterIndex(int filterIndex);
196
197 /**
198 Sets the message that will be displayed on the dialog.
199 */
200 void SetMessage(const wxString& message);
201
202 /**
203 Sets the path (the combined directory and filename that will be returned when
204 the dialog is dismissed).
205 */
206 void SetPath(const wxString& path);
207
208 /**
209 Sets the wildcard, which can contain multiple file types, for example:
0ce6d6c8
FM
210 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
211
23324ae1
FM
212 Note that the native Motif dialog has some limitations with respect to
213 wildcards; see the Remarks section above.
214 */
215 void SetWildcard(const wxString& wildCard);
216
217 /**
218 Shows the dialog, returning wxID_OK if the user pressed OK, and wxID_CANCEL
219 otherwise.
220 */
221 int ShowModal();
222};
223
224
e54c96f1 225
23324ae1
FM
226// ============================================================================
227// Global functions/macros
228// ============================================================================
229
ba2874ff
BP
230/** @ingroup group_funcmacro_dialog */
231//@{
232
23324ae1
FM
233/**
234 Pops up a file selector box. In Windows, this is the common file selector
ba2874ff
BP
235 dialog. In X, this is a file selector box with the same functionality. The
236 path and filename are distinct elements of a full file pathname. If path
237 is empty, the current directory will be used. If filename is empty, no
238 default filename will be supplied. The wildcard determines what files are
239 displayed in the file selector, and file extension supplies a type
240 extension for the required filename. Flags may be a combination of
241 wxFD_OPEN, wxFD_SAVE, wxFD_OVERWRITE_PROMPT or wxFD_FILE_MUST_EXIST.
242
243 @note wxFD_MULTIPLE can only be used with wxFileDialog and not here since
244 this function only returns a single file name.
245
23324ae1
FM
246 Both the Unix and Windows versions implement a wildcard filter. Typing a
247 filename containing wildcards (*, ?) in the filename text item, and
248 clicking on Ok, will result in only those files matching the pattern being
249 displayed.
ba2874ff
BP
250
251 The wildcard may be a specification for multiple types of file with a
252 description for each, such as:
4cc4bfaf 253
23324ae1
FM
254 @code
255 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"
256 @endcode
7c913512 257
23324ae1
FM
258 The application must check for an empty return value (the user pressed
259 Cancel). For example:
4cc4bfaf 260
23324ae1
FM
261 @code
262 wxString filename = wxFileSelector("Choose a file to open");
263 if ( !filename.empty() )
264 {
265 // work with the file
266 ...
267 }
268 //else: cancelled by user
269 @endcode
ba2874ff
BP
270
271 @header{wx/filedlg.h}
23324ae1
FM
272*/
273wxString wxFileSelector(const wxString& message,
274 const wxString& default_path = "",
275 const wxString& default_filename = "",
276 const wxString& default_extension = "",
277 const wxString& wildcard = ".",
278 int flags = 0,
4cc4bfaf 279 wxWindow* parent = NULL,
23324ae1
FM
280 int x = -1,
281 int y = -1);
282
ba2874ff
BP
283//@}
284