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