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