No changes, just some cleanup in wxGenericDirCtrl code.
[wxWidgets.git] / include / wx / generic / dirctrlg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/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: Robert Roebling, Harm van der Heijden, Julian Smart et al
8 // Modified by:
9 // Created: 21/3/2000
10 // RCS-ID: $Id$
11 // Copyright: (c) Robert Roebling, Harm van der Heijden, Julian Smart
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
14
15 #ifndef _WX_DIRCTRL_H_
16 #define _WX_DIRCTRL_H_
17
18 #if wxUSE_DIRDLG
19
20 #include "wx/treectrl.h"
21 #include "wx/dialog.h"
22 #include "wx/dirdlg.h"
23 #include "wx/choice.h"
24
25 //-----------------------------------------------------------------------------
26 // classes
27 //-----------------------------------------------------------------------------
28
29 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
30 class WXDLLIMPEXP_FWD_BASE wxHashTable;
31
32 //-----------------------------------------------------------------------------
33 // Extra styles for wxGenericDirCtrl
34 //-----------------------------------------------------------------------------
35
36 enum
37 {
38 // Only allow directory viewing/selection, no files
39 wxDIRCTRL_DIR_ONLY = 0x0010,
40 // When setting the default path, select the first file in the directory
41 wxDIRCTRL_SELECT_FIRST = 0x0020,
42 #if WXWIN_COMPATIBILITY_2_8
43 // Unused, for compatibility only
44 wxDIRCTRL_SHOW_FILTERS = 0x0040,
45 #endif // WXWIN_COMPATIBILITY_2_8
46 // Use 3D borders on internal controls
47 wxDIRCTRL_3D_INTERNAL = 0x0080,
48 // Editable labels
49 wxDIRCTRL_EDIT_LABELS = 0x0100,
50 // Allow multiple selection
51 wxDIRCTRL_MULTIPLE = 0x0200
52 };
53
54 //-----------------------------------------------------------------------------
55 // wxDirItemData
56 //-----------------------------------------------------------------------------
57
58 class WXDLLIMPEXP_CORE wxDirItemData : public wxTreeItemData
59 {
60 public:
61 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
62 virtual ~wxDirItemData(){}
63 void SetNewDirName(const wxString& path);
64
65 bool HasSubDirs() const;
66 bool HasFiles(const wxString& spec = wxEmptyString) const;
67
68 wxString m_path, m_name;
69 bool m_isHidden;
70 bool m_isExpanded;
71 bool m_isDir;
72 };
73
74 //-----------------------------------------------------------------------------
75 // wxDirCtrl
76 //-----------------------------------------------------------------------------
77
78 class WXDLLIMPEXP_FWD_CORE wxDirFilterListCtrl;
79
80 class WXDLLIMPEXP_CORE wxGenericDirCtrl: public wxControl
81 {
82 public:
83 wxGenericDirCtrl();
84 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = wxID_ANY,
85 const wxString &dir = wxDirDialogDefaultFolderStr,
86 const wxPoint& pos = wxDefaultPosition,
87 const wxSize& size = wxDefaultSize,
88 long style = wxDIRCTRL_3D_INTERNAL,
89 const wxString& filter = wxEmptyString,
90 int defaultFilter = 0,
91 const wxString& name = wxTreeCtrlNameStr )
92 {
93 Init();
94 Create(parent, id, dir, pos, size, style, filter, defaultFilter, name);
95 }
96
97 bool Create(wxWindow *parent, const wxWindowID id = wxID_ANY,
98 const wxString &dir = wxDirDialogDefaultFolderStr,
99 const wxPoint& pos = wxDefaultPosition,
100 const wxSize& size = wxDefaultSize,
101 long style = wxDIRCTRL_3D_INTERNAL,
102 const wxString& filter = wxEmptyString,
103 int defaultFilter = 0,
104 const wxString& name = wxTreeCtrlNameStr );
105
106 virtual void Init();
107
108 virtual ~wxGenericDirCtrl();
109
110 void OnExpandItem(wxTreeEvent &event );
111 void OnCollapseItem(wxTreeEvent &event );
112 void OnBeginEditItem(wxTreeEvent &event );
113 void OnEndEditItem(wxTreeEvent &event );
114 void OnSize(wxSizeEvent &event );
115
116 // Try to expand as much of the given path as possible.
117 virtual bool ExpandPath(const wxString& path);
118 // collapse the path
119 virtual bool CollapsePath(const wxString& path);
120
121 // Accessors
122
123 virtual inline wxString GetDefaultPath() const { return m_defaultPath; }
124 virtual void SetDefaultPath(const wxString& path) { m_defaultPath = path; }
125
126 // Get dir or filename
127 virtual wxString GetPath() const;
128 virtual void GetPaths(wxArrayString& paths) const;
129
130 // Get selected filename path only (else empty string).
131 // I.e. don't count a directory as a selection
132 virtual wxString GetFilePath() const;
133 virtual void GetFilePaths(wxArrayString& paths) const;
134 virtual void SetPath(const wxString& path);
135
136 virtual void SelectPath(const wxString& path, bool select = true);
137 virtual void SelectPaths(const wxArrayString& paths);
138
139 virtual void ShowHidden( bool show );
140 virtual bool GetShowHidden() { return m_showHidden; }
141
142 virtual wxString GetFilter() const { return m_filter; }
143 virtual void SetFilter(const wxString& filter);
144
145 virtual int GetFilterIndex() const { return m_currentFilter; }
146 virtual void SetFilterIndex(int n);
147
148 virtual wxTreeItemId GetRootId() { return m_rootId; }
149
150 virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
151 virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
152
153 virtual void UnselectAll();
154
155 // Helper
156 virtual void SetupSections();
157
158 // Find the child that matches the first part of 'path'.
159 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
160 // then the child for /usr is returned.
161 // If the path string has been used (we're at the leaf), done is set to true
162 virtual wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
163
164 wxString GetPath(wxTreeItemId itemId) const;
165
166 // Resize the components of the control
167 virtual void DoResize();
168
169 // Collapse & expand the tree, thus re-creating it from scratch:
170 virtual void ReCreateTree();
171
172 // Collapse the entire tree
173 virtual void CollapseTree();
174
175 // overridden base class methods
176 virtual void SetFocus();
177
178 protected:
179 virtual void ExpandRoot();
180 virtual void ExpandDir(wxTreeItemId parentId);
181 virtual void CollapseDir(wxTreeItemId parentId);
182 virtual const wxTreeItemId AddSection(const wxString& path, const wxString& name, int imageId = 0);
183 virtual wxTreeItemId AppendItem (const wxTreeItemId & parent,
184 const wxString & text,
185 int image = -1, int selectedImage = -1,
186 wxTreeItemData * data = NULL);
187 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
188 virtual wxTreeCtrl* CreateTreeCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long treeStyle);
189
190 // Extract description and actual filter from overall filter string
191 bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
192
193 private:
194 void PopulateNode(wxTreeItemId node);
195 wxDirItemData* GetItemData(wxTreeItemId itemId);
196
197 bool m_showHidden;
198 wxTreeItemId m_rootId;
199 wxString m_defaultPath; // Starting path
200 long m_styleEx; // Extended style
201 wxString m_filter; // Wildcards in same format as per wxFileDialog
202 int m_currentFilter; // The current filter index
203 wxString m_currentFilterStr; // Current filter string
204 wxTreeCtrl* m_treeCtrl;
205 wxDirFilterListCtrl* m_filterListCtrl;
206
207 private:
208 DECLARE_EVENT_TABLE()
209 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
210 wxDECLARE_NO_COPY_CLASS(wxGenericDirCtrl);
211 };
212
213 //-----------------------------------------------------------------------------
214 // wxDirFilterListCtrl
215 //-----------------------------------------------------------------------------
216
217 class WXDLLIMPEXP_CORE wxDirFilterListCtrl: public wxChoice
218 {
219 public:
220 wxDirFilterListCtrl() { Init(); }
221 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
222 const wxPoint& pos = wxDefaultPosition,
223 const wxSize& size = wxDefaultSize,
224 long style = 0)
225 {
226 Init();
227 Create(parent, id, pos, size, style);
228 }
229
230 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
231 const wxPoint& pos = wxDefaultPosition,
232 const wxSize& size = wxDefaultSize,
233 long style = 0);
234
235 void Init();
236
237 virtual ~wxDirFilterListCtrl() {}
238
239 //// Operations
240 void FillFilterList(const wxString& filter, int defaultFilter);
241
242 //// Events
243 void OnSelFilter(wxCommandEvent& event);
244
245 protected:
246 wxGenericDirCtrl* m_dirCtrl;
247
248 DECLARE_EVENT_TABLE()
249 DECLARE_CLASS(wxDirFilterListCtrl)
250 wxDECLARE_NO_COPY_CLASS(wxDirFilterListCtrl);
251 };
252
253 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
254 #define wxDirCtrl wxGenericDirCtrl
255 #endif
256
257 // Symbols for accessing individual controls
258 #define wxID_TREECTRL 7000
259 #define wxID_FILTERLISTCTRL 7001
260
261 #endif // wxUSE_DIRDLG
262
263 //-------------------------------------------------------------------------
264 // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
265 //-------------------------------------------------------------------------
266
267 #if wxUSE_DIRDLG || wxUSE_FILEDLG || wxUSE_FILECTRL
268
269 class WXDLLIMPEXP_FWD_CORE wxImageList;
270
271 class WXDLLIMPEXP_CORE wxFileIconsTable
272 {
273 public:
274 wxFileIconsTable();
275 ~wxFileIconsTable();
276
277 enum iconId_Type
278 {
279 folder,
280 folder_open,
281 computer,
282 drive,
283 cdrom,
284 floppy,
285 removeable,
286 file,
287 executable
288 };
289
290 int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString);
291 wxImageList *GetSmallImageList();
292
293 protected:
294 void Create(); // create on first use
295
296 wxImageList *m_smallImageList;
297 wxHashTable *m_HashTable;
298 };
299
300 // The global fileicons table
301 extern WXDLLIMPEXP_DATA_CORE(wxFileIconsTable *) wxTheFileIconsTable;
302
303 #endif // wxUSE_DIRDLG || wxUSE_FILEDLG || wxUSE_FILECTRL
304
305 #endif
306 // _WX_DIRCTRLG_H_