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