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