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 #if WXWIN_COMPATIBILITY_2_8
43 // Unused, for compatibility only
44 wxDIRCTRL_SHOW_FILTERS
= 0x0040,
45 #endif // WXWIN_COMPATIBILITY_2_8
46 // Use 3D borders on internal controls
47 wxDIRCTRL_3D_INTERNAL
= 0x0080,
49 wxDIRCTRL_EDIT_LABELS
= 0x0100,
50 // Allow multiple selection
51 wxDIRCTRL_MULTIPLE
= 0x0200
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 class WXDLLIMPEXP_CORE wxDirItemData
: public wxTreeItemData
61 wxDirItemData(const wxString
& path
, const wxString
& name
, bool isDir
);
62 virtual ~wxDirItemData(){}
63 void SetNewDirName(const wxString
& path
);
65 bool HasSubDirs() const;
66 bool HasFiles(const wxString
& spec
= wxEmptyString
) const;
68 wxString m_path
, m_name
;
74 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
78 class WXDLLIMPEXP_FWD_CORE wxDirFilterListCtrl
;
80 class WXDLLIMPEXP_CORE wxGenericDirCtrl
: public wxControl
84 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= wxID_ANY
,
85 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
86 const wxPoint
& pos
= wxDefaultPosition
,
87 const wxSize
& size
= wxDefaultSize
,
88 long style
= wxDIRCTRL_3D_INTERNAL
,
89 const wxString
& filter
= wxEmptyString
,
90 int defaultFilter
= 0,
91 const wxString
& name
= wxTreeCtrlNameStr
)
94 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
97 bool Create(wxWindow
*parent
, const wxWindowID id
= wxID_ANY
,
98 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
99 const wxPoint
& pos
= wxDefaultPosition
,
100 const wxSize
& size
= wxDefaultSize
,
101 long style
= wxDIRCTRL_3D_INTERNAL
,
102 const wxString
& filter
= wxEmptyString
,
103 int defaultFilter
= 0,
104 const wxString
& name
= wxTreeCtrlNameStr
);
108 virtual ~wxGenericDirCtrl();
110 void OnExpandItem(wxTreeEvent
&event
);
111 void OnCollapseItem(wxTreeEvent
&event
);
112 void OnBeginEditItem(wxTreeEvent
&event
);
113 void OnEndEditItem(wxTreeEvent
&event
);
114 void OnTreeSelChange(wxTreeEvent
&event
);
115 void OnSize(wxSizeEvent
&event
);
117 // Try to expand as much of the given path as possible.
118 virtual bool ExpandPath(const wxString
& path
);
120 virtual bool CollapsePath(const wxString
& path
);
124 virtual inline wxString
GetDefaultPath() const { return m_defaultPath
; }
125 virtual void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
127 // Get dir or filename
128 virtual wxString
GetPath() const;
129 virtual void GetPaths(wxArrayString
& paths
) const;
131 // Get selected filename path only (else empty string).
132 // I.e. don't count a directory as a selection
133 virtual wxString
GetFilePath() const;
134 virtual void GetFilePaths(wxArrayString
& paths
) const;
135 virtual void SetPath(const wxString
& path
);
137 virtual void SelectPath(const wxString
& path
, bool select
= true);
138 virtual void SelectPaths(const wxArrayString
& paths
);
140 virtual void ShowHidden( bool show
);
141 virtual bool GetShowHidden() { return m_showHidden
; }
143 virtual wxString
GetFilter() const { return m_filter
; }
144 virtual void SetFilter(const wxString
& filter
);
146 virtual int GetFilterIndex() const { return m_currentFilter
; }
147 virtual void SetFilterIndex(int n
);
149 virtual wxTreeItemId
GetRootId() { return m_rootId
; }
151 virtual wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
152 virtual wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
154 virtual void UnselectAll();
157 virtual void SetupSections();
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
);
165 wxString
GetPath(wxTreeItemId itemId
) const;
167 // Resize the components of the control
168 virtual void DoResize();
170 // Collapse & expand the tree, thus re-creating it from scratch:
171 virtual void ReCreateTree();
173 // Collapse the entire tree
174 virtual void CollapseTree();
176 // overridden base class methods
177 virtual void SetFocus();
180 virtual void ExpandRoot();
181 virtual void ExpandDir(wxTreeItemId parentId
);
182 virtual void CollapseDir(wxTreeItemId parentId
);
183 virtual const wxTreeItemId
AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
184 virtual wxTreeItemId
AppendItem (const wxTreeItemId
& parent
,
185 const wxString
& text
,
186 int image
= -1, int selectedImage
= -1,
187 wxTreeItemData
* data
= NULL
);
188 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
189 virtual wxTreeCtrl
* CreateTreeCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long treeStyle
);
191 // Extract description and actual filter from overall filter string
192 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
195 void PopulateNode(wxTreeItemId node
);
196 wxDirItemData
* GetItemData(wxTreeItemId itemId
);
199 wxTreeItemId m_rootId
;
200 wxString m_defaultPath
; // Starting path
201 long m_styleEx
; // Extended style
202 wxString m_filter
; // Wildcards in same format as per wxFileDialog
203 int m_currentFilter
; // The current filter index
204 wxString m_currentFilterStr
; // Current filter string
205 wxTreeCtrl
* m_treeCtrl
;
206 wxDirFilterListCtrl
* m_filterListCtrl
;
209 DECLARE_EVENT_TABLE()
210 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
211 wxDECLARE_NO_COPY_CLASS(wxGenericDirCtrl
);
214 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_COMMAND_DIRCTRL_CHANGED
, wxTreeEvent
);
216 #define wx__DECLARE_DIRCTRL_EVT(evt, id, fn) \
217 wx__DECLARE_EVT1(wxEVT_COMMAND_DIRCTRL_ ## evt, id, wxTreeEventHandler(fn))
219 #define EVT_DIRCTRL_CHANGED(id, fn) wx__DECLARE_DIRCTRL_EVT(CHANGED, id, fn)
221 //-----------------------------------------------------------------------------
222 // wxDirFilterListCtrl
223 //-----------------------------------------------------------------------------
225 class WXDLLIMPEXP_CORE wxDirFilterListCtrl
: public wxChoice
228 wxDirFilterListCtrl() { Init(); }
229 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
230 const wxPoint
& pos
= wxDefaultPosition
,
231 const wxSize
& size
= wxDefaultSize
,
235 Create(parent
, id
, pos
, size
, style
);
238 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
239 const wxPoint
& pos
= wxDefaultPosition
,
240 const wxSize
& size
= wxDefaultSize
,
245 virtual ~wxDirFilterListCtrl() {}
248 void FillFilterList(const wxString
& filter
, int defaultFilter
);
251 void OnSelFilter(wxCommandEvent
& event
);
254 wxGenericDirCtrl
* m_dirCtrl
;
256 DECLARE_EVENT_TABLE()
257 DECLARE_CLASS(wxDirFilterListCtrl
)
258 wxDECLARE_NO_COPY_CLASS(wxDirFilterListCtrl
);
261 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
262 #define wxDirCtrl wxGenericDirCtrl
265 // Symbols for accessing individual controls
266 #define wxID_TREECTRL 7000
267 #define wxID_FILTERLISTCTRL 7001
269 #endif // wxUSE_DIRDLG
271 //-------------------------------------------------------------------------
272 // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
273 //-------------------------------------------------------------------------
275 #if wxUSE_DIRDLG || wxUSE_FILEDLG || wxUSE_FILECTRL
277 class WXDLLIMPEXP_FWD_CORE wxImageList
;
279 class WXDLLIMPEXP_CORE wxFileIconsTable
298 int GetIconID(const wxString
& extension
, const wxString
& mime
= wxEmptyString
);
299 wxImageList
*GetSmallImageList();
302 void Create(); // create on first use
304 wxImageList
*m_smallImageList
;
305 wxHashTable
*m_HashTable
;
308 // The global fileicons table
309 extern WXDLLIMPEXP_DATA_CORE(wxFileIconsTable
*) wxTheFileIconsTable
;
311 #endif // wxUSE_DIRDLG || wxUSE_FILEDLG || wxUSE_FILECTRL