added default ctor and fixed copying of wxFileData (patch 1149384)
[wxWidgets.git] / include / wx / generic / filedlgg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: filedlgg.h
3 // Purpose: wxGenericFileDialog
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 8/17/99
7 // Copyright: (c) Robert Roebling
8 // RCS-ID: $Id$
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FILEDLGG_H_
13 #define _WX_FILEDLGG_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "filedlgg.h"
17 #endif
18
19 #include "wx/listctrl.h"
20 #include "wx/datetime.h"
21
22 //-----------------------------------------------------------------------------
23 // classes
24 //-----------------------------------------------------------------------------
25
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;
36
37 #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
38 #define USE_GENERIC_FILEDIALOG
39 #endif
40
41 //-------------------------------------------------------------------------
42 // wxGenericFileDialog
43 //-------------------------------------------------------------------------
44
45 class WXDLLEXPORT wxGenericFileDialog: public wxFileDialogBase
46 {
47 public:
48 wxGenericFileDialog() { }
49
50 wxGenericFileDialog(wxWindow *parent,
51 const wxString& message = wxFileSelectorPromptStr,
52 const wxString& defaultDir = wxEmptyString,
53 const wxString& defaultFile = wxEmptyString,
54 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
55 long style = 0,
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,
63 long style = 0,
64 const wxPoint& pos = wxDefaultPosition );
65 virtual ~wxGenericFileDialog();
66
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);
71
72 // for multiple file selection
73 virtual void GetPaths(wxArrayString& paths) const;
74 virtual void GetFilenames(wxArrayString& files) const;
75
76 // implementation only from now on
77 // -------------------------------
78
79 virtual int ShowModal();
80 virtual bool Show( bool show = true );
81
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 );
94
95 virtual void HandleAction( const wxString &fn );
96
97 virtual void UpdateControls();
98
99 private:
100 // Don't use this implementation at all :-)
101 bool m_bypassGenericImpl;
102
103 protected:
104 // use the filter with the given index
105 void DoSetFilterIndex(int filterindex);
106
107 wxString m_filterExtension;
108 wxChoice *m_choice;
109 wxTextCtrl *m_text;
110 wxFileCtrl *m_list;
111 wxCheckBox *m_check;
112 wxStaticText *m_static;
113 wxBitmapButton *m_upDirButton;
114 wxBitmapButton *m_newDirButton;
115
116 private:
117 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog)
118 DECLARE_EVENT_TABLE()
119
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?
123 };
124
125 #ifdef USE_GENERIC_FILEDIALOG
126
127 class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog
128 {
129 public:
130 wxFileDialog() {}
131
132 wxFileDialog(wxWindow *parent,
133 const wxString& message = wxFileSelectorPromptStr,
134 const wxString& defaultDir = wxEmptyString,
135 const wxString& defaultFile = wxEmptyString,
136 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
137 long style = 0,
138 const wxPoint& pos = wxDefaultPosition)
139 :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos)
140 {
141 }
142
143 private:
144 DECLARE_DYNAMIC_CLASS(wxFileDialog)
145 };
146
147 #endif // USE_GENERIC_FILEDIALOG
148
149 //-----------------------------------------------------------------------------
150 // wxFileData - a class to hold the file info for the wxFileCtrl
151 //-----------------------------------------------------------------------------
152
153 class WXDLLEXPORT wxFileData
154 {
155 public:
156 enum fileType
157 {
158 is_file = 0x0000,
159 is_dir = 0x0001,
160 is_link = 0x0002,
161 is_exe = 0x0004,
162 is_drive = 0x0008
163 };
164
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 );
171
172 // make a full copy of the other wxFileData
173 void Copy( const wxFileData &other );
174
175 // (re)read the extra data about the file from the system
176 void ReadData();
177
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 );
184
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; }
197
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; }
203
204 // Get/Set the type of file, file/dir/drive/link
205 int GetType() const { return m_type; }
206
207 // the wxFileCtrl fields in report view
208 enum fileListFieldType
209 {
210 FileList_Name,
211 FileList_Size,
212 FileList_Type,
213 FileList_Time,
214 #if defined(__UNIX__) || defined(__WIN32__)
215 FileList_Perm,
216 #endif // defined(__UNIX__) || defined(__WIN32__)
217 FileList_Max
218 };
219
220 // Get the entry for report view of wxFileCtrl
221 wxString GetEntry( fileListFieldType num ) const;
222
223 // Get a string representation of the file info
224 wxString GetHint() const;
225 // initialize a wxListItem attributes
226 void MakeItem( wxListItem &item );
227
228 // operators
229 wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; }
230
231 protected:
232 wxString m_fileName;
233 wxString m_filePath;
234 long m_size;
235 wxDateTime m_dateTime;
236 wxString m_permissions;
237 int m_type;
238 int m_image;
239
240 private:
241 void Init();
242 };
243
244 //-----------------------------------------------------------------------------
245 // wxFileCtrl
246 //-----------------------------------------------------------------------------
247
248 class WXDLLEXPORT wxFileCtrl : public wxListCtrl
249 {
250 public:
251 wxFileCtrl();
252 wxFileCtrl( wxWindow *win,
253 wxWindowID id,
254 const wxString &wild,
255 bool showHidden,
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();
262
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; }
268
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; }
279
280 void OnListDeleteItem( wxListEvent &event );
281 void OnListDeleteAllItems( wxListEvent &event );
282 void OnListEndLabelEdit( wxListEvent &event );
283 void OnListColClick( wxListEvent &event );
284
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; }
288
289 protected:
290 void FreeItemData(wxListItem& item);
291 void FreeAllItemsData();
292
293 wxString m_dirName;
294 bool m_showHidden;
295 wxString m_wild;
296
297 bool m_sort_foward;
298 wxFileData::fileListFieldType m_sort_field;
299
300 private:
301 DECLARE_DYNAMIC_CLASS(wxFileCtrl)
302 DECLARE_EVENT_TABLE()
303 };
304
305 #endif // _WX_FILEDLGG_H_
306