]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dirctrlg.h
AppleScript that finds and rebuilds all the CodeWarrior projects
[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 #if wxUSE_DIRDLG
23
24 #include "wx/treectrl.h"
25 #include "wx/dirdlg.h"
26 #include "wx/choice.h"
27
28 //-----------------------------------------------------------------------------
29 // classes
30 //-----------------------------------------------------------------------------
31
32 //-----------------------------------------------------------------------------
33 // Extra styles for wxGenericDirCtrl
34 //-----------------------------------------------------------------------------
35
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
44
45 //-----------------------------------------------------------------------------
46 // wxDirItemData
47 //-----------------------------------------------------------------------------
48
49 class WXDLLEXPORT wxDirItemDataEx : public wxTreeItemData
50 {
51 public:
52 wxDirItemDataEx(const wxString& path, const wxString& name, bool isDir);
53 ~wxDirItemDataEx();
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|wxSUNKEN_BORDER,
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|wxSUNKEN_BORDER,
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 // 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) ;
118
119 wxString GetFilter() const { return m_filter; }
120 void SetFilter(const wxString& filter);
121
122 int GetFilterIndex() const { return m_currentFilter; }
123 void SetFilterIndex(int n) ;
124
125 wxTreeItemId GetRootId() { return m_rootId; }
126
127 wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
128 wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
129
130 //// Helpers
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);
139
140 // Resize the components of the control
141 void DoResize();
142 protected:
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);
146
147 // Extract description and actual filter from overall filter string
148 bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
149
150 private:
151 bool m_showHidden;
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;
161
162 private:
163 DECLARE_EVENT_TABLE()
164 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
165 };
166
167 //-----------------------------------------------------------------------------
168 // wxDirFilterListCtrl
169 //-----------------------------------------------------------------------------
170
171 class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice
172 {
173 public:
174 wxDirFilterListCtrl() { Init(); }
175 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
176 const wxPoint& pos = wxDefaultPosition,
177 const wxSize& size = wxDefaultSize,
178 long style = 0)
179 {
180 Init();
181 Create(parent, id, pos, size, style);
182 }
183
184 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
185 const wxPoint& pos = wxDefaultPosition,
186 const wxSize& size = wxDefaultSize,
187 long style = 0);
188
189 void Init();
190
191 ~wxDirFilterListCtrl() {};
192
193 //// Operations
194 void FillFilterList(const wxString& filter, int defaultFilter);
195
196 //// Events
197 void OnSelFilter(wxCommandEvent& event);
198
199 protected:
200 wxGenericDirCtrl* m_dirCtrl;
201
202 DECLARE_EVENT_TABLE()
203 DECLARE_CLASS(wxDirFilterListCtrl)
204 };
205
206 #define wxID_TREECTRL 7000
207 #define wxID_FILTERLISTCTRL 7001
208
209 //-----------------------------------------------------------------------------
210 // wxGenericDirDialog
211 //
212 //-----------------------------------------------------------------------------
213
214 class wxGenericDirDialog: public wxDialog
215 {
216 DECLARE_EVENT_TABLE()
217 public:
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");
221
222 //// Event handlers
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);
228
229 //// Accessors
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; }
233
234 inline wxString GetMessage(void) const { return m_message; }
235 wxString GetPath(void) const ;
236 inline long GetStyle(void) const { return m_dialogStyle; }
237
238 wxTextCtrl* GetInputCtrl() const { return m_input; }
239
240 //// Overrides
241 int ShowModal();
242
243 protected:
244 wxString m_message;
245 long m_dialogStyle;
246 wxString m_path;
247 wxGenericDirCtrl* m_dirCtrl;
248 wxTextCtrl* m_input;
249
250 };
251
252 #endif // wxUSE_DIRDLG
253
254 #endif
255 // _WX_DIRCTRLG_H_