]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dirctrlg.h
A little different fix for how to delay the call to __wxCleanup
[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
18#ifdef __GNUG__
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
VS
33class WXDLLEXPORT wxTextCtrl;
34
51a58d8b
JS
35//-----------------------------------------------------------------------------
36// Extra styles for wxGenericDirCtrl
37//-----------------------------------------------------------------------------
38
748fcded
VS
39enum
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};
51a58d8b
JS
50
51//-----------------------------------------------------------------------------
52// wxDirItemData
53//-----------------------------------------------------------------------------
54
748fcded 55class WXDLLEXPORT wxDirItemData : public wxTreeItemData
51a58d8b
JS
56{
57public:
748fcded
VS
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;
51a58d8b
JS
69};
70
71//-----------------------------------------------------------------------------
72// wxDirCtrl
73//-----------------------------------------------------------------------------
74
75class WXDLLEXPORT wxDirFilterListCtrl;
76
77class WXDLLEXPORT wxGenericDirCtrl: public wxControl
78{
79public:
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,
f9c165b1 85 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
51a58d8b
JS
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,
f9c165b1 98 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
51a58d8b
JS
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
51a58d8b 121 // Get dir or filename
42dcacf0
RR
122 wxString GetPath() const;
123
51a58d8b
JS
124 // Get selected filename path only (else empty string).
125 // I.e. don't count a directory as a selection
42dcacf0
RR
126 wxString GetFilePath() const;
127 void SetPath(const wxString& path);
128
129 void ShowHidden( bool show );
130 bool GetShowHidden() { return m_showHidden; }
51a58d8b
JS
131
132 wxString GetFilter() const { return m_filter; }
133 void SetFilter(const wxString& filter);
134
135 int GetFilterIndex() const { return m_currentFilter; }
42dcacf0 136 void SetFilterIndex(int n);
51a58d8b
JS
137
138 wxTreeItemId GetRootId() { return m_rootId; }
139
140 wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
141 wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
142
42dcacf0 143 // Helper
51a58d8b 144 void SetupSections();
42dcacf0 145
51a58d8b
JS
146 // Parse the filter into an array of filters and an array of descriptions
147 int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
42dcacf0 148
51a58d8b
JS
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();
42dcacf0 157
51a58d8b
JS
158protected:
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
166private:
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
178private:
179 DECLARE_EVENT_TABLE()
180 DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
181};
182
183//-----------------------------------------------------------------------------
184// wxDirFilterListCtrl
185//-----------------------------------------------------------------------------
186
187class WXDLLEXPORT wxDirFilterListCtrl: public wxChoice
188{
189public:
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
748fcded 209 //// Operations
51a58d8b
JS
210 void FillFilterList(const wxString& filter, int defaultFilter);
211
748fcded 212 //// Events
51a58d8b
JS
213 void OnSelFilter(wxCommandEvent& event);
214
215protected:
216 wxGenericDirCtrl* m_dirCtrl;
217
218 DECLARE_EVENT_TABLE()
219 DECLARE_CLASS(wxDirFilterListCtrl)
220};
221
748fcded
VS
222#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
223 #define wxDirCtrl wxGenericDirCtrl
224#endif
51a58d8b 225
1e6feb95
VZ
226#endif // wxUSE_DIRDLG
227
51a58d8b
JS
228#endif
229 // _WX_DIRCTRLG_H_