1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFileDialog
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 This class represents the file chooser dialog.
14 The path and filename are distinct elements of a full file pathname.
15 If path is wxEmptyString, the current directory will be used.
16 If filename is wxEmptyString, no default filename will be supplied.
17 The wildcard determines what files are displayed in the file selector,
18 and file extension supplies a type extension for the required filename.
21 All implementations of the wxFileDialog provide a wildcard filter. Typing a filename
22 containing wildcards (*, ?) in the filename text item, and clicking on Ok, will
23 result in only those files matching the pattern being displayed.
24 The wildcard may be a specification for multiple types of file with a description
27 "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"
36 @style{wxFD_DEFAULT_STYLE}
37 Equivalent to wxFD_OPEN.
39 This is an open dialog; usually this means that the default
40 button's label of the dialog is "Open". Cannot be combined with 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
47 @style{wxFD_FILE_MUST_EXIST}
48 For open dialog only: the user may only select files that actually exist.
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.
55 Show the preview of the selected files (currently only supported by
62 @see @ref overview_cmndlg_file, ::wxFileSelector()
64 class wxFileDialog
: public wxDialog
68 Constructor. Use ShowModal() to show the dialog.
73 Message to show on the dialog.
75 The default directory, or the empty string.
77 The default filename, or the empty string.
79 A wildcard, such as "*.*" or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
80 Note that the native Motif dialog has some limitations with respect to
81 wildcards; see the Remarks section above.
83 A dialog style. See wxFD_* styles for more info.
85 Dialog position. Not implemented.
87 Dialog size. Not implemented.
89 Dialog name. Not implemented.
91 wxFileDialog(wxWindow
* parent
,
92 const wxString
& message
= wxFileSelectorPromptStr
,
93 const wxString
& defaultDir
= wxEmptyString
,
94 const wxString
& defaultFile
= wxEmptyString
,
95 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
96 long style
= wxFD_DEFAULT_STYLE
,
97 const wxPoint
& pos
= wxDefaultPosition
,
98 const wxSize
& size
= wxDefaultSize
,
99 const wxString
& name
= wxFileDialogNameStr
);
104 virtual ~wxFileDialog();
107 Returns the default directory.
109 virtual wxString
GetDirectory() const;
112 If functions SetExtraControlCreator() and ShowModal() were called,
113 returns the extra window. Otherwise returns @NULL.
117 wxWindow
* GetExtraControl() const;
120 Returns the default filename.
122 virtual wxString
GetFilename() const;
125 Fills the array @a filenames with the names of the files chosen.
127 This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
128 use GetFilename() for the others.
130 Note that under Windows, if the user selects shortcuts, the filenames
131 include paths, since the application cannot determine the full path
132 of each referenced file by appending the directory containing the shortcuts
135 virtual void GetFilenames(wxArrayString
& filenames
) const;
138 Returns the index into the list of filters supplied, optionally, in the
141 Before the dialog is shown, this is the index which will be used when the
142 dialog is first displayed.
144 After the dialog is shown, this is the index selected by the user.
146 virtual int GetFilterIndex() const;
149 Returns the message that will be displayed on the dialog.
151 virtual wxString
GetMessage() const;
154 Returns the full path (directory and filename) of the selected file.
156 virtual wxString
GetPath() const;
159 Fills the array @a paths with the full paths of the files chosen.
161 This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
162 use GetPath() for the others.
164 virtual void GetPaths(wxArrayString
& paths
) const;
167 Returns the file dialog wildcard.
169 virtual wxString
GetWildcard() const;
172 Sets the default directory.
174 virtual void SetDirectory(const wxString
& directory
);
177 The type of function used as an argument for SetExtraControlCreator().
181 typedef wxWindow
*(*ExtraControlCreatorFunction
)(wxWindow
*);
184 Customize file dialog by adding extra window, which is typically placed
185 below the list of files and above the buttons.
187 SetExtraControlCreator() can be called only once, before calling ShowModal().
189 The @c creator function should take pointer to parent window (file dialog)
190 and should return a window allocated with operator new.
192 Supported platforms: wxGTK, wxMSW, wxUniv.
196 bool SetExtraControlCreator(ExtraControlCreatorFunction creator
);
199 Sets the default filename.
201 In wxGTK this will have little effect unless a default directory has previously been set.
203 virtual void SetFilename(const wxString
& setfilename
);
206 Sets the default filter index, starting from zero.
208 virtual void SetFilterIndex(int filterIndex
);
211 Sets the message that will be displayed on the dialog.
213 virtual void SetMessage(const wxString
& message
);
216 Sets the path (the combined directory and filename that will be returned when
217 the dialog is dismissed).
219 virtual void SetPath(const wxString
& path
);
222 Sets the wildcard, which can contain multiple file types, for example:
223 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
225 Note that the native Motif dialog has some limitations with respect to
226 wildcards; see the Remarks section above.
228 virtual void SetWildcard(const wxString
& wildCard
);
231 Shows the dialog, returning wxID_OK if the user pressed OK, and wxID_CANCEL
234 virtual int ShowModal();
239 // ============================================================================
240 // Global functions/macros
241 // ============================================================================
243 /** @addtogroup group_funcmacro_dialog */
247 Pops up a file selector box. In Windows, this is the common file selector
248 dialog. In X, this is a file selector box with the same functionality. The
249 path and filename are distinct elements of a full file pathname. If path
250 is empty, the current directory will be used. If filename is empty, no
251 default filename will be supplied. The wildcard determines what files are
252 displayed in the file selector, and file extension supplies a type
253 extension for the required filename. Flags may be a combination of
254 wxFD_OPEN, wxFD_SAVE, wxFD_OVERWRITE_PROMPT or wxFD_FILE_MUST_EXIST.
256 @note wxFD_MULTIPLE can only be used with wxFileDialog and not here since
257 this function only returns a single file name.
259 Both the Unix and Windows versions implement a wildcard filter. Typing a
260 filename containing wildcards (*, ?) in the filename text item, and
261 clicking on Ok, will result in only those files matching the pattern being
264 The wildcard may be a specification for multiple types of file with a
265 description for each, such as:
268 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"
271 The application must check for an empty return value (the user pressed
272 Cancel). For example:
275 wxString filename = wxFileSelector("Choose a file to open");
276 if ( !filename.empty() )
278 // work with the file
281 //else: cancelled by user
284 @header{wx/filedlg.h}
286 wxString
wxFileSelector(const wxString
& message
,
287 const wxString
& default_path
= wxEmptyString
,
288 const wxString
& default_filename
= wxEmptyString
,
289 const wxString
& default_extension
= wxEmptyString
,
290 const wxString
& wildcard
= ".",
292 wxWindow
* parent
= NULL
,