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"
24 #include "wx/treectrl.h"
25 #include "wx/dirdlg.h"
26 #include "wx/choice.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 // Extra styles for wxGenericDirCtrl
34 //-----------------------------------------------------------------------------
36 // Only allow directory viewing/selection, no files
37 #define wxDIRCTRL_DIR_ONLY 0x0010
38 // When setting the default path, select the first file in the directory
39 #define wxDIRCTRL_SELECT_FIRST 0x0020
40 // Show the filter list
41 #define wxDIRCTRL_SHOW_FILTERS 0x0040
42 // Use 3D borders on internal controls
43 #define wxDIRCTRL_3D_INTERNAL 0x0080
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
49 class WXDLLEXPORT wxDirItemDataEx
: public wxTreeItemData
52 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
|wxSUNKEN_BORDER
,
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
|wxSUNKEN_BORDER
,
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 // Get dir or filename
113 wxString
GetPath() const ;
114 // Get selected filename path only (else empty string).
115 // I.e. don't count a directory as a selection
116 wxString
GetFilePath() const ;
117 void SetPath(const wxString
& path
) ;
119 wxString
GetFilter() const { return m_filter
; }
120 void SetFilter(const wxString
& filter
);
122 int GetFilterIndex() const { return m_currentFilter
; }
123 void SetFilterIndex(int n
) ;
125 wxTreeItemId
GetRootId() { return m_rootId
; }
127 wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
128 wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
131 void SetupSections();
132 // Parse the filter into an array of filters and an array of descriptions
133 int ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
);
134 // Find the child that matches the first part of 'path'.
135 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
136 // then the child for /usr is returned.
137 // If the path string has been used (we're at the leaf), done is set to TRUE
138 wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
140 // Resize the components of the control
143 void ExpandDir(wxTreeItemId parentId
);
144 void AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
145 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
147 // Extract description and actual filter from overall filter string
148 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
152 wxTreeItemId m_rootId
;
153 wxImageList
* m_imageList
;
154 wxString m_defaultPath
; // Starting path
155 long m_styleEx
; // Extended style
156 wxString m_filter
; // Wildcards in same format as per wxFileDialog
157 int m_currentFilter
; // The current filter index
158 wxString m_currentFilterStr
; // Current filter string
159 wxTreeCtrl
* m_treeCtrl
;
160 wxDirFilterListCtrl
* m_filterListCtrl
;
163 DECLARE_EVENT_TABLE()
164 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
167 //-----------------------------------------------------------------------------
168 // wxDirFilterListCtrl
169 //-----------------------------------------------------------------------------
171 class WXDLLEXPORT wxDirFilterListCtrl
: public wxChoice
174 wxDirFilterListCtrl() { Init(); }
175 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
176 const wxPoint
& pos
= wxDefaultPosition
,
177 const wxSize
& size
= wxDefaultSize
,
181 Create(parent
, id
, pos
, size
, style
);
184 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
185 const wxPoint
& pos
= wxDefaultPosition
,
186 const wxSize
& size
= wxDefaultSize
,
191 ~wxDirFilterListCtrl() {};
194 void FillFilterList(const wxString
& filter
, int defaultFilter
);
197 void OnSelFilter(wxCommandEvent
& event
);
200 wxGenericDirCtrl
* m_dirCtrl
;
202 DECLARE_EVENT_TABLE()
203 DECLARE_CLASS(wxDirFilterListCtrl
)
206 #define wxID_TREECTRL 7000
207 #define wxID_FILTERLISTCTRL 7001
209 //-----------------------------------------------------------------------------
210 // wxGenericDirDialog
212 //-----------------------------------------------------------------------------
214 class wxGenericDirDialog
: public wxDialog
216 DECLARE_EVENT_TABLE()
218 wxGenericDirDialog(): wxDialog() {}
219 wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
220 const wxString
& defaultPath
= wxEmptyString
, long style
= wxDEFAULT_DIALOG_STYLE
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxSize(450, 550), const wxString
& name
= "dialog");
223 void OnCloseWindow(wxCloseEvent
& event
);
224 void OnOK(wxCommandEvent
& event
);
225 void OnTreeSelected( wxTreeEvent
&event
);
226 void OnTreeKeyDown( wxTreeEvent
&event
);
227 void OnNew(wxCommandEvent
& event
);
230 inline void SetMessage(const wxString
& message
) { m_message
= message
; }
231 void SetPath(const wxString
& path
) ;
232 inline void SetStyle(long style
) { m_dialogStyle
= style
; }
234 inline wxString
GetMessage(void) const { return m_message
; }
235 wxString
GetPath(void) const ;
236 inline long GetStyle(void) const { return m_dialogStyle
; }
238 wxTextCtrl
* GetInputCtrl() const { return m_input
; }
247 wxGenericDirCtrl
* m_dirCtrl
;
252 #endif // wxUSE_DIRDLG