]>
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 |
1e6feb95 | 12 | // Licence: wxWindows licence |
51a58d8b JS |
13 | ///////////////////////////////////////////////////////////////////////////// |
14 | ||
15 | #ifndef _WX_DIRCTRL_H_ | |
16 | #define _WX_DIRCTRL_H_ | |
17 | ||
af49c4b8 | 18 | #if defined(__GNUG__) && !defined(__APPLE__) |
51a58d8b JS |
19 | #pragma interface "dirctrlg.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 | ||
748fcded VS |
33 | class WXDLLEXPORT wxTextCtrl; |
34 | ||
51a58d8b JS |
35 | //----------------------------------------------------------------------------- |
36 | // Extra styles for wxGenericDirCtrl | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
748fcded VS |
39 | enum |
40 | { | |
41 | // Only allow directory viewing/selection, no files | |
42 | wxDIRCTRL_DIR_ONLY = 0x0010, | |
43 | // When setting the default path, select the first file in the directory | |
44 | wxDIRCTRL_SELECT_FIRST = 0x0020, | |
45 | // Show the filter list | |
46 | wxDIRCTRL_SHOW_FILTERS = 0x0040, | |
47 | // Use 3D borders on internal controls | |
fd775aae JS |
48 | wxDIRCTRL_3D_INTERNAL = 0x0080, |
49 | // Editable labels | |
dabd1377 | 50 | wxDIRCTRL_EDIT_LABELS = 0x0100 |
748fcded | 51 | }; |
51a58d8b JS |
52 | |
53 | //----------------------------------------------------------------------------- | |
54 | // wxDirItemData | |
55 | //----------------------------------------------------------------------------- | |
56 | ||
748fcded | 57 | class WXDLLEXPORT wxDirItemData : public wxTreeItemData |
51a58d8b JS |
58 | { |
59 | public: | |
748fcded VS |
60 | wxDirItemData(const wxString& path, const wxString& name, bool isDir); |
61 | ~wxDirItemData(); | |
62 | void SetNewDirName(const wxString& path); | |
63 | ||
64 | bool HasSubDirs() const; | |
65 | bool HasFiles(const wxString& spec = wxEmptyString) const; | |
66 | ||
67 | wxString m_path, m_name; | |
68 | bool m_isHidden; | |
69 | bool m_isExpanded; | |
70 | bool m_isDir; | |
51a58d8b JS |
71 | }; |
72 | ||
73 | //----------------------------------------------------------------------------- | |
74 | // wxDirCtrl | |
75 | //----------------------------------------------------------------------------- | |
76 | ||
77 | class WXDLLEXPORT wxDirFilterListCtrl; | |
78 | ||
79 | class WXDLLEXPORT wxGenericDirCtrl: public wxControl | |
80 | { | |
81 | public: | |
82 | wxGenericDirCtrl(); | |
83 | wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1, | |
84 | const wxString &dir = wxDirDialogDefaultFolderStr, | |
85 | const wxPoint& pos = wxDefaultPosition, | |
86 | const wxSize& size = wxDefaultSize, | |
f9c165b1 | 87 | long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, |
51a58d8b JS |
88 | const wxString& filter = wxEmptyString, |
89 | int defaultFilter = 0, | |
90 | const wxString& name = wxTreeCtrlNameStr ) | |
91 | { | |
92 | Init(); | |
93 | Create(parent, id, dir, pos, size, style, filter, defaultFilter, name); | |
94 | } | |
95 | ||
96 | bool Create(wxWindow *parent, const wxWindowID id = -1, | |
97 | const wxString &dir = wxDirDialogDefaultFolderStr, | |
98 | const wxPoint& pos = wxDefaultPosition, | |
99 | const wxSize& size = wxDefaultSize, | |
f9c165b1 | 100 | long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, |
51a58d8b JS |
101 | const wxString& filter = wxEmptyString, |
102 | int defaultFilter = 0, | |
103 | const wxString& name = wxTreeCtrlNameStr ); | |
104 | ||
2b5f62a0 | 105 | virtual void Init(); |
51a58d8b | 106 | |
2b5f62a0 | 107 | virtual ~wxGenericDirCtrl(); |
51a58d8b JS |
108 | |
109 | void OnExpandItem(wxTreeEvent &event ); | |
110 | void OnCollapseItem(wxTreeEvent &event ); | |
111 | void OnBeginEditItem(wxTreeEvent &event ); | |
112 | void OnEndEditItem(wxTreeEvent &event ); | |
113 | void OnSize(wxSizeEvent &event ); | |
114 | ||
115 | // Try to expand as much of the given path as possible. | |
2b5f62a0 | 116 | virtual bool ExpandPath(const wxString& path); |
51a58d8b JS |
117 | |
118 | // Accessors | |
119 | ||
2b5f62a0 VZ |
120 | virtual inline wxString GetDefaultPath() const { return m_defaultPath; } |
121 | virtual void SetDefaultPath(const wxString& path) { m_defaultPath = path; } | |
51a58d8b | 122 | |
51a58d8b | 123 | // Get dir or filename |
2b5f62a0 | 124 | virtual wxString GetPath() const; |
42dcacf0 | 125 | |
51a58d8b JS |
126 | // Get selected filename path only (else empty string). |
127 | // I.e. don't count a directory as a selection | |
2b5f62a0 VZ |
128 | virtual wxString GetFilePath() const; |
129 | virtual void SetPath(const wxString& path); | |
42dcacf0 | 130 | |
2b5f62a0 VZ |
131 | virtual void ShowHidden( bool show ); |
132 | virtual bool GetShowHidden() { return m_showHidden; } | |
51a58d8b | 133 | |
2b5f62a0 VZ |
134 | virtual wxString GetFilter() const { return m_filter; } |
135 | virtual void SetFilter(const wxString& filter); | |
51a58d8b | 136 | |
2b5f62a0 VZ |
137 | virtual int GetFilterIndex() const { return m_currentFilter; } |
138 | virtual void SetFilterIndex(int n); | |
51a58d8b | 139 | |
2b5f62a0 | 140 | virtual wxTreeItemId GetRootId() { return m_rootId; } |
51a58d8b | 141 | |
2b5f62a0 VZ |
142 | virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; } |
143 | virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; } | |
51a58d8b | 144 | |
42dcacf0 | 145 | // Helper |
2b5f62a0 | 146 | virtual void SetupSections(); |
42dcacf0 | 147 | |
51a58d8b | 148 | // Parse the filter into an array of filters and an array of descriptions |
2b5f62a0 | 149 | virtual int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions); |
42dcacf0 | 150 | |
51a58d8b JS |
151 | // Find the child that matches the first part of 'path'. |
152 | // E.g. if a child path is "/usr" and 'path' is "/usr/include" | |
153 | // then the child for /usr is returned. | |
154 | // If the path string has been used (we're at the leaf), done is set to TRUE | |
2b5f62a0 | 155 | virtual wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done); |
51a58d8b JS |
156 | |
157 | // Resize the components of the control | |
2b5f62a0 | 158 | virtual void DoResize(); |
42dcacf0 | 159 | |
08887820 | 160 | // Collapse & expand the tree, thus re-creating it from scratch: |
2b5f62a0 | 161 | virtual void ReCreateTree(); |
08887820 | 162 | |
51a58d8b JS |
163 | protected: |
164 | void ExpandDir(wxTreeItemId parentId); | |
08887820 | 165 | void CollapseDir(wxTreeItemId parentId); |
51a58d8b JS |
166 | void AddSection(const wxString& path, const wxString& name, int imageId = 0); |
167 | //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames); | |
168 | ||
169 | // Extract description and actual filter from overall filter string | |
170 | bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description); | |
171 | ||
172 | private: | |
173 | bool m_showHidden; | |
174 | wxTreeItemId m_rootId; | |
175 | wxImageList* m_imageList; | |
176 | wxString m_defaultPath; // Starting path | |
177 | long m_styleEx; // Extended style | |
178 | wxString m_filter; // Wildcards in same format as per wxFileDialog | |
179 | int m_currentFilter; // The current filter index | |
180 | wxString m_currentFilterStr; // Current filter string | |
181 | wxTreeCtrl* m_treeCtrl; | |
182 | wxDirFilterListCtrl* m_filterListCtrl; | |
183 | ||
184 | private: | |
185 | DECLARE_EVENT_TABLE() | |
186 | DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl) | |
187 | }; | |
188 | ||
189 | //----------------------------------------------------------------------------- | |
190 | // wxDirFilterListCtrl | |
191 | //----------------------------------------------------------------------------- | |
192 | ||
193 | class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice | |
194 | { | |
195 | public: | |
196 | wxDirFilterListCtrl() { Init(); } | |
197 | wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1, | |
198 | const wxPoint& pos = wxDefaultPosition, | |
199 | const wxSize& size = wxDefaultSize, | |
200 | long style = 0) | |
201 | { | |
202 | Init(); | |
203 | Create(parent, id, pos, size, style); | |
204 | } | |
205 | ||
206 | bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1, | |
207 | const wxPoint& pos = wxDefaultPosition, | |
208 | const wxSize& size = wxDefaultSize, | |
209 | long style = 0); | |
210 | ||
211 | void Init(); | |
212 | ||
213 | ~wxDirFilterListCtrl() {}; | |
214 | ||
748fcded | 215 | //// Operations |
51a58d8b JS |
216 | void FillFilterList(const wxString& filter, int defaultFilter); |
217 | ||
748fcded | 218 | //// Events |
51a58d8b JS |
219 | void OnSelFilter(wxCommandEvent& event); |
220 | ||
221 | protected: | |
222 | wxGenericDirCtrl* m_dirCtrl; | |
223 | ||
224 | DECLARE_EVENT_TABLE() | |
225 | DECLARE_CLASS(wxDirFilterListCtrl) | |
226 | }; | |
227 | ||
748fcded VS |
228 | #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__) |
229 | #define wxDirCtrl wxGenericDirCtrl | |
230 | #endif | |
51a58d8b | 231 | |
a977709b JS |
232 | // Symbols for accessing individual controls |
233 | #define wxID_TREECTRL 7000 | |
234 | #define wxID_FILTERLISTCTRL 7001 | |
235 | ||
1e6feb95 VZ |
236 | #endif // wxUSE_DIRDLG |
237 | ||
51a58d8b JS |
238 | #endif |
239 | // _WX_DIRCTRLG_H_ |