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