]>
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 | ||
12028905 | 18 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
51a58d8b JS |
19 | #pragma interface "dirctrlg.h" |
20 | #endif | |
21 | ||
13de0c8c WS |
22 | #if wxUSE_DIRDLG || wxUSE_FILEDLG |
23 | #include "wx/imaglist.h" | |
24 | #endif | |
25 | ||
1e6feb95 VZ |
26 | #if wxUSE_DIRDLG |
27 | ||
51a58d8b | 28 | #include "wx/treectrl.h" |
748fcded | 29 | #include "wx/dialog.h" |
3509d340 VS |
30 | #include "wx/dirdlg.h" |
31 | #include "wx/choice.h" | |
51a58d8b JS |
32 | |
33 | //----------------------------------------------------------------------------- | |
34 | // classes | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
62a9d04c VS |
37 | class WXDLLIMPEXP_CORE wxTextCtrl; |
38 | class WXDLLIMPEXP_CORE wxImageList; | |
39 | class WXDLLIMPEXP_BASE wxHashTable; | |
748fcded | 40 | |
51a58d8b JS |
41 | //----------------------------------------------------------------------------- |
42 | // Extra styles for wxGenericDirCtrl | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
748fcded VS |
45 | enum |
46 | { | |
47 | // Only allow directory viewing/selection, no files | |
48 | wxDIRCTRL_DIR_ONLY = 0x0010, | |
49 | // When setting the default path, select the first file in the directory | |
50 | wxDIRCTRL_SELECT_FIRST = 0x0020, | |
51 | // Show the filter list | |
52 | wxDIRCTRL_SHOW_FILTERS = 0x0040, | |
53 | // Use 3D borders on internal controls | |
fd775aae JS |
54 | wxDIRCTRL_3D_INTERNAL = 0x0080, |
55 | // Editable labels | |
dabd1377 | 56 | wxDIRCTRL_EDIT_LABELS = 0x0100 |
748fcded | 57 | }; |
51a58d8b JS |
58 | |
59 | //----------------------------------------------------------------------------- | |
60 | // wxDirItemData | |
61 | //----------------------------------------------------------------------------- | |
62 | ||
748fcded | 63 | class WXDLLEXPORT wxDirItemData : public wxTreeItemData |
51a58d8b JS |
64 | { |
65 | public: | |
748fcded | 66 | wxDirItemData(const wxString& path, const wxString& name, bool isDir); |
1b941f2d | 67 | ~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 | ||
83 | class WXDLLEXPORT wxDirFilterListCtrl; | |
84 | ||
85 | class WXDLLEXPORT wxGenericDirCtrl: public wxControl | |
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, | |
f9c165b1 | 93 | long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, |
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, | |
f9c165b1 | 106 | long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, |
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); |
51a58d8b JS |
123 | |
124 | // Accessors | |
125 | ||
2b5f62a0 VZ |
126 | virtual inline wxString GetDefaultPath() const { return m_defaultPath; } |
127 | virtual void SetDefaultPath(const wxString& path) { m_defaultPath = path; } | |
51a58d8b | 128 | |
51a58d8b | 129 | // Get dir or filename |
2b5f62a0 | 130 | virtual wxString GetPath() const; |
ca65c044 | 131 | |
51a58d8b JS |
132 | // Get selected filename path only (else empty string). |
133 | // I.e. don't count a directory as a selection | |
2b5f62a0 VZ |
134 | virtual wxString GetFilePath() const; |
135 | virtual void SetPath(const wxString& path); | |
ca65c044 | 136 | |
2b5f62a0 VZ |
137 | virtual void ShowHidden( bool show ); |
138 | virtual bool GetShowHidden() { return m_showHidden; } | |
51a58d8b | 139 | |
2b5f62a0 VZ |
140 | virtual wxString GetFilter() const { return m_filter; } |
141 | virtual void SetFilter(const wxString& filter); | |
51a58d8b | 142 | |
2b5f62a0 VZ |
143 | virtual int GetFilterIndex() const { return m_currentFilter; } |
144 | virtual void SetFilterIndex(int n); | |
51a58d8b | 145 | |
2b5f62a0 | 146 | virtual wxTreeItemId GetRootId() { return m_rootId; } |
51a58d8b | 147 | |
2b5f62a0 VZ |
148 | virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; } |
149 | virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; } | |
51a58d8b | 150 | |
42dcacf0 | 151 | // Helper |
2b5f62a0 | 152 | virtual void SetupSections(); |
ca65c044 | 153 | |
9e152a55 | 154 | #if WXWIN_COMPATIBILITY_2_4 |
51a58d8b | 155 | // Parse the filter into an array of filters and an array of descriptions |
2b5f62a0 | 156 | virtual int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions); |
9e152a55 | 157 | #endif // WXWIN_COMPATIBILITY_2_4 |
ca65c044 | 158 | |
51a58d8b JS |
159 | // Find the child that matches the first part of 'path'. |
160 | // E.g. if a child path is "/usr" and 'path' is "/usr/include" | |
161 | // then the child for /usr is returned. | |
ca65c044 | 162 | // If the path string has been used (we're at the leaf), done is set to true |
2b5f62a0 | 163 | virtual wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done); |
ca65c044 | 164 | |
51a58d8b | 165 | // Resize the components of the control |
2b5f62a0 | 166 | virtual void DoResize(); |
ca65c044 | 167 | |
08887820 | 168 | // Collapse & expand the tree, thus re-creating it from scratch: |
2b5f62a0 | 169 | virtual void ReCreateTree(); |
ca65c044 | 170 | |
c06dde42 JS |
171 | // Collapse the entire tree |
172 | virtual void CollapseTree(); | |
173 | ||
51a58d8b | 174 | protected: |
c06dde42 | 175 | virtual void ExpandRoot(); |
22328fa4 JS |
176 | virtual void ExpandDir(wxTreeItemId parentId); |
177 | virtual void CollapseDir(wxTreeItemId parentId); | |
178 | virtual const wxTreeItemId AddSection(const wxString& path, const wxString& name, int imageId = 0); | |
179 | virtual wxTreeItemId AppendItem (const wxTreeItemId & parent, | |
180 | const wxString & text, | |
181 | int image = -1, int selectedImage = -1, | |
182 | wxTreeItemData * data = NULL); | |
51a58d8b | 183 | //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames); |
a78955e3 | 184 | virtual wxTreeCtrl* CreateTreeCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long treeStyle); |
51a58d8b JS |
185 | |
186 | // Extract description and actual filter from overall filter string | |
187 | bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description); | |
188 | ||
189 | private: | |
190 | bool m_showHidden; | |
191 | wxTreeItemId m_rootId; | |
51a58d8b JS |
192 | wxString m_defaultPath; // Starting path |
193 | long m_styleEx; // Extended style | |
194 | wxString m_filter; // Wildcards in same format as per wxFileDialog | |
195 | int m_currentFilter; // The current filter index | |
196 | wxString m_currentFilterStr; // Current filter string | |
197 | wxTreeCtrl* m_treeCtrl; | |
198 | wxDirFilterListCtrl* m_filterListCtrl; | |
199 | ||
200 | private: | |
201 | DECLARE_EVENT_TABLE() | |
202 | DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl) | |
22f3361e | 203 | DECLARE_NO_COPY_CLASS(wxGenericDirCtrl) |
51a58d8b JS |
204 | }; |
205 | ||
206 | //----------------------------------------------------------------------------- | |
207 | // wxDirFilterListCtrl | |
208 | //----------------------------------------------------------------------------- | |
209 | ||
210 | class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice | |
211 | { | |
212 | public: | |
213 | wxDirFilterListCtrl() { Init(); } | |
ca65c044 | 214 | wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY, |
51a58d8b JS |
215 | const wxPoint& pos = wxDefaultPosition, |
216 | const wxSize& size = wxDefaultSize, | |
217 | long style = 0) | |
218 | { | |
219 | Init(); | |
220 | Create(parent, id, pos, size, style); | |
221 | } | |
ca65c044 WS |
222 | |
223 | bool Create(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY, | |
51a58d8b JS |
224 | const wxPoint& pos = wxDefaultPosition, |
225 | const wxSize& size = wxDefaultSize, | |
226 | long style = 0); | |
227 | ||
228 | void Init(); | |
229 | ||
6fb99eb3 | 230 | ~wxDirFilterListCtrl() {} |
51a58d8b | 231 | |
748fcded | 232 | //// Operations |
51a58d8b JS |
233 | void FillFilterList(const wxString& filter, int defaultFilter); |
234 | ||
748fcded | 235 | //// Events |
51a58d8b JS |
236 | void OnSelFilter(wxCommandEvent& event); |
237 | ||
238 | protected: | |
239 | wxGenericDirCtrl* m_dirCtrl; | |
240 | ||
241 | DECLARE_EVENT_TABLE() | |
242 | DECLARE_CLASS(wxDirFilterListCtrl) | |
22f3361e | 243 | DECLARE_NO_COPY_CLASS(wxDirFilterListCtrl) |
51a58d8b JS |
244 | }; |
245 | ||
748fcded VS |
246 | #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__) |
247 | #define wxDirCtrl wxGenericDirCtrl | |
248 | #endif | |
51a58d8b | 249 | |
a977709b JS |
250 | // Symbols for accessing individual controls |
251 | #define wxID_TREECTRL 7000 | |
252 | #define wxID_FILTERLISTCTRL 7001 | |
253 | ||
13de0c8c WS |
254 | #endif // wxUSE_DIRDLG |
255 | ||
06cc1fb9 JS |
256 | //------------------------------------------------------------------------- |
257 | // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary | |
258 | //------------------------------------------------------------------------- | |
259 | ||
13de0c8c WS |
260 | #if wxUSE_DIRDLG || wxUSE_FILEDLG |
261 | ||
06cc1fb9 JS |
262 | class WXDLLEXPORT wxFileIconsTable |
263 | { | |
264 | public: | |
265 | wxFileIconsTable(); | |
266 | ~wxFileIconsTable(); | |
267 | ||
268 | enum iconId_Type | |
269 | { | |
270 | folder, | |
271 | folder_open, | |
272 | computer, | |
273 | drive, | |
274 | cdrom, | |
275 | floppy, | |
276 | removeable, | |
277 | file, | |
278 | executable | |
279 | }; | |
280 | ||
281 | int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString); | |
282 | wxImageList *GetSmallImageList(); | |
283 | ||
284 | protected: | |
285 | void Create(); // create on first use | |
286 | ||
287 | wxImageList *m_smallImageList; | |
288 | wxHashTable *m_HashTable; | |
289 | }; | |
290 | ||
291 | // The global fileicons table | |
f4fffffc | 292 | extern WXDLLEXPORT_DATA(wxFileIconsTable *) wxTheFileIconsTable; |
06cc1fb9 | 293 | |
13de0c8c | 294 | #endif // wxUSE_DIRDLG || wxUSE_FILEDLG |
1e6feb95 | 295 | |
51a58d8b JS |
296 | #endif |
297 | // _WX_DIRCTRLG_H_ |