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"
23 #include "wx/dirdlg.h"
24 #include "wx/choice.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 //class wxDirItemData;
33 //-----------------------------------------------------------------------------
34 // Extra styles for wxGenericDirCtrl
35 //-----------------------------------------------------------------------------
37 // Only allow directory viewing/selection, no files
38 #define wxDIRCTRL_DIR_ONLY 0x0010
39 // When setting the default path, select the first file in the directory
40 #define wxDIRCTRL_SELECT_FIRST 0x0020
41 // Show the filter list
42 #define wxDIRCTRL_SHOW_FILTERS 0x0040
43 // Use 3D borders on internal controls
44 #define wxDIRCTRL_3D_INTERNAL 0x0080
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 class WXDLLEXPORT wxDirItemDataEx
: public wxTreeItemData
53 wxDirItemDataEx(const wxString
& path
, const wxString
& name
, bool isDir
);
56 void SetNewDirName( wxString path
);
57 wxString m_path
, m_name
;
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
68 class WXDLLEXPORT wxDirFilterListCtrl
;
70 class WXDLLEXPORT wxGenericDirCtrl
: public wxControl
74 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
75 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
76 const wxPoint
& pos
= wxDefaultPosition
,
77 const wxSize
& size
= wxDefaultSize
,
78 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
79 const wxString
& filter
= wxEmptyString
,
80 int defaultFilter
= 0,
81 const wxString
& name
= wxTreeCtrlNameStr
)
84 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
87 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
88 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
89 const wxPoint
& pos
= wxDefaultPosition
,
90 const wxSize
& size
= wxDefaultSize
,
91 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
92 const wxString
& filter
= wxEmptyString
,
93 int defaultFilter
= 0,
94 const wxString
& name
= wxTreeCtrlNameStr
);
100 void OnExpandItem(wxTreeEvent
&event
);
101 void OnCollapseItem(wxTreeEvent
&event
);
102 void OnBeginEditItem(wxTreeEvent
&event
);
103 void OnEndEditItem(wxTreeEvent
&event
);
104 void OnSize(wxSizeEvent
&event
);
106 // Try to expand as much of the given path as possible.
107 bool ExpandPath(const wxString
& path
);
111 inline wxString
GetDefaultPath() const { return m_defaultPath
; }
112 void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
114 //inline long GetStyleEx() const { return m_styleEx; }
115 //void SetStyleEx(long styleEx) { m_styleEx = styleEx; }
117 // Get dir or filename
118 wxString
GetPath() const ;
119 // Get selected filename path only (else empty string).
120 // I.e. don't count a directory as a selection
121 wxString
GetFilePath() const ;
122 void SetPath(const wxString
& path
) ;
124 wxString
GetFilter() const { return m_filter
; }
125 void SetFilter(const wxString
& filter
);
127 int GetFilterIndex() const { return m_currentFilter
; }
128 void SetFilterIndex(int n
) ;
130 wxTreeItemId
GetRootId() { return m_rootId
; }
132 wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
133 wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
136 void SetupSections();
137 // Parse the filter into an array of filters and an array of descriptions
138 int ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
);
139 // Find the child that matches the first part of 'path'.
140 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
141 // then the child for /usr is returned.
142 // If the path string has been used (we're at the leaf), done is set to TRUE
143 wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
145 // Resize the components of the control
148 void ExpandDir(wxTreeItemId parentId
);
149 void AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
150 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
152 // Extract description and actual filter from overall filter string
153 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
157 wxTreeItemId m_rootId
;
158 wxImageList
* m_imageList
;
159 wxString m_defaultPath
; // Starting path
160 long m_styleEx
; // Extended style
161 wxString m_filter
; // Wildcards in same format as per wxFileDialog
162 int m_currentFilter
; // The current filter index
163 wxString m_currentFilterStr
; // Current filter string
164 wxTreeCtrl
* m_treeCtrl
;
165 wxDirFilterListCtrl
* m_filterListCtrl
;
168 DECLARE_EVENT_TABLE()
169 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
172 //-----------------------------------------------------------------------------
173 // wxDirFilterListCtrl
174 //-----------------------------------------------------------------------------
176 class WXDLLEXPORT wxDirFilterListCtrl
: public wxChoice
179 wxDirFilterListCtrl() { Init(); }
180 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
181 const wxPoint
& pos
= wxDefaultPosition
,
182 const wxSize
& size
= wxDefaultSize
,
186 Create(parent
, id
, pos
, size
, style
);
189 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
190 const wxPoint
& pos
= wxDefaultPosition
,
191 const wxSize
& size
= wxDefaultSize
,
196 ~wxDirFilterListCtrl() {};
199 void FillFilterList(const wxString
& filter
, int defaultFilter
);
202 void OnSelFilter(wxCommandEvent
& event
);
205 wxGenericDirCtrl
* m_dirCtrl
;
207 DECLARE_EVENT_TABLE()
208 DECLARE_CLASS(wxDirFilterListCtrl
)
211 #define wxID_TREECTRL 7000
212 #define wxID_FILTERLISTCTRL 7001
214 //-----------------------------------------------------------------------------
215 // wxGenericDirDialog
217 //-----------------------------------------------------------------------------
219 class wxGenericDirDialog
: public wxDialog
221 DECLARE_EVENT_TABLE()
223 wxGenericDirDialog(): wxDialog() {}
224 wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
225 const wxString
& defaultPath
= wxEmptyString
, long style
= wxDEFAULT_DIALOG_STYLE
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxSize(450, 550), const wxString
& name
= "dialog");
228 void OnCloseWindow(wxCloseEvent
& event
);
229 void OnOK(wxCommandEvent
& event
);
230 void OnTreeSelected( wxTreeEvent
&event
);
231 void OnTreeKeyDown( wxTreeEvent
&event
);
232 void OnNew(wxCommandEvent
& event
);
235 inline void SetMessage(const wxString
& message
) { m_message
= message
; }
236 void SetPath(const wxString
& path
) ;
237 inline void SetStyle(long style
) { m_dialogStyle
= style
; }
239 inline wxString
GetMessage(void) const { return m_message
; }
240 wxString
GetPath(void) const ;
241 inline long GetStyle(void) const { return m_dialogStyle
; }
243 wxTextCtrl
* GetInputCtrl() const { return m_input
; }
252 wxGenericDirCtrl
* m_dirCtrl
;