]>
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 | ||
62a9d04c VS |
33 | class WXDLLIMPEXP_CORE wxTextCtrl; |
34 | class WXDLLIMPEXP_CORE wxImageList; | |
35 | class WXDLLIMPEXP_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, | |
47 | // Show the filter list | |
48 | wxDIRCTRL_SHOW_FILTERS = 0x0040, | |
49 | // Use 3D borders on internal controls | |
fd775aae JS |
50 | wxDIRCTRL_3D_INTERNAL = 0x0080, |
51 | // Editable labels | |
dabd1377 | 52 | wxDIRCTRL_EDIT_LABELS = 0x0100 |
748fcded | 53 | }; |
51a58d8b JS |
54 | |
55 | //----------------------------------------------------------------------------- | |
56 | // wxDirItemData | |
57 | //----------------------------------------------------------------------------- | |
58 | ||
748fcded | 59 | class WXDLLEXPORT wxDirItemData : public wxTreeItemData |
51a58d8b JS |
60 | { |
61 | public: | |
748fcded | 62 | wxDirItemData(const wxString& path, const wxString& name, bool isDir); |
d3c7fc99 | 63 | virtual ~wxDirItemData(){} |
748fcded VS |
64 | void SetNewDirName(const wxString& path); |
65 | ||
66 | bool HasSubDirs() const; | |
67 | bool HasFiles(const wxString& spec = wxEmptyString) const; | |
68 | ||
69 | wxString m_path, m_name; | |
70 | bool m_isHidden; | |
71 | bool m_isExpanded; | |
72 | bool m_isDir; | |
51a58d8b JS |
73 | }; |
74 | ||
75 | //----------------------------------------------------------------------------- | |
76 | // wxDirCtrl | |
77 | //----------------------------------------------------------------------------- | |
78 | ||
79 | class WXDLLEXPORT wxDirFilterListCtrl; | |
80 | ||
81 | class WXDLLEXPORT wxGenericDirCtrl: public wxControl | |
82 | { | |
83 | public: | |
84 | wxGenericDirCtrl(); | |
ca65c044 | 85 | wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = wxID_ANY, |
51a58d8b JS |
86 | const wxString &dir = wxDirDialogDefaultFolderStr, |
87 | const wxPoint& pos = wxDefaultPosition, | |
88 | const wxSize& size = wxDefaultSize, | |
f9c165b1 | 89 | long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, |
51a58d8b JS |
90 | const wxString& filter = wxEmptyString, |
91 | int defaultFilter = 0, | |
92 | const wxString& name = wxTreeCtrlNameStr ) | |
93 | { | |
94 | Init(); | |
95 | Create(parent, id, dir, pos, size, style, filter, defaultFilter, name); | |
96 | } | |
ca65c044 WS |
97 | |
98 | bool Create(wxWindow *parent, const wxWindowID id = wxID_ANY, | |
51a58d8b JS |
99 | const wxString &dir = wxDirDialogDefaultFolderStr, |
100 | const wxPoint& pos = wxDefaultPosition, | |
101 | const wxSize& size = wxDefaultSize, | |
f9c165b1 | 102 | long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, |
51a58d8b JS |
103 | const wxString& filter = wxEmptyString, |
104 | int defaultFilter = 0, | |
105 | const wxString& name = wxTreeCtrlNameStr ); | |
106 | ||
2b5f62a0 | 107 | virtual void Init(); |
51a58d8b | 108 | |
2b5f62a0 | 109 | virtual ~wxGenericDirCtrl(); |
51a58d8b JS |
110 | |
111 | void OnExpandItem(wxTreeEvent &event ); | |
112 | void OnCollapseItem(wxTreeEvent &event ); | |
113 | void OnBeginEditItem(wxTreeEvent &event ); | |
114 | void OnEndEditItem(wxTreeEvent &event ); | |
115 | void OnSize(wxSizeEvent &event ); | |
116 | ||
117 | // Try to expand as much of the given path as possible. | |
2b5f62a0 | 118 | virtual bool ExpandPath(const wxString& path); |
f395a825 VZ |
119 | // collapse the path |
120 | virtual bool CollapsePath(const wxString& path); | |
51a58d8b JS |
121 | |
122 | // Accessors | |
123 | ||
2b5f62a0 VZ |
124 | virtual inline wxString GetDefaultPath() const { return m_defaultPath; } |
125 | virtual void SetDefaultPath(const wxString& path) { m_defaultPath = path; } | |
51a58d8b | 126 | |
51a58d8b | 127 | // Get dir or filename |
2b5f62a0 | 128 | virtual wxString GetPath() 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 VZ |
132 | virtual wxString GetFilePath() const; |
133 | virtual void SetPath(const wxString& path); | |
ca65c044 | 134 | |
2b5f62a0 VZ |
135 | virtual void ShowHidden( bool show ); |
136 | virtual bool GetShowHidden() { return m_showHidden; } | |
51a58d8b | 137 | |
2b5f62a0 VZ |
138 | virtual wxString GetFilter() const { return m_filter; } |
139 | virtual void SetFilter(const wxString& filter); | |
51a58d8b | 140 | |
2b5f62a0 VZ |
141 | virtual int GetFilterIndex() const { return m_currentFilter; } |
142 | virtual void SetFilterIndex(int n); | |
51a58d8b | 143 | |
2b5f62a0 | 144 | virtual wxTreeItemId GetRootId() { return m_rootId; } |
51a58d8b | 145 | |
2b5f62a0 VZ |
146 | virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; } |
147 | virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; } | |
51a58d8b | 148 | |
42dcacf0 | 149 | // Helper |
2b5f62a0 | 150 | virtual void SetupSections(); |
ca65c044 | 151 | |
51a58d8b JS |
152 | // Find the child that matches the first part of 'path'. |
153 | // E.g. if a child path is "/usr" and 'path' is "/usr/include" | |
154 | // then the child for /usr is returned. | |
ca65c044 | 155 | // If the path string has been used (we're at the leaf), done is set to true |
2b5f62a0 | 156 | virtual wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done); |
ca65c044 | 157 | |
51a58d8b | 158 | // Resize the components of the control |
2b5f62a0 | 159 | virtual void DoResize(); |
ca65c044 | 160 | |
08887820 | 161 | // Collapse & expand the tree, thus re-creating it from scratch: |
2b5f62a0 | 162 | virtual void ReCreateTree(); |
ca65c044 | 163 | |
c06dde42 JS |
164 | // Collapse the entire tree |
165 | virtual void CollapseTree(); | |
166 | ||
51a58d8b | 167 | protected: |
c06dde42 | 168 | virtual void ExpandRoot(); |
22328fa4 JS |
169 | virtual void ExpandDir(wxTreeItemId parentId); |
170 | virtual void CollapseDir(wxTreeItemId parentId); | |
171 | virtual const wxTreeItemId AddSection(const wxString& path, const wxString& name, int imageId = 0); | |
172 | virtual wxTreeItemId AppendItem (const wxTreeItemId & parent, | |
173 | const wxString & text, | |
174 | int image = -1, int selectedImage = -1, | |
175 | wxTreeItemData * data = NULL); | |
51a58d8b | 176 | //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames); |
a78955e3 | 177 | virtual wxTreeCtrl* CreateTreeCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long treeStyle); |
51a58d8b JS |
178 | |
179 | // Extract description and actual filter from overall filter string | |
180 | bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description); | |
181 | ||
182 | private: | |
183 | bool m_showHidden; | |
184 | wxTreeItemId m_rootId; | |
51a58d8b JS |
185 | wxString m_defaultPath; // Starting path |
186 | long m_styleEx; // Extended style | |
187 | wxString m_filter; // Wildcards in same format as per wxFileDialog | |
188 | int m_currentFilter; // The current filter index | |
189 | wxString m_currentFilterStr; // Current filter string | |
190 | wxTreeCtrl* m_treeCtrl; | |
191 | wxDirFilterListCtrl* m_filterListCtrl; | |
192 | ||
193 | private: | |
194 | DECLARE_EVENT_TABLE() | |
195 | DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl) | |
22f3361e | 196 | DECLARE_NO_COPY_CLASS(wxGenericDirCtrl) |
51a58d8b JS |
197 | }; |
198 | ||
199 | //----------------------------------------------------------------------------- | |
200 | // wxDirFilterListCtrl | |
201 | //----------------------------------------------------------------------------- | |
202 | ||
203 | class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice | |
204 | { | |
205 | public: | |
206 | wxDirFilterListCtrl() { Init(); } | |
ca65c044 | 207 | wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY, |
51a58d8b JS |
208 | const wxPoint& pos = wxDefaultPosition, |
209 | const wxSize& size = wxDefaultSize, | |
210 | long style = 0) | |
211 | { | |
212 | Init(); | |
213 | Create(parent, id, pos, size, style); | |
214 | } | |
ca65c044 WS |
215 | |
216 | bool Create(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY, | |
51a58d8b JS |
217 | const wxPoint& pos = wxDefaultPosition, |
218 | const wxSize& size = wxDefaultSize, | |
219 | long style = 0); | |
220 | ||
221 | void Init(); | |
222 | ||
d3c7fc99 | 223 | virtual ~wxDirFilterListCtrl() {} |
51a58d8b | 224 | |
748fcded | 225 | //// Operations |
51a58d8b JS |
226 | void FillFilterList(const wxString& filter, int defaultFilter); |
227 | ||
748fcded | 228 | //// Events |
51a58d8b JS |
229 | void OnSelFilter(wxCommandEvent& event); |
230 | ||
231 | protected: | |
232 | wxGenericDirCtrl* m_dirCtrl; | |
233 | ||
234 | DECLARE_EVENT_TABLE() | |
235 | DECLARE_CLASS(wxDirFilterListCtrl) | |
22f3361e | 236 | DECLARE_NO_COPY_CLASS(wxDirFilterListCtrl) |
51a58d8b JS |
237 | }; |
238 | ||
748fcded VS |
239 | #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__) |
240 | #define wxDirCtrl wxGenericDirCtrl | |
241 | #endif | |
51a58d8b | 242 | |
a977709b JS |
243 | // Symbols for accessing individual controls |
244 | #define wxID_TREECTRL 7000 | |
245 | #define wxID_FILTERLISTCTRL 7001 | |
246 | ||
13de0c8c WS |
247 | #endif // wxUSE_DIRDLG |
248 | ||
06cc1fb9 JS |
249 | //------------------------------------------------------------------------- |
250 | // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary | |
251 | //------------------------------------------------------------------------- | |
252 | ||
13de0c8c WS |
253 | #if wxUSE_DIRDLG || wxUSE_FILEDLG |
254 | ||
06cc1fb9 JS |
255 | class WXDLLEXPORT wxFileIconsTable |
256 | { | |
257 | public: | |
258 | wxFileIconsTable(); | |
259 | ~wxFileIconsTable(); | |
260 | ||
261 | enum iconId_Type | |
262 | { | |
263 | folder, | |
264 | folder_open, | |
265 | computer, | |
266 | drive, | |
267 | cdrom, | |
268 | floppy, | |
269 | removeable, | |
270 | file, | |
271 | executable | |
272 | }; | |
273 | ||
274 | int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString); | |
275 | wxImageList *GetSmallImageList(); | |
276 | ||
277 | protected: | |
278 | void Create(); // create on first use | |
279 | ||
280 | wxImageList *m_smallImageList; | |
281 | wxHashTable *m_HashTable; | |
282 | }; | |
283 | ||
284 | // The global fileicons table | |
f4fffffc | 285 | extern WXDLLEXPORT_DATA(wxFileIconsTable *) wxTheFileIconsTable; |
06cc1fb9 | 286 | |
13de0c8c | 287 | #endif // wxUSE_DIRDLG || wxUSE_FILEDLG |
1e6feb95 | 288 | |
51a58d8b JS |
289 | #endif |
290 | // _WX_DIRCTRLG_H_ |