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 WXDLLEXPORT wxBitmapButton
;
25 class WXDLLEXPORT wxCheckBox
;
26 class WXDLLEXPORT wxChoice
;
27 class WXDLLEXPORT wxFileData
;
28 class WXDLLEXPORT wxFileCtrl
;
29 class WXDLLEXPORT wxGenericFileDialog
;
30 class WXDLLEXPORT wxListEvent
;
31 class WXDLLEXPORT wxListItem
;
32 class WXDLLEXPORT wxStaticText
;
33 class WXDLLEXPORT wxTextCtrl
;
35 #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
36 #define USE_GENERIC_FILEDIALOG
39 //-------------------------------------------------------------------------
40 // wxGenericFileDialog
41 //-------------------------------------------------------------------------
43 class WXDLLEXPORT wxGenericFileDialog
: public wxFileDialogBase
46 wxGenericFileDialog() : wxFileDialogBase() { Init(); }
48 wxGenericFileDialog(wxWindow
*parent
,
49 const wxString
& message
= wxFileSelectorPromptStr
,
50 const wxString
& defaultDir
= wxEmptyString
,
51 const wxString
& defaultFile
= wxEmptyString
,
52 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
53 long style
= wxFD_DEFAULT_STYLE
,
54 const wxPoint
& pos
= wxDefaultPosition
,
55 const wxSize
& sz
= wxDefaultSize
,
56 const wxString
& name
= wxFileDialogNameStr
,
57 bool bypassGenericImpl
= false );
59 bool Create( wxWindow
*parent
,
60 const wxString
& message
= wxFileSelectorPromptStr
,
61 const wxString
& defaultDir
= wxEmptyString
,
62 const wxString
& defaultFile
= wxEmptyString
,
63 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
64 long style
= wxFD_DEFAULT_STYLE
,
65 const wxPoint
& pos
= wxDefaultPosition
,
66 const wxSize
& sz
= wxDefaultSize
,
67 const wxString
& name
= wxFileDialogNameStr
,
68 bool bypassGenericImpl
= false );
70 virtual ~wxGenericFileDialog();
72 virtual void SetMessage(const wxString
& message
) { SetTitle(message
); }
73 virtual void SetPath(const wxString
& path
);
74 virtual void SetFilterIndex(int filterIndex
);
75 virtual void SetWildcard(const wxString
& wildCard
);
77 // for multiple file selection
78 virtual void GetPaths(wxArrayString
& paths
) const;
79 virtual void GetFilenames(wxArrayString
& files
) const;
81 // implementation only from now on
82 // -------------------------------
84 virtual int ShowModal();
85 virtual bool Show( bool show
= true );
87 void OnSelected( wxListEvent
&event
);
88 void OnActivated( wxListEvent
&event
);
89 void OnList( wxCommandEvent
&event
);
90 void OnReport( wxCommandEvent
&event
);
91 void OnUp( wxCommandEvent
&event
);
92 void OnHome( wxCommandEvent
&event
);
93 void OnListOk( wxCommandEvent
&event
);
94 void OnNew( wxCommandEvent
&event
);
95 void OnChoiceFilter( wxCommandEvent
&event
);
96 void OnTextEnter( wxCommandEvent
&event
);
97 void OnTextChange( wxCommandEvent
&event
);
98 void OnCheck( wxCommandEvent
&event
);
100 virtual void HandleAction( const wxString
&fn
);
102 virtual void UpdateControls();
105 // Don't use this implementation at all :-)
106 bool m_bypassGenericImpl
;
109 // use the filter with the given index
110 void DoSetFilterIndex(int filterindex
);
112 wxString m_filterExtension
;
117 wxStaticText
*m_static
;
118 wxBitmapButton
*m_upDirButton
;
119 wxBitmapButton
*m_newDirButton
;
123 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog
)
124 DECLARE_EVENT_TABLE()
126 // these variables are preserved between wxGenericFileDialog calls
127 static long ms_lastViewStyle
; // list or report?
128 static bool ms_lastShowHidden
; // did we show hidden files?
131 #ifdef USE_GENERIC_FILEDIALOG
133 class WXDLLEXPORT wxFileDialog
: public wxGenericFileDialog
138 wxFileDialog(wxWindow
*parent
,
139 const wxString
& message
= wxFileSelectorPromptStr
,
140 const wxString
& defaultDir
= wxEmptyString
,
141 const wxString
& defaultFile
= wxEmptyString
,
142 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
144 const wxPoint
& pos
= wxDefaultPosition
)
145 :wxGenericFileDialog(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
)
150 DECLARE_DYNAMIC_CLASS(wxFileDialog
)
153 #endif // USE_GENERIC_FILEDIALOG
155 //-----------------------------------------------------------------------------
156 // wxFileData - a class to hold the file info for the wxFileCtrl
157 //-----------------------------------------------------------------------------
159 class WXDLLEXPORT wxFileData
171 wxFileData() { Init(); }
172 // Full copy constructor
173 wxFileData( const wxFileData
& fileData
) { Copy(fileData
); }
174 // Create a filedata from this information
175 wxFileData( const wxString
&filePath
, const wxString
&fileName
,
176 fileType type
, int image_id
);
178 // make a full copy of the other wxFileData
179 void Copy( const wxFileData
&other
);
181 // (re)read the extra data about the file from the system
184 // get the name of the file, dir, drive
185 wxString
GetFileName() const { return m_fileName
; }
186 // get the full path + name of the file, dir, path
187 wxString
GetFilePath() const { return m_filePath
; }
188 // Set the path + name and name of the item
189 void SetNewName( const wxString
&filePath
, const wxString
&fileName
);
191 // Get the size of the file in bytes
192 wxFileOffset
GetSize() const { return m_size
; }
193 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
194 wxString
GetFileType() const;
195 // get the last modification time
196 wxDateTime
GetDateTime() const { return m_dateTime
; }
197 // Get the time as a formatted string
198 wxString
GetModificationTime() const;
199 // in UNIX get rwx for file, in MSW get attributes ARHS
200 wxString
GetPermissions() const { return m_permissions
; }
201 // Get the id of the image used in a wxImageList
202 int GetImageId() const { return m_image
; }
204 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
205 bool IsDir() const { return (m_type
& is_dir
) != 0; }
206 bool IsLink() const { return (m_type
& is_link
) != 0; }
207 bool IsExe() const { return (m_type
& is_exe
) != 0; }
208 bool IsDrive() const { return (m_type
& is_drive
) != 0; }
210 // Get/Set the type of file, file/dir/drive/link
211 int GetType() const { return m_type
; }
213 // the wxFileCtrl fields in report view
214 enum fileListFieldType
220 #if defined(__UNIX__) || defined(__WIN32__)
222 #endif // defined(__UNIX__) || defined(__WIN32__)
226 // Get the entry for report view of wxFileCtrl
227 wxString
GetEntry( fileListFieldType num
) const;
229 // Get a string representation of the file info
230 wxString
GetHint() const;
231 // initialize a wxListItem attributes
232 void MakeItem( wxListItem
&item
);
235 wxFileData
& operator = (const wxFileData
& fd
) { Copy(fd
); return *this; }
241 wxDateTime m_dateTime
;
242 wxString m_permissions
;
250 //-----------------------------------------------------------------------------
252 //-----------------------------------------------------------------------------
254 class WXDLLEXPORT wxFileCtrl
: public wxListCtrl
258 wxFileCtrl( wxWindow
*win
,
260 const wxString
&wild
,
262 const wxPoint
&pos
= wxDefaultPosition
,
263 const wxSize
&size
= wxDefaultSize
,
264 long style
= wxLC_LIST
,
265 const wxValidator
&validator
= wxDefaultValidator
,
266 const wxString
&name
= wxT("filelist") );
267 virtual ~wxFileCtrl();
269 virtual void ChangeToListMode();
270 virtual void ChangeToReportMode();
271 virtual void ChangeToSmallIconMode();
272 virtual void ShowHidden( bool show
= true );
273 bool GetShowHidden() const { return m_showHidden
; }
275 virtual long Add( wxFileData
*fd
, wxListItem
&item
);
276 virtual void UpdateItem(const wxListItem
&item
);
277 virtual void UpdateFiles();
278 virtual void MakeDir();
279 virtual void GoToParentDir();
280 virtual void GoToHomeDir();
281 virtual void GoToDir( const wxString
&dir
);
282 virtual void SetWild( const wxString
&wild
);
283 wxString
GetWild() const { return m_wild
; }
284 wxString
GetDir() const { return m_dirName
; }
286 void OnListDeleteItem( wxListEvent
&event
);
287 void OnListDeleteAllItems( wxListEvent
&event
);
288 void OnListEndLabelEdit( wxListEvent
&event
);
289 void OnListColClick( wxListEvent
&event
);
291 virtual void SortItems(wxFileData::fileListFieldType field
, bool foward
);
292 bool GetSortDirection() const { return m_sort_foward
; }
293 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
296 void FreeItemData(wxListItem
& item
);
297 void FreeAllItemsData();
304 wxFileData::fileListFieldType m_sort_field
;
307 DECLARE_DYNAMIC_CLASS(wxFileCtrl
)
308 DECLARE_EVENT_TABLE()
311 #endif // _WX_FILEDLGG_H_