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