]>
Commit | Line | Data |
---|---|---|
51a58d8b | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/generic/dirctrlg.h |
51a58d8b JS |
3 | // Purpose: wxGenericDirCtrl class |
4 | // Builds on wxDirCtrl class written by Robert Roebling for the | |
5 | // wxFile application, modified by Harm van der Heijden. | |
6 | // Further modified for Windows. | |
748fcded | 7 | // Author: Robert Roebling, Harm van der Heijden, Julian Smart et al |
51a58d8b JS |
8 | // Modified by: |
9 | // Created: 21/3/2000 | |
10 | // RCS-ID: $Id$ | |
748fcded | 11 | // Copyright: (c) Robert Roebling, Harm van der Heijden, Julian Smart |
65571936 | 12 | // Licence: wxWindows licence |
51a58d8b JS |
13 | ///////////////////////////////////////////////////////////////////////////// |
14 | ||
15 | #ifndef _WX_DIRCTRL_H_ | |
16 | #define _WX_DIRCTRL_H_ | |
17 | ||
1e6feb95 VZ |
18 | #if wxUSE_DIRDLG |
19 | ||
51a58d8b | 20 | #include "wx/treectrl.h" |
748fcded | 21 | #include "wx/dialog.h" |
3509d340 VS |
22 | #include "wx/dirdlg.h" |
23 | #include "wx/choice.h" | |
51a58d8b JS |
24 | |
25 | //----------------------------------------------------------------------------- | |
26 | // classes | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
b5dbe15d | 29 | class WXDLLIMPEXP_FWD_CORE wxTextCtrl; |
b5dbe15d | 30 | class WXDLLIMPEXP_FWD_BASE wxHashTable; |
748fcded | 31 | |
51a58d8b JS |
32 | //----------------------------------------------------------------------------- |
33 | // Extra styles for wxGenericDirCtrl | |
34 | //----------------------------------------------------------------------------- | |
35 | ||
748fcded VS |
36 | enum |
37 | { | |
38 | // Only allow directory viewing/selection, no files | |
39 | wxDIRCTRL_DIR_ONLY = 0x0010, | |
40 | // When setting the default path, select the first file in the directory | |
41 | wxDIRCTRL_SELECT_FIRST = 0x0020, | |
aa9453d6 | 42 | // Show the filter list |
748fcded VS |
43 | wxDIRCTRL_SHOW_FILTERS = 0x0040, |
44 | // Use 3D borders on internal controls | |
fd775aae JS |
45 | wxDIRCTRL_3D_INTERNAL = 0x0080, |
46 | // Editable labels | |
80f624ec VZ |
47 | wxDIRCTRL_EDIT_LABELS = 0x0100, |
48 | // Allow multiple selection | |
49 | wxDIRCTRL_MULTIPLE = 0x0200 | |
748fcded | 50 | }; |
51a58d8b JS |
51 | |
52 | //----------------------------------------------------------------------------- | |
53 | // wxDirItemData | |
54 | //----------------------------------------------------------------------------- | |
55 | ||
53a2db12 | 56 | class WXDLLIMPEXP_CORE wxDirItemData : public wxTreeItemData |
51a58d8b JS |
57 | { |
58 | public: | |
748fcded | 59 | wxDirItemData(const wxString& path, const wxString& name, bool isDir); |
d3c7fc99 | 60 | virtual ~wxDirItemData(){} |
748fcded VS |
61 | void SetNewDirName(const wxString& path); |
62 | ||
63 | bool HasSubDirs() const; | |
64 | bool HasFiles(const wxString& spec = wxEmptyString) const; | |
65 | ||
66 | wxString m_path, m_name; | |
67 | bool m_isHidden; | |
68 | bool m_isExpanded; | |
69 | bool m_isDir; | |
51a58d8b JS |
70 | }; |
71 | ||
72 | //----------------------------------------------------------------------------- | |
73 | // wxDirCtrl | |
74 | //----------------------------------------------------------------------------- | |
75 | ||
b5dbe15d | 76 | class WXDLLIMPEXP_FWD_CORE wxDirFilterListCtrl; |
51a58d8b | 77 | |
53a2db12 | 78 | class WXDLLIMPEXP_CORE wxGenericDirCtrl: public wxControl |
51a58d8b JS |
79 | { |
80 | public: | |
81 | wxGenericDirCtrl(); | |
ca65c044 | 82 | wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = wxID_ANY, |
51a58d8b JS |
83 | const wxString &dir = wxDirDialogDefaultFolderStr, |
84 | const wxPoint& pos = wxDefaultPosition, | |
85 | const wxSize& size = wxDefaultSize, | |
e5048854 | 86 | long style = wxDIRCTRL_3D_INTERNAL, |
51a58d8b JS |
87 | const wxString& filter = wxEmptyString, |
88 | int defaultFilter = 0, | |
89 | const wxString& name = wxTreeCtrlNameStr ) | |
90 | { | |
91 | Init(); | |
92 | Create(parent, id, dir, pos, size, style, filter, defaultFilter, name); | |
93 | } | |
ca65c044 WS |
94 | |
95 | bool Create(wxWindow *parent, const wxWindowID id = wxID_ANY, | |
51a58d8b JS |
96 | const wxString &dir = wxDirDialogDefaultFolderStr, |
97 | const wxPoint& pos = wxDefaultPosition, | |
98 | const wxSize& size = wxDefaultSize, | |
e5048854 | 99 | long style = wxDIRCTRL_3D_INTERNAL, |
51a58d8b JS |
100 | const wxString& filter = wxEmptyString, |
101 | int defaultFilter = 0, | |
102 | const wxString& name = wxTreeCtrlNameStr ); | |
103 | ||
2b5f62a0 | 104 | virtual void Init(); |
51a58d8b | 105 | |
2b5f62a0 | 106 | virtual ~wxGenericDirCtrl(); |
51a58d8b JS |
107 | |
108 | void OnExpandItem(wxTreeEvent &event ); | |
109 | void OnCollapseItem(wxTreeEvent &event ); | |
110 | void OnBeginEditItem(wxTreeEvent &event ); | |
111 | void OnEndEditItem(wxTreeEvent &event ); | |
84605707 | 112 | void OnTreeSelChange(wxTreeEvent &event); |
4d623b67 | 113 | void OnItemActivated(wxTreeEvent &event); |
51a58d8b JS |
114 | void OnSize(wxSizeEvent &event ); |
115 | ||
116 | // Try to expand as much of the given path as possible. | |
2b5f62a0 | 117 | virtual bool ExpandPath(const wxString& path); |
f395a825 VZ |
118 | // collapse the path |
119 | virtual bool CollapsePath(const wxString& path); | |
51a58d8b JS |
120 | |
121 | // Accessors | |
122 | ||
2b5f62a0 VZ |
123 | virtual inline wxString GetDefaultPath() const { return m_defaultPath; } |
124 | virtual void SetDefaultPath(const wxString& path) { m_defaultPath = path; } | |
51a58d8b | 125 | |
51a58d8b | 126 | // Get dir or filename |
2b5f62a0 | 127 | virtual wxString GetPath() const; |
80f624ec | 128 | virtual void GetPaths(wxArrayString& paths) const; |
ca65c044 | 129 | |
51a58d8b JS |
130 | // Get selected filename path only (else empty string). |
131 | // I.e. don't count a directory as a selection | |
2b5f62a0 | 132 | virtual wxString GetFilePath() const; |
80f624ec | 133 | virtual void GetFilePaths(wxArrayString& paths) const; |
2b5f62a0 | 134 | virtual void SetPath(const wxString& path); |
ca65c044 | 135 | |
80f624ec VZ |
136 | virtual void SelectPath(const wxString& path, bool select = true); |
137 | virtual void SelectPaths(const wxArrayString& paths); | |
138 | ||
2b5f62a0 VZ |
139 | virtual void ShowHidden( bool show ); |
140 | virtual bool GetShowHidden() { return m_showHidden; } | |
51a58d8b | 141 | |
2b5f62a0 VZ |
142 | virtual wxString GetFilter() const { return m_filter; } |
143 | virtual void SetFilter(const wxString& filter); | |
51a58d8b | 144 | |
2b5f62a0 VZ |
145 | virtual int GetFilterIndex() const { return m_currentFilter; } |
146 | virtual void SetFilterIndex(int n); | |
51a58d8b | 147 | |
2b5f62a0 | 148 | virtual wxTreeItemId GetRootId() { return m_rootId; } |
51a58d8b | 149 | |
2b5f62a0 VZ |
150 | virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; } |
151 | virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; } | |
51a58d8b | 152 | |
80f624ec VZ |
153 | virtual void UnselectAll(); |
154 | ||
42dcacf0 | 155 | // Helper |
2b5f62a0 | 156 | virtual void SetupSections(); |
ca65c044 | 157 | |
51a58d8b JS |
158 | // Find the child that matches the first part of 'path'. |
159 | // E.g. if a child path is "/usr" and 'path' is "/usr/include" | |
160 | // then the child for /usr is returned. | |
ca65c044 | 161 | // If the path string has been used (we're at the leaf), done is set to true |
2b5f62a0 | 162 | virtual wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done); |
ca65c044 | 163 | |
e3f084fd VZ |
164 | wxString GetPath(wxTreeItemId itemId) const; |
165 | ||
51a58d8b | 166 | // Resize the components of the control |
2b5f62a0 | 167 | virtual void DoResize(); |
ca65c044 | 168 | |
08887820 | 169 | // Collapse & expand the tree, thus re-creating it from scratch: |
2b5f62a0 | 170 | virtual void ReCreateTree(); |
ca65c044 | 171 | |
c06dde42 JS |
172 | // Collapse the entire tree |
173 | virtual void CollapseTree(); | |
174 | ||
905e0905 VZ |
175 | // overridden base class methods |
176 | virtual void SetFocus(); | |
177 | ||
51a58d8b | 178 | protected: |
c06dde42 | 179 | virtual void ExpandRoot(); |
22328fa4 JS |
180 | virtual void ExpandDir(wxTreeItemId parentId); |
181 | virtual void CollapseDir(wxTreeItemId parentId); | |
182 | virtual const wxTreeItemId AddSection(const wxString& path, const wxString& name, int imageId = 0); | |
183 | virtual wxTreeItemId AppendItem (const wxTreeItemId & parent, | |
184 | const wxString & text, | |
185 | int image = -1, int selectedImage = -1, | |
186 | wxTreeItemData * data = NULL); | |
51a58d8b | 187 | //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames); |
a78955e3 | 188 | virtual wxTreeCtrl* CreateTreeCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long treeStyle); |
51a58d8b JS |
189 | |
190 | // Extract description and actual filter from overall filter string | |
191 | bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description); | |
192 | ||
193 | private: | |
ef57807f | 194 | void PopulateNode(wxTreeItemId node); |
0d6f66f4 | 195 | wxDirItemData* GetItemData(wxTreeItemId itemId); |
ef57807f | 196 | |
51a58d8b JS |
197 | bool m_showHidden; |
198 | wxTreeItemId m_rootId; | |
51a58d8b JS |
199 | wxString m_defaultPath; // Starting path |
200 | long m_styleEx; // Extended style | |
201 | wxString m_filter; // Wildcards in same format as per wxFileDialog | |
202 | int m_currentFilter; // The current filter index | |
203 | wxString m_currentFilterStr; // Current filter string | |
204 | wxTreeCtrl* m_treeCtrl; | |
205 | wxDirFilterListCtrl* m_filterListCtrl; | |
206 | ||
207 | private: | |
208 | DECLARE_EVENT_TABLE() | |
209 | DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl) | |
c0c133e1 | 210 | wxDECLARE_NO_COPY_CLASS(wxGenericDirCtrl); |
51a58d8b JS |
211 | }; |
212 | ||
40c7c7f4 | 213 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIRCTRL_SELECTIONCHANGED, wxTreeEvent ); |
4d623b67 | 214 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIRCTRL_FILEACTIVATED, wxTreeEvent ); |
84605707 | 215 | |
40c7c7f4 VZ |
216 | #define wx__DECLARE_DIRCTRL_EVT(evt, id, fn) \ |
217 | wx__DECLARE_EVT1(wxEVT_DIRCTRL_ ## evt, id, wxTreeEventHandler(fn)) | |
218 | ||
219 | #define EVT_DIRCTRL_SELECTIONCHANGED(id, fn) wx__DECLARE_DIRCTRL_EVT(SELECTIONCHANGED, id, fn) | |
4d623b67 | 220 | #define EVT_DIRCTRL_FILEACTIVATED(id, fn) wx__DECLARE_DIRCTRL_EVT(FILEACTIVATED, id, fn) |
84605707 | 221 | |
51a58d8b JS |
222 | //----------------------------------------------------------------------------- |
223 | // wxDirFilterListCtrl | |
224 | //----------------------------------------------------------------------------- | |
225 | ||
53a2db12 | 226 | class WXDLLIMPEXP_CORE wxDirFilterListCtrl: public wxChoice |
51a58d8b JS |
227 | { |
228 | public: | |
229 | wxDirFilterListCtrl() { Init(); } | |
ca65c044 | 230 | wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY, |
51a58d8b JS |
231 | const wxPoint& pos = wxDefaultPosition, |
232 | const wxSize& size = wxDefaultSize, | |
233 | long style = 0) | |
234 | { | |
235 | Init(); | |
236 | Create(parent, id, pos, size, style); | |
237 | } | |
ca65c044 WS |
238 | |
239 | bool Create(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY, | |
51a58d8b JS |
240 | const wxPoint& pos = wxDefaultPosition, |
241 | const wxSize& size = wxDefaultSize, | |
242 | long style = 0); | |
243 | ||
244 | void Init(); | |
245 | ||
d3c7fc99 | 246 | virtual ~wxDirFilterListCtrl() {} |
51a58d8b | 247 | |
748fcded | 248 | //// Operations |
51a58d8b JS |
249 | void FillFilterList(const wxString& filter, int defaultFilter); |
250 | ||
748fcded | 251 | //// Events |
51a58d8b JS |
252 | void OnSelFilter(wxCommandEvent& event); |
253 | ||
254 | protected: | |
255 | wxGenericDirCtrl* m_dirCtrl; | |
256 | ||
257 | DECLARE_EVENT_TABLE() | |
258 | DECLARE_CLASS(wxDirFilterListCtrl) | |
c0c133e1 | 259 | wxDECLARE_NO_COPY_CLASS(wxDirFilterListCtrl); |
51a58d8b JS |
260 | }; |
261 | ||
748fcded VS |
262 | #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__) |
263 | #define wxDirCtrl wxGenericDirCtrl | |
264 | #endif | |
51a58d8b | 265 | |
a977709b JS |
266 | // Symbols for accessing individual controls |
267 | #define wxID_TREECTRL 7000 | |
268 | #define wxID_FILTERLISTCTRL 7001 | |
269 | ||
13de0c8c WS |
270 | #endif // wxUSE_DIRDLG |
271 | ||
06cc1fb9 JS |
272 | //------------------------------------------------------------------------- |
273 | // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary | |
274 | //------------------------------------------------------------------------- | |
275 | ||
ad09ec03 VZ |
276 | #if wxUSE_DIRDLG || wxUSE_FILEDLG || wxUSE_FILECTRL |
277 | ||
278 | class WXDLLIMPEXP_FWD_CORE wxImageList; | |
13de0c8c | 279 | |
53a2db12 | 280 | class WXDLLIMPEXP_CORE wxFileIconsTable |
06cc1fb9 JS |
281 | { |
282 | public: | |
283 | wxFileIconsTable(); | |
284 | ~wxFileIconsTable(); | |
285 | ||
286 | enum iconId_Type | |
287 | { | |
288 | folder, | |
289 | folder_open, | |
290 | computer, | |
291 | drive, | |
292 | cdrom, | |
293 | floppy, | |
294 | removeable, | |
295 | file, | |
296 | executable | |
297 | }; | |
298 | ||
299 | int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString); | |
300 | wxImageList *GetSmallImageList(); | |
301 | ||
302 | protected: | |
303 | void Create(); // create on first use | |
304 | ||
305 | wxImageList *m_smallImageList; | |
306 | wxHashTable *m_HashTable; | |
307 | }; | |
308 | ||
309 | // The global fileicons table | |
53a2db12 | 310 | extern WXDLLIMPEXP_DATA_CORE(wxFileIconsTable *) wxTheFileIconsTable; |
06cc1fb9 | 311 | |
ad09ec03 | 312 | #endif // wxUSE_DIRDLG || wxUSE_FILEDLG || wxUSE_FILECTRL |
1e6feb95 | 313 | |
ce7fe42e | 314 | // old wxEVT_COMMAND_* constants |
40c7c7f4 | 315 | #define wxEVT_COMMAND_DIRCTRL_SELECTIONCHANGED wxEVT_DIRCTRL_SELECTIONCHANGED |
4d623b67 | 316 | #define wxEVT_COMMAND_DIRCTRL_FILEACTIVATED wxEVT_DIRCTRL_FILEACTIVATED |
ce7fe42e | 317 | |
51a58d8b JS |
318 | #endif |
319 | // _WX_DIRCTRLG_H_ |