]>
Commit | Line | Data |
---|---|---|
0cf3e587 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/generic/filectrlg.h | |
3 | // Purpose: wxGenericFileCtrl Header | |
4 | // Author: Diaa M. Sami | |
5 | // Modified by: | |
6 | // Created: Jul-07-2007 | |
0cf3e587 VZ |
7 | // Copyright: (c) Diaa M. Sami |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_GENERIC_FILECTRL_H_ | |
12 | #define _WX_GENERIC_FILECTRL_H_ | |
13 | ||
14 | #if wxUSE_FILECTRL | |
15 | ||
5804d539 | 16 | #include "wx/containr.h" |
0cf3e587 VZ |
17 | #include "wx/listctrl.h" |
18 | #include "wx/filectrl.h" | |
398eebb1 | 19 | #include "wx/filename.h" |
0cf3e587 VZ |
20 | |
21 | class WXDLLIMPEXP_FWD_CORE wxCheckBox; | |
22 | class WXDLLIMPEXP_FWD_CORE wxChoice; | |
23 | class WXDLLIMPEXP_FWD_CORE wxStaticText; | |
24 | class WXDLLIMPEXP_FWD_CORE wxTextCtrl; | |
25 | ||
53a2db12 | 26 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr[]; |
0cf3e587 VZ |
27 | |
28 | //----------------------------------------------------------------------------- | |
16a6b53d | 29 | // wxFileData - a class to hold the file info for the wxFileListCtrl |
0cf3e587 VZ |
30 | //----------------------------------------------------------------------------- |
31 | ||
53a2db12 | 32 | class WXDLLIMPEXP_CORE wxFileData |
0cf3e587 VZ |
33 | { |
34 | public: | |
35 | enum fileType | |
36 | { | |
37 | is_file = 0x0000, | |
38 | is_dir = 0x0001, | |
39 | is_link = 0x0002, | |
40 | is_exe = 0x0004, | |
41 | is_drive = 0x0008 | |
42 | }; | |
43 | ||
44 | wxFileData() { Init(); } | |
45 | // Full copy constructor | |
46 | wxFileData( const wxFileData& fileData ) { Copy(fileData); } | |
47 | // Create a filedata from this information | |
48 | wxFileData( const wxString &filePath, const wxString &fileName, | |
49 | fileType type, int image_id ); | |
50 | ||
51 | // make a full copy of the other wxFileData | |
52 | void Copy( const wxFileData &other ); | |
53 | ||
54 | // (re)read the extra data about the file from the system | |
55 | void ReadData(); | |
56 | ||
57 | // get the name of the file, dir, drive | |
58 | wxString GetFileName() const { return m_fileName; } | |
59 | // get the full path + name of the file, dir, path | |
60 | wxString GetFilePath() const { return m_filePath; } | |
61 | // Set the path + name and name of the item | |
62 | void SetNewName( const wxString &filePath, const wxString &fileName ); | |
63 | ||
64 | // Get the size of the file in bytes | |
65 | wxFileOffset GetSize() const { return m_size; } | |
66 | // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE> | |
67 | wxString GetFileType() const; | |
68 | // get the last modification time | |
69 | wxDateTime GetDateTime() const { return m_dateTime; } | |
70 | // Get the time as a formatted string | |
71 | wxString GetModificationTime() const; | |
72 | // in UNIX get rwx for file, in MSW get attributes ARHS | |
73 | wxString GetPermissions() const { return m_permissions; } | |
74 | // Get the id of the image used in a wxImageList | |
75 | int GetImageId() const { return m_image; } | |
76 | ||
77 | bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); } | |
78 | bool IsDir() const { return (m_type & is_dir ) != 0; } | |
79 | bool IsLink() const { return (m_type & is_link ) != 0; } | |
80 | bool IsExe() const { return (m_type & is_exe ) != 0; } | |
81 | bool IsDrive() const { return (m_type & is_drive) != 0; } | |
82 | ||
83 | // Get/Set the type of file, file/dir/drive/link | |
84 | int GetType() const { return m_type; } | |
85 | ||
16a6b53d | 86 | // the wxFileListCtrl fields in report view |
0cf3e587 VZ |
87 | enum fileListFieldType |
88 | { | |
89 | FileList_Name, | |
90 | FileList_Size, | |
91 | FileList_Type, | |
92 | FileList_Time, | |
93 | #if defined(__UNIX__) || defined(__WIN32__) | |
94 | FileList_Perm, | |
95 | #endif // defined(__UNIX__) || defined(__WIN32__) | |
96 | FileList_Max | |
97 | }; | |
98 | ||
16a6b53d | 99 | // Get the entry for report view of wxFileListCtrl |
0cf3e587 VZ |
100 | wxString GetEntry( fileListFieldType num ) const; |
101 | ||
102 | // Get a string representation of the file info | |
103 | wxString GetHint() const; | |
104 | // initialize a wxListItem attributes | |
105 | void MakeItem( wxListItem &item ); | |
106 | ||
107 | // operators | |
108 | wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; } | |
109 | ||
110 | protected: | |
111 | wxString m_fileName; | |
112 | wxString m_filePath; | |
113 | wxFileOffset m_size; | |
114 | wxDateTime m_dateTime; | |
115 | wxString m_permissions; | |
116 | int m_type; | |
117 | int m_image; | |
118 | ||
119 | private: | |
120 | void Init(); | |
121 | }; | |
122 | ||
123 | //----------------------------------------------------------------------------- | |
16a6b53d | 124 | // wxFileListCtrl |
0cf3e587 VZ |
125 | //----------------------------------------------------------------------------- |
126 | ||
53a2db12 | 127 | class WXDLLIMPEXP_CORE wxFileListCtrl : public wxListCtrl |
0cf3e587 VZ |
128 | { |
129 | public: | |
16a6b53d VZ |
130 | wxFileListCtrl(); |
131 | wxFileListCtrl( wxWindow *win, | |
0cf3e587 VZ |
132 | wxWindowID id, |
133 | const wxString &wild, | |
134 | bool showHidden, | |
135 | const wxPoint &pos = wxDefaultPosition, | |
136 | const wxSize &size = wxDefaultSize, | |
137 | long style = wxLC_LIST, | |
138 | const wxValidator &validator = wxDefaultValidator, | |
139 | const wxString &name = wxT("filelist") ); | |
16a6b53d | 140 | virtual ~wxFileListCtrl(); |
0cf3e587 VZ |
141 | |
142 | virtual void ChangeToListMode(); | |
143 | virtual void ChangeToReportMode(); | |
144 | virtual void ChangeToSmallIconMode(); | |
145 | virtual void ShowHidden( bool show = true ); | |
146 | bool GetShowHidden() const { return m_showHidden; } | |
147 | ||
148 | virtual long Add( wxFileData *fd, wxListItem &item ); | |
149 | virtual void UpdateItem(const wxListItem &item); | |
150 | virtual void UpdateFiles(); | |
151 | virtual void MakeDir(); | |
152 | virtual void GoToParentDir(); | |
153 | virtual void GoToHomeDir(); | |
154 | virtual void GoToDir( const wxString &dir ); | |
155 | virtual void SetWild( const wxString &wild ); | |
156 | wxString GetWild() const { return m_wild; } | |
157 | wxString GetDir() const { return m_dirName; } | |
158 | ||
159 | void OnListDeleteItem( wxListEvent &event ); | |
160 | void OnListDeleteAllItems( wxListEvent &event ); | |
161 | void OnListEndLabelEdit( wxListEvent &event ); | |
162 | void OnListColClick( wxListEvent &event ); | |
163 | ||
260020e3 PC |
164 | virtual void SortItems(wxFileData::fileListFieldType field, bool forward); |
165 | bool GetSortDirection() const { return m_sort_forward; } | |
0cf3e587 VZ |
166 | wxFileData::fileListFieldType GetSortField() const { return m_sort_field; } |
167 | ||
168 | protected: | |
169 | void FreeItemData(wxListItem& item); | |
170 | void FreeAllItemsData(); | |
171 | ||
172 | wxString m_dirName; | |
173 | bool m_showHidden; | |
174 | wxString m_wild; | |
175 | ||
260020e3 | 176 | bool m_sort_forward; |
0cf3e587 VZ |
177 | wxFileData::fileListFieldType m_sort_field; |
178 | ||
179 | private: | |
16a6b53d | 180 | DECLARE_DYNAMIC_CLASS(wxFileListCtrl) |
0cf3e587 VZ |
181 | DECLARE_EVENT_TABLE() |
182 | }; | |
183 | ||
5804d539 | 184 | class WXDLLIMPEXP_CORE wxGenericFileCtrl : public wxNavigationEnabled<wxControl>, |
0cf3e587 VZ |
185 | public wxFileCtrlBase |
186 | { | |
187 | public: | |
188 | wxGenericFileCtrl() | |
189 | { | |
190 | m_ignoreChanges = false; | |
191 | } | |
192 | ||
193 | wxGenericFileCtrl ( wxWindow *parent, | |
194 | wxWindowID id, | |
195 | const wxString& defaultDirectory = wxEmptyString, | |
196 | const wxString& defaultFilename = wxEmptyString, | |
197 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, | |
198 | long style = wxFC_DEFAULT_STYLE, | |
199 | const wxPoint& pos = wxDefaultPosition, | |
200 | const wxSize& size = wxDefaultSize, | |
201 | const wxString& name = wxFileCtrlNameStr ) | |
202 | { | |
203 | m_ignoreChanges = false; | |
8522a545 VZ |
204 | Create(parent, id, defaultDirectory, defaultFilename, wildCard, |
205 | style, pos, size, name ); | |
0cf3e587 VZ |
206 | } |
207 | ||
208 | virtual ~wxGenericFileCtrl() {} | |
209 | ||
210 | bool Create( wxWindow *parent, | |
211 | wxWindowID id, | |
212 | const wxString& defaultDirectory = wxEmptyString, | |
213 | const wxString& defaultFileName = wxEmptyString, | |
214 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, | |
215 | long style = wxFC_DEFAULT_STYLE, | |
216 | const wxPoint& pos = wxDefaultPosition, | |
217 | const wxSize& size = wxDefaultSize, | |
218 | const wxString& name = wxFileCtrlNameStr ); | |
219 | ||
220 | virtual void SetWildcard( const wxString& wildCard ); | |
221 | virtual void SetFilterIndex( int filterindex ); | |
222 | virtual bool SetDirectory( const wxString& dir ); | |
223 | ||
224 | // Selects a certain file. | |
8522a545 VZ |
225 | // In case the filename specified isn't found/couldn't be shown with |
226 | // currently selected filter, false is returned and nothing happens | |
0cf3e587 VZ |
227 | virtual bool SetFilename( const wxString& name ); |
228 | ||
8522a545 VZ |
229 | // Changes to a certain directory and selects a certain file. |
230 | // In case the filename specified isn't found/couldn't be shown with | |
231 | // currently selected filter, false is returned and if directory exists | |
232 | // it's chdir'ed to | |
0cf3e587 VZ |
233 | virtual bool SetPath( const wxString& path ); |
234 | ||
235 | virtual wxString GetFilename() const; | |
236 | virtual wxString GetDirectory() const; | |
237 | virtual wxString GetWildcard() const { return this->m_wildCard; } | |
238 | virtual wxString GetPath() const; | |
239 | virtual void GetPaths( wxArrayString& paths ) const; | |
240 | virtual void GetFilenames( wxArrayString& files ) const; | |
241 | virtual int GetFilterIndex() const { return m_filterIndex; } | |
242 | ||
8522a545 VZ |
243 | virtual bool HasMultipleFileSelection() const |
244 | { return HasFlag(wxFC_MULTIPLE); } | |
260020e3 | 245 | virtual void ShowHidden(bool show) { m_list->ShowHidden( show ); } |
0cf3e587 VZ |
246 | |
247 | void GoToParentDir(); | |
248 | void GoToHomeDir(); | |
249 | ||
398eebb1 VZ |
250 | // get the directory currently shown in the control: this can be different |
251 | // from GetDirectory() if the user entered a full path (with a path other | |
252 | // than the one currently shown in the control) in the text control | |
253 | // manually | |
254 | wxString GetShownDirectory() const { return m_list->GetDir(); } | |
255 | ||
16a6b53d | 256 | wxFileListCtrl *GetFileList() { return m_list; } |
0cf3e587 VZ |
257 | |
258 | void ChangeToReportMode() { m_list->ChangeToReportMode(); } | |
259 | void ChangeToListMode() { m_list->ChangeToListMode(); } | |
260 | ||
261 | ||
262 | private: | |
263 | void OnChoiceFilter( wxCommandEvent &event ); | |
264 | void OnCheck( wxCommandEvent &event ); | |
265 | void OnActivated( wxListEvent &event ); | |
266 | void OnTextEnter( wxCommandEvent &WXUNUSED( event ) ); | |
267 | void OnTextChange( wxCommandEvent &WXUNUSED( event ) ); | |
268 | void OnSelected( wxListEvent &event ); | |
269 | void HandleAction( const wxString &fn ); | |
270 | ||
271 | void DoSetFilterIndex( int filterindex ); | |
272 | void UpdateControls(); | |
398eebb1 VZ |
273 | |
274 | // the first of these methods can only be used for the controls with single | |
275 | // selection (i.e. without wxFC_MULTIPLE style), the second one in any case | |
276 | wxFileName DoGetFileName() const; | |
0f1b6d7b | 277 | void DoGetFilenames( wxArrayString& filenames, bool fullPath ) const; |
0cf3e587 VZ |
278 | |
279 | int m_style; | |
280 | ||
16a6b53d VZ |
281 | wxString m_filterExtension; |
282 | wxChoice *m_choice; | |
283 | wxTextCtrl *m_text; | |
284 | wxFileListCtrl *m_list; | |
285 | wxCheckBox *m_check; | |
286 | wxStaticText *m_static; | |
0cf3e587 | 287 | |
16a6b53d VZ |
288 | wxString m_dir; |
289 | wxString m_fileName; | |
290 | wxString m_wildCard; // wild card in one string as we got it | |
0cf3e587 VZ |
291 | |
292 | int m_filterIndex; | |
16a6b53d | 293 | bool m_inSelected; |
0cf3e587 | 294 | bool m_ignoreChanges; |
16a6b53d | 295 | bool m_noSelChgEvent; // suppress selection changed events. |
0cf3e587 VZ |
296 | |
297 | DECLARE_DYNAMIC_CLASS( wxGenericFileCtrl ) | |
298 | DECLARE_EVENT_TABLE() | |
299 | }; | |
300 | ||
301 | #endif // wxUSE_FILECTRL | |
302 | ||
303 | #endif // _WX_GENERIC_FILECTRL_H_ |