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(NO_GCC_PRAGMA)
16 #pragma interface "filedlgg.h"
19 #include "wx/listctrl.h"
20 #include "wx/datetime.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 class WXDLLEXPORT wxBitmapButton
;
27 class WXDLLEXPORT wxCheckBox
;
28 class WXDLLEXPORT wxChoice
;
29 class WXDLLEXPORT wxFileData
;
30 class WXDLLEXPORT wxFileCtrl
;
31 class WXDLLEXPORT wxGenericFileDialog
;
32 class WXDLLEXPORT wxListEvent
;
33 class WXDLLEXPORT wxListItem
;
34 class WXDLLEXPORT wxStaticText
;
35 class WXDLLEXPORT wxTextCtrl
;
37 #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
38 #define USE_GENERIC_FILEDIALOG
41 //-------------------------------------------------------------------------
42 // wxGenericFileDialog
43 //-------------------------------------------------------------------------
45 class WXDLLEXPORT wxGenericFileDialog
: public wxFileDialogBase
48 wxGenericFileDialog() : wxFileDialogBase() { Init(); }
50 wxGenericFileDialog(wxWindow
*parent
,
51 const wxString
& message
= wxFileSelectorPromptStr
,
52 const wxString
& defaultDir
= wxEmptyString
,
53 const wxString
& defaultFile
= wxEmptyString
,
54 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
56 const wxPoint
& pos
= wxDefaultPosition
,
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
,
65 const wxPoint
& pos
= wxDefaultPosition
,
66 bool bypassGenericImpl
= false );
68 virtual ~wxGenericFileDialog();
70 virtual void SetMessage(const wxString
& message
) { SetTitle(message
); }
71 virtual void SetPath(const wxString
& path
);
72 virtual void SetFilterIndex(int filterIndex
);
73 virtual void SetWildcard(const wxString
& wildCard
);
75 // for multiple file selection
76 virtual void GetPaths(wxArrayString
& paths
) const;
77 virtual void GetFilenames(wxArrayString
& files
) const;
79 // implementation only from now on
80 // -------------------------------
82 virtual int ShowModal();
83 virtual bool Show( bool show
= true );
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 // Don't use this implementation at all :-)
104 bool m_bypassGenericImpl
;
107 // use the filter with the given index
108 void DoSetFilterIndex(int filterindex
);
110 wxString m_filterExtension
;
115 wxStaticText
*m_static
;
116 wxBitmapButton
*m_upDirButton
;
117 wxBitmapButton
*m_newDirButton
;
121 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog
)
122 DECLARE_EVENT_TABLE()
124 // these variables are preserved between wxGenericFileDialog calls
125 static long ms_lastViewStyle
; // list or report?
126 static bool ms_lastShowHidden
; // did we show hidden files?
129 #ifdef USE_GENERIC_FILEDIALOG
131 class WXDLLEXPORT wxFileDialog
: public wxGenericFileDialog
136 wxFileDialog(wxWindow
*parent
,
137 const wxString
& message
= wxFileSelectorPromptStr
,
138 const wxString
& defaultDir
= wxEmptyString
,
139 const wxString
& defaultFile
= wxEmptyString
,
140 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
142 const wxPoint
& pos
= wxDefaultPosition
)
143 :wxGenericFileDialog(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
)
148 DECLARE_DYNAMIC_CLASS(wxFileDialog
)
151 #endif // USE_GENERIC_FILEDIALOG
153 //-----------------------------------------------------------------------------
154 // wxFileData - a class to hold the file info for the wxFileCtrl
155 //-----------------------------------------------------------------------------
157 class WXDLLEXPORT wxFileData
169 wxFileData() { Init(); }
170 // Full copy constructor
171 wxFileData( const wxFileData
& fileData
) { Copy(fileData
); }
172 // Create a filedata from this information
173 wxFileData( const wxString
&filePath
, const wxString
&fileName
,
174 fileType type
, int image_id
);
176 // make a full copy of the other wxFileData
177 void Copy( const wxFileData
&other
);
179 // (re)read the extra data about the file from the system
182 // get the name of the file, dir, drive
183 wxString
GetFileName() const { return m_fileName
; }
184 // get the full path + name of the file, dir, path
185 wxString
GetFilePath() const { return m_filePath
; }
186 // Set the path + name and name of the item
187 void SetNewName( const wxString
&filePath
, const wxString
&fileName
);
189 // Get the size of the file in bytes
190 long GetSize() const { return m_size
; }
191 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
192 wxString
GetFileType() const;
193 // get the last modification time
194 wxDateTime
GetDateTime() const { return m_dateTime
; }
195 // Get the time as a formatted string
196 wxString
GetModificationTime() const;
197 // in UNIX get rwx for file, in MSW get attributes ARHS
198 wxString
GetPermissions() const { return m_permissions
; }
199 // Get the id of the image used in a wxImageList
200 int GetImageId() const { return m_image
; }
202 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
203 bool IsDir() const { return (m_type
& is_dir
) != 0; }
204 bool IsLink() const { return (m_type
& is_link
) != 0; }
205 bool IsExe() const { return (m_type
& is_exe
) != 0; }
206 bool IsDrive() const { return (m_type
& is_drive
) != 0; }
208 // Get/Set the type of file, file/dir/drive/link
209 int GetType() const { return m_type
; }
211 // the wxFileCtrl fields in report view
212 enum fileListFieldType
218 #if defined(__UNIX__) || defined(__WIN32__)
220 #endif // defined(__UNIX__) || defined(__WIN32__)
224 // Get the entry for report view of wxFileCtrl
225 wxString
GetEntry( fileListFieldType num
) const;
227 // Get a string representation of the file info
228 wxString
GetHint() const;
229 // initialize a wxListItem attributes
230 void MakeItem( wxListItem
&item
);
233 wxFileData
& operator = (const wxFileData
& fd
) { Copy(fd
); return *this; }
239 wxDateTime m_dateTime
;
240 wxString m_permissions
;
248 //-----------------------------------------------------------------------------
250 //-----------------------------------------------------------------------------
252 class WXDLLEXPORT wxFileCtrl
: public wxListCtrl
256 wxFileCtrl( wxWindow
*win
,
258 const wxString
&wild
,
260 const wxPoint
&pos
= wxDefaultPosition
,
261 const wxSize
&size
= wxDefaultSize
,
262 long style
= wxLC_LIST
,
263 const wxValidator
&validator
= wxDefaultValidator
,
264 const wxString
&name
= wxT("filelist") );
265 virtual ~wxFileCtrl();
267 virtual void ChangeToListMode();
268 virtual void ChangeToReportMode();
269 virtual void ChangeToSmallIconMode();
270 virtual void ShowHidden( bool show
= true );
271 bool GetShowHidden() const { return m_showHidden
; }
273 virtual long Add( wxFileData
*fd
, wxListItem
&item
);
274 virtual void UpdateItem(const wxListItem
&item
);
275 virtual void UpdateFiles();
276 virtual void MakeDir();
277 virtual void GoToParentDir();
278 virtual void GoToHomeDir();
279 virtual void GoToDir( const wxString
&dir
);
280 virtual void SetWild( const wxString
&wild
);
281 wxString
GetWild() const { return m_wild
; }
282 wxString
GetDir() const { return m_dirName
; }
284 void OnListDeleteItem( wxListEvent
&event
);
285 void OnListDeleteAllItems( wxListEvent
&event
);
286 void OnListEndLabelEdit( wxListEvent
&event
);
287 void OnListColClick( wxListEvent
&event
);
289 virtual void SortItems(wxFileData::fileListFieldType field
, bool foward
);
290 bool GetSortDirection() const { return m_sort_foward
; }
291 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
294 void FreeItemData(wxListItem
& item
);
295 void FreeAllItemsData();
302 wxFileData::fileListFieldType m_sort_field
;
305 DECLARE_DYNAMIC_CLASS(wxFileCtrl
)
306 DECLARE_EVENT_TABLE()
309 #endif // _WX_FILEDLGG_H_