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: Julian Smart et al
11 // Copyright: (c) Julian Smart
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
15 #ifndef _WX_DIRCTRL_H_
16 #define _WX_DIRCTRL_H_
19 #pragma interface "dirctrlg.h"
22 #include "wx/treectrl.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
32 // Extra styles for wxGenericDirCtrl
33 //-----------------------------------------------------------------------------
35 // Only allow directory viewing/selection, no files
36 #define wxDIRCTRL_DIR_ONLY 0x0010
37 // When setting the default path, select the first file in the directory
38 #define wxDIRCTRL_SELECT_FIRST 0x0020
39 // Show the filter list
40 #define wxDIRCTRL_SHOW_FILTERS 0x0040
41 // Use 3D borders on internal controls
42 #define wxDIRCTRL_3D_INTERNAL 0x0080
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
48 class WXDLLEXPORT wxDirItemDataEx
: public wxTreeItemData
51 wxDirItemDataEx(const wxString
& path
, const wxString
& name
, bool isDir
);
54 void SetNewDirName( wxString path
);
55 wxString m_path
, m_name
;
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
66 class WXDLLEXPORT wxDirFilterListCtrl
;
68 class WXDLLEXPORT wxGenericDirCtrl
: public wxControl
72 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
73 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
74 const wxPoint
& pos
= wxDefaultPosition
,
75 const wxSize
& size
= wxDefaultSize
,
76 long style
= wxDIRCTRL_3D_INTERNAL
,
77 const wxString
& filter
= wxEmptyString
,
78 int defaultFilter
= 0,
79 const wxString
& name
= wxTreeCtrlNameStr
)
82 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
85 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
86 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
87 const wxPoint
& pos
= wxDefaultPosition
,
88 const wxSize
& size
= wxDefaultSize
,
89 long style
= wxDIRCTRL_3D_INTERNAL
,
90 const wxString
& filter
= wxEmptyString
,
91 int defaultFilter
= 0,
92 const wxString
& name
= wxTreeCtrlNameStr
);
98 void OnExpandItem(wxTreeEvent
&event
);
99 void OnCollapseItem(wxTreeEvent
&event
);
100 void OnBeginEditItem(wxTreeEvent
&event
);
101 void OnEndEditItem(wxTreeEvent
&event
);
102 void OnSize(wxSizeEvent
&event
);
104 // Try to expand as much of the given path as possible.
105 bool ExpandPath(const wxString
& path
);
109 inline wxString
GetDefaultPath() const { return m_defaultPath
; }
110 void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
112 //inline long GetStyleEx() const { return m_styleEx; }
113 //void SetStyleEx(long styleEx) { m_styleEx = styleEx; }
115 // Get dir or filename
116 wxString
GetPath() const ;
117 // Get selected filename path only (else empty string).
118 // I.e. don't count a directory as a selection
119 wxString
GetFilePath() const ;
120 void SetPath(const wxString
& path
) ;
122 wxString
GetFilter() const { return m_filter
; }
123 void SetFilter(const wxString
& filter
);
125 int GetFilterIndex() const { return m_currentFilter
; }
126 void SetFilterIndex(int n
) ;
128 wxTreeItemId
GetRootId() { return m_rootId
; }
130 wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
131 wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
134 void SetupSections();
135 // Parse the filter into an array of filters and an array of descriptions
136 int ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
);
137 // Find the child that matches the first part of 'path'.
138 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
139 // then the child for /usr is returned.
140 // If the path string has been used (we're at the leaf), done is set to TRUE
141 wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
143 // Resize the components of the control
146 void ExpandDir(wxTreeItemId parentId
);
147 void AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
148 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
150 // Extract description and actual filter from overall filter string
151 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
155 wxTreeItemId m_rootId
;
156 wxImageList
* m_imageList
;
157 wxString m_defaultPath
; // Starting path
158 long m_styleEx
; // Extended style
159 wxString m_filter
; // Wildcards in same format as per wxFileDialog
160 int m_currentFilter
; // The current filter index
161 wxString m_currentFilterStr
; // Current filter string
162 wxTreeCtrl
* m_treeCtrl
;
163 wxDirFilterListCtrl
* m_filterListCtrl
;
166 DECLARE_EVENT_TABLE()
167 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
170 //-----------------------------------------------------------------------------
171 // wxDirFilterListCtrl
172 //-----------------------------------------------------------------------------
174 class WXDLLEXPORT wxDirFilterListCtrl
: public wxChoice
177 wxDirFilterListCtrl() { Init(); }
178 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
179 const wxPoint
& pos
= wxDefaultPosition
,
180 const wxSize
& size
= wxDefaultSize
,
184 Create(parent
, id
, pos
, size
, style
);
187 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
188 const wxPoint
& pos
= wxDefaultPosition
,
189 const wxSize
& size
= wxDefaultSize
,
194 ~wxDirFilterListCtrl() {};
197 void FillFilterList(const wxString
& filter
, int defaultFilter
);
200 void OnSelFilter(wxCommandEvent
& event
);
203 wxGenericDirCtrl
* m_dirCtrl
;
205 DECLARE_EVENT_TABLE()
206 DECLARE_CLASS(wxDirFilterListCtrl
)
209 #define wxID_TREECTRL 7000
210 #define wxID_FILTERLISTCTRL 7001
212 //-----------------------------------------------------------------------------
213 // wxGenericDirDialog
215 //-----------------------------------------------------------------------------
217 class wxGenericDirDialog
: public wxDialog
219 DECLARE_EVENT_TABLE()
221 wxGenericDirDialog(): wxDialog() {}
222 wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
223 const wxString
& defaultPath
= wxEmptyString
, long style
= wxDEFAULT_DIALOG_STYLE
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxSize(450, 550), const wxString
& name
= "dialog");
225 void OnCloseWindow(wxCloseEvent
& event
);
226 void OnOK(wxCommandEvent
& event
);
228 inline void SetMessage(const wxString
& message
) { m_message
= message
; }
229 void SetPath(const wxString
& path
) ;
230 inline void SetStyle(long style
) { m_dialogStyle
= style
; }
232 inline wxString
GetMessage(void) const { return m_message
; }
233 wxString
GetPath(void) const ;
234 inline long GetStyle(void) const { return m_dialogStyle
; }
240 wxGenericDirCtrl
* m_dirCtrl
;