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}
53 @event{EVT_DIRCTRL_SELECTIONCHANGED(id, func)}
54 Selected directory has changed.
55 Processes a @c wxEVT_DIRCTRL_SELECTIONCHANGED event type.
56 Notice that this event is generated even for the changes done by the
57 program itself and not only those done by the user.
59 @event{EVT_DIRCTRL_FILEACTIVATED(id, func)}
60 The user activated a file by double-clicking or pressing Enter.
63 class wxGenericDirCtrl
: public wxControl
85 Window style. Please see wxGenericDirCtrl for a list of possible
88 A filter string, using the same syntax as that for wxFileDialog.
89 This may be empty if filters are not being used. Example:
90 @c "All files (*.*)|*.*|JPEG files (*.jpg)|*.jpg"
92 The zero-indexed default filter setting.
96 wxGenericDirCtrl(wxWindow
* parent
, const wxWindowID id
= wxID_ANY
,
97 const wxString
& dir
= wxDirDialogDefaultFolderStr
,
98 const wxPoint
& pos
= wxDefaultPosition
,
99 const wxSize
& size
= wxDefaultSize
,
100 long style
= wxDIRCTRL_3D_INTERNAL
,
101 const wxString
& filter
= wxEmptyString
,
102 int defaultFilter
= 0,
103 const wxString
& name
= wxTreeCtrlNameStr
);
108 virtual ~wxGenericDirCtrl();
111 Collapse the given @a path.
113 virtual bool CollapsePath(const wxString
& path
);
116 Collapses the entire tree.
118 virtual void CollapseTree();
121 Create function for two-step construction. See wxGenericDirCtrl() for
124 bool Create(wxWindow
* parent
, const wxWindowID id
= wxID_ANY
,
125 const wxString
& dir
= wxDirDialogDefaultFolderStr
,
126 const wxPoint
& pos
= wxDefaultPosition
,
127 const wxSize
& size
= wxDefaultSize
,
128 long style
= wxDIRCTRL_3D_INTERNAL
,
129 const wxString
& filter
= wxEmptyString
, int defaultFilter
= 0,
130 const wxString
& name
= wxTreeCtrlNameStr
);
133 Tries to expand as much of the given @a path as possible, so that the
134 filename or directory is visible in the tree control.
136 virtual bool ExpandPath(const wxString
& path
);
139 Gets the default path.
141 virtual wxString
GetDefaultPath() const;
144 Gets selected filename path only (else empty string).
146 This function doesn't count a directory as a selection.
148 virtual wxString
GetFilePath() const;
151 Fills the array @a paths with the currently selected filepaths.
153 This function doesn't count a directory as a selection.
155 virtual void GetFilePaths(wxArrayString
& paths
) const;
158 Returns the filter string.
160 virtual wxString
GetFilter() const;
163 Returns the current filter index (zero-based).
165 virtual int GetFilterIndex() const;
168 Returns a pointer to the filter list control (if present).
170 virtual wxDirFilterListCtrl
* GetFilterListCtrl() const;
173 Gets the currently-selected directory or filename.
175 virtual wxString
GetPath() const;
178 Gets the path corresponding to the given tree control item.
182 wxString
GetPath(wxTreeItemId itemId
) const;
185 Fills the array @a paths with the selected directories and filenames.
187 virtual void GetPaths(wxArrayString
& paths
) const;
190 Returns the root id for the tree control.
192 virtual wxTreeItemId
GetRootId();
195 Returns a pointer to the tree control.
197 virtual wxTreeCtrl
* GetTreeCtrl() const;
200 Initializes variables.
205 Collapse and expand the tree, thus re-creating it from scratch. May be
206 used to update the displayed directory content.
208 virtual void ReCreateTree();
211 Sets the default path.
213 virtual void SetDefaultPath(const wxString
& path
);
216 Sets the filter string.
218 virtual void SetFilter(const wxString
& filter
);
221 Sets the current filter index (zero-based).
223 virtual void SetFilterIndex(int n
);
226 Sets the current path.
228 virtual void SetPath(const wxString
& path
);
232 If @true, hidden folders and files will be displayed by the
233 control. If @false, they will not be displayed.
235 virtual void ShowHidden(bool show
);
238 Selects the given item.
240 In multiple selection controls, can be also used to deselect a
241 currently selected item if the value of @a select is false.
242 Existing selections are not changed. Only visible items can be
243 (de)selected, otherwise use ExpandPath().
245 virtual void SelectPath(const wxString
& path
, bool select
= true);
248 Selects only the specified paths, clearing any previous selection.
250 Only supported when wxDIRCTRL_MULTIPLE is set.
252 virtual void SelectPaths(const wxArrayString
& paths
);
255 Removes the selection from all currently selected items.
257 virtual void UnselectAll();
262 class wxDirFilterListCtrl
: public wxChoice
265 wxDirFilterListCtrl();
266 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
267 const wxPoint
& pos
= wxDefaultPosition
,
268 const wxSize
& size
= wxDefaultSize
,
270 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
271 const wxPoint
& pos
= wxDefaultPosition
,
272 const wxSize
& size
= wxDefaultSize
,
275 virtual ~wxDirFilterListCtrl() {}
280 void FillFilterList(const wxString
& filter
, int defaultFilter
);
283 wxEventType wxEVT_DIRCTRL_SELECTIONCHANGED
;
284 wxEventType wxEVT_DIRCTRL_FILEACTIVATED
;