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 //-----------------------------------------------------------------------------
31 // Extra styles for wxGenericDirCtrl
32 //-----------------------------------------------------------------------------
34 // Only allow directory viewing/selection, no files
35 #define wxDIRCTRL_DIR_ONLY 0x0010
36 // When setting the default path, select the first file in the directory
37 #define wxDIRCTRL_SELECT_FIRST 0x0020
38 // Show the filter list
39 #define wxDIRCTRL_SHOW_FILTERS 0x0040
40 // Use 3D borders on internal controls
41 #define wxDIRCTRL_3D_INTERNAL 0x0080
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 class WXDLLEXPORT wxDirItemDataEx
: public wxTreeItemData
50 wxDirItemDataEx(const wxString
& path
, const wxString
& name
, bool isDir
);
53 void SetNewDirName( wxString path
);
54 wxString m_path
, m_name
;
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 class WXDLLEXPORT wxDirFilterListCtrl
;
67 class WXDLLEXPORT wxGenericDirCtrl
: public wxControl
71 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
72 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
73 const wxPoint
& pos
= wxDefaultPosition
,
74 const wxSize
& size
= wxDefaultSize
,
75 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
76 const wxString
& filter
= wxEmptyString
,
77 int defaultFilter
= 0,
78 const wxString
& name
= wxTreeCtrlNameStr
)
81 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
84 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
85 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
86 const wxPoint
& pos
= wxDefaultPosition
,
87 const wxSize
& size
= wxDefaultSize
,
88 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
89 const wxString
& filter
= wxEmptyString
,
90 int defaultFilter
= 0,
91 const wxString
& name
= wxTreeCtrlNameStr
);
97 void OnExpandItem(wxTreeEvent
&event
);
98 void OnCollapseItem(wxTreeEvent
&event
);
99 void OnBeginEditItem(wxTreeEvent
&event
);
100 void OnEndEditItem(wxTreeEvent
&event
);
101 void OnSize(wxSizeEvent
&event
);
103 // Try to expand as much of the given path as possible.
104 bool ExpandPath(const wxString
& path
);
108 inline wxString
GetDefaultPath() const { return m_defaultPath
; }
109 void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
111 // Get dir or filename
112 wxString
GetPath() const ;
113 // Get selected filename path only (else empty string).
114 // I.e. don't count a directory as a selection
115 wxString
GetFilePath() const ;
116 void SetPath(const wxString
& path
) ;
118 wxString
GetFilter() const { return m_filter
; }
119 void SetFilter(const wxString
& filter
);
121 int GetFilterIndex() const { return m_currentFilter
; }
122 void SetFilterIndex(int n
) ;
124 wxTreeItemId
GetRootId() { return m_rootId
; }
126 wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
127 wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
130 void SetupSections();
131 // Parse the filter into an array of filters and an array of descriptions
132 int ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
);
133 // Find the child that matches the first part of 'path'.
134 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
135 // then the child for /usr is returned.
136 // If the path string has been used (we're at the leaf), done is set to TRUE
137 wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
139 // Resize the components of the control
142 void ExpandDir(wxTreeItemId parentId
);
143 void AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
144 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
146 // Extract description and actual filter from overall filter string
147 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
151 wxTreeItemId m_rootId
;
152 wxImageList
* m_imageList
;
153 wxString m_defaultPath
; // Starting path
154 long m_styleEx
; // Extended style
155 wxString m_filter
; // Wildcards in same format as per wxFileDialog
156 int m_currentFilter
; // The current filter index
157 wxString m_currentFilterStr
; // Current filter string
158 wxTreeCtrl
* m_treeCtrl
;
159 wxDirFilterListCtrl
* m_filterListCtrl
;
162 DECLARE_EVENT_TABLE()
163 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
166 //-----------------------------------------------------------------------------
167 // wxDirFilterListCtrl
168 //-----------------------------------------------------------------------------
170 class WXDLLEXPORT wxDirFilterListCtrl
: public wxChoice
173 wxDirFilterListCtrl() { Init(); }
174 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
175 const wxPoint
& pos
= wxDefaultPosition
,
176 const wxSize
& size
= wxDefaultSize
,
180 Create(parent
, id
, pos
, size
, style
);
183 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
184 const wxPoint
& pos
= wxDefaultPosition
,
185 const wxSize
& size
= wxDefaultSize
,
190 ~wxDirFilterListCtrl() {};
193 void FillFilterList(const wxString
& filter
, int defaultFilter
);
196 void OnSelFilter(wxCommandEvent
& event
);
199 wxGenericDirCtrl
* m_dirCtrl
;
201 DECLARE_EVENT_TABLE()
202 DECLARE_CLASS(wxDirFilterListCtrl
)
205 #define wxID_TREECTRL 7000
206 #define wxID_FILTERLISTCTRL 7001
208 //-----------------------------------------------------------------------------
209 // wxGenericDirDialog
211 //-----------------------------------------------------------------------------
213 class wxGenericDirDialog
: public wxDialog
215 DECLARE_EVENT_TABLE()
217 wxGenericDirDialog(): wxDialog() {}
218 wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
219 const wxString
& defaultPath
= wxEmptyString
, long style
= wxDEFAULT_DIALOG_STYLE
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxSize(450, 550), const wxString
& name
= "dialog");
222 void OnCloseWindow(wxCloseEvent
& event
);
223 void OnOK(wxCommandEvent
& event
);
224 void OnTreeSelected( wxTreeEvent
&event
);
225 void OnTreeKeyDown( wxTreeEvent
&event
);
226 void OnNew(wxCommandEvent
& event
);
229 inline void SetMessage(const wxString
& message
) { m_message
= message
; }
230 void SetPath(const wxString
& path
) ;
231 inline void SetStyle(long style
) { m_dialogStyle
= style
; }
233 inline wxString
GetMessage(void) const { return m_message
; }
234 wxString
GetPath(void) const ;
235 inline long GetStyle(void) const { return m_dialogStyle
; }
237 wxTextCtrl
* GetInputCtrl() const { return m_input
; }
246 wxGenericDirCtrl
* m_dirCtrl
;