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 #ifdef USE_GENERIC_FILEDIALOG
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
48 WXDLLEXPORT_DATA(extern const wxChar
*)wxFileSelectorPromptStr
;
49 WXDLLEXPORT_DATA(extern const wxChar
*)wxFileSelectorDefaultWildcardStr
;
51 #endif // USE_GENERIC_FILEDIALOG
53 //-------------------------------------------------------------------------
55 //-------------------------------------------------------------------------
57 class WXDLLEXPORT wxGenericFileDialog
: public wxDialog
60 wxGenericFileDialog() { }
62 wxGenericFileDialog(wxWindow
*parent
,
63 const wxString
& message
= wxFileSelectorPromptStr
,
64 const wxString
& defaultDir
= _T(""),
65 const wxString
& defaultFile
= _T(""),
66 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
68 const wxPoint
& pos
= wxDefaultPosition
);
69 virtual ~wxGenericFileDialog();
71 void SetMessage(const wxString
& message
) { SetTitle(message
); }
72 void SetPath(const wxString
& path
);
73 void SetDirectory(const wxString
& dir
) { m_dir
= dir
; }
74 void SetFilename(const wxString
& name
) { m_fileName
= name
; }
75 void SetWildcard(const wxString
& wildCard
) { m_wildCard
= wildCard
; }
76 void SetStyle(long style
) { m_dialogStyle
= style
; }
77 void SetFilterIndex(int filterIndex
);
79 wxString
GetMessage() const { return m_message
; }
80 wxString
GetPath() const { return m_path
; }
81 wxString
GetDirectory() const { return m_dir
; }
82 wxString
GetFilename() const { return m_fileName
; }
83 wxString
GetWildcard() const { return m_wildCard
; }
84 long GetStyle() const { return m_dialogStyle
; }
85 int GetFilterIndex() const { return m_filterIndex
; }
87 // for multiple file selection
88 void GetPaths(wxArrayString
& paths
) const;
89 void GetFilenames(wxArrayString
& files
) const;
91 // implementation only from now on
92 // -------------------------------
94 virtual int ShowModal();
96 void OnSelected( wxListEvent
&event
);
97 void OnActivated( wxListEvent
&event
);
98 void OnList( wxCommandEvent
&event
);
99 void OnReport( wxCommandEvent
&event
);
100 void OnUp( wxCommandEvent
&event
);
101 void OnHome( wxCommandEvent
&event
);
102 void OnListOk( wxCommandEvent
&event
);
103 void OnNew( wxCommandEvent
&event
);
104 void OnChoiceFilter( wxCommandEvent
&event
);
105 void OnTextEnter( wxCommandEvent
&event
);
106 void OnTextChange( wxCommandEvent
&event
);
107 void OnCheck( wxCommandEvent
&event
);
109 virtual void HandleAction( const wxString
&fn
);
111 virtual void UpdateControls();
114 // use the filter with the given index
115 void DoSetFilterIndex(int filterindex
);
120 wxString m_path
; // Full path
124 wxString m_filterExtension
;
129 wxStaticText
*m_static
;
130 wxBitmapButton
*m_upDirButton
;
131 wxBitmapButton
*m_newDirButton
;
134 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog
)
135 DECLARE_EVENT_TABLE()
137 // these variables are preserved between wxGenericFileDialog calls
138 static long ms_lastViewStyle
; // list or report?
139 static bool ms_lastShowHidden
; // did we show hidden files?
142 #ifdef USE_GENERIC_FILEDIALOG
144 class WXDLLEXPORT wxFileDialog
: public wxGenericFileDialog
146 DECLARE_DYNAMIC_CLASS(wxFileDialog
)
151 wxFileDialog(wxWindow
*parent
,
152 const wxString
& message
= wxFileSelectorPromptStr
,
153 const wxString
& defaultDir
= _T(""),
154 const wxString
& defaultFile
= _T(""),
155 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
157 const wxPoint
& pos
= wxDefaultPosition
)
158 :wxGenericFileDialog(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
)
163 // File selector - backward compatibility
165 wxFileSelector(const wxChar
*message
= wxFileSelectorPromptStr
,
166 const wxChar
*default_path
= NULL
,
167 const wxChar
*default_filename
= NULL
,
168 const wxChar
*default_extension
= NULL
,
169 const wxChar
*wildcard
= wxFileSelectorDefaultWildcardStr
,
171 wxWindow
*parent
= NULL
,
172 int x
= -1, int y
= -1);
174 // An extended version of wxFileSelector
176 wxFileSelectorEx(const wxChar
*message
= wxFileSelectorPromptStr
,
177 const wxChar
*default_path
= NULL
,
178 const wxChar
*default_filename
= NULL
,
179 int *indexDefaultExtension
= NULL
,
180 const wxChar
*wildcard
= wxFileSelectorDefaultWildcardStr
,
182 wxWindow
*parent
= NULL
,
183 int x
= -1, int y
= -1);
185 // Ask for filename to load
187 wxLoadFileSelector(const wxChar
*what
,
188 const wxChar
*extension
,
189 const wxChar
*default_name
= (const wxChar
*)NULL
,
190 wxWindow
*parent
= (wxWindow
*) NULL
);
192 // Ask for filename to save
194 wxSaveFileSelector(const wxChar
*what
,
195 const wxChar
*extension
,
196 const wxChar
*default_name
= (const wxChar
*) NULL
,
197 wxWindow
*parent
= (wxWindow
*) NULL
);
199 #endif // USE_GENERIC_FILEDIALOG
201 //-----------------------------------------------------------------------------
203 //-----------------------------------------------------------------------------
205 class WXDLLEXPORT wxFileData
217 wxFileData( const wxString
&filePath
, const wxString
&fileName
,
218 fileType type
, int image_id
);
220 // get the name of the file, dir, drive
221 wxString
GetFileName() const { return m_fileName
; }
222 // get the full path + name of the file, dir, path
223 wxString
GetFilePath() const { return m_filePath
; }
224 long GetSize() const { return m_size
; }
225 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
226 wxString
GetType() const;
227 // get the last modification time
228 wxDateTime
GetTime() const { return m_dateTime
; }
229 wxString
GetModificationTime() const;
230 // in UNIX get rwx for file, in MSW get attributes ARHS
231 wxString
GetPermissions() const { return m_permissions
; }
232 int GetImageId() const { return m_image
; }
234 bool IsDir() const { return (m_type
& is_dir
) != 0; }
235 bool IsLink() const { return (m_type
& is_link
) != 0; }
236 bool IsExe() const { return (m_type
& is_exe
) != 0; }
237 bool IsDrive() const { return (m_type
& is_drive
) != 0; }
239 int GetFileType() const { return m_type
; }
241 // the wxFileCtrl fields in report view
242 enum fileListFieldType
248 #if defined(__UNIX__) || defined(__WIN32__)
250 #endif // defined(__UNIX__) || defined(__WIN32__)
254 wxString
GetEntry( fileListFieldType num
) const;
256 // Get a string representation of the file info
257 wxString
GetHint() const;
258 void MakeItem( wxListItem
&item
);
259 void SetNewName( const wxString
&filePath
, const wxString
&fileName
);
265 wxDateTime m_dateTime
;
266 wxString m_permissions
;
271 //-----------------------------------------------------------------------------
273 //-----------------------------------------------------------------------------
275 class WXDLLEXPORT wxFileCtrl
: public wxListCtrl
279 wxFileCtrl( wxWindow
*win
,
281 const wxString
&wild
,
283 const wxPoint
&pos
= wxDefaultPosition
,
284 const wxSize
&size
= wxDefaultSize
,
285 long style
= wxLC_LIST
,
286 const wxValidator
&validator
= wxDefaultValidator
,
287 const wxString
&name
= wxT("filelist") );
288 virtual ~wxFileCtrl();
290 virtual void ChangeToListMode();
291 virtual void ChangeToReportMode();
292 virtual void ChangeToSmallIconMode();
293 virtual void ShowHidden( bool show
= TRUE
);
294 bool GetShowHidden() const { return m_showHidden
; }
296 virtual long Add( wxFileData
*fd
, wxListItem
&item
);
297 virtual void UpdateFiles();
298 virtual void MakeDir();
299 virtual void GoToParentDir();
300 virtual void GoToHomeDir();
301 virtual void GoToDir( const wxString
&dir
);
302 virtual void SetWild( const wxString
&wild
);
303 wxString
GetWild() const { return m_wild
; }
304 wxString
GetDir() const { return m_dirName
; }
306 void OnListDeleteItem( wxListEvent
&event
);
307 void OnListEndLabelEdit( wxListEvent
&event
);
308 void OnListColClick( wxListEvent
&event
);
310 virtual void SortItems(wxFileData::fileListFieldType field
, bool foward
);
311 bool GetSortDirection() const { return m_sort_foward
; }
312 wxFileData::fileListFieldType
GetSortField() const { return m_sort_field
; }
315 void FreeItemData(const wxListItem
& item
);
316 void FreeAllItemsData();
323 wxFileData::fileListFieldType m_sort_field
;
326 DECLARE_DYNAMIC_CLASS(wxFileCtrl
);
327 DECLARE_EVENT_TABLE()