1 /////////////////////////////////////////////////////////////////////////////
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_
18 #if wxUSE_DIRDLG || wxUSE_FILEDLG
19 #include "wx/imaglist.h"
24 #include "wx/treectrl.h"
25 #include "wx/dialog.h"
26 #include "wx/dirdlg.h"
27 #include "wx/choice.h"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
34 class WXDLLIMPEXP_FWD_CORE wxImageList
;
35 class WXDLLIMPEXP_FWD_BASE wxHashTable
;
37 //-----------------------------------------------------------------------------
38 // Extra styles for wxGenericDirCtrl
39 //-----------------------------------------------------------------------------
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 #if WXWIN_COMPATIBILITY_2_8
48 // Unused, for compatibility only
49 wxDIRCTRL_SHOW_FILTERS
= 0x0040,
50 #endif // WXWIN_COMPATIBILITY_2_8
51 // Use 3D borders on internal controls
52 wxDIRCTRL_3D_INTERNAL
= 0x0080,
54 wxDIRCTRL_EDIT_LABELS
= 0x0100,
55 // Allow multiple selection
56 wxDIRCTRL_MULTIPLE
= 0x0200
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 class WXDLLIMPEXP_CORE wxDirItemData
: public wxTreeItemData
66 wxDirItemData(const wxString
& path
, const wxString
& name
, bool isDir
);
67 virtual ~wxDirItemData(){}
68 void SetNewDirName(const wxString
& path
);
70 bool HasSubDirs() const;
71 bool HasFiles(const wxString
& spec
= wxEmptyString
) const;
73 wxString m_path
, m_name
;
79 //-----------------------------------------------------------------------------
81 //-----------------------------------------------------------------------------
83 class WXDLLIMPEXP_FWD_CORE wxDirFilterListCtrl
;
85 class WXDLLIMPEXP_CORE wxGenericDirCtrl
: public wxControl
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
,
94 const wxString
& filter
= wxEmptyString
,
95 int defaultFilter
= 0,
96 const wxString
& name
= wxTreeCtrlNameStr
)
99 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
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
,
107 const wxString
& filter
= wxEmptyString
,
108 int defaultFilter
= 0,
109 const wxString
& name
= wxTreeCtrlNameStr
);
113 virtual ~wxGenericDirCtrl();
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
);
121 // Try to expand as much of the given path as possible.
122 virtual bool ExpandPath(const wxString
& path
);
124 virtual bool CollapsePath(const wxString
& path
);
128 virtual inline wxString
GetDefaultPath() const { return m_defaultPath
; }
129 virtual void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
131 // Get dir or filename
132 virtual wxString
GetPath() const;
133 virtual void GetPaths(wxArrayString
& paths
) const;
135 // Get selected filename path only (else empty string).
136 // I.e. don't count a directory as a selection
137 virtual wxString
GetFilePath() const;
138 virtual void GetFilePaths(wxArrayString
& paths
) const;
139 virtual void SetPath(const wxString
& path
);
141 virtual void SelectPath(const wxString
& path
, bool select
= true);
142 virtual void SelectPaths(const wxArrayString
& paths
);
144 virtual void ShowHidden( bool show
);
145 virtual bool GetShowHidden() { return m_showHidden
; }
147 virtual wxString
GetFilter() const { return m_filter
; }
148 virtual void SetFilter(const wxString
& filter
);
150 virtual int GetFilterIndex() const { return m_currentFilter
; }
151 virtual void SetFilterIndex(int n
);
153 virtual wxTreeItemId
GetRootId() { return m_rootId
; }
155 virtual wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
156 virtual wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
158 virtual void UnselectAll();
161 virtual void SetupSections();
163 // Find the child that matches the first part of 'path'.
164 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
165 // then the child for /usr is returned.
166 // If the path string has been used (we're at the leaf), done is set to true
167 virtual wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
169 // Resize the components of the control
170 virtual void DoResize();
172 // Collapse & expand the tree, thus re-creating it from scratch:
173 virtual void ReCreateTree();
175 // Collapse the entire tree
176 virtual void CollapseTree();
178 // overridden base class methods
179 virtual void SetFocus();
182 virtual void ExpandRoot();
183 virtual void ExpandDir(wxTreeItemId parentId
);
184 virtual void CollapseDir(wxTreeItemId parentId
);
185 virtual const wxTreeItemId
AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
186 virtual wxTreeItemId
AppendItem (const wxTreeItemId
& parent
,
187 const wxString
& text
,
188 int image
= -1, int selectedImage
= -1,
189 wxTreeItemData
* data
= NULL
);
190 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
191 virtual wxTreeCtrl
* CreateTreeCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long treeStyle
);
193 // Extract description and actual filter from overall filter string
194 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
198 wxTreeItemId m_rootId
;
199 wxString m_defaultPath
; // Starting path
200 long m_styleEx
; // Extended style
201 wxString m_filter
; // Wildcards in same format as per wxFileDialog
202 int m_currentFilter
; // The current filter index
203 wxString m_currentFilterStr
; // Current filter string
204 wxTreeCtrl
* m_treeCtrl
;
205 wxDirFilterListCtrl
* m_filterListCtrl
;
208 DECLARE_EVENT_TABLE()
209 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
210 wxDECLARE_NO_COPY_CLASS(wxGenericDirCtrl
);
213 //-----------------------------------------------------------------------------
214 // wxDirFilterListCtrl
215 //-----------------------------------------------------------------------------
217 class WXDLLIMPEXP_CORE wxDirFilterListCtrl
: public wxChoice
220 wxDirFilterListCtrl() { Init(); }
221 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
222 const wxPoint
& pos
= wxDefaultPosition
,
223 const wxSize
& size
= wxDefaultSize
,
227 Create(parent
, id
, pos
, size
, style
);
230 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
231 const wxPoint
& pos
= wxDefaultPosition
,
232 const wxSize
& size
= wxDefaultSize
,
237 virtual ~wxDirFilterListCtrl() {}
240 void FillFilterList(const wxString
& filter
, int defaultFilter
);
243 void OnSelFilter(wxCommandEvent
& event
);
246 wxGenericDirCtrl
* m_dirCtrl
;
248 DECLARE_EVENT_TABLE()
249 DECLARE_CLASS(wxDirFilterListCtrl
)
250 wxDECLARE_NO_COPY_CLASS(wxDirFilterListCtrl
);
253 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
254 #define wxDirCtrl wxGenericDirCtrl
257 // Symbols for accessing individual controls
258 #define wxID_TREECTRL 7000
259 #define wxID_FILTERLISTCTRL 7001
261 #endif // wxUSE_DIRDLG
263 //-------------------------------------------------------------------------
264 // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
265 //-------------------------------------------------------------------------
267 #if wxUSE_DIRDLG || wxUSE_FILEDLG
269 class WXDLLIMPEXP_CORE wxFileIconsTable
288 int GetIconID(const wxString
& extension
, const wxString
& mime
= wxEmptyString
);
289 wxImageList
*GetSmallImageList();
292 void Create(); // create on first use
294 wxImageList
*m_smallImageList
;
295 wxHashTable
*m_HashTable
;
298 // The global fileicons table
299 extern WXDLLIMPEXP_DATA_CORE(wxFileIconsTable
*) wxTheFileIconsTable
;
301 #endif // wxUSE_DIRDLG || wxUSE_FILEDLG