1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/filedlgg.h
3 // Purpose: wxGenericFileDialog
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FILEDLGG_H_
13 #define _WX_FILEDLGG_H_
15 #include "wx/listctrl.h"
16 #include "wx/datetime.h"
17 #include "wx/filefn.h"
18 #include "wx/filedlg.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 class WXDLLIMPEXP_FWD_CORE wxBitmapButton
;
25 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
26 class WXDLLIMPEXP_FWD_CORE wxChoice
;
27 class WXDLLIMPEXP_FWD_CORE wxFileData
;
28 class WXDLLIMPEXP_FWD_CORE wxFileCtrl
;
29 class WXDLLIMPEXP_FWD_CORE wxGenericFileDialog
;
30 class WXDLLIMPEXP_FWD_CORE wxListEvent
;
31 class WXDLLIMPEXP_FWD_CORE wxListItem
;
32 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
33 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
35 //-------------------------------------------------------------------------
36 // wxGenericFileDialog
37 //-------------------------------------------------------------------------
39 class WXDLLEXPORT wxGenericFileDialog
: public wxFileDialogBase
42 wxGenericFileDialog() : wxFileDialogBase() { Init(); }
44 wxGenericFileDialog(wxWindow
*parent
,
45 const wxString
& message
= wxFileSelectorPromptStr
,
46 const wxString
& defaultDir
= wxEmptyString
,
47 const wxString
& defaultFile
= wxEmptyString
,
48 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
49 long style
= wxFD_DEFAULT_STYLE
,
50 const wxPoint
& pos
= wxDefaultPosition
,
51 const wxSize
& sz
= wxDefaultSize
,
52 const wxString
& name
= wxFileDialogNameStr
,
53 bool bypassGenericImpl
= false );
55 bool Create( wxWindow
*parent
,
56 const wxString
& message
= wxFileSelectorPromptStr
,
57 const wxString
& defaultDir
= wxEmptyString
,
58 const wxString
& defaultFile
= wxEmptyString
,
59 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
60 long style
= wxFD_DEFAULT_STYLE
,
61 const wxPoint
& pos
= wxDefaultPosition
,
62 const wxSize
& sz
= wxDefaultSize
,
63 const wxString
& name
= wxFileDialogNameStr
,
64 bool bypassGenericImpl
= false );
66 virtual ~wxGenericFileDialog();
68 virtual void SetMessage(const wxString
& message
) { SetTitle(message
); }
69 virtual void SetPath(const wxString
& path
);
70 virtual void SetFilterIndex(int filterIndex
);
71 virtual void SetWildcard(const wxString
& wildCard
);
73 // for multiple file selection
74 virtual void GetPaths(wxArrayString
& paths
) const;
75 virtual void GetFilenames(wxArrayString
& files
) const;
77 // implementation only from now on
78 // -------------------------------
80 virtual int ShowModal();
81 virtual bool Show( bool show
= true );
83 void OnSelected( wxListEvent
&event
);
84 void OnActivated( wxListEvent
&event
);
85 void OnList( wxCommandEvent
&event
);
86 void OnReport( wxCommandEvent
&event
);
87 void OnUp( wxCommandEvent
&event
);
88 void OnHome( wxCommandEvent
&event
);
89 void OnListOk( wxCommandEvent
&event
);
90 void OnNew( wxCommandEvent
&event
);
91 void OnChoiceFilter( wxCommandEvent
&event
);
92 void OnTextEnter( wxCommandEvent
&event
);
93 void OnTextChange( wxCommandEvent
&event
);
94 void OnCheck( wxCommandEvent
&event
);
96 virtual void HandleAction( const wxString
&fn
);
98 virtual void UpdateControls();
101 // Don't use this implementation at all :-)
102 bool m_bypassGenericImpl
;
105 // use the filter with the given index
106 void DoSetFilterIndex(int filterindex
);
108 wxString m_filterExtension
;
113 wxStaticText
*m_static
;
114 wxBitmapButton
*m_upDirButton
;
115 wxBitmapButton
*m_newDirButton
;
119 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog
)
120 DECLARE_EVENT_TABLE()
122 // these variables are preserved between wxGenericFileDialog calls
123 static long ms_lastViewStyle
; // list or report?
124 static bool ms_lastShowHidden
; // did we show hidden files?
127 #ifdef wxHAS_GENERIC_FILEDIALOG
129 class WXDLLEXPORT wxFileDialog
: public wxGenericFileDialog
134 wxFileDialog(wxWindow
*parent
,
135 const wxString
& message
= wxFileSelectorPromptStr
,
136 const wxString
& defaultDir
= wxEmptyString
,
137 const wxString
& defaultFile
= wxEmptyString
,
138 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
140 const wxPoint
& pos
= wxDefaultPosition
)
141 :wxGenericFileDialog(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
)
146 DECLARE_DYNAMIC_CLASS(wxFileDialog
)
149 #endif // wxHAS_GENERIC_FILEDIALOG
151 //-----------------------------------------------------------------------------
152 // wxFileData - a class to hold the file info for the wxFileCtrl
153 //-----------------------------------------------------------------------------
155 class WXDLLEXPORT wxFileData
167 wxFileData() { Init(); }
168 // Full copy constructor
169 wxFileData( const wxFileData
& fileData
) { Copy(fileData
); }
170 // Create a filedata from this information
171 wxFileData( const wxString
&filePath
, const wxString
&fileName
,
172 fileType type
, int image_id
);
174 // make a full copy of the other wxFileData
175 void Copy( const wxFileData
&other
);
177 // (re)read the extra data about the file from the system
180 // get the name of the file, dir, drive
181 wxString
GetFileName() const { return m_fileName
; }
182 // get the full path + name of the file, dir, path
183 wxString
GetFilePath() const { return m_filePath
; }
184 // Set the path + name and name of the item
185 void SetNewName( const wxString
&filePath
, const wxString
&fileName
);
187 // Get the size of the file in bytes
188 wxFileOffset
GetSize() const { return m_size
; }
189 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
190 wxString
GetFileType() const;
191 // get the last modification time
192 wxDateTime
GetDateTime() const { return m_dateTime
; }
193 // Get the time as a formatted string
194 wxString
GetModificationTime() const;
195 // in UNIX get rwx for file, in MSW get attributes ARHS
196 wxString
GetPermissions() const { return m_permissions
; }
197 // Get the id of the image used in a wxImageList
198 int GetImageId() const { return m_image
; }
200 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
201 bool IsDir() const { return (m_type
& is_dir
) != 0; }
202 bool IsLink() const { return (m_type
& is_link
) != 0; }
203 bool IsExe() const { return (m_type
& is_exe
) != 0; }
204 bool IsDrive() const { return (m_type
& is_drive
) != 0; }
206 // Get/Set the type of file, file/dir/drive/link
207 int GetType() const { return m_type
; }
209 // the wxFileCtrl fields in report view
210 enum fileListFieldType
216 #if defined(__UNIX__) || defined(__WIN32__)
218 #endif // defined(__UNIX__) || defined(__WIN32__)
222 // Get the entry for report view of wxFileCtrl
223 wxString
GetEntry( fileListFieldType num
) const;
225 // Get a string representation of the file info
226 wxString
GetHint() const;
227 // initialize a wxListItem attributes
228 void MakeItem( wxListItem
&item
);
231 wxFileData
& operator = (const wxFileData
& fd
) { Copy(fd
); return *this; }
237 wxDateTime m_dateTime
;
238 wxString m_permissions
;
246 //-----------------------------------------------------------------------------
248 //-----------------------------------------------------------------------------
250 class WXDLLEXPORT wxFileCtrl
: public wxListCtrl
254 wxFileCtrl( wxWindow
*win
,
256 const wxString
&wild
,
258 const wxPoint
&pos
= wxDefaultPosition
,
259 const wxSize
&size
= wxDefaultSize
,
260 long style
= wxLC_LIST
,
261 const wxValidator
&validator
= wxDefaultValidator
,
262 const wxString
&name
= wxT("filelist") );
263 virtual ~wxFileCtrl();
265 virtual void ChangeToListMode();
266 virtual void ChangeToReportMode();
267 virtual void ChangeToSmallIconMode();
268 virtual void ShowHidden( bool show
= true );
269 bool GetShowHidden() const { return m_showHidden
; }
271 virtual long Add( wxFileData
*fd
, wxListItem
&item
);
272 virtual void UpdateItem(const wxListItem
&item
);
273 virtual void UpdateFiles();
274 virtual void MakeDir();
275 virtual void GoToParentDir();
276 virtual void GoToHomeDir();
277 virtual void GoToDir( const wxString
&dir
);
278 virtual void SetWild( const wxString
&wild
);
279 wxString
GetWild() const { return m_wild
; }
280 wxString
GetDir() const { return m_dirName
; }
282 void OnListDeleteItem( wxListEvent
&event
);
283 void OnListDeleteAllItems( wxListEvent
&event
);
284 void OnListEndLabelEdit( wxListEvent
&event
);
285 void OnListColClick( wxListEvent
&event
);
287 virtual void SortItems(wxFileData::fileListFieldType field
, bool foward
);
288 bool GetSortDirection() const { return m_sort_foward
; }
289 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
292 void FreeItemData(wxListItem
& item
);
293 void FreeAllItemsData();
300 wxFileData::fileListFieldType m_sort_field
;
303 DECLARE_DYNAMIC_CLASS(wxFileCtrl
)
304 DECLARE_EVENT_TABLE()
307 #endif // _WX_FILEDLGG_H_