Added wxGenericDirCtrl, wxGenericDirDialog and associated icons.
[wxWidgets.git] / include / wx / generic / dirctrlg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dirctrlg.h
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
8 // Modified by:
9 // Created: 21/3/2000
10 // RCS-ID: $Id$
11 // Copyright: (c) Julian Smart
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
14
15 #ifndef _WX_DIRCTRL_H_
16 #define _WX_DIRCTRL_H_
17
18 #ifdef __GNUG__
19 #pragma interface "dirctrlg.h"
20 #endif
21
22 #include "wx/treectrl.h"
23
24 //-----------------------------------------------------------------------------
25 // classes
26 //-----------------------------------------------------------------------------
27
28 class wxDirItemData;
29 class wxDirCtrl;
30
31 //-----------------------------------------------------------------------------
32 // Extra styles for wxGenericDirCtrl
33 //-----------------------------------------------------------------------------
34
35 // Only allow directory viewing/selection, no files
36 #define wxDIRCTRL_DIR_ONLY 0x0010
37 // When setting the default path, select the first file in the directory
38 #define wxDIRCTRL_SELECT_FIRST 0x0020
39 // Show the filter list
40 #define wxDIRCTRL_SHOW_FILTERS 0x0040
41 // Use 3D borders on internal controls
42 #define wxDIRCTRL_3D_INTERNAL 0x0080
43
44 //-----------------------------------------------------------------------------
45 // wxDirItemData
46 //-----------------------------------------------------------------------------
47
48 class WXDLLEXPORT wxDirItemDataEx : public wxTreeItemData
49 {
50 public:
51 wxDirItemDataEx(const wxString& path, const wxString& name, bool isDir);
52 ~wxDirItemDataEx();
53 bool HasSubDirs();
54 void SetNewDirName( wxString path );
55 wxString m_path, m_name;
56 bool m_isHidden;
57 bool m_hasSubDirs;
58 bool m_isExpanded;
59 bool m_isDir;
60 };
61
62 //-----------------------------------------------------------------------------
63 // wxDirCtrl
64 //-----------------------------------------------------------------------------
65
66 class WXDLLEXPORT wxDirFilterListCtrl;
67
68 class WXDLLEXPORT wxGenericDirCtrl: public wxControl
69 {
70 public:
71 wxGenericDirCtrl();
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,
77 const wxString& filter = wxEmptyString,
78 int defaultFilter = 0,
79 const wxString& name = wxTreeCtrlNameStr )
80 {
81 Init();
82 Create(parent, id, dir, pos, size, style, filter, defaultFilter, name);
83 }
84
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,
90 const wxString& filter = wxEmptyString,
91 int defaultFilter = 0,
92 const wxString& name = wxTreeCtrlNameStr );
93
94 void Init();
95
96 ~wxGenericDirCtrl();
97
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 );
103
104 // Try to expand as much of the given path as possible.
105 bool ExpandPath(const wxString& path);
106
107 // Accessors
108
109 inline wxString GetDefaultPath() const { return m_defaultPath; }
110 void SetDefaultPath(const wxString& path) { m_defaultPath = path; }
111
112 //inline long GetStyleEx() const { return m_styleEx; }
113 //void SetStyleEx(long styleEx) { m_styleEx = styleEx; }
114
115 // Get dir or filename
116 wxString GetPath() const ;
117 // Get selected filename path only (else empty string).
118 // I.e. don't count a directory as a selection
119 wxString GetFilePath() const ;
120 void SetPath(const wxString& path) ;
121
122 wxString GetFilter() const { return m_filter; }
123 void SetFilter(const wxString& filter);
124
125 int GetFilterIndex() const { return m_currentFilter; }
126 void SetFilterIndex(int n) ;
127
128 wxTreeItemId GetRootId() { return m_rootId; }
129
130 wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
131 wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
132
133 //// Helpers
134 void SetupSections();
135 // Parse the filter into an array of filters and an array of descriptions
136 int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
137 // Find the child that matches the first part of 'path'.
138 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
139 // then the child for /usr is returned.
140 // If the path string has been used (we're at the leaf), done is set to TRUE
141 wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
142
143 // Resize the components of the control
144 void DoResize();
145 protected:
146 void ExpandDir(wxTreeItemId parentId);
147 void AddSection(const wxString& path, const wxString& name, int imageId = 0);
148 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
149
150 // Extract description and actual filter from overall filter string
151 bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
152
153 private:
154 bool m_showHidden;
155 wxTreeItemId m_rootId;
156 wxImageList* m_imageList;
157 wxString m_defaultPath; // Starting path
158 long m_styleEx; // Extended style
159 wxString m_filter; // Wildcards in same format as per wxFileDialog
160 int m_currentFilter; // The current filter index
161 wxString m_currentFilterStr; // Current filter string
162 wxTreeCtrl* m_treeCtrl;
163 wxDirFilterListCtrl* m_filterListCtrl;
164
165 private:
166 DECLARE_EVENT_TABLE()
167 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
168 };
169
170 //-----------------------------------------------------------------------------
171 // wxDirFilterListCtrl
172 //-----------------------------------------------------------------------------
173
174 class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice
175 {
176 public:
177 wxDirFilterListCtrl() { Init(); }
178 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
179 const wxPoint& pos = wxDefaultPosition,
180 const wxSize& size = wxDefaultSize,
181 long style = 0)
182 {
183 Init();
184 Create(parent, id, pos, size, style);
185 }
186
187 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
188 const wxPoint& pos = wxDefaultPosition,
189 const wxSize& size = wxDefaultSize,
190 long style = 0);
191
192 void Init();
193
194 ~wxDirFilterListCtrl() {};
195
196 //// Operations
197 void FillFilterList(const wxString& filter, int defaultFilter);
198
199 //// Events
200 void OnSelFilter(wxCommandEvent& event);
201
202 protected:
203 wxGenericDirCtrl* m_dirCtrl;
204
205 DECLARE_EVENT_TABLE()
206 DECLARE_CLASS(wxDirFilterListCtrl)
207 };
208
209 #define wxID_TREECTRL 7000
210 #define wxID_FILTERLISTCTRL 7001
211
212 //-----------------------------------------------------------------------------
213 // wxGenericDirDialog
214 //
215 //-----------------------------------------------------------------------------
216
217 class wxGenericDirDialog: public wxDialog
218 {
219 DECLARE_EVENT_TABLE()
220 public:
221 wxGenericDirDialog(): wxDialog() {}
222 wxGenericDirDialog(wxWindow* parent, const wxString& title,
223 const wxString& defaultPath = wxEmptyString, long style = wxDEFAULT_DIALOG_STYLE, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxSize(450, 550), const wxString& name = "dialog");
224
225 void OnCloseWindow(wxCloseEvent& event);
226 void OnOK(wxCommandEvent& event);
227
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; }
231
232 inline wxString GetMessage(void) const { return m_message; }
233 wxString GetPath(void) const ;
234 inline long GetStyle(void) const { return m_dialogStyle; }
235
236 protected:
237 wxString m_message;
238 long m_dialogStyle;
239 wxString m_path;
240 wxGenericDirCtrl* m_dirCtrl;
241
242 };
243
244 #endif
245 // _WX_DIRCTRLG_H_