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: Robert Roebling, Harm van der Heijden, Julian Smart et al
11 // Copyright: (c) Robert Roebling, Harm van der Heijden, 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/dialog.h"
26 #include "wx/dirdlg.h"
27 #include "wx/choice.h"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 class WXDLLEXPORT wxTextCtrl
;
35 //-----------------------------------------------------------------------------
36 // Extra styles for wxGenericDirCtrl
37 //-----------------------------------------------------------------------------
41 // Only allow directory viewing/selection, no files
42 wxDIRCTRL_DIR_ONLY
= 0x0010,
43 // When setting the default path, select the first file in the directory
44 wxDIRCTRL_SELECT_FIRST
= 0x0020,
45 // Show the filter list
46 wxDIRCTRL_SHOW_FILTERS
= 0x0040,
47 // Use 3D borders on internal controls
48 wxDIRCTRL_3D_INTERNAL
= 0x0080
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 class WXDLLEXPORT wxDirItemData
: public wxTreeItemData
58 wxDirItemData(const wxString
& path
, const wxString
& name
, bool isDir
);
60 void SetNewDirName(const wxString
& path
);
62 bool HasSubDirs() const;
63 bool HasFiles(const wxString
& spec
= wxEmptyString
) const;
65 wxString m_path
, m_name
;
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
75 class WXDLLEXPORT wxDirFilterListCtrl
;
77 class WXDLLEXPORT wxGenericDirCtrl
: public wxControl
81 wxGenericDirCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
82 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
83 const wxPoint
& pos
= wxDefaultPosition
,
84 const wxSize
& size
= wxDefaultSize
,
85 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
86 const wxString
& filter
= wxEmptyString
,
87 int defaultFilter
= 0,
88 const wxString
& name
= wxTreeCtrlNameStr
)
91 Create(parent
, id
, dir
, pos
, size
, style
, filter
, defaultFilter
, name
);
94 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
95 const wxString
&dir
= wxDirDialogDefaultFolderStr
,
96 const wxPoint
& pos
= wxDefaultPosition
,
97 const wxSize
& size
= wxDefaultSize
,
98 long style
= wxDIRCTRL_3D_INTERNAL
|wxSUNKEN_BORDER
,
99 const wxString
& filter
= wxEmptyString
,
100 int defaultFilter
= 0,
101 const wxString
& name
= wxTreeCtrlNameStr
);
107 void OnExpandItem(wxTreeEvent
&event
);
108 void OnCollapseItem(wxTreeEvent
&event
);
109 void OnBeginEditItem(wxTreeEvent
&event
);
110 void OnEndEditItem(wxTreeEvent
&event
);
111 void OnSize(wxSizeEvent
&event
);
113 // Try to expand as much of the given path as possible.
114 bool ExpandPath(const wxString
& path
);
118 inline wxString
GetDefaultPath() const { return m_defaultPath
; }
119 void SetDefaultPath(const wxString
& path
) { m_defaultPath
= path
; }
121 // Get dir or filename
122 wxString
GetPath() const;
124 // Get selected filename path only (else empty string).
125 // I.e. don't count a directory as a selection
126 wxString
GetFilePath() const;
127 void SetPath(const wxString
& path
);
129 void ShowHidden( bool show
);
130 bool GetShowHidden() { return m_showHidden
; }
132 wxString
GetFilter() const { return m_filter
; }
133 void SetFilter(const wxString
& filter
);
135 int GetFilterIndex() const { return m_currentFilter
; }
136 void SetFilterIndex(int n
);
138 wxTreeItemId
GetRootId() { return m_rootId
; }
140 wxTreeCtrl
* GetTreeCtrl() const { return m_treeCtrl
; }
141 wxDirFilterListCtrl
* GetFilterListCtrl() const { return m_filterListCtrl
; }
144 void SetupSections();
146 // Parse the filter into an array of filters and an array of descriptions
147 int ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
);
149 // Find the child that matches the first part of 'path'.
150 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
151 // then the child for /usr is returned.
152 // If the path string has been used (we're at the leaf), done is set to TRUE
153 wxTreeItemId
FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
);
155 // Resize the components of the control
159 void ExpandDir(wxTreeItemId parentId
);
160 void AddSection(const wxString
& path
, const wxString
& name
, int imageId
= 0);
161 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
163 // Extract description and actual filter from overall filter string
164 bool ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
);
168 wxTreeItemId m_rootId
;
169 wxImageList
* m_imageList
;
170 wxString m_defaultPath
; // Starting path
171 long m_styleEx
; // Extended style
172 wxString m_filter
; // Wildcards in same format as per wxFileDialog
173 int m_currentFilter
; // The current filter index
174 wxString m_currentFilterStr
; // Current filter string
175 wxTreeCtrl
* m_treeCtrl
;
176 wxDirFilterListCtrl
* m_filterListCtrl
;
179 DECLARE_EVENT_TABLE()
180 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl
)
183 //-----------------------------------------------------------------------------
184 // wxDirFilterListCtrl
185 //-----------------------------------------------------------------------------
187 class WXDLLEXPORT wxDirFilterListCtrl
: public wxChoice
190 wxDirFilterListCtrl() { Init(); }
191 wxDirFilterListCtrl(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
192 const wxPoint
& pos
= wxDefaultPosition
,
193 const wxSize
& size
= wxDefaultSize
,
197 Create(parent
, id
, pos
, size
, style
);
200 bool Create(wxGenericDirCtrl
* parent
, const wxWindowID id
= -1,
201 const wxPoint
& pos
= wxDefaultPosition
,
202 const wxSize
& size
= wxDefaultSize
,
207 ~wxDirFilterListCtrl() {};
210 void FillFilterList(const wxString
& filter
, int defaultFilter
);
213 void OnSelFilter(wxCommandEvent
& event
);
216 wxGenericDirCtrl
* m_dirCtrl
;
218 DECLARE_EVENT_TABLE()
219 DECLARE_CLASS(wxDirFilterListCtrl
)
222 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
223 #define wxDirCtrl wxGenericDirCtrl
226 #endif // wxUSE_DIRDLG