1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFilePickerCtrl
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
8 #define wxFLP_OPEN 0x0400
9 #define wxFLP_SAVE 0x0800
10 #define wxFLP_OVERWRITE_PROMPT 0x1000
11 #define wxFLP_FILE_MUST_EXIST 0x2000
12 #define wxFLP_CHANGE_DIR 0x4000
13 #define wxFLP_SMALL wxPB_SMALL
14 #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
15 #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
17 #define wxDIRP_DIR_MUST_EXIST 0x0008
18 #define wxDIRP_CHANGE_DIR 0x0010
19 #define wxDIRP_SMALL wxPB_SMALL
20 #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
21 #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST)
23 wxEventType wxEVT_FILEPICKER_CHANGED
;
24 wxEventType wxEVT_DIRPICKER_CHANGED
;
28 @class wxFilePickerCtrl
30 This control allows the user to select a file. The generic implementation is
31 a button which brings up a wxFileDialog when clicked. Native implementation
32 may differ but this is usually a (small) widget which give access to the
34 It is only available if @c wxUSE_FILEPICKERCTRL is set to 1 (the default).
37 @style{wxFLP_DEFAULT_STYLE}
38 The default style: includes wxFLP_OPEN | wxFLP_FILE_MUST_EXIST and,
39 under wxMSW only, wxFLP_USE_TEXTCTRL.
40 @style{wxFLP_USE_TEXTCTRL}
41 Creates a text control to the left of the picker button which is
42 completely managed by the wxFilePickerCtrl and which can be used by
43 the user to specify a path (see SetPath). The text control is
44 automatically synchronized with button's value. Use functions
45 defined in wxPickerBase to modify the text control.
47 Creates a picker which allows the user to select a file to open.
49 Creates a picker which allows the user to select a file to save.
50 @style{wxFLP_OVERWRITE_PROMPT}
51 Can be combined with wxFLP_SAVE only: ask confirmation to the user
52 before selecting a file.
53 @style{wxFLP_FILE_MUST_EXIST}
54 Can be combined with wxFLP_OPEN only: the selected file must be an
56 @style{wxFLP_CHANGE_DIR}
57 Change current working directory on each user file selection change.
59 Use smaller version of the control with a small "..." button instead
60 of the normal "Browse" one. This flag is new since wxWidgets 2.9.3.
64 @beginEventEmissionTable{wxFileDirPickerEvent}
65 @event{EVT_FILEPICKER_CHANGED(id, func)}
66 The user changed the file selected in the control either using the
67 button or using text control (see wxFLP_USE_TEXTCTRL; note that in
68 this case the event is fired only if the user's input is valid,
69 e.g. an existing file path if wxFLP_FILE_MUST_EXIST was given).
74 @appearance{filepickerctrl}
76 @see wxFileDialog, wxFileDirPickerEvent
78 class wxFilePickerCtrl
: public wxPickerBase
84 Initializes the object and calls Create() with
87 wxFilePickerCtrl(wxWindow
* parent
, wxWindowID id
,
88 const wxString
& path
= wxEmptyString
,
89 const wxString
& message
= wxFileSelectorPromptStr
,
90 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
91 const wxPoint
& pos
= wxDefaultPosition
,
92 const wxSize
& size
= wxDefaultSize
,
93 long style
= wxFLP_DEFAULT_STYLE
,
94 const wxValidator
& validator
= wxDefaultValidator
,
95 const wxString
& name
= wxFilePickerCtrlNameStr
);
98 Creates this widget with the given parameters.
101 Parent window, must not be non-@NULL.
103 The identifier for the control.
105 The initial file shown in the control. Must be a valid path to a file or
108 The message shown to the user in the wxFileDialog shown by the control.
110 A wildcard which defines user-selectable files (use the same syntax as for
111 wxFileDialog's wildcards).
117 The window style, see wxFLP_* flags.
119 Validator which can be used for additional data checks.
123 @return @true if the control was successfully created or @false if
126 bool Create(wxWindow
* parent
, wxWindowID id
,
127 const wxString
& path
= wxEmptyString
,
128 const wxString
& message
= wxFileSelectorPromptStr
,
129 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
130 const wxPoint
& pos
= wxDefaultPosition
,
131 const wxSize
& size
= wxDefaultSize
,
132 long style
= wxFLP_DEFAULT_STYLE
,
133 const wxValidator
& validator
= wxDefaultValidator
,
134 const wxString
& name
= wxFilePickerCtrlNameStr
);
137 Similar to GetPath() but returns the path of the currently selected
138 file as a wxFileName object.
140 wxFileName
GetFileName() const;
143 Returns the absolute path of the currently selected file.
145 wxString
GetPath() const;
148 This method does the same thing as SetPath() but takes a wxFileName
149 object instead of a string.
151 void SetFileName(const wxFileName
& filename
);
154 Set the directory to show when starting to browse for files.
156 This function is mostly useful for the file picker controls which have
157 no selection initially to configure the directory that should be shown
158 if the user starts browsing for files as otherwise the directory of
159 initially selected file is used, which is usually the desired
160 behaviour and so the directory specified by this function is ignored in
165 void SetInitialDirectory(const wxString
& dir
);
168 Sets the absolute path of the currently selected file.
169 This must be a valid file if the @c wxFLP_FILE_MUST_EXIST style was given.
171 void SetPath(const wxString
& filename
);
177 @class wxDirPickerCtrl
179 This control allows the user to select a directory. The generic implementation
180 is a button which brings up a wxDirDialog when clicked. Native implementation
181 may differ but this is usually a (small) widget which give access to the
183 It is only available if @c wxUSE_DIRPICKERCTRL is set to 1 (the default).
186 @style{wxDIRP_DEFAULT_STYLE}
187 The default style: includes wxDIRP_DIR_MUST_EXIST and, under wxMSW
188 only, wxDIRP_USE_TEXTCTRL.
189 @style{wxDIRP_USE_TEXTCTRL}
190 Creates a text control to the left of the picker button which is
191 completely managed by the wxDirPickerCtrl and which can be used by
192 the user to specify a path (see SetPath). The text control is
193 automatically synchronized with button's value. Use functions
194 defined in wxPickerBase to modify the text control.
195 @style{wxDIRP_DIR_MUST_EXIST}
196 Creates a picker which allows to select only existing directories.
197 wxGTK control always adds this flag internally as it does not
199 @style{wxDIRP_CHANGE_DIR}
200 Change current working directory on each user directory selection change.
202 Use smaller version of the control with a small "..." button instead
203 of the normal "Browse" one. This flag is new since wxWidgets 2.9.3.
206 @beginEventEmissionTable{wxFileDirPickerEvent}
207 @event{EVT_DIRPICKER_CHANGED(id, func)}
208 The user changed the directory selected in the control either using the
209 button or using text control (see wxDIRP_USE_TEXTCTRL; note that in this
210 case the event is fired only if the user's input is valid, e.g. an
211 existing directory path).
217 @appearance{dirpickerctrl}
219 @see wxDirDialog, wxFileDirPickerEvent
221 class wxDirPickerCtrl
: public wxPickerBase
227 Initializes the object and calls Create() with
230 wxDirPickerCtrl(wxWindow
* parent
, wxWindowID id
,
231 const wxString
& path
= wxEmptyString
,
232 const wxString
& message
= wxDirSelectorPromptStr
,
233 const wxPoint
& pos
= wxDefaultPosition
,
234 const wxSize
& size
= wxDefaultSize
,
235 long style
= wxDIRP_DEFAULT_STYLE
,
236 const wxValidator
& validator
= wxDefaultValidator
,
237 const wxString
& name
= wxDirPickerCtrlNameStr
);
240 Creates the widgets with the given parameters.
243 Parent window, must not be non-@NULL.
245 The identifier for the control.
247 The initial directory shown in the control. Must be a valid path to a
248 directory or the empty string.
250 The message shown to the user in the wxDirDialog shown by the control.
256 The window style, see wxDIRP_* flags.
258 Validator which can be used for additional date checks.
262 @return @true if the control was successfully created or @false if
265 bool Create(wxWindow
* parent
, wxWindowID id
,
266 const wxString
& path
= wxEmptyString
,
267 const wxString
& message
= wxDirSelectorPromptStr
,
268 const wxPoint
& pos
= wxDefaultPosition
,
269 const wxSize
& size
= wxDefaultSize
,
270 long style
= wxDIRP_DEFAULT_STYLE
,
271 const wxValidator
& validator
= wxDefaultValidator
,
272 const wxString
& name
= wxDirPickerCtrlNameStr
);
275 Returns the absolute path of the currently selected directory as a
277 This function is equivalent to GetPath().
279 wxFileName
GetDirName() const;
282 Returns the absolute path of the currently selected directory.
284 wxString
GetPath() const;
287 Just like SetPath() but this function takes a wxFileName object.
289 void SetDirName(const wxFileName
& dirname
);
292 Set the directory to show when starting to browse for directories.
294 This function is mostly useful for the directory picker controls which
295 have no selection initially to configure the directory that should be
296 shown if the user starts browsing for directories as otherwise the
297 initially selected directory is used, which is usually the desired
298 behaviour and so the directory specified by this function is ignored in
303 void SetInitialDirectory(const wxString
& dir
);
306 Sets the absolute path of the currently selected directory (the default converter uses current locale's
308 This must be a valid directory if @c wxDIRP_DIR_MUST_EXIST style was given.
310 void SetPath(const wxString
& dirname
);
316 @class wxFileDirPickerEvent
318 This event class is used for the events generated by
319 wxFilePickerCtrl and by wxDirPickerCtrl.
321 @beginEventTable{wxFileDirPickerEvent}
322 @event{EVT_FILEPICKER_CHANGED(id, func)}
323 Generated whenever the selected file changes.
324 @event{EVT_DIRPICKER_CHANGED(id, func)}
325 Generated whenever the selected directory changes.
331 @see wxFilePickerCtrl, wxDirPickerCtrl
333 class wxFileDirPickerEvent
: public wxCommandEvent
336 wxFileDirPickerEvent();
339 The constructor is not normally used by the user code.
341 wxFileDirPickerEvent(wxEventType type
, wxObject
* generator
,
343 const wxString
& path
);
346 Retrieve the absolute path of the file/directory the user has just selected.
348 wxString
GetPath() const;
351 Set the absolute path of the file/directory associated with the event.
353 void SetPath(const wxString
& path
);