1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFilePickerCtrl
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 #define wxFLP_OPEN 0x0400
10 #define wxFLP_SAVE 0x0800
11 #define wxFLP_OVERWRITE_PROMPT 0x1000
12 #define wxFLP_FILE_MUST_EXIST 0x2000
13 #define wxFLP_CHANGE_DIR 0x4000
14 #define wxFLP_SMALL wxPB_SMALL
15 #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
16 #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
18 #define wxDIRP_DIR_MUST_EXIST 0x0008
19 #define wxDIRP_CHANGE_DIR 0x0010
20 #define wxDIRP_SMALL wxPB_SMALL
21 #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
22 #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST)
24 wxEventType wxEVT_FILEPICKER_CHANGED
;
25 wxEventType wxEVT_DIRPICKER_CHANGED
;
29 @class wxFilePickerCtrl
31 This control allows the user to select a file. The generic implementation is
32 a button which brings up a wxFileDialog when clicked. Native implementation
33 may differ but this is usually a (small) widget which give access to the
35 It is only available if @c wxUSE_FILEPICKERCTRL is set to 1 (the default).
38 @style{wxFLP_DEFAULT_STYLE}
39 The default style: includes wxFLP_OPEN | wxFLP_FILE_MUST_EXIST and,
40 under wxMSW only, wxFLP_USE_TEXTCTRL.
41 @style{wxFLP_USE_TEXTCTRL}
42 Creates a text control to the left of the picker button which is
43 completely managed by the wxFilePickerCtrl and which can be used by
44 the user to specify a path (see SetPath). The text control is
45 automatically synchronized with button's value. Use functions
46 defined in wxPickerBase to modify the text control.
48 Creates a picker which allows the user to select a file to open.
50 Creates a picker which allows the user to select a file to save.
51 @style{wxFLP_OVERWRITE_PROMPT}
52 Can be combined with wxFLP_SAVE only: ask confirmation to the user
53 before selecting a file.
54 @style{wxFLP_FILE_MUST_EXIST}
55 Can be combined with wxFLP_OPEN only: the selected file must be an
57 @style{wxFLP_CHANGE_DIR}
58 Change current working directory on each user file selection change.
60 Use smaller version of the control with a small "..." button instead
61 of the normal "Browse" one. This flag is new since wxWidgets 2.9.3.
65 @beginEventEmissionTable{wxFileDirPickerEvent}
66 @event{EVT_FILEPICKER_CHANGED(id, func)}
67 The user changed the file selected in the control either using the
68 button or using text control (see wxFLP_USE_TEXTCTRL; note that in
69 this case the event is fired only if the user's input is valid,
70 e.g. an existing file path if wxFLP_FILE_MUST_EXIST was given).
75 @appearance{filepickerctrl}
77 @see wxFileDialog, wxFileDirPickerEvent
79 class wxFilePickerCtrl
: public wxPickerBase
85 Initializes the object and calls Create() with
88 wxFilePickerCtrl(wxWindow
* parent
, wxWindowID id
,
89 const wxString
& path
= wxEmptyString
,
90 const wxString
& message
= wxFileSelectorPromptStr
,
91 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
92 const wxPoint
& pos
= wxDefaultPosition
,
93 const wxSize
& size
= wxDefaultSize
,
94 long style
= wxFLP_DEFAULT_STYLE
,
95 const wxValidator
& validator
= wxDefaultValidator
,
96 const wxString
& name
= wxFilePickerCtrlNameStr
);
99 Creates this widget with the given parameters.
102 Parent window, must not be non-@NULL.
104 The identifier for the control.
106 The initial file shown in the control. Must be a valid path to a file or
109 The message shown to the user in the wxFileDialog shown by the control.
111 A wildcard which defines user-selectable files (use the same syntax as for
112 wxFileDialog's wildcards).
118 The window style, see wxFLP_* flags.
120 Validator which can be used for additional data checks.
124 @return @true if the control was successfully created or @false if
127 bool Create(wxWindow
* parent
, wxWindowID id
,
128 const wxString
& path
= wxEmptyString
,
129 const wxString
& message
= wxFileSelectorPromptStr
,
130 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
131 const wxPoint
& pos
= wxDefaultPosition
,
132 const wxSize
& size
= wxDefaultSize
,
133 long style
= wxFLP_DEFAULT_STYLE
,
134 const wxValidator
& validator
= wxDefaultValidator
,
135 const wxString
& name
= wxFilePickerCtrlNameStr
);
138 Similar to GetPath() but returns the path of the currently selected
139 file as a wxFileName object.
141 wxFileName
GetFileName() const;
144 Returns the absolute path of the currently selected file.
146 wxString
GetPath() const;
149 This method does the same thing as SetPath() but takes a wxFileName
150 object instead of a string.
152 void SetFileName(const wxFileName
& filename
);
155 Set the directory to show when starting to browse for files.
157 This function is mostly useful for the file picker controls which have
158 no selection initially to configure the directory that should be shown
159 if the user starts browsing for files as otherwise the directory of
160 initially selected file is used, which is usually the desired
161 behaviour and so the directory specified by this function is ignored in
166 void SetInitialDirectory(const wxString
& dir
);
169 Sets the absolute path of the currently selected file.
170 This must be a valid file if the @c wxFLP_FILE_MUST_EXIST style was given.
172 void SetPath(const wxString
& filename
);
178 @class wxDirPickerCtrl
180 This control allows the user to select a directory. The generic implementation
181 is a button which brings up a wxDirDialog when clicked. Native implementation
182 may differ but this is usually a (small) widget which give access to the
184 It is only available if @c wxUSE_DIRPICKERCTRL is set to 1 (the default).
187 @style{wxDIRP_DEFAULT_STYLE}
188 The default style: includes wxDIRP_DIR_MUST_EXIST and, under wxMSW
189 only, wxDIRP_USE_TEXTCTRL.
190 @style{wxDIRP_USE_TEXTCTRL}
191 Creates a text control to the left of the picker button which is
192 completely managed by the wxDirPickerCtrl and which can be used by
193 the user to specify a path (see SetPath). The text control is
194 automatically synchronized with button's value. Use functions
195 defined in wxPickerBase to modify the text control.
196 @style{wxDIRP_DIR_MUST_EXIST}
197 Creates a picker which allows to select only existing directories.
198 wxGTK control always adds this flag internally as it does not
200 @style{wxDIRP_CHANGE_DIR}
201 Change current working directory on each user directory selection change.
203 Use smaller version of the control with a small "..." button instead
204 of the normal "Browse" one. This flag is new since wxWidgets 2.9.3.
207 @beginEventEmissionTable{wxFileDirPickerEvent}
208 @event{EVT_DIRPICKER_CHANGED(id, func)}
209 The user changed the directory selected in the control either using the
210 button or using text control (see wxDIRP_USE_TEXTCTRL; note that in this
211 case the event is fired only if the user's input is valid, e.g. an
212 existing directory path).
218 @appearance{dirpickerctrl}
220 @see wxDirDialog, wxFileDirPickerEvent
222 class wxDirPickerCtrl
: public wxPickerBase
228 Initializes the object and calls Create() with
231 wxDirPickerCtrl(wxWindow
* parent
, wxWindowID id
,
232 const wxString
& path
= wxEmptyString
,
233 const wxString
& message
= wxDirSelectorPromptStr
,
234 const wxPoint
& pos
= wxDefaultPosition
,
235 const wxSize
& size
= wxDefaultSize
,
236 long style
= wxDIRP_DEFAULT_STYLE
,
237 const wxValidator
& validator
= wxDefaultValidator
,
238 const wxString
& name
= wxDirPickerCtrlNameStr
);
241 Creates the widgets with the given parameters.
244 Parent window, must not be non-@NULL.
246 The identifier for the control.
248 The initial directory shown in the control. Must be a valid path to a
249 directory or the empty string.
251 The message shown to the user in the wxDirDialog shown by the control.
257 The window style, see wxDIRP_* flags.
259 Validator which can be used for additional date checks.
263 @return @true if the control was successfully created or @false if
266 bool Create(wxWindow
* parent
, wxWindowID id
,
267 const wxString
& path
= wxEmptyString
,
268 const wxString
& message
= wxDirSelectorPromptStr
,
269 const wxPoint
& pos
= wxDefaultPosition
,
270 const wxSize
& size
= wxDefaultSize
,
271 long style
= wxDIRP_DEFAULT_STYLE
,
272 const wxValidator
& validator
= wxDefaultValidator
,
273 const wxString
& name
= wxDirPickerCtrlNameStr
);
276 Returns the absolute path of the currently selected directory as a
278 This function is equivalent to GetPath().
280 wxFileName
GetDirName() const;
283 Returns the absolute path of the currently selected directory.
285 wxString
GetPath() const;
288 Just like SetPath() but this function takes a wxFileName object.
290 void SetDirName(const wxFileName
& dirname
);
293 Set the directory to show when starting to browse for directories.
295 This function is mostly useful for the directory picker controls which
296 have no selection initially to configure the directory that should be
297 shown if the user starts browsing for directories as otherwise the
298 initially selected directory is used, which is usually the desired
299 behaviour and so the directory specified by this function is ignored in
304 void SetInitialDirectory(const wxString
& dir
);
307 Sets the absolute path of the currently selected directory (the default converter uses current locale's
309 This must be a valid directory if @c wxDIRP_DIR_MUST_EXIST style was given.
311 void SetPath(const wxString
& dirname
);
317 @class wxFileDirPickerEvent
319 This event class is used for the events generated by
320 wxFilePickerCtrl and by wxDirPickerCtrl.
322 @beginEventTable{wxFileDirPickerEvent}
323 @event{EVT_FILEPICKER_CHANGED(id, func)}
324 Generated whenever the selected file changes.
325 @event{EVT_DIRPICKER_CHANGED(id, func)}
326 Generated whenever the selected directory changes.
332 @see wxFilePickerCtrl, wxDirPickerCtrl
334 class wxFileDirPickerEvent
: public wxCommandEvent
337 wxFileDirPickerEvent();
340 The constructor is not normally used by the user code.
342 wxFileDirPickerEvent(wxEventType type
, wxObject
* generator
,
344 const wxString
& path
);
347 Retrieve the absolute path of the file/directory the user has just selected.
349 wxString
GetPath() const;
352 Set the absolute path of the file/directory associated with the event.
354 void SetPath(const wxString
& path
);