]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dirctrlg.h
Fix wxMotif build.
[wxWidgets.git] / include / wx / generic / dirctrlg.h
CommitLineData
51a58d8b
JS
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.
748fcded 7// Author: Robert Roebling, Harm van der Heijden, Julian Smart et al
51a58d8b
JS
8// Modified by:
9// Created: 21/3/2000
10// RCS-ID: $Id$
748fcded 11// Copyright: (c) Robert Roebling, Harm van der Heijden, Julian Smart
1e6feb95 12// Licence: wxWindows licence
51a58d8b
JS
13/////////////////////////////////////////////////////////////////////////////
14
15#ifndef _WX_DIRCTRL_H_
16#define _WX_DIRCTRL_H_
17
af49c4b8 18#if defined(__GNUG__) && !defined(__APPLE__)
51a58d8b
JS
19#pragma interface "dirctrlg.h"
20#endif
21
1e6feb95
VZ
22#if wxUSE_DIRDLG
23
51a58d8b 24#include "wx/treectrl.h"
748fcded 25#include "wx/dialog.h"
3509d340
VS
26#include "wx/dirdlg.h"
27#include "wx/choice.h"
51a58d8b
JS
28
29//-----------------------------------------------------------------------------
30// classes
31//-----------------------------------------------------------------------------
32
748fcded 33class WXDLLEXPORT wxTextCtrl;
06cc1fb9
JS
34class WXDLLEXPORT wxImageList;
35class WXDLLEXPORT wxHashTable;
748fcded 36
51a58d8b
JS
37//-----------------------------------------------------------------------------
38// Extra styles for wxGenericDirCtrl
39//-----------------------------------------------------------------------------
40
748fcded
VS
41enum
42{
43 // Only allow directory viewing/selection, no files
44 wxDIRCTRL_DIR_ONLY = 0x0010,
45 // When setting the default path, select the first file in the directory
46 wxDIRCTRL_SELECT_FIRST = 0x0020,
47 // Show the filter list
48 wxDIRCTRL_SHOW_FILTERS = 0x0040,
49 // Use 3D borders on internal controls
fd775aae
JS
50 wxDIRCTRL_3D_INTERNAL = 0x0080,
51 // Editable labels
dabd1377 52 wxDIRCTRL_EDIT_LABELS = 0x0100
748fcded 53};
51a58d8b
JS
54
55//-----------------------------------------------------------------------------
56// wxDirItemData
57//-----------------------------------------------------------------------------
58
748fcded 59class WXDLLEXPORT wxDirItemData : public wxTreeItemData
51a58d8b
JS
60{
61public:
748fcded
VS
62 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
63 ~wxDirItemData();
64 void SetNewDirName(const wxString& path);
65
66 bool HasSubDirs() const;
67 bool HasFiles(const wxString& spec = wxEmptyString) const;
68
69 wxString m_path, m_name;
70 bool m_isHidden;
71 bool m_isExpanded;
72 bool m_isDir;
51a58d8b
JS
73};
74
75//-----------------------------------------------------------------------------
76// wxDirCtrl
77//-----------------------------------------------------------------------------
78
79class WXDLLEXPORT wxDirFilterListCtrl;
80
81class WXDLLEXPORT wxGenericDirCtrl: public wxControl
82{
83public:
84 wxGenericDirCtrl();
85 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
86 const wxString &dir = wxDirDialogDefaultFolderStr,
87 const wxPoint& pos = wxDefaultPosition,
88 const wxSize& size = wxDefaultSize,
f9c165b1 89 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
51a58d8b
JS
90 const wxString& filter = wxEmptyString,
91 int defaultFilter = 0,
92 const wxString& name = wxTreeCtrlNameStr )
93 {
94 Init();
95 Create(parent, id, dir, pos, size, style, filter, defaultFilter, name);
96 }
97
98 bool Create(wxWindow *parent, const wxWindowID id = -1,
99 const wxString &dir = wxDirDialogDefaultFolderStr,
100 const wxPoint& pos = wxDefaultPosition,
101 const wxSize& size = wxDefaultSize,
f9c165b1 102 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
51a58d8b
JS
103 const wxString& filter = wxEmptyString,
104 int defaultFilter = 0,
105 const wxString& name = wxTreeCtrlNameStr );
106
2b5f62a0 107 virtual void Init();
51a58d8b 108
2b5f62a0 109 virtual ~wxGenericDirCtrl();
51a58d8b
JS
110
111 void OnExpandItem(wxTreeEvent &event );
112 void OnCollapseItem(wxTreeEvent &event );
113 void OnBeginEditItem(wxTreeEvent &event );
114 void OnEndEditItem(wxTreeEvent &event );
115 void OnSize(wxSizeEvent &event );
116
117 // Try to expand as much of the given path as possible.
2b5f62a0 118 virtual bool ExpandPath(const wxString& path);
51a58d8b
JS
119
120 // Accessors
121
2b5f62a0
VZ
122 virtual inline wxString GetDefaultPath() const { return m_defaultPath; }
123 virtual void SetDefaultPath(const wxString& path) { m_defaultPath = path; }
51a58d8b 124
51a58d8b 125 // Get dir or filename
2b5f62a0 126 virtual wxString GetPath() const;
42dcacf0 127
51a58d8b
JS
128 // Get selected filename path only (else empty string).
129 // I.e. don't count a directory as a selection
2b5f62a0
VZ
130 virtual wxString GetFilePath() const;
131 virtual void SetPath(const wxString& path);
42dcacf0 132
2b5f62a0
VZ
133 virtual void ShowHidden( bool show );
134 virtual bool GetShowHidden() { return m_showHidden; }
51a58d8b 135
2b5f62a0
VZ
136 virtual wxString GetFilter() const { return m_filter; }
137 virtual void SetFilter(const wxString& filter);
51a58d8b 138
2b5f62a0
VZ
139 virtual int GetFilterIndex() const { return m_currentFilter; }
140 virtual void SetFilterIndex(int n);
51a58d8b 141
2b5f62a0 142 virtual wxTreeItemId GetRootId() { return m_rootId; }
51a58d8b 143
2b5f62a0
VZ
144 virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
145 virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
51a58d8b 146
42dcacf0 147 // Helper
2b5f62a0 148 virtual void SetupSections();
42dcacf0 149
51a58d8b 150 // Parse the filter into an array of filters and an array of descriptions
2b5f62a0 151 virtual int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
42dcacf0 152
51a58d8b
JS
153 // Find the child that matches the first part of 'path'.
154 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
155 // then the child for /usr is returned.
156 // If the path string has been used (we're at the leaf), done is set to TRUE
2b5f62a0 157 virtual wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
51a58d8b
JS
158
159 // Resize the components of the control
2b5f62a0 160 virtual void DoResize();
42dcacf0 161
08887820 162 // Collapse & expand the tree, thus re-creating it from scratch:
2b5f62a0 163 virtual void ReCreateTree();
08887820 164
51a58d8b
JS
165protected:
166 void ExpandDir(wxTreeItemId parentId);
08887820 167 void CollapseDir(wxTreeItemId parentId);
51a58d8b
JS
168 void AddSection(const wxString& path, const wxString& name, int imageId = 0);
169 //void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
170
171 // Extract description and actual filter from overall filter string
172 bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
173
174private:
175 bool m_showHidden;
176 wxTreeItemId m_rootId;
51a58d8b
JS
177 wxString m_defaultPath; // Starting path
178 long m_styleEx; // Extended style
179 wxString m_filter; // Wildcards in same format as per wxFileDialog
180 int m_currentFilter; // The current filter index
181 wxString m_currentFilterStr; // Current filter string
182 wxTreeCtrl* m_treeCtrl;
183 wxDirFilterListCtrl* m_filterListCtrl;
184
185private:
186 DECLARE_EVENT_TABLE()
187 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
22f3361e 188 DECLARE_NO_COPY_CLASS(wxGenericDirCtrl)
51a58d8b
JS
189};
190
191//-----------------------------------------------------------------------------
192// wxDirFilterListCtrl
193//-----------------------------------------------------------------------------
194
195class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice
196{
197public:
198 wxDirFilterListCtrl() { Init(); }
199 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
200 const wxPoint& pos = wxDefaultPosition,
201 const wxSize& size = wxDefaultSize,
202 long style = 0)
203 {
204 Init();
205 Create(parent, id, pos, size, style);
206 }
207
208 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
209 const wxPoint& pos = wxDefaultPosition,
210 const wxSize& size = wxDefaultSize,
211 long style = 0);
212
213 void Init();
214
215 ~wxDirFilterListCtrl() {};
216
748fcded 217 //// Operations
51a58d8b
JS
218 void FillFilterList(const wxString& filter, int defaultFilter);
219
748fcded 220 //// Events
51a58d8b
JS
221 void OnSelFilter(wxCommandEvent& event);
222
223protected:
224 wxGenericDirCtrl* m_dirCtrl;
225
226 DECLARE_EVENT_TABLE()
227 DECLARE_CLASS(wxDirFilterListCtrl)
22f3361e 228 DECLARE_NO_COPY_CLASS(wxDirFilterListCtrl)
51a58d8b
JS
229};
230
748fcded
VS
231#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
232 #define wxDirCtrl wxGenericDirCtrl
233#endif
51a58d8b 234
a977709b
JS
235// Symbols for accessing individual controls
236#define wxID_TREECTRL 7000
237#define wxID_FILTERLISTCTRL 7001
238
06cc1fb9
JS
239//-------------------------------------------------------------------------
240// wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
241//-------------------------------------------------------------------------
242
243class WXDLLEXPORT wxFileIconsTable
244{
245public:
246 wxFileIconsTable();
247 ~wxFileIconsTable();
248
249 enum iconId_Type
250 {
251 folder,
252 folder_open,
253 computer,
254 drive,
255 cdrom,
256 floppy,
257 removeable,
258 file,
259 executable
260 };
261
262 int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString);
263 wxImageList *GetSmallImageList();
264
265protected:
266 void Create(); // create on first use
267
268 wxImageList *m_smallImageList;
269 wxHashTable *m_HashTable;
270};
271
272// The global fileicons table
273WXDLLEXPORT_DATA(extern wxFileIconsTable *) wxTheFileIconsTable;
274
1e6feb95
VZ
275#endif // wxUSE_DIRDLG
276
51a58d8b
JS
277#endif
278 // _WX_DIRCTRLG_H_