]>
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. | |
7 | // Author: Julian Smart et al | |
8 | // Modified by: | |
9 | // Created: 21/3/2000 | |
10 | // RCS-ID: $Id$ | |
11 | // Copyright: (c) Julian Smart | |
12 | // Licence: wxWindows licence | |
13 | ///////////////////////////////////////////////////////////////////////////// | |
14 | ||
15 | #ifndef _WX_DIRCTRL_H_ | |
16 | #define _WX_DIRCTRL_H_ | |
17 | ||
18 | #ifdef __GNUG__ | |
19 | #pragma interface "dirctrlg.h" | |
20 | #endif | |
21 | ||
22 | #include "wx/treectrl.h" | |
3509d340 VS |
23 | #include "wx/dirdlg.h" |
24 | #include "wx/choice.h" | |
51a58d8b JS |
25 | |
26 | //----------------------------------------------------------------------------- | |
27 | // classes | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
51a58d8b JS |
30 | //----------------------------------------------------------------------------- |
31 | // Extra styles for wxGenericDirCtrl | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
34 | // Only allow directory viewing/selection, no files | |
35 | #define wxDIRCTRL_DIR_ONLY 0x0010 | |
36 | // When setting the default path, select the first file in the directory | |
37 | #define wxDIRCTRL_SELECT_FIRST 0x0020 | |
38 | // Show the filter list | |
39 | #define wxDIRCTRL_SHOW_FILTERS 0x0040 | |
40 | // Use 3D borders on internal controls | |
41 | #define wxDIRCTRL_3D_INTERNAL 0x0080 | |
42 | ||
43 | //----------------------------------------------------------------------------- | |
44 | // wxDirItemData | |
45 | //----------------------------------------------------------------------------- | |
46 | ||
47 | class WXDLLEXPORT wxDirItemDataEx : public wxTreeItemData | |
48 | { | |
49 | public: | |
50 | wxDirItemDataEx(const wxString& path, const wxString& name, bool isDir); | |
51 | ~wxDirItemDataEx(); | |
52 | bool HasSubDirs(); | |
53 | void SetNewDirName( wxString path ); | |
54 | wxString m_path, m_name; | |
55 | bool m_isHidden; | |
56 | bool m_hasSubDirs; | |
57 | bool m_isExpanded; | |
58 | bool m_isDir; | |
59 | }; | |
60 | ||
61 | //----------------------------------------------------------------------------- | |
62 | // wxDirCtrl | |
63 | //----------------------------------------------------------------------------- | |
64 | ||
65 | class WXDLLEXPORT wxDirFilterListCtrl; | |
66 | ||
67 | class WXDLLEXPORT wxGenericDirCtrl: public wxControl | |
68 | { | |
69 | public: | |
70 | wxGenericDirCtrl(); | |
71 | wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1, | |
72 | const wxString &dir = wxDirDialogDefaultFolderStr, | |
73 | const wxPoint& pos = wxDefaultPosition, | |
74 | const wxSize& size = wxDefaultSize, | |
f9c165b1 | 75 | long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, |
51a58d8b JS |
76 | const wxString& filter = wxEmptyString, |
77 | int defaultFilter = 0, | |
78 | const wxString& name = wxTreeCtrlNameStr ) | |
79 | { | |
80 | Init(); | |
81 | Create(parent, id, dir, pos, size, style, filter, defaultFilter, name); | |
82 | } | |
83 | ||
84 | bool Create(wxWindow *parent, const wxWindowID id = -1, | |
85 | const wxString &dir = wxDirDialogDefaultFolderStr, | |
86 | const wxPoint& pos = wxDefaultPosition, | |
87 | const wxSize& size = wxDefaultSize, | |
f9c165b1 | 88 | long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, |
51a58d8b JS |
89 | const wxString& filter = wxEmptyString, |
90 | int defaultFilter = 0, | |
91 | const wxString& name = wxTreeCtrlNameStr ); | |
92 | ||
93 | void Init(); | |
94 | ||
95 | ~wxGenericDirCtrl(); | |
96 | ||
97 | void OnExpandItem(wxTreeEvent &event ); | |
98 | void OnCollapseItem(wxTreeEvent &event ); | |
99 | void OnBeginEditItem(wxTreeEvent &event ); | |
100 | void OnEndEditItem(wxTreeEvent &event ); | |
101 | void OnSize(wxSizeEvent &event ); | |
102 | ||
103 | // Try to expand as much of the given path as possible. | |
104 | bool ExpandPath(const wxString& path); | |
105 | ||
106 | // Accessors | |
107 | ||
108 | inline wxString GetDefaultPath() const { return m_defaultPath; } | |
109 | void SetDefaultPath(const wxString& path) { m_defaultPath = path; } | |
110 | ||
51a58d8b JS |
111 | // Get dir or filename |
112 | wxString GetPath() const ; | |
113 | // Get selected filename path only (else empty string). | |
114 | // I.e. don't count a directory as a selection | |
115 | wxString GetFilePath() const ; | |
116 | void SetPath(const wxString& path) ; | |
117 | ||
118 | wxString GetFilter() const { return m_filter; } | |
119 | void SetFilter(const wxString& filter); | |
120 | ||
121 | int GetFilterIndex() const { return m_currentFilter; } | |
122 | void SetFilterIndex(int n) ; | |
123 | ||
124 | wxTreeItemId GetRootId() { return m_rootId; } | |
125 | ||
126 | wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; } | |
127 | wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; } | |
128 | ||
129 | //// Helpers | |
130 | void SetupSections(); | |
131 | // Parse the filter into an array of filters and an array of descriptions | |
132 | int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions); | |
133 | // Find the child that matches the first part of 'path'. | |
134 | // E.g. if a child path is "/usr" and 'path' is "/usr/include" | |
135 | // then the child for /usr is returned. | |
136 | // If the path string has been used (we're at the leaf), done is set to TRUE | |
137 | wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done); | |
138 | ||
139 | // Resize the components of the control | |
140 | void DoResize(); | |
141 | protected: | |
142 | void ExpandDir(wxTreeItemId parentId); | |
143 | void AddSection(const wxString& path, const wxString& name, int imageId = 0); | |
144 | //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames); | |
145 | ||
146 | // Extract description and actual filter from overall filter string | |
147 | bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description); | |
148 | ||
149 | private: | |
150 | bool m_showHidden; | |
151 | wxTreeItemId m_rootId; | |
152 | wxImageList* m_imageList; | |
153 | wxString m_defaultPath; // Starting path | |
154 | long m_styleEx; // Extended style | |
155 | wxString m_filter; // Wildcards in same format as per wxFileDialog | |
156 | int m_currentFilter; // The current filter index | |
157 | wxString m_currentFilterStr; // Current filter string | |
158 | wxTreeCtrl* m_treeCtrl; | |
159 | wxDirFilterListCtrl* m_filterListCtrl; | |
160 | ||
161 | private: | |
162 | DECLARE_EVENT_TABLE() | |
163 | DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl) | |
164 | }; | |
165 | ||
166 | //----------------------------------------------------------------------------- | |
167 | // wxDirFilterListCtrl | |
168 | //----------------------------------------------------------------------------- | |
169 | ||
170 | class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice | |
171 | { | |
172 | public: | |
173 | wxDirFilterListCtrl() { Init(); } | |
174 | wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1, | |
175 | const wxPoint& pos = wxDefaultPosition, | |
176 | const wxSize& size = wxDefaultSize, | |
177 | long style = 0) | |
178 | { | |
179 | Init(); | |
180 | Create(parent, id, pos, size, style); | |
181 | } | |
182 | ||
183 | bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1, | |
184 | const wxPoint& pos = wxDefaultPosition, | |
185 | const wxSize& size = wxDefaultSize, | |
186 | long style = 0); | |
187 | ||
188 | void Init(); | |
189 | ||
190 | ~wxDirFilterListCtrl() {}; | |
191 | ||
192 | //// Operations | |
193 | void FillFilterList(const wxString& filter, int defaultFilter); | |
194 | ||
195 | //// Events | |
196 | void OnSelFilter(wxCommandEvent& event); | |
197 | ||
198 | protected: | |
199 | wxGenericDirCtrl* m_dirCtrl; | |
200 | ||
201 | DECLARE_EVENT_TABLE() | |
202 | DECLARE_CLASS(wxDirFilterListCtrl) | |
203 | }; | |
204 | ||
205 | #define wxID_TREECTRL 7000 | |
206 | #define wxID_FILTERLISTCTRL 7001 | |
207 | ||
208 | //----------------------------------------------------------------------------- | |
209 | // wxGenericDirDialog | |
210 | // | |
211 | //----------------------------------------------------------------------------- | |
212 | ||
213 | class wxGenericDirDialog: public wxDialog | |
214 | { | |
215 | DECLARE_EVENT_TABLE() | |
216 | public: | |
217 | wxGenericDirDialog(): wxDialog() {} | |
218 | wxGenericDirDialog(wxWindow* parent, const wxString& title, | |
219 | const wxString& defaultPath = wxEmptyString, long style = wxDEFAULT_DIALOG_STYLE, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxSize(450, 550), const wxString& name = "dialog"); | |
220 | ||
e63fdcd6 | 221 | //// Event handlers |
51a58d8b JS |
222 | void OnCloseWindow(wxCloseEvent& event); |
223 | void OnOK(wxCommandEvent& event); | |
e63fdcd6 JS |
224 | void OnTreeSelected( wxTreeEvent &event ); |
225 | void OnTreeKeyDown( wxTreeEvent &event ); | |
226 | void OnNew(wxCommandEvent& event); | |
51a58d8b | 227 | |
e63fdcd6 | 228 | //// Accessors |
51a58d8b JS |
229 | inline void SetMessage(const wxString& message) { m_message = message; } |
230 | void SetPath(const wxString& path) ; | |
231 | inline void SetStyle(long style) { m_dialogStyle = style; } | |
232 | ||
233 | inline wxString GetMessage(void) const { return m_message; } | |
234 | wxString GetPath(void) const ; | |
235 | inline long GetStyle(void) const { return m_dialogStyle; } | |
236 | ||
e63fdcd6 JS |
237 | wxTextCtrl* GetInputCtrl() const { return m_input; } |
238 | ||
239 | //// Overrides | |
240 | int ShowModal(); | |
241 | ||
51a58d8b JS |
242 | protected: |
243 | wxString m_message; | |
244 | long m_dialogStyle; | |
245 | wxString m_path; | |
246 | wxGenericDirCtrl* m_dirCtrl; | |
e63fdcd6 | 247 | wxTextCtrl* m_input; |
51a58d8b JS |
248 | |
249 | }; | |
250 | ||
251 | #endif | |
252 | // _WX_DIRCTRLG_H_ |