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