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_
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 WXDLLEXPORT wxTextCtrl
;
35 //-----------------------------------------------------------------------------
36 // Extra styles for wxGenericDirCtrl
37 //-----------------------------------------------------------------------------
41 // Only allow directory viewing/selection, no files
42 wxDIRCTRL_DIR_ONLY
= 0x0010,
43 // When setting the default path, select the first file in the directory
44 wxDIRCTRL_SELECT_FIRST
= 0x0020,
45 // Show the filter list
46 wxDIRCTRL_SHOW_FILTERS
= 0x0040,
47 // Use 3D borders on internal controls
48 wxDIRCTRL_3D_INTERNAL
= 0x0080,
50 wxDIRCTRL_EDITABLE
= 0x0100
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
57 class WXDLLEXPORT wxDirItemData
: public wxTreeItemData
60 wxDirItemData(const wxString
& path
, const wxString
& name
, bool isDir
);
62 void SetNewDirName(const wxString
& path
);
64 bool HasSubDirs() const;
65 bool HasFiles(const wxString
& spec
= wxEmptyString
) const;
67 wxString m_path
, m_name
;
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
77 class WXDLLEXPORT wxDirFilterListCtrl
;
79 class WXDLLEXPORT wxGenericDirCtrl
: public wxControl
83 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
84 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
85 const wxPoint
& pos
= wxDefaultPosition
,
86 const wxSize
& size
= wxDefaultSize
,
87 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
88 const wxString
& filter
= wxEmptyString
,
89 int defaultFilter
= 0,
90 const wxString
& name
= wxTreeCtrlNameStr
)
93 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
96 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
97 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
98 const wxPoint
& pos
= wxDefaultPosition
,
99 const wxSize
& size
= wxDefaultSize
,
100 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
101 const wxString
& filter
= wxEmptyString
,
102 int defaultFilter
= 0,
103 const wxString
& name
= wxTreeCtrlNameStr
);
109 void OnExpandItem(wxTreeEvent
&event
);
110 void OnCollapseItem(wxTreeEvent
&event
);
111 void OnBeginEditItem(wxTreeEvent
&event
);
112 void OnEndEditItem(wxTreeEvent
&event
);
113 void OnSize(wxSizeEvent
&event
);
115 // Try to expand as much of the given path as possible.
116 bool ExpandPath(const wxString
& path
);
120 inline wxString
GetDefaultPath() const { return m_defaultPath
; }
121 void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
123 // Get dir or filename
124 wxString
GetPath() const;
126 // Get selected filename path only (else empty string).
127 // I.e. don't count a directory as a selection
128 wxString
GetFilePath() const;
129 void SetPath(const wxString
& path
);
131 void ShowHidden( bool show
);
132 bool GetShowHidden() { return m_showHidden
; }
134 wxString
GetFilter() const { return m_filter
; }
135 void SetFilter(const wxString
& filter
);
137 int GetFilterIndex() const { return m_currentFilter
; }
138 void SetFilterIndex(int n
);
140 wxTreeItemId
GetRootId() { return m_rootId
; }
142 wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
143 wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
146 void SetupSections();
148 // Parse the filter into an array of filters and an array of descriptions
149 int ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
);
151 // Find the child that matches the first part of 'path'.
152 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
153 // then the child for /usr is returned.
154 // If the path string has been used (we're at the leaf), done is set to TRUE
155 wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
157 // Resize the components of the control
161 void ExpandDir(wxTreeItemId parentId
);
162 void AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
163 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
165 // Extract description and actual filter from overall filter string
166 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
170 wxTreeItemId m_rootId
;
171 wxImageList
* m_imageList
;
172 wxString m_defaultPath
; // Starting path
173 long m_styleEx
; // Extended style
174 wxString m_filter
; // Wildcards in same format as per wxFileDialog
175 int m_currentFilter
; // The current filter index
176 wxString m_currentFilterStr
; // Current filter string
177 wxTreeCtrl
* m_treeCtrl
;
178 wxDirFilterListCtrl
* m_filterListCtrl
;
181 DECLARE_EVENT_TABLE()
182 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
185 //-----------------------------------------------------------------------------
186 // wxDirFilterListCtrl
187 //-----------------------------------------------------------------------------
189 class WXDLLEXPORT wxDirFilterListCtrl
: public wxChoice
192 wxDirFilterListCtrl() { Init(); }
193 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
194 const wxPoint
& pos
= wxDefaultPosition
,
195 const wxSize
& size
= wxDefaultSize
,
199 Create(parent
, id
, pos
, size
, style
);
202 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
203 const wxPoint
& pos
= wxDefaultPosition
,
204 const wxSize
& size
= wxDefaultSize
,
209 ~wxDirFilterListCtrl() {};
212 void FillFilterList(const wxString
& filter
, int defaultFilter
);
215 void OnSelFilter(wxCommandEvent
& event
);
218 wxGenericDirCtrl
* m_dirCtrl
;
220 DECLARE_EVENT_TABLE()
221 DECLARE_CLASS(wxDirFilterListCtrl
)
224 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
225 #define wxDirCtrl wxGenericDirCtrl
228 // Symbols for accessing individual controls
229 #define wxID_TREECTRL 7000
230 #define wxID_FILTERLISTCTRL 7001
232 #endif // wxUSE_DIRDLG