1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFileDialog
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 This class represents the file chooser dialog.
15 It pops up a file selector box (native for Windows and GTK2.4+).
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.
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
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"
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
56 wxGTK using GTK+ 2.4 or later).
62 @see @ref overview_wxfiledialog, ::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
= "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");
107 Returns the default directory.
109 wxString
GetDirectory() const;
112 If functions SetExtraControlCreator() and ShowModal() were called,
113 returns the extra window. Otherwise returns @NULL.
115 wxWindow
* GetExtraControl() const;
118 Returns the default filename.
120 wxString
GetFilename() const;
123 Fills the array @a filenames with the names of the files chosen.
125 This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
126 use GetFilename() for the others.
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
133 void GetFilenames(wxArrayString
& filenames
) const;
136 Returns the index into the list of filters supplied, optionally, in the
139 Before the dialog is shown, this is the index which will be used when the
140 dialog is first displayed.
142 After the dialog is shown, this is the index selected by the user.
144 int GetFilterIndex() const;
147 Returns the message that will be displayed on the dialog.
149 wxString
GetMessage() const;
152 Returns the full path (directory and filename) of the selected file.
154 wxString
GetPath() const;
157 Fills the array @a paths with the full paths of the files chosen.
159 This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
160 use GetPath() for the others.
162 void GetPaths(wxArrayString
& paths
) const;
165 Returns the file dialog wildcard.
167 wxString
GetWildcard() const;
170 Sets the default directory.
172 void SetDirectory(const wxString
& directory
);
175 Customize file dialog by adding extra window, which is typically placed
176 below the list of files and above the buttons.
178 SetExtraControlCreator() can be called only once, before calling ShowModal().
180 The @c creator function should take pointer to parent window (file dialog)
181 and should return a window allocated with operator new.
183 Supported platforms: wxGTK, wxUniv.
185 bool SetExtraControlCreator(t_extraControlCreator creator
);
188 Sets the default filename.
190 void SetFilename(const wxString
& setfilename
);
193 Sets the default filter index, starting from zero.
195 void SetFilterIndex(int filterIndex
);
198 Sets the message that will be displayed on the dialog.
200 void SetMessage(const wxString
& message
);
203 Sets the path (the combined directory and filename that will be returned when
204 the dialog is dismissed).
206 void SetPath(const wxString
& path
);
209 Sets the wildcard, which can contain multiple file types, for example:
210 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
212 Note that the native Motif dialog has some limitations with respect to
213 wildcards; see the Remarks section above.
215 void SetWildcard(const wxString
& wildCard
);
218 Shows the dialog, returning wxID_OK if the user pressed OK, and wxID_CANCEL
226 // ============================================================================
227 // Global functions/macros
228 // ============================================================================
230 /** @ingroup group_funcmacro_dialog */
234 Pops up a file selector box. In Windows, this is the common file selector
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.
243 @note wxFD_MULTIPLE can only be used with wxFileDialog and not here since
244 this function only returns a single file name.
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
251 The wildcard may be a specification for multiple types of file with a
252 description for each, such as:
255 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"
258 The application must check for an empty return value (the user pressed
259 Cancel). For example:
262 wxString filename = wxFileSelector("Choose a file to open");
263 if ( !filename.empty() )
265 // work with the file
268 //else: cancelled by user
271 @header{wx/filedlg.h}
273 wxString
wxFileSelector(const wxString
& message
,
274 const wxString
& default_path
= "",
275 const wxString
& default_filename
= "",
276 const wxString
& default_extension
= "",
277 const wxString
& wildcard
= ".",
279 wxWindow
* parent
= NULL
,