1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxGenericDirCtrl
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
10 // Only allow directory viewing/selection, no files
11 wxDIRCTRL_DIR_ONLY
= 0x0010,
12 // When setting the default path, select the first file in the directory
13 wxDIRCTRL_SELECT_FIRST
= 0x0020,
14 // Show the filter list
15 wxDIRCTRL_SHOW_FILTERS
= 0x0040,
16 // Use 3D borders on internal controls
17 wxDIRCTRL_3D_INTERNAL
= 0x0080,
19 wxDIRCTRL_EDIT_LABELS
= 0x0100,
20 // Allow multiple selection
21 wxDIRCTRL_MULTIPLE
= 0x0200
26 @class wxGenericDirCtrl
28 This control can be used to place a directory listing (with optional
29 files) on an arbitrary window.
31 The control contains a wxTreeCtrl window representing the directory
32 hierarchy, and optionally, a wxChoice window containing a list of filters.
35 @style{wxDIRCTRL_DIR_ONLY}
36 Only show directories, and not files.
37 @style{wxDIRCTRL_3D_INTERNAL}
38 Use 3D borders for internal controls.
39 @style{wxDIRCTRL_SELECT_FIRST}
40 When setting the default path, select the first file in the
42 @style{wxDIRCTRL_SHOW_FILTERS}
43 Show the drop-down filter list.
44 @style{wxDIRCTRL_EDIT_LABELS}
45 Allow the folder and file labels to be editable.
46 @style{wxDIRCTRL_MULTIPLE}
47 Allows multiple files and folders to be selected.
52 @appearance{genericdirctrl}
54 @beginEventEmissionTable
55 @event{EVT_DIRCTRL_SELECTIONCHANGED(id, func)}
56 Selected directory has changed.
57 Processes a @c wxEVT_DIRCTRL_SELECTIONCHANGED event type.
58 Notice that this event is generated even for the changes done by the
59 program itself and not only those done by the user.
60 Available since wxWidgets 2.9.5.
61 @event{EVT_DIRCTRL_FILEACTIVATED(id, func)}
62 The user activated a file by double-clicking or pressing Enter.
63 Available since wxWidgets 2.9.5.
66 class wxGenericDirCtrl
: public wxControl
88 Window style. Please see wxGenericDirCtrl for a list of possible
91 A filter string, using the same syntax as that for wxFileDialog.
92 This may be empty if filters are not being used. Example:
93 @c "All files (*.*)|*.*|JPEG files (*.jpg)|*.jpg"
95 The zero-indexed default filter setting.
99 wxGenericDirCtrl(wxWindow
* parent
, const wxWindowID id
= wxID_ANY
,
100 const wxString
& dir
= wxDirDialogDefaultFolderStr
,
101 const wxPoint
& pos
= wxDefaultPosition
,
102 const wxSize
& size
= wxDefaultSize
,
103 long style
= wxDIRCTRL_3D_INTERNAL
,
104 const wxString
& filter
= wxEmptyString
,
105 int defaultFilter
= 0,
106 const wxString
& name
= wxTreeCtrlNameStr
);
111 virtual ~wxGenericDirCtrl();
114 Collapse the given @a path.
116 virtual bool CollapsePath(const wxString
& path
);
119 Collapses the entire tree.
121 virtual void CollapseTree();
124 Create function for two-step construction. See wxGenericDirCtrl() for
127 bool Create(wxWindow
* parent
, const wxWindowID id
= wxID_ANY
,
128 const wxString
& dir
= wxDirDialogDefaultFolderStr
,
129 const wxPoint
& pos
= wxDefaultPosition
,
130 const wxSize
& size
= wxDefaultSize
,
131 long style
= wxDIRCTRL_3D_INTERNAL
,
132 const wxString
& filter
= wxEmptyString
, int defaultFilter
= 0,
133 const wxString
& name
= wxTreeCtrlNameStr
);
136 Tries to expand as much of the given @a path as possible, so that the
137 filename or directory is visible in the tree control.
139 virtual bool ExpandPath(const wxString
& path
);
142 Gets the default path.
144 virtual wxString
GetDefaultPath() const;
147 Gets selected filename path only (else empty string).
149 This function doesn't count a directory as a selection.
151 virtual wxString
GetFilePath() const;
154 Fills the array @a paths with the currently selected filepaths.
156 This function doesn't count a directory as a selection.
158 virtual void GetFilePaths(wxArrayString
& paths
) const;
161 Returns the filter string.
163 virtual wxString
GetFilter() const;
166 Returns the current filter index (zero-based).
168 virtual int GetFilterIndex() const;
171 Returns a pointer to the filter list control (if present).
173 virtual wxDirFilterListCtrl
* GetFilterListCtrl() const;
176 Gets the currently-selected directory or filename.
178 virtual wxString
GetPath() const;
181 Gets the path corresponding to the given tree control item.
185 wxString
GetPath(wxTreeItemId itemId
) const;
188 Fills the array @a paths with the selected directories and filenames.
190 virtual void GetPaths(wxArrayString
& paths
) const;
193 Returns the root id for the tree control.
195 virtual wxTreeItemId
GetRootId();
198 Returns a pointer to the tree control.
200 virtual wxTreeCtrl
* GetTreeCtrl() const;
203 Initializes variables.
208 Collapse and expand the tree, thus re-creating it from scratch. May be
209 used to update the displayed directory content.
211 virtual void ReCreateTree();
214 Sets the default path.
216 virtual void SetDefaultPath(const wxString
& path
);
219 Sets the filter string.
221 virtual void SetFilter(const wxString
& filter
);
224 Sets the current filter index (zero-based).
226 virtual void SetFilterIndex(int n
);
229 Sets the current path.
231 virtual void SetPath(const wxString
& path
);
235 If @true, hidden folders and files will be displayed by the
236 control. If @false, they will not be displayed.
238 virtual void ShowHidden(bool show
);
241 Selects the given item.
243 In multiple selection controls, can be also used to deselect a
244 currently selected item if the value of @a select is false.
245 Existing selections are not changed. Only visible items can be
246 (de)selected, otherwise use ExpandPath().
248 virtual void SelectPath(const wxString
& path
, bool select
= true);
251 Selects only the specified paths, clearing any previous selection.
253 Only supported when wxDIRCTRL_MULTIPLE is set.
255 virtual void SelectPaths(const wxArrayString
& paths
);
258 Removes the selection from all currently selected items.
260 virtual void UnselectAll();
265 class wxDirFilterListCtrl
: public wxChoice
268 wxDirFilterListCtrl();
269 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
270 const wxPoint
& pos
= wxDefaultPosition
,
271 const wxSize
& size
= wxDefaultSize
,
273 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
274 const wxPoint
& pos
= wxDefaultPosition
,
275 const wxSize
& size
= wxDefaultSize
,
278 virtual ~wxDirFilterListCtrl() {}
283 void FillFilterList(const wxString
& filter
, int defaultFilter
);
286 wxEventType wxEVT_DIRCTRL_SELECTIONCHANGED
;
287 wxEventType wxEVT_DIRCTRL_FILEACTIVATED
;