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
);
52 void SetNewDirName( wxString path
);
53 wxString m_path
, m_name
;
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 class WXDLLEXPORT wxDirFilterListCtrl
;
66 class WXDLLEXPORT wxGenericDirCtrl
: public wxControl
70 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
71 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
72 const wxPoint
& pos
= wxDefaultPosition
,
73 const wxSize
& size
= wxDefaultSize
,
74 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
75 const wxString
& filter
= wxEmptyString
,
76 int defaultFilter
= 0,
77 const wxString
& name
= wxTreeCtrlNameStr
)
80 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
83 bool Create(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
);
96 void OnExpandItem(wxTreeEvent
&event
);
97 void OnCollapseItem(wxTreeEvent
&event
);
98 void OnBeginEditItem(wxTreeEvent
&event
);
99 void OnEndEditItem(wxTreeEvent
&event
);
100 void OnSize(wxSizeEvent
&event
);
102 // Try to expand as much of the given path as possible.
103 bool ExpandPath(const wxString
& path
);
107 inline wxString
GetDefaultPath() const { return m_defaultPath
; }
108 void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
110 // Get dir or filename
111 wxString
GetPath() const ;
112 // Get selected filename path only (else empty string).
113 // I.e. don't count a directory as a selection
114 wxString
GetFilePath() const ;
115 void SetPath(const wxString
& path
) ;
117 wxString
GetFilter() const { return m_filter
; }
118 void SetFilter(const wxString
& filter
);
120 int GetFilterIndex() const { return m_currentFilter
; }
121 void SetFilterIndex(int n
) ;
123 wxTreeItemId
GetRootId() { return m_rootId
; }
125 wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
126 wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
129 void SetupSections();
130 // Parse the filter into an array of filters and an array of descriptions
131 int ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
);
132 // Find the child that matches the first part of 'path'.
133 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
134 // then the child for /usr is returned.
135 // If the path string has been used (we're at the leaf), done is set to TRUE
136 wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
138 // Resize the components of the control
141 void ExpandDir(wxTreeItemId parentId
);
142 void AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
143 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
145 // Extract description and actual filter from overall filter string
146 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
150 wxTreeItemId m_rootId
;
151 wxImageList
* m_imageList
;
152 wxString m_defaultPath
; // Starting path
153 long m_styleEx
; // Extended style
154 wxString m_filter
; // Wildcards in same format as per wxFileDialog
155 int m_currentFilter
; // The current filter index
156 wxString m_currentFilterStr
; // Current filter string
157 wxTreeCtrl
* m_treeCtrl
;
158 wxDirFilterListCtrl
* m_filterListCtrl
;
161 DECLARE_EVENT_TABLE()
162 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
165 //-----------------------------------------------------------------------------
166 // wxDirFilterListCtrl
167 //-----------------------------------------------------------------------------
169 class WXDLLEXPORT wxDirFilterListCtrl
: public wxChoice
172 wxDirFilterListCtrl() { Init(); }
173 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
174 const wxPoint
& pos
= wxDefaultPosition
,
175 const wxSize
& size
= wxDefaultSize
,
179 Create(parent
, id
, pos
, size
, style
);
182 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
183 const wxPoint
& pos
= wxDefaultPosition
,
184 const wxSize
& size
= wxDefaultSize
,
189 ~wxDirFilterListCtrl() {};
192 void FillFilterList(const wxString
& filter
, int defaultFilter
);
195 void OnSelFilter(wxCommandEvent
& event
);
198 wxGenericDirCtrl
* m_dirCtrl
;
200 DECLARE_EVENT_TABLE()
201 DECLARE_CLASS(wxDirFilterListCtrl
)
204 #define wxID_TREECTRL 7000
205 #define wxID_FILTERLISTCTRL 7001
207 //-----------------------------------------------------------------------------
208 // wxGenericDirDialog
210 //-----------------------------------------------------------------------------
212 class wxGenericDirDialog
: public wxDialog
214 DECLARE_EVENT_TABLE()
216 wxGenericDirDialog(): wxDialog() {}
217 wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
218 const wxString
& defaultPath
= wxEmptyString
, long style
= wxDEFAULT_DIALOG_STYLE
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxSize(450, 550), const wxString
& name
= "dialog");
221 void OnCloseWindow(wxCloseEvent
& event
);
222 void OnOK(wxCommandEvent
& event
);
223 void OnTreeSelected( wxTreeEvent
&event
);
224 void OnTreeKeyDown( wxTreeEvent
&event
);
225 void OnNew(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
; }
236 wxTextCtrl
* GetInputCtrl() const { return m_input
; }
245 wxGenericDirCtrl
* m_dirCtrl
;