]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dirctrlg.h
merged both implementations of wxGenericDirCtrl
[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: Robert Roebling, Harm van der Heijden, Julian Smart et al
8 // Modified by:
9 // Created: 21/3/2000
10 // RCS-ID: $Id$
11 // Copyright: (c) Robert Roebling, Harm van der Heijden, 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/dialog.h"
26 #include "wx/dirdlg.h"
27 #include "wx/choice.h"
28
29 //-----------------------------------------------------------------------------
30 // classes
31 //-----------------------------------------------------------------------------
32
33 class WXDLLEXPORT wxTextCtrl;
34
35 //-----------------------------------------------------------------------------
36 // Extra styles for wxGenericDirCtrl
37 //-----------------------------------------------------------------------------
38
39 enum
40 {
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
49 };
50
51 //-----------------------------------------------------------------------------
52 // wxDirItemData
53 //-----------------------------------------------------------------------------
54
55 class WXDLLEXPORT wxDirItemData : public wxTreeItemData
56 {
57 public:
58 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
59 ~wxDirItemData();
60 void SetNewDirName(const wxString& path);
61
62 bool HasSubDirs() const;
63 bool HasFiles(const wxString& spec = wxEmptyString) const;
64
65 wxString m_path, m_name;
66 bool m_isHidden;
67 bool m_isExpanded;
68 bool m_isDir;
69 };
70
71 //-----------------------------------------------------------------------------
72 // wxDirCtrl
73 //-----------------------------------------------------------------------------
74
75 class WXDLLEXPORT wxDirFilterListCtrl;
76
77 class WXDLLEXPORT wxGenericDirCtrl: public wxControl
78 {
79 public:
80 wxGenericDirCtrl();
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 )
89 {
90 Init();
91 Create(parent, id, dir, pos, size, style, filter, defaultFilter, name);
92 }
93
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 );
102
103 void Init();
104
105 ~wxGenericDirCtrl();
106
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 );
112
113 // Try to expand as much of the given path as possible.
114 bool ExpandPath(const wxString& path);
115
116 // Accessors
117
118 inline wxString GetDefaultPath() const { return m_defaultPath; }
119 void SetDefaultPath(const wxString& path) { m_defaultPath = path; }
120
121 // Get dir or filename
122 wxString GetPath() const ;
123 // Get selected filename path only (else empty string).
124 // I.e. don't count a directory as a selection
125 wxString GetFilePath() const ;
126 void SetPath(const wxString& path) ;
127
128 wxString GetFilter() const { return m_filter; }
129 void SetFilter(const wxString& filter);
130
131 int GetFilterIndex() const { return m_currentFilter; }
132 void SetFilterIndex(int n) ;
133
134 wxTreeItemId GetRootId() { return m_rootId; }
135
136 wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
137 wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
138
139 //// Helpers
140 void SetupSections();
141 // Parse the filter into an array of filters and an array of descriptions
142 int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
143 // Find the child that matches the first part of 'path'.
144 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
145 // then the child for /usr is returned.
146 // If the path string has been used (we're at the leaf), done is set to TRUE
147 wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
148
149 // Resize the components of the control
150 void DoResize();
151 protected:
152 void ExpandDir(wxTreeItemId parentId);
153 void AddSection(const wxString& path, const wxString& name, int imageId = 0);
154 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
155
156 // Extract description and actual filter from overall filter string
157 bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
158
159 private:
160 bool m_showHidden;
161 wxTreeItemId m_rootId;
162 wxImageList* m_imageList;
163 wxString m_defaultPath; // Starting path
164 long m_styleEx; // Extended style
165 wxString m_filter; // Wildcards in same format as per wxFileDialog
166 int m_currentFilter; // The current filter index
167 wxString m_currentFilterStr; // Current filter string
168 wxTreeCtrl* m_treeCtrl;
169 wxDirFilterListCtrl* m_filterListCtrl;
170
171 private:
172 DECLARE_EVENT_TABLE()
173 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
174 };
175
176 //-----------------------------------------------------------------------------
177 // wxDirFilterListCtrl
178 //-----------------------------------------------------------------------------
179
180 class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice
181 {
182 public:
183 wxDirFilterListCtrl() { Init(); }
184 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
185 const wxPoint& pos = wxDefaultPosition,
186 const wxSize& size = wxDefaultSize,
187 long style = 0)
188 {
189 Init();
190 Create(parent, id, pos, size, style);
191 }
192
193 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
194 const wxPoint& pos = wxDefaultPosition,
195 const wxSize& size = wxDefaultSize,
196 long style = 0);
197
198 void Init();
199
200 ~wxDirFilterListCtrl() {};
201
202 //// Operations
203 void FillFilterList(const wxString& filter, int defaultFilter);
204
205 //// Events
206 void OnSelFilter(wxCommandEvent& event);
207
208 protected:
209 wxGenericDirCtrl* m_dirCtrl;
210
211 DECLARE_EVENT_TABLE()
212 DECLARE_CLASS(wxDirFilterListCtrl)
213 };
214
215 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
216 #define wxDirCtrl wxGenericDirCtrl
217 #endif
218
219 #endif // wxUSE_DIRDLG
220
221 #endif
222 // _WX_DIRCTRLG_H_