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