]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dirctrlg.h
compilation fix (extra semicolon)
[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 defined(__GNUG__) && !defined(__APPLE__)
19 #pragma interface "dirctrlg.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 WXDLLEXPORT wxTextCtrl;
34 class WXDLLEXPORT wxImageList;
35 class WXDLLEXPORT 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 ~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 = -1,
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 = -1,
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
120 // Accessors
121
122 virtual inline wxString GetDefaultPath() const { return m_defaultPath; }
123 virtual void SetDefaultPath(const wxString& path) { m_defaultPath = path; }
124
125 // Get dir or filename
126 virtual wxString GetPath() const;
127
128 // Get selected filename path only (else empty string).
129 // I.e. don't count a directory as a selection
130 virtual wxString GetFilePath() const;
131 virtual void SetPath(const wxString& path);
132
133 virtual void ShowHidden( bool show );
134 virtual bool GetShowHidden() { return m_showHidden; }
135
136 virtual wxString GetFilter() const { return m_filter; }
137 virtual void SetFilter(const wxString& filter);
138
139 virtual int GetFilterIndex() const { return m_currentFilter; }
140 virtual void SetFilterIndex(int n);
141
142 virtual wxTreeItemId GetRootId() { return m_rootId; }
143
144 virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
145 virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
146
147 // Helper
148 virtual void SetupSections();
149
150 // Parse the filter into an array of filters and an array of descriptions
151 virtual int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
152
153 // Find the child that matches the first part of 'path'.
154 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
155 // then the child for /usr is returned.
156 // If the path string has been used (we're at the leaf), done is set to TRUE
157 virtual wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
158
159 // Resize the components of the control
160 virtual void DoResize();
161
162 // Collapse & expand the tree, thus re-creating it from scratch:
163 virtual void ReCreateTree();
164
165 protected:
166 virtual void ExpandDir(wxTreeItemId parentId);
167 virtual void CollapseDir(wxTreeItemId parentId);
168 virtual const wxTreeItemId AddSection(const wxString& path, const wxString& name, int imageId = 0);
169 virtual wxTreeItemId AppendItem (const wxTreeItemId & parent,
170 const wxString & text,
171 int image = -1, int selectedImage = -1,
172 wxTreeItemData * data = NULL);
173 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
174
175 // Extract description and actual filter from overall filter string
176 bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
177
178 private:
179 bool m_showHidden;
180 wxTreeItemId m_rootId;
181 wxString m_defaultPath; // Starting path
182 long m_styleEx; // Extended style
183 wxString m_filter; // Wildcards in same format as per wxFileDialog
184 int m_currentFilter; // The current filter index
185 wxString m_currentFilterStr; // Current filter string
186 wxTreeCtrl* m_treeCtrl;
187 wxDirFilterListCtrl* m_filterListCtrl;
188
189 private:
190 DECLARE_EVENT_TABLE()
191 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
192 DECLARE_NO_COPY_CLASS(wxGenericDirCtrl)
193 };
194
195 //-----------------------------------------------------------------------------
196 // wxDirFilterListCtrl
197 //-----------------------------------------------------------------------------
198
199 class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice
200 {
201 public:
202 wxDirFilterListCtrl() { Init(); }
203 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
204 const wxPoint& pos = wxDefaultPosition,
205 const wxSize& size = wxDefaultSize,
206 long style = 0)
207 {
208 Init();
209 Create(parent, id, pos, size, style);
210 }
211
212 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
213 const wxPoint& pos = wxDefaultPosition,
214 const wxSize& size = wxDefaultSize,
215 long style = 0);
216
217 void Init();
218
219 ~wxDirFilterListCtrl() {};
220
221 //// Operations
222 void FillFilterList(const wxString& filter, int defaultFilter);
223
224 //// Events
225 void OnSelFilter(wxCommandEvent& event);
226
227 protected:
228 wxGenericDirCtrl* m_dirCtrl;
229
230 DECLARE_EVENT_TABLE()
231 DECLARE_CLASS(wxDirFilterListCtrl)
232 DECLARE_NO_COPY_CLASS(wxDirFilterListCtrl)
233 };
234
235 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
236 #define wxDirCtrl wxGenericDirCtrl
237 #endif
238
239 // Symbols for accessing individual controls
240 #define wxID_TREECTRL 7000
241 #define wxID_FILTERLISTCTRL 7001
242
243 //-------------------------------------------------------------------------
244 // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
245 //-------------------------------------------------------------------------
246
247 class WXDLLEXPORT wxFileIconsTable
248 {
249 public:
250 wxFileIconsTable();
251 ~wxFileIconsTable();
252
253 enum iconId_Type
254 {
255 folder,
256 folder_open,
257 computer,
258 drive,
259 cdrom,
260 floppy,
261 removeable,
262 file,
263 executable
264 };
265
266 int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString);
267 wxImageList *GetSmallImageList();
268
269 protected:
270 void Create(); // create on first use
271
272 wxImageList *m_smallImageList;
273 wxHashTable *m_HashTable;
274 };
275
276 // The global fileicons table
277 WXDLLEXPORT_DATA(extern wxFileIconsTable *) wxTheFileIconsTable;
278
279 #endif // wxUSE_DIRDLG
280
281 #endif
282 // _WX_DIRCTRLG_H_