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() { }
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 );
58 bool Create( wxWindow
*parent
,
59 const wxString
& message
= wxFileSelectorPromptStr
,
60 const wxString
& defaultDir
= wxEmptyString
,
61 const wxString
& defaultFile
= wxEmptyString
,
62 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
64 const wxPoint
& pos
= wxDefaultPosition
);
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
;
117 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog
)
118 DECLARE_EVENT_TABLE()
120 // these variables are preserved between wxGenericFileDialog calls
121 static long ms_lastViewStyle
; // list or report?
122 static bool ms_lastShowHidden
; // did we show hidden files?
125 #ifdef USE_GENERIC_FILEDIALOG
127 class WXDLLEXPORT wxFileDialog
: public wxGenericFileDialog
132 wxFileDialog(wxWindow
*parent
,
133 const wxString
& message
= wxFileSelectorPromptStr
,
134 const wxString
& defaultDir
= wxEmptyString
,
135 const wxString
& defaultFile
= wxEmptyString
,
136 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
138 const wxPoint
& pos
= wxDefaultPosition
)
139 :wxGenericFileDialog(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
)
144 DECLARE_DYNAMIC_CLASS(wxFileDialog
)
147 #endif // USE_GENERIC_FILEDIALOG
149 //-----------------------------------------------------------------------------
150 // wxFileData - a class to hold the file info for the wxFileCtrl
151 //-----------------------------------------------------------------------------
153 class WXDLLEXPORT wxFileData
165 // Full copy constructor
166 wxFileData( const wxFileData
& fileData
) { Copy(fileData
); }
167 // Create a filedata from this information
168 wxFileData( const wxString
&filePath
, const wxString
&fileName
,
169 fileType type
, int image_id
);
171 // make a full copy of the other wxFileData
172 void Copy( const wxFileData
&other
);
174 // (re)read the extra data about the file from the system
177 // get the name of the file, dir, drive
178 wxString
GetFileName() const { return m_fileName
; }
179 // get the full path + name of the file, dir, path
180 wxString
GetFilePath() const { return m_filePath
; }
181 // Set the path + name and name of the item
182 void SetNewName( const wxString
&filePath
, const wxString
&fileName
);
184 // Get the size of the file in bytes
185 long GetSize() const { return m_size
; }
186 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
187 wxString
GetFileType() const;
188 // get the last modification time
189 wxDateTime
GetDateTime() const { return m_dateTime
; }
190 // Get the time as a formatted string
191 wxString
GetModificationTime() const;
192 // in UNIX get rwx for file, in MSW get attributes ARHS
193 wxString
GetPermissions() const { return m_permissions
; }
194 // Get the id of the image used in a wxImageList
195 int GetImageId() const { return m_image
; }
197 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
198 bool IsDir() const { return (m_type
& is_dir
) != 0; }
199 bool IsLink() const { return (m_type
& is_link
) != 0; }
200 bool IsExe() const { return (m_type
& is_exe
) != 0; }
201 bool IsDrive() const { return (m_type
& is_drive
) != 0; }
203 // Get/Set the type of file, file/dir/drive/link
204 int GetType() const { return m_type
; }
206 // the wxFileCtrl fields in report view
207 enum fileListFieldType
213 #if defined(__UNIX__) || defined(__WIN32__)
215 #endif // defined(__UNIX__) || defined(__WIN32__)
219 // Get the entry for report view of wxFileCtrl
220 wxString
GetEntry( fileListFieldType num
) const;
222 // Get a string representation of the file info
223 wxString
GetHint() const;
224 // initialize a wxListItem attributes
225 void MakeItem( wxListItem
&item
);
228 wxFileData
& operator = (const wxFileData
& fd
) { Copy(fd
); return *this; }
234 wxDateTime m_dateTime
;
235 wxString m_permissions
;
240 //-----------------------------------------------------------------------------
242 //-----------------------------------------------------------------------------
244 class WXDLLEXPORT wxFileCtrl
: public wxListCtrl
248 wxFileCtrl( wxWindow
*win
,
250 const wxString
&wild
,
252 const wxPoint
&pos
= wxDefaultPosition
,
253 const wxSize
&size
= wxDefaultSize
,
254 long style
= wxLC_LIST
,
255 const wxValidator
&validator
= wxDefaultValidator
,
256 const wxString
&name
= wxT("filelist") );
257 virtual ~wxFileCtrl();
259 virtual void ChangeToListMode();
260 virtual void ChangeToReportMode();
261 virtual void ChangeToSmallIconMode();
262 virtual void ShowHidden( bool show
= true );
263 bool GetShowHidden() const { return m_showHidden
; }
265 virtual long Add( wxFileData
*fd
, wxListItem
&item
);
266 virtual void UpdateItem(const wxListItem
&item
);
267 virtual void UpdateFiles();
268 virtual void MakeDir();
269 virtual void GoToParentDir();
270 virtual void GoToHomeDir();
271 virtual void GoToDir( const wxString
&dir
);
272 virtual void SetWild( const wxString
&wild
);
273 wxString
GetWild() const { return m_wild
; }
274 wxString
GetDir() const { return m_dirName
; }
276 void OnListDeleteItem( wxListEvent
&event
);
277 void OnListDeleteAllItems( wxListEvent
&event
);
278 void OnListEndLabelEdit( wxListEvent
&event
);
279 void OnListColClick( wxListEvent
&event
);
281 virtual void SortItems(wxFileData::fileListFieldType field
, bool foward
);
282 bool GetSortDirection() const { return m_sort_foward
; }
283 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
286 void FreeItemData(wxListItem
& item
);
287 void FreeAllItemsData();
294 wxFileData::fileListFieldType m_sort_field
;
297 DECLARE_DYNAMIC_CLASS(wxFileCtrl
);
298 DECLARE_EVENT_TABLE()
301 #endif // _WX_FILEDLGG_H_