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