1 /////////////////////////////////////////////////////////////////////////////
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"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 class WXDLLEXPORT wxBitmapButton
;
24 class WXDLLEXPORT wxCheckBox
;
25 class WXDLLEXPORT wxChoice
;
26 class WXDLLEXPORT wxFileData
;
27 class WXDLLEXPORT wxFileCtrl
;
28 class WXDLLEXPORT wxGenericFileDialog
;
29 class WXDLLEXPORT wxListEvent
;
30 class WXDLLEXPORT wxListItem
;
31 class WXDLLEXPORT wxStaticText
;
32 class WXDLLEXPORT wxTextCtrl
;
34 #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
35 #define USE_GENERIC_FILEDIALOG
38 //-------------------------------------------------------------------------
39 // wxGenericFileDialog
40 //-------------------------------------------------------------------------
42 class WXDLLEXPORT wxGenericFileDialog
: public wxFileDialogBase
45 wxGenericFileDialog() : wxFileDialogBase() { Init(); }
47 wxGenericFileDialog(wxWindow
*parent
,
48 const wxString
& message
= wxFileSelectorPromptStr
,
49 const wxString
& defaultDir
= wxEmptyString
,
50 const wxString
& defaultFile
= wxEmptyString
,
51 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
53 const wxPoint
& pos
= wxDefaultPosition
,
54 bool bypassGenericImpl
= false );
56 bool Create( wxWindow
*parent
,
57 const wxString
& message
= wxFileSelectorPromptStr
,
58 const wxString
& defaultDir
= wxEmptyString
,
59 const wxString
& defaultFile
= wxEmptyString
,
60 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
62 const wxPoint
& pos
= wxDefaultPosition
,
63 bool bypassGenericImpl
= false );
65 virtual ~wxGenericFileDialog();
67 virtual void SetMessage(const wxString
& message
) { SetTitle(message
); }
68 virtual void SetPath(const wxString
& path
);
69 virtual void SetFilterIndex(int filterIndex
);
70 virtual void SetWildcard(const wxString
& wildCard
);
72 // for multiple file selection
73 virtual void GetPaths(wxArrayString
& paths
) const;
74 virtual void GetFilenames(wxArrayString
& files
) const;
76 // implementation only from now on
77 // -------------------------------
79 virtual int ShowModal();
80 virtual bool Show( bool show
= true );
82 void OnSelected( wxListEvent
&event
);
83 void OnActivated( wxListEvent
&event
);
84 void OnList( wxCommandEvent
&event
);
85 void OnReport( wxCommandEvent
&event
);
86 void OnUp( wxCommandEvent
&event
);
87 void OnHome( wxCommandEvent
&event
);
88 void OnListOk( wxCommandEvent
&event
);
89 void OnNew( wxCommandEvent
&event
);
90 void OnChoiceFilter( wxCommandEvent
&event
);
91 void OnTextEnter( wxCommandEvent
&event
);
92 void OnTextChange( wxCommandEvent
&event
);
93 void OnCheck( wxCommandEvent
&event
);
95 virtual void HandleAction( const wxString
&fn
);
97 virtual void UpdateControls();
100 // Don't use this implementation at all :-)
101 bool m_bypassGenericImpl
;
104 // use the filter with the given index
105 void DoSetFilterIndex(int filterindex
);
107 wxString m_filterExtension
;
112 wxStaticText
*m_static
;
113 wxBitmapButton
*m_upDirButton
;
114 wxBitmapButton
*m_newDirButton
;
118 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog
)
119 DECLARE_EVENT_TABLE()
121 // these variables are preserved between wxGenericFileDialog calls
122 static long ms_lastViewStyle
; // list or report?
123 static bool ms_lastShowHidden
; // did we show hidden files?
126 #ifdef USE_GENERIC_FILEDIALOG
128 class WXDLLEXPORT wxFileDialog
: public wxGenericFileDialog
133 wxFileDialog(wxWindow
*parent
,
134 const wxString
& message
= wxFileSelectorPromptStr
,
135 const wxString
& defaultDir
= wxEmptyString
,
136 const wxString
& defaultFile
= wxEmptyString
,
137 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
139 const wxPoint
& pos
= wxDefaultPosition
)
140 :wxGenericFileDialog(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
)
145 DECLARE_DYNAMIC_CLASS(wxFileDialog
)
148 #endif // USE_GENERIC_FILEDIALOG
150 //-----------------------------------------------------------------------------
151 // wxFileData - a class to hold the file info for the wxFileCtrl
152 //-----------------------------------------------------------------------------
154 class WXDLLEXPORT wxFileData
166 wxFileData() { Init(); }
167 // Full copy constructor
168 wxFileData( const wxFileData
& fileData
) { Copy(fileData
); }
169 // Create a filedata from this information
170 wxFileData( const wxString
&filePath
, const wxString
&fileName
,
171 fileType type
, int image_id
);
173 // make a full copy of the other wxFileData
174 void Copy( const wxFileData
&other
);
176 // (re)read the extra data about the file from the system
179 // get the name of the file, dir, drive
180 wxString
GetFileName() const { return m_fileName
; }
181 // get the full path + name of the file, dir, path
182 wxString
GetFilePath() const { return m_filePath
; }
183 // Set the path + name and name of the item
184 void SetNewName( const wxString
&filePath
, const wxString
&fileName
);
186 // Get the size of the file in bytes
187 wxFileOffset
GetSize() const { return m_size
; }
188 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
189 wxString
GetFileType() const;
190 // get the last modification time
191 wxDateTime
GetDateTime() const { return m_dateTime
; }
192 // Get the time as a formatted string
193 wxString
GetModificationTime() const;
194 // in UNIX get rwx for file, in MSW get attributes ARHS
195 wxString
GetPermissions() const { return m_permissions
; }
196 // Get the id of the image used in a wxImageList
197 int GetImageId() const { return m_image
; }
199 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
200 bool IsDir() const { return (m_type
& is_dir
) != 0; }
201 bool IsLink() const { return (m_type
& is_link
) != 0; }
202 bool IsExe() const { return (m_type
& is_exe
) != 0; }
203 bool IsDrive() const { return (m_type
& is_drive
) != 0; }
205 // Get/Set the type of file, file/dir/drive/link
206 int GetType() const { return m_type
; }
208 // the wxFileCtrl fields in report view
209 enum fileListFieldType
215 #if defined(__UNIX__) || defined(__WIN32__)
217 #endif // defined(__UNIX__) || defined(__WIN32__)
221 // Get the entry for report view of wxFileCtrl
222 wxString
GetEntry( fileListFieldType num
) const;
224 // Get a string representation of the file info
225 wxString
GetHint() const;
226 // initialize a wxListItem attributes
227 void MakeItem( wxListItem
&item
);
230 wxFileData
& operator = (const wxFileData
& fd
) { Copy(fd
); return *this; }
236 wxDateTime m_dateTime
;
237 wxString m_permissions
;
245 //-----------------------------------------------------------------------------
247 //-----------------------------------------------------------------------------
249 class WXDLLEXPORT wxFileCtrl
: public wxListCtrl
253 wxFileCtrl( wxWindow
*win
,
255 const wxString
&wild
,
257 const wxPoint
&pos
= wxDefaultPosition
,
258 const wxSize
&size
= wxDefaultSize
,
259 long style
= wxLC_LIST
,
260 const wxValidator
&validator
= wxDefaultValidator
,
261 const wxString
&name
= wxT("filelist") );
262 virtual ~wxFileCtrl();
264 virtual void ChangeToListMode();
265 virtual void ChangeToReportMode();
266 virtual void ChangeToSmallIconMode();
267 virtual void ShowHidden( bool show
= true );
268 bool GetShowHidden() const { return m_showHidden
; }
270 virtual long Add( wxFileData
*fd
, wxListItem
&item
);
271 virtual void UpdateItem(const wxListItem
&item
);
272 virtual void UpdateFiles();
273 virtual void MakeDir();
274 virtual void GoToParentDir();
275 virtual void GoToHomeDir();
276 virtual void GoToDir( const wxString
&dir
);
277 virtual void SetWild( const wxString
&wild
);
278 wxString
GetWild() const { return m_wild
; }
279 wxString
GetDir() const { return m_dirName
; }
281 void OnListDeleteItem( wxListEvent
&event
);
282 void OnListDeleteAllItems( wxListEvent
&event
);
283 void OnListEndLabelEdit( wxListEvent
&event
);
284 void OnListColClick( wxListEvent
&event
);
286 virtual void SortItems(wxFileData::fileListFieldType field
, bool foward
);
287 bool GetSortDirection() const { return m_sort_foward
; }
288 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
291 void FreeItemData(wxListItem
& item
);
292 void FreeAllItemsData();
299 wxFileData::fileListFieldType m_sort_field
;
302 DECLARE_DYNAMIC_CLASS(wxFileCtrl
)
303 DECLARE_EVENT_TABLE()
306 #endif // _WX_FILEDLGG_H_