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(__WXGTK__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
38 #define USE_GENERIC_FILEDIALOG
41 //-------------------------------------------------------------------------
42 // wxGenericFileDialog
43 //-------------------------------------------------------------------------
45 class WXDLLEXPORT wxGenericFileDialog
: public wxFileDialogBase
48 wxGenericFileDialog() { }
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 virtual ~wxGenericFileDialog();
59 virtual void SetMessage(const wxString
& message
) { SetTitle(message
); }
60 virtual void SetPath(const wxString
& path
);
61 virtual void SetFilterIndex(int filterIndex
);
63 // for multiple file selection
64 virtual void GetPaths(wxArrayString
& paths
) const;
65 virtual void GetFilenames(wxArrayString
& files
) const;
67 // implementation only from now on
68 // -------------------------------
70 virtual int ShowModal();
72 void OnSelected( wxListEvent
&event
);
73 void OnActivated( wxListEvent
&event
);
74 void OnList( wxCommandEvent
&event
);
75 void OnReport( wxCommandEvent
&event
);
76 void OnUp( wxCommandEvent
&event
);
77 void OnHome( wxCommandEvent
&event
);
78 void OnListOk( wxCommandEvent
&event
);
79 void OnNew( wxCommandEvent
&event
);
80 void OnChoiceFilter( wxCommandEvent
&event
);
81 void OnTextEnter( wxCommandEvent
&event
);
82 void OnTextChange( wxCommandEvent
&event
);
83 void OnCheck( wxCommandEvent
&event
);
85 virtual void HandleAction( const wxString
&fn
);
87 virtual void UpdateControls();
90 // use the filter with the given index
91 void DoSetFilterIndex(int filterindex
);
93 wxString m_filterExtension
;
98 wxStaticText
*m_static
;
99 wxBitmapButton
*m_upDirButton
;
100 wxBitmapButton
*m_newDirButton
;
103 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog
)
104 DECLARE_EVENT_TABLE()
106 // these variables are preserved between wxGenericFileDialog calls
107 static long ms_lastViewStyle
; // list or report?
108 static bool ms_lastShowHidden
; // did we show hidden files?
111 #ifdef USE_GENERIC_FILEDIALOG
113 class WXDLLEXPORT wxFileDialog
: public wxGenericFileDialog
115 DECLARE_DYNAMIC_CLASS(wxFileDialog
)
120 wxFileDialog(wxWindow
*parent
,
121 const wxString
& message
= wxFileSelectorPromptStr
,
122 const wxString
& defaultDir
= _T(""),
123 const wxString
& defaultFile
= _T(""),
124 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
126 const wxPoint
& pos
= wxDefaultPosition
)
127 :wxGenericFileDialog(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
)
132 #endif // USE_GENERIC_FILEDIALOG
134 //-----------------------------------------------------------------------------
135 // wxFileData - a class to hold the file info for the wxFileCtrl
136 //-----------------------------------------------------------------------------
138 class WXDLLEXPORT wxFileData
150 // Full copy constructor
151 wxFileData( const wxFileData
& fileData
) { Copy(fileData
); }
152 // Create a filedata from this information
153 wxFileData( const wxString
&filePath
, const wxString
&fileName
,
154 fileType type
, int image_id
);
156 // make a full copy of the other wxFileData
157 void Copy( const wxFileData
&other
);
159 // (re)read the extra data about the file from the system
162 // get the name of the file, dir, drive
163 wxString
GetFileName() const { return m_fileName
; }
164 // get the full path + name of the file, dir, path
165 wxString
GetFilePath() const { return m_filePath
; }
166 // Set the path + name and name of the item
167 void SetNewName( const wxString
&filePath
, const wxString
&fileName
);
169 // Get the size of the file in bytes
170 long GetSize() const { return m_size
; }
171 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
172 wxString
GetFileType() const;
173 // get the last modification time
174 wxDateTime
GetDateTime() const { return m_dateTime
; }
175 // Get the time as a formatted string
176 wxString
GetModificationTime() const;
177 // in UNIX get rwx for file, in MSW get attributes ARHS
178 wxString
GetPermissions() const { return m_permissions
; }
179 // Get the id of the image used in a wxImageList
180 int GetImageId() const { return m_image
; }
182 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
183 bool IsDir() const { return (m_type
& is_dir
) != 0; }
184 bool IsLink() const { return (m_type
& is_link
) != 0; }
185 bool IsExe() const { return (m_type
& is_exe
) != 0; }
186 bool IsDrive() const { return (m_type
& is_drive
) != 0; }
188 // Get/Set the type of file, file/dir/drive/link
189 int GetType() const { return m_type
; }
191 // the wxFileCtrl fields in report view
192 enum fileListFieldType
198 #if defined(__UNIX__) || defined(__WIN32__)
200 #endif // defined(__UNIX__) || defined(__WIN32__)
204 // Get the entry for report view of wxFileCtrl
205 wxString
GetEntry( fileListFieldType num
) const;
207 // Get a string representation of the file info
208 wxString
GetHint() const;
209 // initialize a wxListItem attributes
210 void MakeItem( wxListItem
&item
);
213 wxFileData
& operator = (const wxFileData
& fd
) { Copy(fd
); return *this; }
219 wxDateTime m_dateTime
;
220 wxString m_permissions
;
225 //-----------------------------------------------------------------------------
227 //-----------------------------------------------------------------------------
229 class WXDLLEXPORT wxFileCtrl
: public wxListCtrl
233 wxFileCtrl( wxWindow
*win
,
235 const wxString
&wild
,
237 const wxPoint
&pos
= wxDefaultPosition
,
238 const wxSize
&size
= wxDefaultSize
,
239 long style
= wxLC_LIST
,
240 const wxValidator
&validator
= wxDefaultValidator
,
241 const wxString
&name
= wxT("filelist") );
242 virtual ~wxFileCtrl();
244 virtual void ChangeToListMode();
245 virtual void ChangeToReportMode();
246 virtual void ChangeToSmallIconMode();
247 virtual void ShowHidden( bool show
= TRUE
);
248 bool GetShowHidden() const { return m_showHidden
; }
250 virtual long Add( wxFileData
*fd
, wxListItem
&item
);
251 virtual void UpdateItem(const wxListItem
&item
);
252 virtual void UpdateFiles();
253 virtual void MakeDir();
254 virtual void GoToParentDir();
255 virtual void GoToHomeDir();
256 virtual void GoToDir( const wxString
&dir
);
257 virtual void SetWild( const wxString
&wild
);
258 wxString
GetWild() const { return m_wild
; }
259 wxString
GetDir() const { return m_dirName
; }
261 void OnListDeleteItem( wxListEvent
&event
);
262 void OnListDeleteAllItems( wxListEvent
&event
);
263 void OnListEndLabelEdit( wxListEvent
&event
);
264 void OnListColClick( wxListEvent
&event
);
266 virtual void SortItems(wxFileData::fileListFieldType field
, bool foward
);
267 bool GetSortDirection() const { return m_sort_foward
; }
268 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
271 void FreeItemData(wxListItem
& item
);
272 void FreeAllItemsData();
279 wxFileData::fileListFieldType m_sort_field
;
282 DECLARE_DYNAMIC_CLASS(wxFileCtrl
);
283 DECLARE_EVENT_TABLE()
286 #endif // _WX_FILEDLGG_H_