]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dirctrlg.h
Little tweaks and fixes.
[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
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);
128
129 void ShowHidden( bool show );
130 bool GetShowHidden() { return m_showHidden; }
131
132 wxString GetFilter() const { return m_filter; }
133 void SetFilter(const wxString& filter);
134
135 int GetFilterIndex() const { return m_currentFilter; }
136 void SetFilterIndex(int n);
137
138 wxTreeItemId GetRootId() { return m_rootId; }
139
140 wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
141 wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
142
143 // Helper
144 void SetupSections();
145
146 // Parse the filter into an array of filters and an array of descriptions
147 int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
148
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);
154
155 // Resize the components of the control
156 void DoResize();
157
158 protected:
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);
162
163 // Extract description and actual filter from overall filter string
164 bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
165
166 private:
167 bool m_showHidden;
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;
177
178 private:
179 DECLARE_EVENT_TABLE()
180 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
181 };
182
183 //-----------------------------------------------------------------------------
184 // wxDirFilterListCtrl
185 //-----------------------------------------------------------------------------
186
187 class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice
188 {
189 public:
190 wxDirFilterListCtrl() { Init(); }
191 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
192 const wxPoint& pos = wxDefaultPosition,
193 const wxSize& size = wxDefaultSize,
194 long style = 0)
195 {
196 Init();
197 Create(parent, id, pos, size, style);
198 }
199
200 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
201 const wxPoint& pos = wxDefaultPosition,
202 const wxSize& size = wxDefaultSize,
203 long style = 0);
204
205 void Init();
206
207 ~wxDirFilterListCtrl() {};
208
209 //// Operations
210 void FillFilterList(const wxString& filter, int defaultFilter);
211
212 //// Events
213 void OnSelFilter(wxCommandEvent& event);
214
215 protected:
216 wxGenericDirCtrl* m_dirCtrl;
217
218 DECLARE_EVENT_TABLE()
219 DECLARE_CLASS(wxDirFilterListCtrl)
220 };
221
222 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
223 #define wxDirCtrl wxGenericDirCtrl
224 #endif
225
226 #endif // wxUSE_DIRDLG
227
228 #endif
229 // _WX_DIRCTRLG_H_