]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/filedlg.h
Update wxHtmlWindow documentation to refer to wxWebView.
[wxWidgets.git] / interface / wx / 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$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
e9321277
RD
9enum
10{
11 wxFD_OPEN = 0x0001,
12 wxFD_SAVE = 0x0002,
13 wxFD_OVERWRITE_PROMPT = 0x0004,
14 wxFD_FILE_MUST_EXIST = 0x0010,
15 wxFD_MULTIPLE = 0x0020,
16 wxFD_CHANGE_DIR = 0x0080,
17 wxFD_PREVIEW = 0x0100
18};
19
23324ae1
FM
20/**
21 @class wxFileDialog
7c913512 22
23324ae1 23 This class represents the file chooser dialog.
7c913512 24
0ce6d6c8 25 The path and filename are distinct elements of a full file pathname.
9d90f08b
FM
26 If path is ::wxEmptyString, the current directory will be used.
27 If filename is ::wxEmptyString, no default filename will be supplied.
e9c3992c
FM
28 The wildcard determines what files are displayed in the file selector,
29 and file extension supplies a type extension for the required filename.
0ce6d6c8 30
9d90f08b
FM
31 The typical usage for the open file dialog is:
32 @code
33 void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
34 {
35 if (...current content has not been saved...)
36 {
37 if (wxMessageBox(_("Current content has not been saved! Proceed?"), _("Please confirm"),
38 wxICON_QUESTION | wxYES_NO, this) == wxNO )
39 return;
40 //else: proceed asking to the user the new file to open
41 }
42
43 wxFileDialog
44 openFileDialog(this, _("Open XYZ file"), "", "",
45 "XYZ files (*.xyz)|*.xyz", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
46
47 if (openFileDialog.ShowModal() == wxID_CANCEL)
48 return; // the user changed idea...
49
50 // proceed loading the file chosen by the user;
51 // this can be done with e.g. wxWidgets input streams:
52 wxFileInputStream input_stream(openFileDialog.GetPath());
53 if (!input_stream.IsOk())
54 {
55 wxLogError("Cannot open file '%s'.", openFileDialog.GetPath());
56 return;
57 }
58
59 ...
60 }
61 @endcode
62
63 The typical usage for the save file dialog is instead somewhat simpler:
64 @code
65 void MyFrame::OnSaveAs(wxCommandEvent& WXUNUSED(event))
66 {
67 wxFileDialog
68 saveFileDialog(this, _("Save XYZ file"), "", "",
69 "XYZ files (*.xyz)|*.xyz", wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
70
71 if (saveFileDialog.ShowModal() == wxID_CANCEL)
72 return; // the user changed idea...
73
74 // save the current contents in the file;
75 // this can be done with e.g. wxWidgets output streams:
76 wxFileOutputStream output_stream(saveFileDialog.GetPath());
77 if (!output_stream.IsOk())
78 {
79 wxLogError("Cannot save current contents in file '%s'.", saveFileDialog.GetPath());
80 return;
81 }
82
83 ...
84 }
85 @endcode
86
0ce6d6c8
FM
87 @remarks
88 All implementations of the wxFileDialog provide a wildcard filter. Typing a filename
89 containing wildcards (*, ?) in the filename text item, and clicking on Ok, will
90 result in only those files matching the pattern being displayed.
91 The wildcard may be a specification for multiple types of file with a description
92 for each, such as:
0b70c946 93 @code
0ce6d6c8 94 "BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png"
0b70c946 95 @endcode
0ce6d6c8 96 It must be noted that wildcard support in the native Motif file dialog is quite
806f8df3 97 limited: only one file type is supported, and it is displayed without the
0ce6d6c8
FM
98 descriptive test; "BMP files (*.bmp)|*.bmp" is displayed as "*.bmp", and both
99 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif" and "Image files|*.bmp;*.gif"
100 are errors.
101
23324ae1 102 @beginStyleTable
8c6791e4 103 @style{wxFD_DEFAULT_STYLE}
9d90f08b 104 Equivalent to @c wxFD_OPEN.
8c6791e4 105 @style{wxFD_OPEN}
23324ae1 106 This is an open dialog; usually this means that the default
9d90f08b 107 button's label of the dialog is "Open". Cannot be combined with @c wxFD_SAVE.
8c6791e4 108 @style{wxFD_SAVE}
23324ae1 109 This is a save dialog; usually this means that the default button's
9d90f08b 110 label of the dialog is "Save". Cannot be combined with @c wxFD_OPEN.
8c6791e4 111 @style{wxFD_OVERWRITE_PROMPT}
23324ae1
FM
112 For save dialog only: prompt for a confirmation if a file will be
113 overwritten.
8c6791e4 114 @style{wxFD_FILE_MUST_EXIST}
83527a0a
VZ
115 For open dialog only: the user may only select files that actually
116 exist. Notice that under OS X the file dialog with @c wxFD_OPEN
117 style always behaves as if this style was specified, because it is
118 impossible to choose a file that doesn't exist from a standard OS X
119 file dialog.
8c6791e4 120 @style{wxFD_MULTIPLE}
23324ae1 121 For open dialog only: allows selecting multiple files.
8c6791e4 122 @style{wxFD_CHANGE_DIR}
9d90f08b
FM
123 Change the current working directory (when the dialog is dismissed)
124 to the directory where the file(s) chosen by the user are.
8c6791e4 125 @style{wxFD_PREVIEW}
23324ae1 126 Show the preview of the selected files (currently only supported by
d6dae1b4 127 wxGTK).
23324ae1 128 @endStyleTable
7c913512 129
23324ae1
FM
130 @library{wxcore}
131 @category{cmndlg}
7c913512 132
23b7f0cb 133 @see @ref overview_cmndlg_file, ::wxFileSelector()
23324ae1
FM
134*/
135class wxFileDialog : public wxDialog
136{
137public:
138 /**
139 Constructor. Use ShowModal() to show the dialog.
3c4f71cc 140
7c913512 141 @param parent
4cc4bfaf 142 Parent window.
7c913512 143 @param message
4cc4bfaf 144 Message to show on the dialog.
7c913512 145 @param defaultDir
4cc4bfaf 146 The default directory, or the empty string.
7c913512 147 @param defaultFile
4cc4bfaf 148 The default filename, or the empty string.
7c913512 149 @param wildcard
0ce6d6c8 150 A wildcard, such as "*.*" or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
4cc4bfaf
FM
151 Note that the native Motif dialog has some limitations with respect to
152 wildcards; see the Remarks section above.
7c913512 153 @param style
9d90f08b 154 A dialog style. See @c wxFD_* styles for more info.
7c913512 155 @param pos
4cc4bfaf 156 Dialog position. Not implemented.
7c913512 157 @param size
4cc4bfaf 158 Dialog size. Not implemented.
7c913512 159 @param name
4cc4bfaf 160 Dialog name. Not implemented.
23324ae1
FM
161 */
162 wxFileDialog(wxWindow* parent,
a44f3b5a
FM
163 const wxString& message = wxFileSelectorPromptStr,
164 const wxString& defaultDir = wxEmptyString,
165 const wxString& defaultFile = wxEmptyString,
166 const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
23324ae1
FM
167 long style = wxFD_DEFAULT_STYLE,
168 const wxPoint& pos = wxDefaultPosition,
76e9224e 169 const wxSize& size = wxDefaultSize,
a44f3b5a 170 const wxString& name = wxFileDialogNameStr);
23324ae1
FM
171
172 /**
173 Destructor.
174 */
adaaa686 175 virtual ~wxFileDialog();
23324ae1
FM
176
177 /**
178 Returns the default directory.
179 */
adaaa686 180 virtual wxString GetDirectory() const;
23324ae1
FM
181
182 /**
0ce6d6c8 183 If functions SetExtraControlCreator() and ShowModal() were called,
23324ae1 184 returns the extra window. Otherwise returns @NULL.
d6dae1b4
VZ
185
186 @since 2.9.0
23324ae1 187 */
328f5751 188 wxWindow* GetExtraControl() const;
23324ae1
FM
189
190 /**
191 Returns the default filename.
192 */
adaaa686 193 virtual wxString GetFilename() const;
23324ae1
FM
194
195 /**
0ce6d6c8
FM
196 Fills the array @a filenames with the names of the files chosen.
197
198 This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
23324ae1 199 use GetFilename() for the others.
0ce6d6c8 200
23324ae1
FM
201 Note that under Windows, if the user selects shortcuts, the filenames
202 include paths, since the application cannot determine the full path
203 of each referenced file by appending the directory containing the shortcuts
204 to the filename.
205 */
adaaa686 206 virtual void GetFilenames(wxArrayString& filenames) const;
23324ae1
FM
207
208 /**
209 Returns the index into the list of filters supplied, optionally, in the
210 wildcard parameter.
0ce6d6c8 211
23324ae1
FM
212 Before the dialog is shown, this is the index which will be used when the
213 dialog is first displayed.
0ce6d6c8 214
23324ae1
FM
215 After the dialog is shown, this is the index selected by the user.
216 */
adaaa686 217 virtual int GetFilterIndex() const;
23324ae1
FM
218
219 /**
220 Returns the message that will be displayed on the dialog.
221 */
adaaa686 222 virtual wxString GetMessage() const;
23324ae1
FM
223
224 /**
225 Returns the full path (directory and filename) of the selected file.
226 */
adaaa686 227 virtual wxString GetPath() const;
23324ae1
FM
228
229 /**
0ce6d6c8
FM
230 Fills the array @a paths with the full paths of the files chosen.
231
232 This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
23324ae1
FM
233 use GetPath() for the others.
234 */
adaaa686 235 virtual void GetPaths(wxArrayString& paths) const;
23324ae1
FM
236
237 /**
238 Returns the file dialog wildcard.
239 */
adaaa686 240 virtual wxString GetWildcard() const;
23324ae1
FM
241
242 /**
243 Sets the default directory.
244 */
adaaa686 245 virtual void SetDirectory(const wxString& directory);
23324ae1 246
d6dae1b4
VZ
247 /**
248 The type of function used as an argument for SetExtraControlCreator().
249
250 @since 2.9.0
251 */
252 typedef wxWindow *(*ExtraControlCreatorFunction)(wxWindow*);
253
23324ae1
FM
254 /**
255 Customize file dialog by adding extra window, which is typically placed
256 below the list of files and above the buttons.
0ce6d6c8
FM
257
258 SetExtraControlCreator() can be called only once, before calling ShowModal().
259
23324ae1
FM
260 The @c creator function should take pointer to parent window (file dialog)
261 and should return a window allocated with operator new.
0ce6d6c8 262
d6dae1b4
VZ
263 Supported platforms: wxGTK, wxMSW, wxUniv.
264
265 @since 2.9.0
23324ae1 266 */
d6dae1b4 267 bool SetExtraControlCreator(ExtraControlCreatorFunction creator);
23324ae1
FM
268
269 /**
270 Sets the default filename.
02a40b8a
JS
271
272 In wxGTK this will have little effect unless a default directory has previously been set.
23324ae1 273 */
adaaa686 274 virtual void SetFilename(const wxString& setfilename);
23324ae1
FM
275
276 /**
277 Sets the default filter index, starting from zero.
278 */
adaaa686 279 virtual void SetFilterIndex(int filterIndex);
23324ae1
FM
280
281 /**
282 Sets the message that will be displayed on the dialog.
283 */
adaaa686 284 virtual void SetMessage(const wxString& message);
23324ae1
FM
285
286 /**
287 Sets the path (the combined directory and filename that will be returned when
288 the dialog is dismissed).
289 */
adaaa686 290 virtual void SetPath(const wxString& path);
23324ae1
FM
291
292 /**
293 Sets the wildcard, which can contain multiple file types, for example:
0ce6d6c8
FM
294 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
295
23324ae1
FM
296 Note that the native Motif dialog has some limitations with respect to
297 wildcards; see the Remarks section above.
298 */
adaaa686 299 virtual void SetWildcard(const wxString& wildCard);
23324ae1
FM
300
301 /**
9d90f08b 302 Shows the dialog, returning @c wxID_OK if the user pressed OK, and @c wxID_CANCEL
23324ae1
FM
303 otherwise.
304 */
adaaa686 305 virtual int ShowModal();
23324ae1
FM
306};
307
308
e54c96f1 309
23324ae1
FM
310// ============================================================================
311// Global functions/macros
312// ============================================================================
313
b21126db 314/** @addtogroup group_funcmacro_dialog */
ba2874ff
BP
315//@{
316
23324ae1
FM
317/**
318 Pops up a file selector box. In Windows, this is the common file selector
ba2874ff
BP
319 dialog. In X, this is a file selector box with the same functionality. The
320 path and filename are distinct elements of a full file pathname. If path
321 is empty, the current directory will be used. If filename is empty, no
322 default filename will be supplied. The wildcard determines what files are
323 displayed in the file selector, and file extension supplies a type
324 extension for the required filename. Flags may be a combination of
325 wxFD_OPEN, wxFD_SAVE, wxFD_OVERWRITE_PROMPT or wxFD_FILE_MUST_EXIST.
326
327 @note wxFD_MULTIPLE can only be used with wxFileDialog and not here since
328 this function only returns a single file name.
329
23324ae1
FM
330 Both the Unix and Windows versions implement a wildcard filter. Typing a
331 filename containing wildcards (*, ?) in the filename text item, and
332 clicking on Ok, will result in only those files matching the pattern being
333 displayed.
ba2874ff
BP
334
335 The wildcard may be a specification for multiple types of file with a
336 description for each, such as:
4cc4bfaf 337
23324ae1
FM
338 @code
339 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"
340 @endcode
7c913512 341
23324ae1
FM
342 The application must check for an empty return value (the user pressed
343 Cancel). For example:
4cc4bfaf 344
23324ae1
FM
345 @code
346 wxString filename = wxFileSelector("Choose a file to open");
347 if ( !filename.empty() )
348 {
349 // work with the file
350 ...
351 }
352 //else: cancelled by user
353 @endcode
ba2874ff
BP
354
355 @header{wx/filedlg.h}
23324ae1
FM
356*/
357wxString wxFileSelector(const wxString& message,
e9c3992c
FM
358 const wxString& default_path = wxEmptyString,
359 const wxString& default_filename = wxEmptyString,
360 const wxString& default_extension = wxEmptyString,
23324ae1
FM
361 const wxString& wildcard = ".",
362 int flags = 0,
4cc4bfaf 363 wxWindow* parent = NULL,
23324ae1
FM
364 int x = -1,
365 int y = -1);
366
ba2874ff
BP
367//@}
368