]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dirctrlg.h
added const for Mac OS X compilation
[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 #include "wx/dirdlg.h"
24 #include "wx/choice.h"
25
26 //-----------------------------------------------------------------------------
27 // classes
28 //-----------------------------------------------------------------------------
29
30 //-----------------------------------------------------------------------------
31 // Extra styles for wxGenericDirCtrl
32 //-----------------------------------------------------------------------------
33
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
42
43 //-----------------------------------------------------------------------------
44 // wxDirItemData
45 //-----------------------------------------------------------------------------
46
47 class WXDLLEXPORT wxDirItemDataEx : public wxTreeItemData
48 {
49 public:
50 wxDirItemDataEx(const wxString& path, const wxString& name, bool isDir);
51 ~wxDirItemDataEx();
52 void SetNewDirName( wxString path );
53 wxString m_path, m_name;
54 bool m_isHidden;
55 bool m_hasSubDirs;
56 bool m_isExpanded;
57 bool m_isDir;
58 };
59
60 //-----------------------------------------------------------------------------
61 // wxDirCtrl
62 //-----------------------------------------------------------------------------
63
64 class WXDLLEXPORT wxDirFilterListCtrl;
65
66 class WXDLLEXPORT wxGenericDirCtrl: public wxControl
67 {
68 public:
69 wxGenericDirCtrl();
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 )
78 {
79 Init();
80 Create(parent, id, dir, pos, size, style, filter, defaultFilter, name);
81 }
82
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 );
91
92 void Init();
93
94 ~wxGenericDirCtrl();
95
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 );
101
102 // Try to expand as much of the given path as possible.
103 bool ExpandPath(const wxString& path);
104
105 // Accessors
106
107 inline wxString GetDefaultPath() const { return m_defaultPath; }
108 void SetDefaultPath(const wxString& path) { m_defaultPath = path; }
109
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) ;
116
117 wxString GetFilter() const { return m_filter; }
118 void SetFilter(const wxString& filter);
119
120 int GetFilterIndex() const { return m_currentFilter; }
121 void SetFilterIndex(int n) ;
122
123 wxTreeItemId GetRootId() { return m_rootId; }
124
125 wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
126 wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
127
128 //// Helpers
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);
137
138 // Resize the components of the control
139 void DoResize();
140 protected:
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);
144
145 // Extract description and actual filter from overall filter string
146 bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
147
148 private:
149 bool m_showHidden;
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;
159
160 private:
161 DECLARE_EVENT_TABLE()
162 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
163 };
164
165 //-----------------------------------------------------------------------------
166 // wxDirFilterListCtrl
167 //-----------------------------------------------------------------------------
168
169 class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice
170 {
171 public:
172 wxDirFilterListCtrl() { Init(); }
173 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
174 const wxPoint& pos = wxDefaultPosition,
175 const wxSize& size = wxDefaultSize,
176 long style = 0)
177 {
178 Init();
179 Create(parent, id, pos, size, style);
180 }
181
182 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
183 const wxPoint& pos = wxDefaultPosition,
184 const wxSize& size = wxDefaultSize,
185 long style = 0);
186
187 void Init();
188
189 ~wxDirFilterListCtrl() {};
190
191 //// Operations
192 void FillFilterList(const wxString& filter, int defaultFilter);
193
194 //// Events
195 void OnSelFilter(wxCommandEvent& event);
196
197 protected:
198 wxGenericDirCtrl* m_dirCtrl;
199
200 DECLARE_EVENT_TABLE()
201 DECLARE_CLASS(wxDirFilterListCtrl)
202 };
203
204 #define wxID_TREECTRL 7000
205 #define wxID_FILTERLISTCTRL 7001
206
207 //-----------------------------------------------------------------------------
208 // wxGenericDirDialog
209 //
210 //-----------------------------------------------------------------------------
211
212 class wxGenericDirDialog: public wxDialog
213 {
214 DECLARE_EVENT_TABLE()
215 public:
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");
219
220 //// Event handlers
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);
226
227 //// Accessors
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 wxTextCtrl* GetInputCtrl() const { return m_input; }
237
238 //// Overrides
239 int ShowModal();
240
241 protected:
242 wxString m_message;
243 long m_dialogStyle;
244 wxString m_path;
245 wxGenericDirCtrl* m_dirCtrl;
246 wxTextCtrl* m_input;
247
248 };
249
250 #endif
251 // _WX_DIRCTRLG_H_