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 wxFileData() { Init(); }
166 // Full copy constructor
167 wxFileData( const wxFileData
& fileData
) { Copy(fileData
); }
168 // Create a filedata from this information
169 wxFileData( const wxString
&filePath
, const wxString
&fileName
,
170 fileType type
, int image_id
);
172 // make a full copy of the other wxFileData
173 void Copy( const wxFileData
&other
);
175 // (re)read the extra data about the file from the system
178 // get the name of the file, dir, drive
179 wxString
GetFileName() const { return m_fileName
; }
180 // get the full path + name of the file, dir, path
181 wxString
GetFilePath() const { return m_filePath
; }
182 // Set the path + name and name of the item
183 void SetNewName( const wxString
&filePath
, const wxString
&fileName
);
185 // Get the size of the file in bytes
186 long GetSize() const { return m_size
; }
187 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
188 wxString
GetFileType() const;
189 // get the last modification time
190 wxDateTime
GetDateTime() const { return m_dateTime
; }
191 // Get the time as a formatted string
192 wxString
GetModificationTime() const;
193 // in UNIX get rwx for file, in MSW get attributes ARHS
194 wxString
GetPermissions() const { return m_permissions
; }
195 // Get the id of the image used in a wxImageList
196 int GetImageId() const { return m_image
; }
198 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
199 bool IsDir() const { return (m_type
& is_dir
) != 0; }
200 bool IsLink() const { return (m_type
& is_link
) != 0; }
201 bool IsExe() const { return (m_type
& is_exe
) != 0; }
202 bool IsDrive() const { return (m_type
& is_drive
) != 0; }
204 // Get/Set the type of file, file/dir/drive/link
205 int GetType() const { return m_type
; }
207 // the wxFileCtrl fields in report view
208 enum fileListFieldType
214 #if defined(__UNIX__) || defined(__WIN32__)
216 #endif // defined(__UNIX__) || defined(__WIN32__)
220 // Get the entry for report view of wxFileCtrl
221 wxString
GetEntry( fileListFieldType num
) const;
223 // Get a string representation of the file info
224 wxString
GetHint() const;
225 // initialize a wxListItem attributes
226 void MakeItem( wxListItem
&item
);
229 wxFileData
& operator = (const wxFileData
& fd
) { Copy(fd
); return *this; }
235 wxDateTime m_dateTime
;
236 wxString m_permissions
;
244 //-----------------------------------------------------------------------------
246 //-----------------------------------------------------------------------------
248 class WXDLLEXPORT wxFileCtrl
: public wxListCtrl
252 wxFileCtrl( wxWindow
*win
,
254 const wxString
&wild
,
256 const wxPoint
&pos
= wxDefaultPosition
,
257 const wxSize
&size
= wxDefaultSize
,
258 long style
= wxLC_LIST
,
259 const wxValidator
&validator
= wxDefaultValidator
,
260 const wxString
&name
= wxT("filelist") );
261 virtual ~wxFileCtrl();
263 virtual void ChangeToListMode();
264 virtual void ChangeToReportMode();
265 virtual void ChangeToSmallIconMode();
266 virtual void ShowHidden( bool show
= true );
267 bool GetShowHidden() const { return m_showHidden
; }
269 virtual long Add( wxFileData
*fd
, wxListItem
&item
);
270 virtual void UpdateItem(const wxListItem
&item
);
271 virtual void UpdateFiles();
272 virtual void MakeDir();
273 virtual void GoToParentDir();
274 virtual void GoToHomeDir();
275 virtual void GoToDir( const wxString
&dir
);
276 virtual void SetWild( const wxString
&wild
);
277 wxString
GetWild() const { return m_wild
; }
278 wxString
GetDir() const { return m_dirName
; }
280 void OnListDeleteItem( wxListEvent
&event
);
281 void OnListDeleteAllItems( wxListEvent
&event
);
282 void OnListEndLabelEdit( wxListEvent
&event
);
283 void OnListColClick( wxListEvent
&event
);
285 virtual void SortItems(wxFileData::fileListFieldType field
, bool foward
);
286 bool GetSortDirection() const { return m_sort_foward
; }
287 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
290 void FreeItemData(wxListItem
& item
);
291 void FreeAllItemsData();
298 wxFileData::fileListFieldType m_sort_field
;
301 DECLARE_DYNAMIC_CLASS(wxFileCtrl
)
302 DECLARE_EVENT_TABLE()
305 #endif // _WX_FILEDLGG_H_