1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/filectrlg.h
3 // Purpose: wxGenericFileCtrl Header
4 // Author: Diaa M. Sami
6 // Created: Jul-07-2007
7 // Copyright: (c) Diaa M. Sami
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GENERIC_FILECTRL_H_
12 #define _WX_GENERIC_FILECTRL_H_
16 #include "wx/containr.h"
17 #include "wx/listctrl.h"
18 #include "wx/filectrl.h"
19 #include "wx/filename.h"
21 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
22 class WXDLLIMPEXP_FWD_CORE wxChoice
;
23 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
24 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
26 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr
[];
28 //-----------------------------------------------------------------------------
29 // wxFileData - a class to hold the file info for the wxFileListCtrl
30 //-----------------------------------------------------------------------------
32 class WXDLLIMPEXP_CORE wxFileData
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
);
51 // make a full copy of the other wxFileData
52 void Copy( const wxFileData
&other
);
54 // (re)read the extra data about the file from the system
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
);
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
; }
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; }
83 // Get/Set the type of file, file/dir/drive/link
84 int GetType() const { return m_type
; }
86 // the wxFileListCtrl fields in report view
87 enum fileListFieldType
93 #if defined(__UNIX__) || defined(__WIN32__)
95 #endif // defined(__UNIX__) || defined(__WIN32__)
99 // Get the entry for report view of wxFileListCtrl
100 wxString
GetEntry( fileListFieldType num
) const;
102 // Get a string representation of the file info
103 wxString
GetHint() const;
104 // initialize a wxListItem attributes
105 void MakeItem( wxListItem
&item
);
108 wxFileData
& operator = (const wxFileData
& fd
) { Copy(fd
); return *this; }
114 wxDateTime m_dateTime
;
115 wxString m_permissions
;
123 //-----------------------------------------------------------------------------
125 //-----------------------------------------------------------------------------
127 class WXDLLIMPEXP_CORE wxFileListCtrl
: public wxListCtrl
131 wxFileListCtrl( wxWindow
*win
,
133 const wxString
&wild
,
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 ~wxFileListCtrl();
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
; }
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
; }
159 void OnListDeleteItem( wxListEvent
&event
);
160 void OnListDeleteAllItems( wxListEvent
&event
);
161 void OnListEndLabelEdit( wxListEvent
&event
);
162 void OnListColClick( wxListEvent
&event
);
164 virtual void SortItems(wxFileData::fileListFieldType field
, bool forward
);
165 bool GetSortDirection() const { return m_sort_forward
; }
166 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
169 void FreeItemData(wxListItem
& item
);
170 void FreeAllItemsData();
177 wxFileData::fileListFieldType m_sort_field
;
180 DECLARE_DYNAMIC_CLASS(wxFileListCtrl
)
181 DECLARE_EVENT_TABLE()
184 class WXDLLIMPEXP_CORE wxGenericFileCtrl
: public wxNavigationEnabled
<wxControl
>,
185 public wxFileCtrlBase
190 m_ignoreChanges
= false;
193 wxGenericFileCtrl ( wxWindow
*parent
,
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
)
203 m_ignoreChanges
= false;
204 Create(parent
, id
, defaultDirectory
, defaultFilename
, wildCard
,
205 style
, pos
, size
, name
);
208 virtual ~wxGenericFileCtrl() {}
210 bool Create( wxWindow
*parent
,
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
);
220 virtual void SetWildcard( const wxString
& wildCard
);
221 virtual void SetFilterIndex( int filterindex
);
222 virtual bool SetDirectory( const wxString
& dir
);
224 // Selects a certain file.
225 // In case the filename specified isn't found/couldn't be shown with
226 // currently selected filter, false is returned and nothing happens
227 virtual bool SetFilename( const wxString
& name
);
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
233 virtual bool SetPath( const wxString
& path
);
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
; }
243 virtual bool HasMultipleFileSelection() const
244 { return HasFlag(wxFC_MULTIPLE
); }
245 virtual void ShowHidden(bool show
) { m_list
->ShowHidden( show
); }
247 void GoToParentDir();
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
254 wxString
GetShownDirectory() const { return m_list
->GetDir(); }
256 wxFileListCtrl
*GetFileList() { return m_list
; }
258 void ChangeToReportMode() { m_list
->ChangeToReportMode(); }
259 void ChangeToListMode() { m_list
->ChangeToListMode(); }
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
);
271 void DoSetFilterIndex( int filterindex
);
272 void UpdateControls();
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;
277 void DoGetFilenames( wxArrayString
& filenames
, bool fullPath
) const;
281 wxString m_filterExtension
;
284 wxFileListCtrl
*m_list
;
286 wxStaticText
*m_static
;
290 wxString m_wildCard
; // wild card in one string as we got it
294 bool m_ignoreChanges
;
295 bool m_noSelChgEvent
; // suppress selection changed events.
297 DECLARE_DYNAMIC_CLASS( wxGenericFileCtrl
)
298 DECLARE_EVENT_TABLE()
301 #endif // wxUSE_FILECTRL
303 #endif // _WX_GENERIC_FILECTRL_H_