]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/filectrlg.h
reverted accidental change to this file as part of rev 48732
[wxWidgets.git] / include / wx / generic / filectrlg.h
CommitLineData
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
7// RCS-ID: $Id$
8// Copyright: (c) Diaa M. Sami
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_GENERIC_FILECTRL_H_
13#define _WX_GENERIC_FILECTRL_H_
14
15#if wxUSE_FILECTRL
16
17#include "wx/panel.h"
18#include "wx/listctrl.h"
19#include "wx/filectrl.h"
20
21class WXDLLIMPEXP_FWD_CORE wxCheckBox;
22class WXDLLIMPEXP_FWD_CORE wxChoice;
23class WXDLLIMPEXP_FWD_CORE wxStaticText;
24class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
25
26extern WXDLLEXPORT_DATA(const wxChar) wxFileSelectorDefaultWildcardStr[];
27
28//-----------------------------------------------------------------------------
29// wxFileData - a class to hold the file info for the wxFileList
30//-----------------------------------------------------------------------------
31
32class WXDLLEXPORT wxFileData
33{
34public:
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
86 // the wxFileList fields in report view
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
99 // Get the entry for report view of wxFileList
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
110protected:
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
119private:
120 void Init();
121};
122
123//-----------------------------------------------------------------------------
124// wxFileList
125//-----------------------------------------------------------------------------
126
127class WXDLLEXPORT wxFileList : public wxListCtrl
128{
129public:
130 wxFileList();
131 wxFileList( wxWindow *win,
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") );
140 virtual ~wxFileList();
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
164 virtual void SortItems(wxFileData::fileListFieldType field, bool foward);
165 bool GetSortDirection() const { return m_sort_foward; }
166 wxFileData::fileListFieldType GetSortField() const { return m_sort_field; }
167
168protected:
169 void FreeItemData(wxListItem& item);
170 void FreeAllItemsData();
171
172 wxString m_dirName;
173 bool m_showHidden;
174 wxString m_wild;
175
176 bool m_sort_foward;
177 wxFileData::fileListFieldType m_sort_field;
178
179private:
180 DECLARE_DYNAMIC_CLASS(wxFileList)
181 DECLARE_EVENT_TABLE()
182};
183
184class WXDLLIMPEXP_CORE wxGenericFileCtrl : public wxPanel,
185 public wxFileCtrlBase
186{
187public:
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;
204 Create( parent, id, defaultDirectory, defaultFilename, wildCard, style, pos, size, name );
205 }
206
207 virtual ~wxGenericFileCtrl() {}
208
209 bool Create( wxWindow *parent,
210 wxWindowID id,
211 const wxString& defaultDirectory = wxEmptyString,
212 const wxString& defaultFileName = wxEmptyString,
213 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
214 long style = wxFC_DEFAULT_STYLE,
215 const wxPoint& pos = wxDefaultPosition,
216 const wxSize& size = wxDefaultSize,
217 const wxString& name = wxFileCtrlNameStr );
218
219 virtual void SetWildcard( const wxString& wildCard );
220 virtual void SetFilterIndex( int filterindex );
221 virtual bool SetDirectory( const wxString& dir );
222
223 // Selects a certain file.
224 // In case the filename specified isn't found/couldn't be shown with currently selected filter, false is returned and nothing happens
225 virtual bool SetFilename( const wxString& name );
226
227 // chdirs to a certain directory and selects a certain file.
228 // In case the filename specified isn't found/couldn't be shown with currently selected filter, false is returned and if directory exists it's chdir'ed to
229 virtual bool SetPath( const wxString& path );
230
231 virtual wxString GetFilename() const;
232 virtual wxString GetDirectory() const;
233 virtual wxString GetWildcard() const { return this->m_wildCard; }
234 virtual wxString GetPath() const;
235 virtual void GetPaths( wxArrayString& paths ) const;
236 virtual void GetFilenames( wxArrayString& files ) const;
237 virtual int GetFilterIndex() const { return m_filterIndex; }
238
239 virtual bool HasMultipleFileSelection() const { return m_style & wxFC_MULTIPLE; }
240 virtual void ShowHidden(const bool show) { m_list->ShowHidden( show ); }
241
242 void GoToParentDir();
243 void GoToHomeDir();
244
245 wxFileList *GetFileList() { return m_list; }
246
247 void ChangeToReportMode() { m_list->ChangeToReportMode(); }
248 void ChangeToListMode() { m_list->ChangeToListMode(); }
249
250
251private:
252 void OnChoiceFilter( wxCommandEvent &event );
253 void OnCheck( wxCommandEvent &event );
254 void OnActivated( wxListEvent &event );
255 void OnTextEnter( wxCommandEvent &WXUNUSED( event ) );
256 void OnTextChange( wxCommandEvent &WXUNUSED( event ) );
257 void OnSelected( wxListEvent &event );
258 void HandleAction( const wxString &fn );
259
260 void DoSetFilterIndex( int filterindex );
261 void UpdateControls();
262 wxString DoGetFilename( const bool fullPath ) const;
263 void DoGetFilenames( wxArrayString& filenames, const bool fullPath ) const;
264 wxString GetProperFileListDir() const;
265
266 int m_style;
267
268 wxString m_filterExtension;
269 wxChoice *m_choice;
270 wxTextCtrl *m_text;
271 wxFileList *m_list;
272 wxCheckBox *m_check;
273 wxStaticText *m_static;
274
275 wxString m_dir;
276 wxString m_fileName;
277 wxString m_wildCard; // wild card in one string as passed to the object previously.
278
279 int m_filterIndex;
280 bool m_inSelected;
281 bool m_ignoreChanges;
282 bool m_noSelChgEvent; // suppress selection changed events.
283
284 DECLARE_DYNAMIC_CLASS( wxGenericFileCtrl )
285 DECLARE_EVENT_TABLE()
286};
287
288#endif // wxUSE_FILECTRL
289
290#endif // _WX_GENERIC_FILECTRL_H_