1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFileCtrl
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 This control allows the user to select a file.
14 Two implementations of this class exist, one for Gtk and another generic
15 one for all the other ports.
17 This class is only available if @c wxUSE_FILECTRL is set to 1.
20 @style{wxFC_DEFAULT_STYLE}
21 The default style: wxFC_OPEN
23 Creates an file control suitable for opening files. Cannot be
24 combined with wxFC_SAVE.
26 Creates an file control suitable for saving files. Cannot be
27 combined with wxFC_OPEN.
29 For open control only, Allows selecting multiple files. Cannot be
30 combined with wxFC_SAVE
31 @style{wxFC_NOSHOWHIDDEN}
32 Hides the "Show Hidden Files" checkbox (Generic only)
35 @beginEventEmissionTable{wxFileCtrlEvent}
36 @event{EVT_FILECTRL_FILEACTIVATED(id, func)}
37 The user activated a file(by double-clicking or pressing Enter)
38 @event{EVT_FILECTRL_SELECTIONCHANGED(id, func)}
39 The user changed the current selection(by selecting or deselecting a file)
40 @event{EVT_FILECTRL_FOLDERCHANGED(id, func)}
41 The current folder of the file control has been changed
42 @event{EVT_FILECTRL_FILTERCHANGED(id, func)}
43 The current file filter of the file control has been changed. This
44 event is new in wxWidgets 2.9.1.
49 @appearance{filectrl.png}
55 class wxFileCtrl
: public wxControl
61 Constructs the window.
64 Parent window, must not be non-@NULL.
66 The identifier for the control.
67 @param defaultDirectory
68 The initial directory shown in the control.
69 Must be a valid path to a directory or the empty string.
70 In case it is the empty string, the current working directory is used.
71 @param defaultFilename
72 The default filename, or the empty string.
74 A wildcard specifying which files can be selected,
75 such as "*.*" or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
77 The window style, see wxFC_* flags.
85 @return @true if the control was successfully created or @false if
89 wxFileCtrl(wxWindow
* parent
, wxWindowID id
,
90 const wxString
& defaultDirectory
= wxEmptyString
,
91 const wxString
& defaultFilename
= wxEmptyString
,
92 const wxPoint
& wildCard
= wxFileSelectorDefaultWildcardStr
,
93 long style
= wxFC_DEFAULT_STYLE
,
94 const wxPoint
& pos
= wxDefaultPosition
,
95 const wxSize
& size
= wxDefaultSize
,
96 const wxString
& name
= wxFileCtrlNameStr
);
99 Create function for two-step construction. See wxFileCtrl() for details.
101 bool Create(wxWindow
* parent
, wxWindowID id
,
102 const wxString
& defaultDirectory
= wxEmptyString
,
103 const wxString
& defaultFilename
= wxEmptyString
,
104 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
105 long style
= wxFC_DEFAULT_STYLE
, const wxPoint
& pos
= wxDefaultPosition
,
106 const wxSize
& size
= wxDefaultSize
,
107 const wxString
& name
= wxFileCtrlNameStr
);
110 Returns the current directory of the file control (i.e. the directory shown by it).
112 virtual wxString
GetDirectory() const;
115 Returns the currently selected filename.
117 For the controls having the @c wxFC_MULTIPLE style, use GetFilenames() instead.
119 virtual wxString
GetFilename() const;
122 Fills the array @a filenames with the filenames only of selected items.
124 This function should only be used with the controls having the @c wxFC_MULTIPLE
125 style, use GetFilename() for the others.
127 @remarks filenames is emptied first.
129 virtual void GetFilenames(wxArrayString
& filenames
) const;
132 Returns the zero-based index of the currently selected filter.
134 virtual int GetFilterIndex() const;
137 Returns the full path (directory and filename) of the currently selected file.
138 For the controls having the @c wxFC_MULTIPLE style, use GetPaths() instead.
140 virtual wxString
GetPath() const;
143 Fills the array @a paths with the full paths of the files chosen.
145 This function should be used with the controls having the @c wxFC_MULTIPLE style,
146 use GetPath() otherwise.
148 @remarks paths is emptied first.
150 virtual void GetPaths(wxArrayString
& paths
) const;
153 Returns the current wildcard.
155 virtual wxString
GetWildcard() const;
158 Sets(changes) the current directory displayed in the control.
160 @return Returns @true on success, @false otherwise.
162 virtual bool SetDirectory(const wxString
& directory
);
165 Selects a certain file.
167 @return Returns @true on success, @false otherwise
169 virtual bool SetFilename(const wxString
& filename
);
172 Sets the current filter index, starting from zero.
174 virtual void SetFilterIndex(int filterIndex
);
177 Sets the wildcard, which can contain multiple file types, for example:
178 "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"
180 virtual void SetWildcard(const wxString
& wildCard
);
183 Sets whether hidden files and folders are shown or not.
185 virtual void ShowHidden(bool show
);
191 @class wxFileCtrlEvent
193 A file control event holds information about events associated with
196 @beginEventTable{wxFileCtrlEvent}
197 @event{EVT_FILECTRL_FILEACTIVATED(id, func)}
198 The user activated a file(by double-clicking or pressing Enter)
199 @event{EVT_FILECTRL_SELECTIONCHANGED(id, func)}
200 The user changed the current selection(by selecting or deselecting a file)
201 @event{EVT_FILECTRL_FOLDERCHANGED(id, func)}
202 The current folder of the file control has been changed
203 @event{EVT_FILECTRL_FILTERCHANGED(id, func)}
204 The current file filter of the file control has been changed
210 class wxFileCtrlEvent
: public wxCommandEvent
216 wxFileCtrlEvent(wxEventType type
, wxObject
*evtObject
, int id
);
219 Returns the current directory.
221 In case of a @b EVT_FILECTRL_FOLDERCHANGED, this method returns the new
224 wxString
GetDirectory() const;
227 Returns the file selected (assuming it is only one file).
229 wxString
GetFile() const;
232 Returns the files selected.
234 In case of a @b EVT_FILECTRL_SELECTIONCHANGED, this method returns the
235 files selected after the event.
237 wxArrayString
GetFiles() const;
240 Returns the current file filter index.
242 For a @b EVT_FILECTRL_FILTERCHANGED event, this method returns the new
247 int GetFilterIndex() const;
250 Sets the files changed by this event.
252 void SetFiles(const wxArrayString
& files
);
256 Sets the directory of this event.
258 void SetDirectory( const wxString
&directory
);
261 Sets the filter index changed by this event.
265 void SetFilterIndex(int index
);