]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: filectrl.h | |
e54c96f1 | 3 | // Purpose: interface of wxFileCtrl |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
34a9a352 RD |
8 | enum |
9 | { | |
10 | wxFC_OPEN = 0x0001, | |
11 | wxFC_SAVE = 0x0002, | |
12 | wxFC_MULTIPLE = 0x0004, | |
13 | wxFC_NOSHOWHIDDEN = 0x0008 | |
14 | }; | |
15 | ||
16 | #define wxFC_DEFAULT_STYLE wxFC_OPEN | |
17 | ||
23324ae1 FM |
18 | /** |
19 | @class wxFileCtrl | |
7c913512 | 20 | |
0ce6d6c8 FM |
21 | This control allows the user to select a file. |
22 | ||
d82b0abc VZ |
23 | Two implementations of this class exist, one for Gtk and another generic |
24 | one for all the other ports. | |
25 | ||
26 | This class is only available if @c wxUSE_FILECTRL is set to 1. | |
7c913512 | 27 | |
23324ae1 | 28 | @beginStyleTable |
8c6791e4 | 29 | @style{wxFC_DEFAULT_STYLE} |
23324ae1 | 30 | The default style: wxFC_OPEN |
8c6791e4 | 31 | @style{wxFC_OPEN} |
23324ae1 FM |
32 | Creates an file control suitable for opening files. Cannot be |
33 | combined with wxFC_SAVE. | |
8c6791e4 | 34 | @style{wxFC_SAVE} |
23324ae1 FM |
35 | Creates an file control suitable for saving files. Cannot be |
36 | combined with wxFC_OPEN. | |
8c6791e4 | 37 | @style{wxFC_MULTIPLE} |
23324ae1 FM |
38 | For open control only, Allows selecting multiple files. Cannot be |
39 | combined with wxFC_SAVE | |
8c6791e4 | 40 | @style{wxFC_NOSHOWHIDDEN} |
23324ae1 FM |
41 | Hides the "Show Hidden Files" checkbox (Generic only) |
42 | @endStyleTable | |
7c913512 | 43 | |
3051a44a | 44 | @beginEventEmissionTable{wxFileCtrlEvent} |
8c6791e4 | 45 | @event{EVT_FILECTRL_FILEACTIVATED(id, func)} |
0ce6d6c8 | 46 | The user activated a file(by double-clicking or pressing Enter) |
8c6791e4 | 47 | @event{EVT_FILECTRL_SELECTIONCHANGED(id, func)} |
0ce6d6c8 | 48 | The user changed the current selection(by selecting or deselecting a file) |
8c6791e4 | 49 | @event{EVT_FILECTRL_FOLDERCHANGED(id, func)} |
0ce6d6c8 | 50 | The current folder of the file control has been changed |
6305f044 | 51 | @event{EVT_FILECTRL_FILTERCHANGED(id, func)} |
4c9ccee7 VZ |
52 | The current file filter of the file control has been changed. |
53 | @since 2.9.1. | |
54 | ||
0ce6d6c8 FM |
55 | @endEventTable |
56 | ||
3f42c239 | 57 | @library{wxcore} |
3c99e2fd | 58 | @category{ctrl} |
ce154616 | 59 | @appearance{filectrl} |
5f12fb35 FM |
60 | |
61 | @nativeimpl{wxgtk} | |
7c913512 | 62 | |
e54c96f1 | 63 | @see wxGenericDirCtrl |
23324ae1 | 64 | */ |
3c99e2fd | 65 | class wxFileCtrl : public wxControl |
23324ae1 FM |
66 | { |
67 | public: | |
0ce6d6c8 FM |
68 | wxFileCtrl(); |
69 | ||
23324ae1 | 70 | /** |
0ce6d6c8 FM |
71 | Constructs the window. |
72 | ||
7c913512 | 73 | @param parent |
4cc4bfaf | 74 | Parent window, must not be non-@NULL. |
7c913512 | 75 | @param id |
4cc4bfaf | 76 | The identifier for the control. |
7c913512 | 77 | @param defaultDirectory |
76e9224e FM |
78 | The initial directory shown in the control. |
79 | Must be a valid path to a directory or the empty string. | |
4cc4bfaf | 80 | In case it is the empty string, the current working directory is used. |
7c913512 | 81 | @param defaultFilename |
4cc4bfaf | 82 | The default filename, or the empty string. |
76e9224e | 83 | @param wildCard |
4cc4bfaf FM |
84 | A wildcard specifying which files can be selected, |
85 | such as "*.*" or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif". | |
7c913512 | 86 | @param style |
4cc4bfaf | 87 | The window style, see wxFC_* flags. |
7c913512 | 88 | @param pos |
4cc4bfaf | 89 | Initial position. |
7c913512 | 90 | @param size |
4cc4bfaf | 91 | Initial size. |
7c913512 | 92 | @param name |
4cc4bfaf | 93 | Control name. |
3c4f71cc | 94 | |
d29a9a8a | 95 | @return @true if the control was successfully created or @false if |
4cc4bfaf | 96 | creation failed. |
23324ae1 | 97 | */ |
0ce6d6c8 | 98 | |
4cc4bfaf | 99 | wxFileCtrl(wxWindow* parent, wxWindowID id, |
7c913512 FM |
100 | const wxString& defaultDirectory = wxEmptyString, |
101 | const wxString& defaultFilename = wxEmptyString, | |
b3a3a879 | 102 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, |
7c913512 FM |
103 | long style = wxFC_DEFAULT_STYLE, |
104 | const wxPoint& pos = wxDefaultPosition, | |
105 | const wxSize& size = wxDefaultSize, | |
a44f3b5a | 106 | const wxString& name = wxFileCtrlNameStr); |
23324ae1 FM |
107 | |
108 | /** | |
109 | Create function for two-step construction. See wxFileCtrl() for details. | |
110 | */ | |
4cc4bfaf | 111 | bool Create(wxWindow* parent, wxWindowID id, |
23324ae1 FM |
112 | const wxString& defaultDirectory = wxEmptyString, |
113 | const wxString& defaultFilename = wxEmptyString, | |
43c48e1e FM |
114 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, |
115 | long style = wxFC_DEFAULT_STYLE, const wxPoint& pos = wxDefaultPosition, | |
23324ae1 | 116 | const wxSize& size = wxDefaultSize, |
43c48e1e | 117 | const wxString& name = wxFileCtrlNameStr); |
23324ae1 FM |
118 | |
119 | /** | |
0824e369 | 120 | Returns the current directory of the file control (i.e.\ the directory shown by it). |
23324ae1 | 121 | */ |
adaaa686 | 122 | virtual wxString GetDirectory() const; |
23324ae1 FM |
123 | |
124 | /** | |
125 | Returns the currently selected filename. | |
0ce6d6c8 FM |
126 | |
127 | For the controls having the @c wxFC_MULTIPLE style, use GetFilenames() instead. | |
23324ae1 | 128 | */ |
adaaa686 | 129 | virtual wxString GetFilename() const; |
23324ae1 FM |
130 | |
131 | /** | |
0ce6d6c8 FM |
132 | Fills the array @a filenames with the filenames only of selected items. |
133 | ||
134 | This function should only be used with the controls having the @c wxFC_MULTIPLE | |
135 | style, use GetFilename() for the others. | |
3c4f71cc | 136 | |
23324ae1 FM |
137 | @remarks filenames is emptied first. |
138 | */ | |
adaaa686 | 139 | virtual void GetFilenames(wxArrayString& filenames) const; |
23324ae1 FM |
140 | |
141 | /** | |
142 | Returns the zero-based index of the currently selected filter. | |
143 | */ | |
adaaa686 | 144 | virtual int GetFilterIndex() const; |
23324ae1 FM |
145 | |
146 | /** | |
147 | Returns the full path (directory and filename) of the currently selected file. | |
0ce6d6c8 | 148 | For the controls having the @c wxFC_MULTIPLE style, use GetPaths() instead. |
23324ae1 | 149 | */ |
adaaa686 | 150 | virtual wxString GetPath() const; |
23324ae1 FM |
151 | |
152 | /** | |
0ce6d6c8 FM |
153 | Fills the array @a paths with the full paths of the files chosen. |
154 | ||
155 | This function should be used with the controls having the @c wxFC_MULTIPLE style, | |
23324ae1 | 156 | use GetPath() otherwise. |
3c4f71cc | 157 | |
23324ae1 FM |
158 | @remarks paths is emptied first. |
159 | */ | |
adaaa686 | 160 | virtual void GetPaths(wxArrayString& paths) const; |
23324ae1 FM |
161 | |
162 | /** | |
163 | Returns the current wildcard. | |
164 | */ | |
adaaa686 | 165 | virtual wxString GetWildcard() const; |
23324ae1 FM |
166 | |
167 | /** | |
168 | Sets(changes) the current directory displayed in the control. | |
3c4f71cc | 169 | |
d29a9a8a | 170 | @return Returns @true on success, @false otherwise. |
23324ae1 | 171 | */ |
adaaa686 | 172 | virtual bool SetDirectory(const wxString& directory); |
23324ae1 FM |
173 | |
174 | /** | |
175 | Selects a certain file. | |
3c4f71cc | 176 | |
d29a9a8a | 177 | @return Returns @true on success, @false otherwise |
23324ae1 | 178 | */ |
adaaa686 | 179 | virtual bool SetFilename(const wxString& filename); |
23324ae1 | 180 | |
34a9a352 RD |
181 | /** |
182 | Changes to a certain directory and selects a certain file. | |
183 | ||
184 | In case the filename specified isn't found/couldn't be shown with | |
185 | currently selected filter, false is returned. | |
186 | ||
187 | @return Returns @true on success, @false otherwise | |
188 | */ | |
189 | virtual bool SetPath(const wxString& path); | |
190 | ||
23324ae1 FM |
191 | /** |
192 | Sets the current filter index, starting from zero. | |
193 | */ | |
adaaa686 | 194 | virtual void SetFilterIndex(int filterIndex); |
23324ae1 FM |
195 | |
196 | /** | |
197 | Sets the wildcard, which can contain multiple file types, for example: | |
23324ae1 FM |
198 | "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif" |
199 | */ | |
adaaa686 | 200 | virtual void SetWildcard(const wxString& wildCard); |
23324ae1 FM |
201 | |
202 | /** | |
203 | Sets whether hidden files and folders are shown or not. | |
204 | */ | |
43c48e1e | 205 | virtual void ShowHidden(bool show); |
23324ae1 FM |
206 | }; |
207 | ||
208 | ||
34a9a352 RD |
209 | wxEventType wxEVT_FILECTRL_SELECTIONCHANGED; |
210 | wxEventType wxEVT_FILECTRL_FILEACTIVATED; | |
211 | wxEventType wxEVT_FILECTRL_FOLDERCHANGED; | |
212 | wxEventType wxEVT_FILECTRL_FILTERCHANGED; | |
213 | ||
e54c96f1 | 214 | |
23324ae1 FM |
215 | /** |
216 | @class wxFileCtrlEvent | |
7c913512 | 217 | |
23324ae1 FM |
218 | A file control event holds information about events associated with |
219 | wxFileCtrl objects. | |
7c913512 | 220 | |
0ce6d6c8 | 221 | @beginEventTable{wxFileCtrlEvent} |
8c6791e4 | 222 | @event{EVT_FILECTRL_FILEACTIVATED(id, func)} |
0ce6d6c8 | 223 | The user activated a file(by double-clicking or pressing Enter) |
8c6791e4 | 224 | @event{EVT_FILECTRL_SELECTIONCHANGED(id, func)} |
0ce6d6c8 | 225 | The user changed the current selection(by selecting or deselecting a file) |
8c6791e4 | 226 | @event{EVT_FILECTRL_FOLDERCHANGED(id, func)} |
0ce6d6c8 | 227 | The current folder of the file control has been changed |
6305f044 VZ |
228 | @event{EVT_FILECTRL_FILTERCHANGED(id, func)} |
229 | The current file filter of the file control has been changed | |
0ce6d6c8 FM |
230 | @endEventTable |
231 | ||
f00f01b3 | 232 | @library{wxcore} |
0ce6d6c8 | 233 | @category{events} |
23324ae1 FM |
234 | */ |
235 | class wxFileCtrlEvent : public wxCommandEvent | |
236 | { | |
237 | public: | |
238 | /** | |
239 | Constructor. | |
240 | */ | |
a44f3b5a | 241 | wxFileCtrlEvent(wxEventType type, wxObject *evtObject, int id); |
23324ae1 FM |
242 | |
243 | /** | |
244 | Returns the current directory. | |
0ce6d6c8 | 245 | |
23324ae1 FM |
246 | In case of a @b EVT_FILECTRL_FOLDERCHANGED, this method returns the new |
247 | directory. | |
248 | */ | |
328f5751 | 249 | wxString GetDirectory() const; |
23324ae1 FM |
250 | |
251 | /** | |
0ce6d6c8 | 252 | Returns the file selected (assuming it is only one file). |
23324ae1 | 253 | */ |
328f5751 | 254 | wxString GetFile() const; |
23324ae1 FM |
255 | |
256 | /** | |
257 | Returns the files selected. | |
0ce6d6c8 | 258 | |
23324ae1 FM |
259 | In case of a @b EVT_FILECTRL_SELECTIONCHANGED, this method returns the |
260 | files selected after the event. | |
261 | */ | |
328f5751 | 262 | wxArrayString GetFiles() const; |
23324ae1 | 263 | |
6305f044 VZ |
264 | /** |
265 | Returns the current file filter index. | |
266 | ||
267 | For a @b EVT_FILECTRL_FILTERCHANGED event, this method returns the new | |
268 | file filter index. | |
269 | ||
270 | @since 2.9.1 | |
271 | */ | |
272 | int GetFilterIndex() const; | |
273 | ||
23324ae1 FM |
274 | /** |
275 | Sets the files changed by this event. | |
276 | */ | |
43c48e1e | 277 | void SetFiles(const wxArrayString& files); |
0ce6d6c8 FM |
278 | |
279 | ||
280 | /** | |
281 | Sets the directory of this event. | |
282 | */ | |
283 | void SetDirectory( const wxString &directory ); | |
6305f044 VZ |
284 | |
285 | /** | |
286 | Sets the filter index changed by this event. | |
287 | ||
288 | @since 2.9.1 | |
289 | */ | |
290 | void SetFilterIndex(int index); | |
23324ae1 | 291 | }; |
e54c96f1 | 292 |