]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/filectrlg.h
Forgot to commit
[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//-----------------------------------------------------------------------------
16a6b53d 29// wxFileData - a class to hold the file info for the wxFileListCtrl
0cf3e587
VZ
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
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
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//-----------------------------------------------------------------------------
16a6b53d 124// wxFileListCtrl
0cf3e587
VZ
125//-----------------------------------------------------------------------------
126
16a6b53d 127class WXDLLEXPORT wxFileListCtrl : public wxListCtrl
0cf3e587
VZ
128{
129public:
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
168protected:
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
179private:
16a6b53d 180 DECLARE_DYNAMIC_CLASS(wxFileListCtrl)
0cf3e587
VZ
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;
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
16a6b53d 250 wxFileListCtrl *GetFileList() { return m_list; }
0cf3e587
VZ
251
252 void ChangeToReportMode() { m_list->ChangeToReportMode(); }
253 void ChangeToListMode() { m_list->ChangeToListMode(); }
254
255
256private:
257 void OnChoiceFilter( wxCommandEvent &event );
258 void OnCheck( wxCommandEvent &event );
259 void OnActivated( wxListEvent &event );
260 void OnTextEnter( wxCommandEvent &WXUNUSED( event ) );
261 void OnTextChange( wxCommandEvent &WXUNUSED( event ) );
262 void OnSelected( wxListEvent &event );
263 void HandleAction( const wxString &fn );
264
265 void DoSetFilterIndex( int filterindex );
266 void UpdateControls();
267 wxString DoGetFilename( const bool fullPath ) const;
268 void DoGetFilenames( wxArrayString& filenames, const bool fullPath ) const;
269 wxString GetProperFileListDir() const;
270
271 int m_style;
272
16a6b53d
VZ
273 wxString m_filterExtension;
274 wxChoice *m_choice;
275 wxTextCtrl *m_text;
276 wxFileListCtrl *m_list;
277 wxCheckBox *m_check;
278 wxStaticText *m_static;
0cf3e587 279
16a6b53d
VZ
280 wxString m_dir;
281 wxString m_fileName;
282 wxString m_wildCard; // wild card in one string as we got it
0cf3e587
VZ
283
284 int m_filterIndex;
16a6b53d 285 bool m_inSelected;
0cf3e587 286 bool m_ignoreChanges;
16a6b53d 287 bool m_noSelChgEvent; // suppress selection changed events.
0cf3e587
VZ
288
289 DECLARE_DYNAMIC_CLASS( wxGenericFileCtrl )
290 DECLARE_EVENT_TABLE()
291};
292
293#endif // wxUSE_FILECTRL
294
295#endif // _WX_GENERIC_FILECTRL_H_