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