1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/filectrlg.h
3 // Purpose: wxGenericFileCtrl Header
4 // Author: Diaa M. Sami
6 // Created: Jul-07-2007
8 // Copyright: (c) Diaa M. Sami
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_FILECTRL_H_
13 #define _WX_GENERIC_FILECTRL_H_
17 #include "wx/containr.h"
18 #include "wx/listctrl.h"
19 #include "wx/filectrl.h"
20 #include "wx/filename.h"
22 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
23 class WXDLLIMPEXP_FWD_CORE wxChoice
;
24 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
25 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
27 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr
[];
29 //-----------------------------------------------------------------------------
30 // wxFileData - a class to hold the file info for the wxFileListCtrl
31 //-----------------------------------------------------------------------------
33 class WXDLLIMPEXP_CORE wxFileData
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
);
52 // make a full copy of the other wxFileData
53 void Copy( const wxFileData
&other
);
55 // (re)read the extra data about the file from the system
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
);
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
; }
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; }
84 // Get/Set the type of file, file/dir/drive/link
85 int GetType() const { return m_type
; }
87 // the wxFileListCtrl fields in report view
88 enum fileListFieldType
94 #if defined(__UNIX__) || defined(__WIN32__)
96 #endif // defined(__UNIX__) || defined(__WIN32__)
100 // Get the entry for report view of wxFileListCtrl
101 wxString
GetEntry( fileListFieldType num
) const;
103 // Get a string representation of the file info
104 wxString
GetHint() const;
105 // initialize a wxListItem attributes
106 void MakeItem( wxListItem
&item
);
109 wxFileData
& operator = (const wxFileData
& fd
) { Copy(fd
); return *this; }
115 wxDateTime m_dateTime
;
116 wxString m_permissions
;
124 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
128 class WXDLLIMPEXP_CORE wxFileListCtrl
: public wxListCtrl
132 wxFileListCtrl( wxWindow
*win
,
134 const wxString
&wild
,
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();
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
; }
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
; }
160 void OnListDeleteItem( wxListEvent
&event
);
161 void OnListDeleteAllItems( wxListEvent
&event
);
162 void OnListEndLabelEdit( wxListEvent
&event
);
163 void OnListColClick( wxListEvent
&event
);
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
; }
170 void FreeItemData(wxListItem
& item
);
171 void FreeAllItemsData();
178 wxFileData::fileListFieldType m_sort_field
;
181 DECLARE_DYNAMIC_CLASS(wxFileListCtrl
)
182 DECLARE_EVENT_TABLE()
185 class WXDLLIMPEXP_CORE wxGenericFileCtrl
: public wxNavigationEnabled
<wxControl
>,
186 public wxFileCtrlBase
191 m_ignoreChanges
= false;
194 wxGenericFileCtrl ( wxWindow
*parent
,
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
)
204 m_ignoreChanges
= false;
205 Create(parent
, id
, defaultDirectory
, defaultFilename
, wildCard
,
206 style
, pos
, size
, name
);
209 virtual ~wxGenericFileCtrl() {}
211 bool Create( wxWindow
*parent
,
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
);
221 virtual void SetWildcard( const wxString
& wildCard
);
222 virtual void SetFilterIndex( int filterindex
);
223 virtual bool SetDirectory( const wxString
& dir
);
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
);
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
234 virtual bool SetPath( const wxString
& path
);
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
; }
244 virtual bool HasMultipleFileSelection() const
245 { return HasFlag(wxFC_MULTIPLE
); }
246 virtual void ShowHidden(bool show
) { m_list
->ShowHidden( show
); }
248 void GoToParentDir();
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
255 wxString
GetShownDirectory() const { return m_list
->GetDir(); }
257 wxFileListCtrl
*GetFileList() { return m_list
; }
259 void ChangeToReportMode() { m_list
->ChangeToReportMode(); }
260 void ChangeToListMode() { m_list
->ChangeToListMode(); }
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
);
272 void DoSetFilterIndex( int filterindex
);
273 void UpdateControls();
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;
282 wxString m_filterExtension
;
285 wxFileListCtrl
*m_list
;
287 wxStaticText
*m_static
;
291 wxString m_wildCard
; // wild card in one string as we got it
295 bool m_ignoreChanges
;
296 bool m_noSelChgEvent
; // suppress selection changed events.
298 DECLARE_DYNAMIC_CLASS( wxGenericFileCtrl
)
299 DECLARE_EVENT_TABLE()
302 #endif // wxUSE_FILECTRL
304 #endif // _WX_GENERIC_FILECTRL_H_