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
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 class WXDLLIMPEXP_CORE wxDirItemData
: public wxTreeItemData
64 wxDirItemData(const wxString
& path
, const wxString
& name
, bool isDir
);
65 virtual ~wxDirItemData(){}
66 void SetNewDirName(const wxString
& path
);
68 bool HasSubDirs() const;
69 bool HasFiles(const wxString
& spec
= wxEmptyString
) const;
71 wxString m_path
, m_name
;
77 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
81 class WXDLLIMPEXP_FWD_CORE wxDirFilterListCtrl
;
83 class WXDLLIMPEXP_CORE wxGenericDirCtrl
: public wxControl
87 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= wxID_ANY
,
88 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
89 const wxPoint
& pos
= wxDefaultPosition
,
90 const wxSize
& size
= wxDefaultSize
,
91 long style
= wxDIRCTRL_3D_INTERNAL
,
92 const wxString
& filter
= wxEmptyString
,
93 int defaultFilter
= 0,
94 const wxString
& name
= wxTreeCtrlNameStr
)
97 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
100 bool Create(wxWindow
*parent
, const wxWindowID id
= wxID_ANY
,
101 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
102 const wxPoint
& pos
= wxDefaultPosition
,
103 const wxSize
& size
= wxDefaultSize
,
104 long style
= wxDIRCTRL_3D_INTERNAL
,
105 const wxString
& filter
= wxEmptyString
,
106 int defaultFilter
= 0,
107 const wxString
& name
= wxTreeCtrlNameStr
);
111 virtual ~wxGenericDirCtrl();
113 void OnExpandItem(wxTreeEvent
&event
);
114 void OnCollapseItem(wxTreeEvent
&event
);
115 void OnBeginEditItem(wxTreeEvent
&event
);
116 void OnEndEditItem(wxTreeEvent
&event
);
117 void OnSize(wxSizeEvent
&event
);
119 // Try to expand as much of the given path as possible.
120 virtual bool ExpandPath(const wxString
& path
);
122 virtual bool CollapsePath(const wxString
& path
);
126 virtual inline wxString
GetDefaultPath() const { return m_defaultPath
; }
127 virtual void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
129 // Get dir or filename
130 virtual wxString
GetPath() const;
132 // Get selected filename path only (else empty string).
133 // I.e. don't count a directory as a selection
134 virtual wxString
GetFilePath() const;
135 virtual void SetPath(const wxString
& path
);
137 virtual void ShowHidden( bool show
);
138 virtual bool GetShowHidden() { return m_showHidden
; }
140 virtual wxString
GetFilter() const { return m_filter
; }
141 virtual void SetFilter(const wxString
& filter
);
143 virtual int GetFilterIndex() const { return m_currentFilter
; }
144 virtual void SetFilterIndex(int n
);
146 virtual wxTreeItemId
GetRootId() { return m_rootId
; }
148 virtual wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
149 virtual wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
152 virtual void SetupSections();
154 // Find the child that matches the first part of 'path'.
155 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
156 // then the child for /usr is returned.
157 // If the path string has been used (we're at the leaf), done is set to true
158 virtual wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
160 // Resize the components of the control
161 virtual void DoResize();
163 // Collapse & expand the tree, thus re-creating it from scratch:
164 virtual void ReCreateTree();
166 // Collapse the entire tree
167 virtual void CollapseTree();
170 // overridden base class methods
171 virtual void SetFocus();
174 virtual void ExpandRoot();
175 virtual void ExpandDir(wxTreeItemId parentId
);
176 virtual void CollapseDir(wxTreeItemId parentId
);
177 virtual const wxTreeItemId
AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
178 virtual wxTreeItemId
AppendItem (const wxTreeItemId
& parent
,
179 const wxString
& text
,
180 int image
= -1, int selectedImage
= -1,
181 wxTreeItemData
* data
= NULL
);
182 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
183 virtual wxTreeCtrl
* CreateTreeCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long treeStyle
);
185 // Extract description and actual filter from overall filter string
186 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
190 wxTreeItemId m_rootId
;
191 wxString m_defaultPath
; // Starting path
192 long m_styleEx
; // Extended style
193 wxString m_filter
; // Wildcards in same format as per wxFileDialog
194 int m_currentFilter
; // The current filter index
195 wxString m_currentFilterStr
; // Current filter string
196 wxTreeCtrl
* m_treeCtrl
;
197 wxDirFilterListCtrl
* m_filterListCtrl
;
200 DECLARE_EVENT_TABLE()
201 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
202 DECLARE_NO_COPY_CLASS(wxGenericDirCtrl
)
205 //-----------------------------------------------------------------------------
206 // wxDirFilterListCtrl
207 //-----------------------------------------------------------------------------
209 class WXDLLIMPEXP_CORE wxDirFilterListCtrl
: public wxChoice
212 wxDirFilterListCtrl() { Init(); }
213 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
214 const wxPoint
& pos
= wxDefaultPosition
,
215 const wxSize
& size
= wxDefaultSize
,
219 Create(parent
, id
, pos
, size
, style
);
222 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
223 const wxPoint
& pos
= wxDefaultPosition
,
224 const wxSize
& size
= wxDefaultSize
,
229 virtual ~wxDirFilterListCtrl() {}
232 void FillFilterList(const wxString
& filter
, int defaultFilter
);
235 void OnSelFilter(wxCommandEvent
& event
);
238 wxGenericDirCtrl
* m_dirCtrl
;
240 DECLARE_EVENT_TABLE()
241 DECLARE_CLASS(wxDirFilterListCtrl
)
242 DECLARE_NO_COPY_CLASS(wxDirFilterListCtrl
)
245 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
246 #define wxDirCtrl wxGenericDirCtrl
249 // Symbols for accessing individual controls
250 #define wxID_TREECTRL 7000
251 #define wxID_FILTERLISTCTRL 7001
253 #endif // wxUSE_DIRDLG
255 //-------------------------------------------------------------------------
256 // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
257 //-------------------------------------------------------------------------
259 #if wxUSE_DIRDLG || wxUSE_FILEDLG
261 class WXDLLIMPEXP_CORE wxFileIconsTable
280 int GetIconID(const wxString
& extension
, const wxString
& mime
= wxEmptyString
);
281 wxImageList
*GetSmallImageList();
284 void Create(); // create on first use
286 wxImageList
*m_smallImageList
;
287 wxHashTable
*m_HashTable
;
290 // The global fileicons table
291 extern WXDLLIMPEXP_DATA_CORE(wxFileIconsTable
*) wxTheFileIconsTable
;
293 #endif // wxUSE_DIRDLG || wxUSE_FILEDLG