]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dirctrlg.h
wxXML load/save improvements: added ability to not ignore whitespace and specify...
[wxWidgets.git] / include / wx / generic / dirctrlg.h
CommitLineData
51a58d8b
JS
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.
748fcded 7// Author: Robert Roebling, Harm van der Heijden, Julian Smart et al
51a58d8b
JS
8// Modified by:
9// Created: 21/3/2000
10// RCS-ID: $Id$
748fcded 11// Copyright: (c) Robert Roebling, Harm van der Heijden, Julian Smart
65571936 12// Licence: wxWindows licence
51a58d8b
JS
13/////////////////////////////////////////////////////////////////////////////
14
15#ifndef _WX_DIRCTRL_H_
16#define _WX_DIRCTRL_H_
17
13de0c8c
WS
18#if wxUSE_DIRDLG || wxUSE_FILEDLG
19 #include "wx/imaglist.h"
20#endif
21
1e6feb95
VZ
22#if wxUSE_DIRDLG
23
51a58d8b 24#include "wx/treectrl.h"
748fcded 25#include "wx/dialog.h"
3509d340
VS
26#include "wx/dirdlg.h"
27#include "wx/choice.h"
51a58d8b
JS
28
29//-----------------------------------------------------------------------------
30// classes
31//-----------------------------------------------------------------------------
32
62a9d04c
VS
33class WXDLLIMPEXP_CORE wxTextCtrl;
34class WXDLLIMPEXP_CORE wxImageList;
35class WXDLLIMPEXP_BASE wxHashTable;
748fcded 36
51a58d8b
JS
37//-----------------------------------------------------------------------------
38// Extra styles for wxGenericDirCtrl
39//-----------------------------------------------------------------------------
40
748fcded
VS
41enum
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
fd775aae
JS
50 wxDIRCTRL_3D_INTERNAL = 0x0080,
51 // Editable labels
dabd1377 52 wxDIRCTRL_EDIT_LABELS = 0x0100
748fcded 53};
51a58d8b
JS
54
55//-----------------------------------------------------------------------------
56// wxDirItemData
57//-----------------------------------------------------------------------------
58
748fcded 59class WXDLLEXPORT wxDirItemData : public wxTreeItemData
51a58d8b
JS
60{
61public:
748fcded 62 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
d3c7fc99 63 virtual ~wxDirItemData(){}
748fcded
VS
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;
51a58d8b
JS
73};
74
75//-----------------------------------------------------------------------------
76// wxDirCtrl
77//-----------------------------------------------------------------------------
78
79class WXDLLEXPORT wxDirFilterListCtrl;
80
81class WXDLLEXPORT wxGenericDirCtrl: public wxControl
82{
83public:
84 wxGenericDirCtrl();
ca65c044 85 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = wxID_ANY,
51a58d8b
JS
86 const wxString &dir = wxDirDialogDefaultFolderStr,
87 const wxPoint& pos = wxDefaultPosition,
88 const wxSize& size = wxDefaultSize,
f9c165b1 89 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
51a58d8b
JS
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 }
ca65c044
WS
97
98 bool Create(wxWindow *parent, const wxWindowID id = wxID_ANY,
51a58d8b
JS
99 const wxString &dir = wxDirDialogDefaultFolderStr,
100 const wxPoint& pos = wxDefaultPosition,
101 const wxSize& size = wxDefaultSize,
f9c165b1 102 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
51a58d8b
JS
103 const wxString& filter = wxEmptyString,
104 int defaultFilter = 0,
105 const wxString& name = wxTreeCtrlNameStr );
106
2b5f62a0 107 virtual void Init();
51a58d8b 108
2b5f62a0 109 virtual ~wxGenericDirCtrl();
51a58d8b
JS
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.
2b5f62a0 118 virtual bool ExpandPath(const wxString& path);
f395a825
VZ
119 // collapse the path
120 virtual bool CollapsePath(const wxString& path);
51a58d8b
JS
121
122 // Accessors
123
2b5f62a0
VZ
124 virtual inline wxString GetDefaultPath() const { return m_defaultPath; }
125 virtual void SetDefaultPath(const wxString& path) { m_defaultPath = path; }
51a58d8b 126
51a58d8b 127 // Get dir or filename
2b5f62a0 128 virtual wxString GetPath() const;
ca65c044 129
51a58d8b
JS
130 // Get selected filename path only (else empty string).
131 // I.e. don't count a directory as a selection
2b5f62a0
VZ
132 virtual wxString GetFilePath() const;
133 virtual void SetPath(const wxString& path);
ca65c044 134
2b5f62a0
VZ
135 virtual void ShowHidden( bool show );
136 virtual bool GetShowHidden() { return m_showHidden; }
51a58d8b 137
2b5f62a0
VZ
138 virtual wxString GetFilter() const { return m_filter; }
139 virtual void SetFilter(const wxString& filter);
51a58d8b 140
2b5f62a0
VZ
141 virtual int GetFilterIndex() const { return m_currentFilter; }
142 virtual void SetFilterIndex(int n);
51a58d8b 143
2b5f62a0 144 virtual wxTreeItemId GetRootId() { return m_rootId; }
51a58d8b 145
2b5f62a0
VZ
146 virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
147 virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
51a58d8b 148
42dcacf0 149 // Helper
2b5f62a0 150 virtual void SetupSections();
ca65c044 151
9e152a55 152#if WXWIN_COMPATIBILITY_2_4
51a58d8b 153 // Parse the filter into an array of filters and an array of descriptions
2b5f62a0 154 virtual int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
9e152a55 155#endif // WXWIN_COMPATIBILITY_2_4
ca65c044 156
51a58d8b
JS
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.
ca65c044 160 // If the path string has been used (we're at the leaf), done is set to true
2b5f62a0 161 virtual wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
ca65c044 162
51a58d8b 163 // Resize the components of the control
2b5f62a0 164 virtual void DoResize();
ca65c044 165
08887820 166 // Collapse & expand the tree, thus re-creating it from scratch:
2b5f62a0 167 virtual void ReCreateTree();
ca65c044 168
c06dde42
JS
169 // Collapse the entire tree
170 virtual void CollapseTree();
171
51a58d8b 172protected:
c06dde42 173 virtual void ExpandRoot();
22328fa4
JS
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);
51a58d8b 181 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
a78955e3 182 virtual wxTreeCtrl* CreateTreeCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long treeStyle);
51a58d8b
JS
183
184 // Extract description and actual filter from overall filter string
185 bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
186
187private:
188 bool m_showHidden;
189 wxTreeItemId m_rootId;
51a58d8b
JS
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
198private:
199 DECLARE_EVENT_TABLE()
200 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
22f3361e 201 DECLARE_NO_COPY_CLASS(wxGenericDirCtrl)
51a58d8b
JS
202};
203
204//-----------------------------------------------------------------------------
205// wxDirFilterListCtrl
206//-----------------------------------------------------------------------------
207
208class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice
209{
210public:
211 wxDirFilterListCtrl() { Init(); }
ca65c044 212 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
51a58d8b
JS
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 }
ca65c044
WS
220
221 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
51a58d8b
JS
222 const wxPoint& pos = wxDefaultPosition,
223 const wxSize& size = wxDefaultSize,
224 long style = 0);
225
226 void Init();
227
d3c7fc99 228 virtual ~wxDirFilterListCtrl() {}
51a58d8b 229
748fcded 230 //// Operations
51a58d8b
JS
231 void FillFilterList(const wxString& filter, int defaultFilter);
232
748fcded 233 //// Events
51a58d8b
JS
234 void OnSelFilter(wxCommandEvent& event);
235
236protected:
237 wxGenericDirCtrl* m_dirCtrl;
238
239 DECLARE_EVENT_TABLE()
240 DECLARE_CLASS(wxDirFilterListCtrl)
22f3361e 241 DECLARE_NO_COPY_CLASS(wxDirFilterListCtrl)
51a58d8b
JS
242};
243
748fcded
VS
244#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
245 #define wxDirCtrl wxGenericDirCtrl
246#endif
51a58d8b 247
a977709b
JS
248// Symbols for accessing individual controls
249#define wxID_TREECTRL 7000
250#define wxID_FILTERLISTCTRL 7001
251
13de0c8c
WS
252#endif // wxUSE_DIRDLG
253
06cc1fb9
JS
254//-------------------------------------------------------------------------
255// wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
256//-------------------------------------------------------------------------
257
13de0c8c
WS
258#if wxUSE_DIRDLG || wxUSE_FILEDLG
259
06cc1fb9
JS
260class WXDLLEXPORT wxFileIconsTable
261{
262public:
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
282protected:
283 void Create(); // create on first use
284
285 wxImageList *m_smallImageList;
286 wxHashTable *m_HashTable;
287};
288
289// The global fileicons table
f4fffffc 290extern WXDLLEXPORT_DATA(wxFileIconsTable *) wxTheFileIconsTable;
06cc1fb9 291
13de0c8c 292#endif // wxUSE_DIRDLG || wxUSE_FILEDLG
1e6feb95 293
51a58d8b
JS
294#endif
295 // _WX_DIRCTRLG_H_