Add wxDirCtrl::GetPath().
[wxWidgets.git] / interface / wx / dirctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dirctrl.h
3 // Purpose: interface of wxGenericDirCtrl
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 enum
10 {
11 // Only allow directory viewing/selection, no files
12 wxDIRCTRL_DIR_ONLY = 0x0010,
13 // When setting the default path, select the first file in the directory
14 wxDIRCTRL_SELECT_FIRST = 0x0020,
15 // Use 3D borders on internal controls
16 wxDIRCTRL_3D_INTERNAL = 0x0080,
17 // Editable labels
18 wxDIRCTRL_EDIT_LABELS = 0x0100,
19 // Allow multiple selection
20 wxDIRCTRL_MULTIPLE = 0x0200
21 };
22
23
24 /**
25 @class wxGenericDirCtrl
26
27 This control can be used to place a directory listing (with optional
28 files) on an arbitrary window.
29
30 The control contains a wxTreeCtrl window representing the directory
31 hierarchy, and optionally, a wxChoice window containing a list of filters.
32
33 @beginStyleTable
34 @style{wxDIRCTRL_DIR_ONLY}
35 Only show directories, and not files.
36 @style{wxDIRCTRL_3D_INTERNAL}
37 Use 3D borders for internal controls.
38 @style{wxDIRCTRL_SELECT_FIRST}
39 When setting the default path, select the first file in the
40 directory.
41 @style{wxDIRCTRL_EDIT_LABELS}
42 Allow the folder and file labels to be editable.
43 @style{wxDIRCTRL_MULTIPLE}
44 Allows multiple files and folders to be selected.
45 @endStyleTable
46
47 @library{wxcore}
48 @category{ctrl}
49 @appearance{genericdirctrl.png}
50 */
51 class wxGenericDirCtrl : public wxControl
52 {
53 public:
54 /**
55 Default constructor.
56 */
57 wxGenericDirCtrl();
58
59 /**
60 Main constructor.
61
62 @param parent
63 Parent window.
64 @param id
65 Window identifier.
66 @param dir
67 Initial folder.
68 @param pos
69 Position.
70 @param size
71 Size.
72 @param style
73 Window style. Please see wxGenericDirCtrl for a list of possible
74 styles.
75 @param filter
76 A filter string, using the same syntax as that for wxFileDialog.
77 This may be empty if filters are not being used. Example:
78 @c "All files (*.*)|*.*|JPEG files (*.jpg)|*.jpg"
79 @param defaultFilter
80 The zero-indexed default filter setting.
81 @param name
82 The window name.
83 */
84 wxGenericDirCtrl(wxWindow* parent, const wxWindowID id = wxID_ANY,
85 const wxString& dir = wxDirDialogDefaultFolderStr,
86 const wxPoint& pos = wxDefaultPosition,
87 const wxSize& size = wxDefaultSize,
88 long style = wxDIRCTRL_3D_INTERNAL,
89 const wxString& filter = wxEmptyString,
90 int defaultFilter = 0,
91 const wxString& name = wxTreeCtrlNameStr);
92
93 /**
94 Destructor.
95 */
96 virtual ~wxGenericDirCtrl();
97
98 /**
99 Collapse the given @a path.
100 */
101 virtual bool CollapsePath(const wxString& path);
102
103 /**
104 Collapses the entire tree.
105 */
106 virtual void CollapseTree();
107
108 /**
109 Create function for two-step construction. See wxGenericDirCtrl() for
110 details.
111 */
112 bool Create(wxWindow* parent, const wxWindowID id = wxID_ANY,
113 const wxString& dir = wxDirDialogDefaultFolderStr,
114 const wxPoint& pos = wxDefaultPosition,
115 const wxSize& size = wxDefaultSize,
116 long style = wxDIRCTRL_3D_INTERNAL,
117 const wxString& filter = wxEmptyString, int defaultFilter = 0,
118 const wxString& name = wxTreeCtrlNameStr);
119
120 /**
121 Tries to expand as much of the given @a path as possible, so that the
122 filename or directory is visible in the tree control.
123 */
124 virtual bool ExpandPath(const wxString& path);
125
126 /**
127 Gets the default path.
128 */
129 virtual wxString GetDefaultPath() const;
130
131 /**
132 Gets selected filename path only (else empty string).
133
134 This function doesn't count a directory as a selection.
135 */
136 virtual wxString GetFilePath() const;
137
138 /**
139 Fills the array @a paths with the currently selected filepaths.
140
141 This function doesn't count a directory as a selection.
142 */
143 virtual void GetFilePaths(wxArrayString& paths) const;
144
145 /**
146 Returns the filter string.
147 */
148 virtual wxString GetFilter() const;
149
150 /**
151 Returns the current filter index (zero-based).
152 */
153 virtual int GetFilterIndex() const;
154
155 /**
156 Returns a pointer to the filter list control (if present).
157 */
158 virtual wxDirFilterListCtrl* GetFilterListCtrl() const;
159
160 /**
161 Gets the currently-selected directory or filename.
162 */
163 virtual wxString GetPath() const;
164
165 /**
166 Gets the path corresponding to the given tree control item.
167
168 @since 2.9.5
169 */
170 wxString GetPath(wxTreeItemId itemId) const;
171
172 /**
173 Fills the array @a paths with the selected directories and filenames.
174 */
175 virtual void GetPaths(wxArrayString& paths) const;
176
177 /**
178 Returns the root id for the tree control.
179 */
180 virtual wxTreeItemId GetRootId();
181
182 /**
183 Returns a pointer to the tree control.
184 */
185 virtual wxTreeCtrl* GetTreeCtrl() const;
186
187 /**
188 Initializes variables.
189 */
190 virtual void Init();
191
192 /**
193 Collapse and expand the tree, thus re-creating it from scratch. May be
194 used to update the displayed directory content.
195 */
196 virtual void ReCreateTree();
197
198 /**
199 Sets the default path.
200 */
201 virtual void SetDefaultPath(const wxString& path);
202
203 /**
204 Sets the filter string.
205 */
206 virtual void SetFilter(const wxString& filter);
207
208 /**
209 Sets the current filter index (zero-based).
210 */
211 virtual void SetFilterIndex(int n);
212
213 /**
214 Sets the current path.
215 */
216 virtual void SetPath(const wxString& path);
217
218 /**
219 @param show
220 If @true, hidden folders and files will be displayed by the
221 control. If @false, they will not be displayed.
222 */
223 virtual void ShowHidden(bool show);
224
225 /**
226 Selects the given item.
227
228 In multiple selection controls, can be also used to deselect a
229 currently selected item if the value of @a select is false.
230 Existing selections are not changed. Only visible items can be
231 (de)selected, otherwise use ExpandPath().
232 */
233 virtual void SelectPath(const wxString& path, bool select = true);
234
235 /**
236 Selects only the specified paths, clearing any previous selection.
237
238 Only supported when wxDIRCTRL_MULTIPLE is set.
239 */
240 virtual void SelectPaths(const wxArrayString& paths);
241
242 /**
243 Removes the selection from all currently selected items.
244 */
245 virtual void UnselectAll();
246 };
247
248
249
250 class wxDirFilterListCtrl: public wxChoice
251 {
252 public:
253 wxDirFilterListCtrl();
254 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
255 const wxPoint& pos = wxDefaultPosition,
256 const wxSize& size = wxDefaultSize,
257 long style = 0);
258 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
259 const wxPoint& pos = wxDefaultPosition,
260 const wxSize& size = wxDefaultSize,
261 long style = 0);
262
263 virtual ~wxDirFilterListCtrl() {}
264
265 void Init();
266
267 //// Operations
268 void FillFilterList(const wxString& filter, int defaultFilter);
269 };