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 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "filedlgg.h"
19 #include "wx/dialog.h"
20 #include "wx/listctrl.h"
21 #include "wx/datetime.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 class WXDLLEXPORT wxBitmapButton
;
28 class WXDLLEXPORT wxCheckBox
;
29 class WXDLLEXPORT wxChoice
;
30 class WXDLLEXPORT wxFileData
;
31 class WXDLLEXPORT wxFileCtrl
;
32 class WXDLLEXPORT wxGenericFileDialog
;
33 class WXDLLEXPORT wxListEvent
;
34 class WXDLLEXPORT wxListItem
;
35 class WXDLLEXPORT wxStaticText
;
36 class WXDLLEXPORT wxTextCtrl
;
38 #if defined(__WXUNIVERSAL__)||defined(__WXGTK__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
39 #define USE_GENERIC_FILEDIALOG
42 //-------------------------------------------------------------------------
43 // wxGenericFileDialog
44 //-------------------------------------------------------------------------
46 class WXDLLEXPORT wxGenericFileDialog
: public wxDialog
49 wxGenericFileDialog() { }
51 wxGenericFileDialog(wxWindow
*parent
,
52 const wxString
& message
= wxFileSelectorPromptStr
,
53 const wxString
& defaultDir
= _T(""),
54 const wxString
& defaultFile
= _T(""),
55 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
57 const wxPoint
& pos
= wxDefaultPosition
);
58 virtual ~wxGenericFileDialog();
60 void SetMessage(const wxString
& message
) { SetTitle(message
); }
61 void SetPath(const wxString
& path
);
62 void SetDirectory(const wxString
& dir
) { m_dir
= dir
; }
63 void SetFilename(const wxString
& name
) { m_fileName
= name
; }
64 void SetWildcard(const wxString
& wildCard
) { m_wildCard
= wildCard
; }
65 void SetStyle(long style
) { m_dialogStyle
= style
; }
66 void SetFilterIndex(int filterIndex
);
68 wxString
GetMessage() const { return m_message
; }
69 wxString
GetPath() const { return m_path
; }
70 wxString
GetDirectory() const { return m_dir
; }
71 wxString
GetFilename() const { return m_fileName
; }
72 wxString
GetWildcard() const { return m_wildCard
; }
73 long GetStyle() const { return m_dialogStyle
; }
74 int GetFilterIndex() const { return m_filterIndex
; }
76 // for multiple file selection
77 void GetPaths(wxArrayString
& paths
) const;
78 void GetFilenames(wxArrayString
& files
) const;
80 // implementation only from now on
81 // -------------------------------
83 virtual int ShowModal();
85 void OnSelected( wxListEvent
&event
);
86 void OnActivated( wxListEvent
&event
);
87 void OnList( wxCommandEvent
&event
);
88 void OnReport( wxCommandEvent
&event
);
89 void OnUp( wxCommandEvent
&event
);
90 void OnHome( wxCommandEvent
&event
);
91 void OnListOk( wxCommandEvent
&event
);
92 void OnNew( wxCommandEvent
&event
);
93 void OnChoiceFilter( wxCommandEvent
&event
);
94 void OnTextEnter( wxCommandEvent
&event
);
95 void OnTextChange( wxCommandEvent
&event
);
96 void OnCheck( wxCommandEvent
&event
);
98 virtual void HandleAction( const wxString
&fn
);
100 virtual void UpdateControls();
103 // use the filter with the given index
104 void DoSetFilterIndex(int filterindex
);
109 wxString m_path
; // Full path
113 wxString m_filterExtension
;
118 wxStaticText
*m_static
;
119 wxBitmapButton
*m_upDirButton
;
120 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
135 DECLARE_DYNAMIC_CLASS(wxFileDialog
)
140 wxFileDialog(wxWindow
*parent
,
141 const wxString
& message
= wxFileSelectorPromptStr
,
142 const wxString
& defaultDir
= _T(""),
143 const wxString
& defaultFile
= _T(""),
144 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
146 const wxPoint
& pos
= wxDefaultPosition
)
147 :wxGenericFileDialog(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
)
152 #endif // USE_GENERIC_FILEDIALOG
154 //-----------------------------------------------------------------------------
155 // wxFileData - a class to hold the file info for the wxFileCtrl
156 //-----------------------------------------------------------------------------
158 class WXDLLEXPORT wxFileData
170 // Full copy constructor
171 wxFileData( const wxFileData
& fileData
);
172 // Create a filedata from this information
173 wxFileData( const wxString
&filePath
, const wxString
&fileName
,
174 fileType type
, int image_id
);
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 long 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
);
233 wxDateTime m_dateTime
;
234 wxString m_permissions
;
239 //-----------------------------------------------------------------------------
241 //-----------------------------------------------------------------------------
243 class WXDLLEXPORT wxFileCtrl
: public wxListCtrl
247 wxFileCtrl( wxWindow
*win
,
249 const wxString
&wild
,
251 const wxPoint
&pos
= wxDefaultPosition
,
252 const wxSize
&size
= wxDefaultSize
,
253 long style
= wxLC_LIST
,
254 const wxValidator
&validator
= wxDefaultValidator
,
255 const wxString
&name
= wxT("filelist") );
256 virtual ~wxFileCtrl();
258 virtual void ChangeToListMode();
259 virtual void ChangeToReportMode();
260 virtual void ChangeToSmallIconMode();
261 virtual void ShowHidden( bool show
= TRUE
);
262 bool GetShowHidden() const { return m_showHidden
; }
264 virtual long Add( wxFileData
*fd
, wxListItem
&item
);
265 virtual void UpdateItem(const wxListItem
&item
);
266 virtual void UpdateFiles();
267 virtual void MakeDir();
268 virtual void GoToParentDir();
269 virtual void GoToHomeDir();
270 virtual void GoToDir( const wxString
&dir
);
271 virtual void SetWild( const wxString
&wild
);
272 wxString
GetWild() const { return m_wild
; }
273 wxString
GetDir() const { return m_dirName
; }
275 void OnListDeleteItem( wxListEvent
&event
);
276 void OnListEndLabelEdit( wxListEvent
&event
);
277 void OnListColClick( wxListEvent
&event
);
279 virtual void SortItems(wxFileData::fileListFieldType field
, bool foward
);
280 bool GetSortDirection() const { return m_sort_foward
; }
281 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
284 void FreeItemData(const wxListItem
& item
);
285 void FreeAllItemsData();
292 wxFileData::fileListFieldType m_sort_field
;
295 DECLARE_DYNAMIC_CLASS(wxFileCtrl
);
296 DECLARE_EVENT_TABLE()
299 #endif // _WX_FILEDLGG_H_