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 defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
19 #pragma interface "dirctrlg.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_CORE wxTextCtrl
;
34 class WXDLLIMPEXP_CORE wxImageList
;
35 class WXDLLIMPEXP_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 // Show the filter list
48 wxDIRCTRL_SHOW_FILTERS
= 0x0040,
49 // Use 3D borders on internal controls
50 wxDIRCTRL_3D_INTERNAL
= 0x0080,
52 wxDIRCTRL_EDIT_LABELS
= 0x0100
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
59 class WXDLLEXPORT wxDirItemData
: public wxTreeItemData
62 wxDirItemData(const wxString
& path
, const wxString
& name
, bool isDir
);
64 void SetNewDirName(const wxString
& path
);
66 bool HasSubDirs() const;
67 bool HasFiles(const wxString
& spec
= wxEmptyString
) const;
69 wxString m_path
, m_name
;
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
79 class WXDLLEXPORT wxDirFilterListCtrl
;
81 class WXDLLEXPORT wxGenericDirCtrl
: public wxControl
85 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= wxID_ANY
,
86 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
87 const wxPoint
& pos
= wxDefaultPosition
,
88 const wxSize
& size
= wxDefaultSize
,
89 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
90 const wxString
& filter
= wxEmptyString
,
91 int defaultFilter
= 0,
92 const wxString
& name
= wxTreeCtrlNameStr
)
95 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
98 bool Create(wxWindow
*parent
, const wxWindowID id
= wxID_ANY
,
99 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
100 const wxPoint
& pos
= wxDefaultPosition
,
101 const wxSize
& size
= wxDefaultSize
,
102 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
103 const wxString
& filter
= wxEmptyString
,
104 int defaultFilter
= 0,
105 const wxString
& name
= wxTreeCtrlNameStr
);
109 virtual ~wxGenericDirCtrl();
111 void OnExpandItem(wxTreeEvent
&event
);
112 void OnCollapseItem(wxTreeEvent
&event
);
113 void OnBeginEditItem(wxTreeEvent
&event
);
114 void OnEndEditItem(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
);
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;
128 // Get selected filename path only (else empty string).
129 // I.e. don't count a directory as a selection
130 virtual wxString
GetFilePath() const;
131 virtual void SetPath(const wxString
& path
);
133 virtual void ShowHidden( bool show
);
134 virtual bool GetShowHidden() { return m_showHidden
; }
136 virtual wxString
GetFilter() const { return m_filter
; }
137 virtual void SetFilter(const wxString
& filter
);
139 virtual int GetFilterIndex() const { return m_currentFilter
; }
140 virtual void SetFilterIndex(int n
);
142 virtual wxTreeItemId
GetRootId() { return m_rootId
; }
144 virtual wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
145 virtual wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
148 virtual void SetupSections();
150 #if WXWIN_COMPATIBILITY_2_4
151 // Parse the filter into an array of filters and an array of descriptions
152 virtual int ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
);
153 #endif // WXWIN_COMPATIBILITY_2_4
155 // Find the child that matches the first part of 'path'.
156 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
157 // then the child for /usr is returned.
158 // If the path string has been used (we're at the leaf), done is set to true
159 virtual wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
161 // Resize the components of the control
162 virtual void DoResize();
164 // Collapse & expand the tree, thus re-creating it from scratch:
165 virtual void ReCreateTree();
168 virtual void ExpandDir(wxTreeItemId parentId
);
169 virtual void CollapseDir(wxTreeItemId parentId
);
170 virtual const wxTreeItemId
AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
171 virtual wxTreeItemId
AppendItem (const wxTreeItemId
& parent
,
172 const wxString
& text
,
173 int image
= -1, int selectedImage
= -1,
174 wxTreeItemData
* data
= NULL
);
175 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
177 // Extract description and actual filter from overall filter string
178 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
182 wxTreeItemId m_rootId
;
183 wxString m_defaultPath
; // Starting path
184 long m_styleEx
; // Extended style
185 wxString m_filter
; // Wildcards in same format as per wxFileDialog
186 int m_currentFilter
; // The current filter index
187 wxString m_currentFilterStr
; // Current filter string
188 wxTreeCtrl
* m_treeCtrl
;
189 wxDirFilterListCtrl
* m_filterListCtrl
;
192 DECLARE_EVENT_TABLE()
193 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
194 DECLARE_NO_COPY_CLASS(wxGenericDirCtrl
)
197 //-----------------------------------------------------------------------------
198 // wxDirFilterListCtrl
199 //-----------------------------------------------------------------------------
201 class WXDLLEXPORT wxDirFilterListCtrl
: public wxChoice
204 wxDirFilterListCtrl() { Init(); }
205 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
206 const wxPoint
& pos
= wxDefaultPosition
,
207 const wxSize
& size
= wxDefaultSize
,
211 Create(parent
, id
, pos
, size
, style
);
214 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= wxID_ANY
,
215 const wxPoint
& pos
= wxDefaultPosition
,
216 const wxSize
& size
= wxDefaultSize
,
221 ~wxDirFilterListCtrl() {};
224 void FillFilterList(const wxString
& filter
, int defaultFilter
);
227 void OnSelFilter(wxCommandEvent
& event
);
230 wxGenericDirCtrl
* m_dirCtrl
;
232 DECLARE_EVENT_TABLE()
233 DECLARE_CLASS(wxDirFilterListCtrl
)
234 DECLARE_NO_COPY_CLASS(wxDirFilterListCtrl
)
237 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
238 #define wxDirCtrl wxGenericDirCtrl
241 // Symbols for accessing individual controls
242 #define wxID_TREECTRL 7000
243 #define wxID_FILTERLISTCTRL 7001
245 //-------------------------------------------------------------------------
246 // wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
247 //-------------------------------------------------------------------------
249 class WXDLLEXPORT wxFileIconsTable
268 int GetIconID(const wxString
& extension
, const wxString
& mime
= wxEmptyString
);
269 wxImageList
*GetSmallImageList();
272 void Create(); // create on first use
274 wxImageList
*m_smallImageList
;
275 wxHashTable
*m_HashTable
;
278 // The global fileicons table
279 WXDLLEXPORT_DATA(extern wxFileIconsTable
*) wxTheFileIconsTable
;
281 #endif // wxUSE_DIRDLG