1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/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
11 // Copyright: (c) Robert Roebling, Harm van der Heijden, Julian Smart
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
15 #ifndef _WX_DIRCTRL_H_
16 #define _WX_DIRCTRL_H_
20 #include "wx/treectrl.h"
21 #include "wx/dialog.h"
22 #include "wx/dirdlg.h"
23 #include "wx/choice.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
30 class WXDLLIMPEXP_FWD_BASE wxHashTable
;
32 //-----------------------------------------------------------------------------
33 // Extra styles for wxGenericDirCtrl
34 //-----------------------------------------------------------------------------
38 // Only allow directory viewing/selection, no files
39 wxDIRCTRL_DIR_ONLY
= 0x0010,
40 // When setting the default path, select the first file in the directory
41 wxDIRCTRL_SELECT_FIRST
= 0x0020,
42 // Show the filter list
43 wxDIRCTRL_SHOW_FILTERS
= 0x0040,
44 // Use 3D borders on internal controls
45 wxDIRCTRL_3D_INTERNAL
= 0x0080,
47 wxDIRCTRL_EDIT_LABELS
= 0x0100,
48 // Allow multiple selection
49 wxDIRCTRL_MULTIPLE
= 0x0200
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
56 class WXDLLIMPEXP_CORE wxDirItemData
: public wxTreeItemData
59 wxDirItemData(const wxString
& path
, const wxString
& name
, bool isDir
);
60 virtual ~wxDirItemData(){}
61 void SetNewDirName(const wxString
& path
);
63 bool HasSubDirs() const;
64 bool HasFiles(const wxString
& spec
= wxEmptyString
) const;
66 wxString m_path
, m_name
;
72 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
76 class WXDLLIMPEXP_FWD_CORE wxDirFilterListCtrl
;
78 class WXDLLIMPEXP_CORE wxGenericDirCtrl
: public wxControl
82 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= wxID_ANY
,
83 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
84 const wxPoint
& pos
= wxDefaultPosition
,
85 const wxSize
& size
= wxDefaultSize
,
86 long style
= wxDIRCTRL_3D_INTERNAL
,
87 const wxString
& filter
= wxEmptyString
,
88 int defaultFilter
= 0,
89 const wxString
& name
= wxTreeCtrlNameStr
)
92 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
95 bool Create(wxWindow
*parent
, const wxWindowID id
= wxID_ANY
,
96 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
97 const wxPoint
& pos
= wxDefaultPosition
,
98 const wxSize
& size
= wxDefaultSize
,
99 long style
= wxDIRCTRL_3D_INTERNAL
,
100 const wxString
& filter
= wxEmptyString
,
101 int defaultFilter
= 0,
102 const wxString
& name
= wxTreeCtrlNameStr
);
106 virtual ~wxGenericDirCtrl();
108 void OnExpandItem(wxTreeEvent
&event
);
109 void OnCollapseItem(wxTreeEvent
&event
);
110 void OnBeginEditItem(wxTreeEvent
&event
);
111 void OnEndEditItem(wxTreeEvent
&event
);
112 void OnTreeSelChange(wxTreeEvent
&event
);
113 void OnSize(wxSizeEvent
&event
);
115 // Try to expand as much of the given path as possible.
116 virtual bool ExpandPath(const wxString
& path
);
118 virtual bool CollapsePath(const wxString
& path
);
122 virtual inline wxString
GetDefaultPath() const { return m_defaultPath
; }
123 virtual void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
125 // Get dir or filename
126 virtual wxString
GetPath() const;
127 virtual void GetPaths(wxArrayString
& paths
) const;
129 // Get selected filename path only (else empty string).
130 // I.e. don't count a directory as a selection
131 virtual wxString
GetFilePath() const;
132 virtual void GetFilePaths(wxArrayString
& paths
) const;
133 virtual void SetPath(const wxString
& path
);
135 virtual void SelectPath(const wxString
& path
, bool select
= true);
136 virtual void SelectPaths(const wxArrayString
& paths
);
138 virtual void ShowHidden( bool show
);
139 virtual bool GetShowHidden() { return m_showHidden
; }
141 virtual wxString
GetFilter() const { return m_filter
; }
142 virtual void SetFilter(const wxString
& filter
);
144 virtual int GetFilterIndex() const { return m_currentFilter
; }
145 virtual void SetFilterIndex(int n
);
147 virtual wxTreeItemId
GetRootId() { return m_rootId
; }
149 virtual wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
150 virtual wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
152 virtual void UnselectAll();
155 virtual void SetupSections();
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
);
163 wxString
GetPath(wxTreeItemId itemId
) const;
165 // Resize the components of the control
166 virtual void DoResize();
168 // Collapse & expand the tree, thus re-creating it from scratch:
169 virtual void ReCreateTree();
171 // Collapse the entire tree
172 virtual void CollapseTree();
174 // overridden base class methods
175 virtual void SetFocus();
178 virtual void ExpandRoot();
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
);
186 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
187 virtual wxTreeCtrl
* CreateTreeCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long treeStyle
);
189 // Extract description and actual filter from overall filter string
190 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
193 void PopulateNode(wxTreeItemId node
);
194 wxDirItemData
* GetItemData(wxTreeItemId itemId
);
197 wxTreeItemId m_rootId
;
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
;
207 DECLARE_EVENT_TABLE()
208 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
209 wxDECLARE_NO_COPY_CLASS(wxGenericDirCtrl
);
212 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_COMMAND_DIRCTRL_CHANGED
, wxTreeEvent
);
214 #define wx__DECLARE_DIRCTRL_EVT(evt, id, fn) \
215 wx__DECLARE_EVT1(wxEVT_COMMAND_DIRCTRL_ ## evt, id, wxTreeEventHandler(fn))
217 #define EVT_DIRCTRL_CHANGED(id, fn) wx__DECLARE_DIRCTRL_EVT(CHANGED, id, fn)
219 //-----------------------------------------------------------------------------
220 // wxDirFilterListCtrl
221 //-----------------------------------------------------------------------------
223 class WXDLLIMPEXP_CORE wxDirFilterListCtrl
: public wxChoice
226 wxDirFilterListCtrl() { Init(); }
227 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
228 const wxPoint
& pos
= wxDefaultPosition
,
229 const wxSize
& size
= wxDefaultSize
,
233 Create(parent
, id
, pos
, size
, style
);
236 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
237 const wxPoint
& pos
= wxDefaultPosition
,
238 const wxSize
& size
= wxDefaultSize
,
243 virtual ~wxDirFilterListCtrl() {}
246 void FillFilterList(const wxString
& filter
, int defaultFilter
);
249 void OnSelFilter(wxCommandEvent
& event
);
252 wxGenericDirCtrl
* m_dirCtrl
;
254 DECLARE_EVENT_TABLE()
255 DECLARE_CLASS(wxDirFilterListCtrl
)
256 wxDECLARE_NO_COPY_CLASS(wxDirFilterListCtrl
);
259 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
260 #define wxDirCtrl wxGenericDirCtrl
263 // Symbols for accessing individual controls
264 #define wxID_TREECTRL 7000
265 #define wxID_FILTERLISTCTRL 7001
267 #endif // wxUSE_DIRDLG
269 //-------------------------------------------------------------------------
270 // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
271 //-------------------------------------------------------------------------
273 #if wxUSE_DIRDLG || wxUSE_FILEDLG || wxUSE_FILECTRL
275 class WXDLLIMPEXP_FWD_CORE wxImageList
;
277 class WXDLLIMPEXP_CORE wxFileIconsTable
296 int GetIconID(const wxString
& extension
, const wxString
& mime
= wxEmptyString
);
297 wxImageList
*GetSmallImageList();
300 void Create(); // create on first use
302 wxImageList
*m_smallImageList
;
303 wxHashTable
*m_HashTable
;
306 // The global fileicons table
307 extern WXDLLIMPEXP_DATA_CORE(wxFileIconsTable
*) wxTheFileIconsTable
;
309 #endif // wxUSE_DIRDLG || wxUSE_FILEDLG || wxUSE_FILECTRL