]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/filedlgg.h
Further wxAUI commits
[wxWidgets.git] / include / wx / generic / filedlgg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/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 #include "wx/listctrl.h"
16 #include "wx/datetime.h"
17 #include "wx/filefn.h"
18 #include "wx/filedlg.h"
19
20 //-----------------------------------------------------------------------------
21 // classes
22 //-----------------------------------------------------------------------------
23
24 class WXDLLEXPORT wxBitmapButton;
25 class WXDLLEXPORT wxCheckBox;
26 class WXDLLEXPORT wxChoice;
27 class WXDLLEXPORT wxFileData;
28 class WXDLLEXPORT wxFileCtrl;
29 class WXDLLEXPORT wxGenericFileDialog;
30 class WXDLLEXPORT wxListEvent;
31 class WXDLLEXPORT wxListItem;
32 class WXDLLEXPORT wxStaticText;
33 class WXDLLEXPORT wxTextCtrl;
34
35 #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
36 #define USE_GENERIC_FILEDIALOG
37 #endif
38
39 //-------------------------------------------------------------------------
40 // wxGenericFileDialog
41 //-------------------------------------------------------------------------
42
43 class WXDLLEXPORT wxGenericFileDialog: public wxFileDialogBase
44 {
45 public:
46 wxGenericFileDialog() : wxFileDialogBase() { Init(); }
47
48 wxGenericFileDialog(wxWindow *parent,
49 const wxString& message = wxFileSelectorPromptStr,
50 const wxString& defaultDir = wxEmptyString,
51 const wxString& defaultFile = wxEmptyString,
52 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
53 long style = wxFD_DEFAULT_STYLE,
54 const wxPoint& pos = wxDefaultPosition,
55 const wxSize& sz = wxDefaultSize,
56 const wxString& name = wxFileDialogNameStr,
57 bool bypassGenericImpl = false );
58
59 bool Create( wxWindow *parent,
60 const wxString& message = wxFileSelectorPromptStr,
61 const wxString& defaultDir = wxEmptyString,
62 const wxString& defaultFile = wxEmptyString,
63 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
64 long style = wxFD_DEFAULT_STYLE,
65 const wxPoint& pos = wxDefaultPosition,
66 const wxSize& sz = wxDefaultSize,
67 const wxString& name = wxFileDialogNameStr,
68 bool bypassGenericImpl = false );
69
70 virtual ~wxGenericFileDialog();
71
72 virtual void SetMessage(const wxString& message) { SetTitle(message); }
73 virtual void SetPath(const wxString& path);
74 virtual void SetFilterIndex(int filterIndex);
75 virtual void SetWildcard(const wxString& wildCard);
76
77 // for multiple file selection
78 virtual void GetPaths(wxArrayString& paths) const;
79 virtual void GetFilenames(wxArrayString& files) const;
80
81 // implementation only from now on
82 // -------------------------------
83
84 virtual int ShowModal();
85 virtual bool Show( bool show = true );
86
87 void OnSelected( wxListEvent &event );
88 void OnActivated( wxListEvent &event );
89 void OnList( wxCommandEvent &event );
90 void OnReport( wxCommandEvent &event );
91 void OnUp( wxCommandEvent &event );
92 void OnHome( wxCommandEvent &event );
93 void OnListOk( wxCommandEvent &event );
94 void OnNew( wxCommandEvent &event );
95 void OnChoiceFilter( wxCommandEvent &event );
96 void OnTextEnter( wxCommandEvent &event );
97 void OnTextChange( wxCommandEvent &event );
98 void OnCheck( wxCommandEvent &event );
99
100 virtual void HandleAction( const wxString &fn );
101
102 virtual void UpdateControls();
103
104 private:
105 // Don't use this implementation at all :-)
106 bool m_bypassGenericImpl;
107
108 protected:
109 // use the filter with the given index
110 void DoSetFilterIndex(int filterindex);
111
112 wxString m_filterExtension;
113 wxChoice *m_choice;
114 wxTextCtrl *m_text;
115 wxFileCtrl *m_list;
116 wxCheckBox *m_check;
117 wxStaticText *m_static;
118 wxBitmapButton *m_upDirButton;
119 wxBitmapButton *m_newDirButton;
120
121 private:
122 void Init();
123 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog)
124 DECLARE_EVENT_TABLE()
125
126 // these variables are preserved between wxGenericFileDialog calls
127 static long ms_lastViewStyle; // list or report?
128 static bool ms_lastShowHidden; // did we show hidden files?
129 };
130
131 #ifdef USE_GENERIC_FILEDIALOG
132
133 class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog
134 {
135 public:
136 wxFileDialog() {}
137
138 wxFileDialog(wxWindow *parent,
139 const wxString& message = wxFileSelectorPromptStr,
140 const wxString& defaultDir = wxEmptyString,
141 const wxString& defaultFile = wxEmptyString,
142 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
143 long style = 0,
144 const wxPoint& pos = wxDefaultPosition)
145 :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos)
146 {
147 }
148
149 private:
150 DECLARE_DYNAMIC_CLASS(wxFileDialog)
151 };
152
153 #endif // USE_GENERIC_FILEDIALOG
154
155 //-----------------------------------------------------------------------------
156 // wxFileData - a class to hold the file info for the wxFileCtrl
157 //-----------------------------------------------------------------------------
158
159 class WXDLLEXPORT wxFileData
160 {
161 public:
162 enum fileType
163 {
164 is_file = 0x0000,
165 is_dir = 0x0001,
166 is_link = 0x0002,
167 is_exe = 0x0004,
168 is_drive = 0x0008
169 };
170
171 wxFileData() { Init(); }
172 // Full copy constructor
173 wxFileData( const wxFileData& fileData ) { Copy(fileData); }
174 // Create a filedata from this information
175 wxFileData( const wxString &filePath, const wxString &fileName,
176 fileType type, int image_id );
177
178 // make a full copy of the other wxFileData
179 void Copy( const wxFileData &other );
180
181 // (re)read the extra data about the file from the system
182 void ReadData();
183
184 // get the name of the file, dir, drive
185 wxString GetFileName() const { return m_fileName; }
186 // get the full path + name of the file, dir, path
187 wxString GetFilePath() const { return m_filePath; }
188 // Set the path + name and name of the item
189 void SetNewName( const wxString &filePath, const wxString &fileName );
190
191 // Get the size of the file in bytes
192 wxFileOffset GetSize() const { return m_size; }
193 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
194 wxString GetFileType() const;
195 // get the last modification time
196 wxDateTime GetDateTime() const { return m_dateTime; }
197 // Get the time as a formatted string
198 wxString GetModificationTime() const;
199 // in UNIX get rwx for file, in MSW get attributes ARHS
200 wxString GetPermissions() const { return m_permissions; }
201 // Get the id of the image used in a wxImageList
202 int GetImageId() const { return m_image; }
203
204 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
205 bool IsDir() const { return (m_type & is_dir ) != 0; }
206 bool IsLink() const { return (m_type & is_link ) != 0; }
207 bool IsExe() const { return (m_type & is_exe ) != 0; }
208 bool IsDrive() const { return (m_type & is_drive) != 0; }
209
210 // Get/Set the type of file, file/dir/drive/link
211 int GetType() const { return m_type; }
212
213 // the wxFileCtrl fields in report view
214 enum fileListFieldType
215 {
216 FileList_Name,
217 FileList_Size,
218 FileList_Type,
219 FileList_Time,
220 #if defined(__UNIX__) || defined(__WIN32__)
221 FileList_Perm,
222 #endif // defined(__UNIX__) || defined(__WIN32__)
223 FileList_Max
224 };
225
226 // Get the entry for report view of wxFileCtrl
227 wxString GetEntry( fileListFieldType num ) const;
228
229 // Get a string representation of the file info
230 wxString GetHint() const;
231 // initialize a wxListItem attributes
232 void MakeItem( wxListItem &item );
233
234 // operators
235 wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; }
236
237 protected:
238 wxString m_fileName;
239 wxString m_filePath;
240 wxFileOffset m_size;
241 wxDateTime m_dateTime;
242 wxString m_permissions;
243 int m_type;
244 int m_image;
245
246 private:
247 void Init();
248 };
249
250 //-----------------------------------------------------------------------------
251 // wxFileCtrl
252 //-----------------------------------------------------------------------------
253
254 class WXDLLEXPORT wxFileCtrl : public wxListCtrl
255 {
256 public:
257 wxFileCtrl();
258 wxFileCtrl( wxWindow *win,
259 wxWindowID id,
260 const wxString &wild,
261 bool showHidden,
262 const wxPoint &pos = wxDefaultPosition,
263 const wxSize &size = wxDefaultSize,
264 long style = wxLC_LIST,
265 const wxValidator &validator = wxDefaultValidator,
266 const wxString &name = wxT("filelist") );
267 virtual ~wxFileCtrl();
268
269 virtual void ChangeToListMode();
270 virtual void ChangeToReportMode();
271 virtual void ChangeToSmallIconMode();
272 virtual void ShowHidden( bool show = true );
273 bool GetShowHidden() const { return m_showHidden; }
274
275 virtual long Add( wxFileData *fd, wxListItem &item );
276 virtual void UpdateItem(const wxListItem &item);
277 virtual void UpdateFiles();
278 virtual void MakeDir();
279 virtual void GoToParentDir();
280 virtual void GoToHomeDir();
281 virtual void GoToDir( const wxString &dir );
282 virtual void SetWild( const wxString &wild );
283 wxString GetWild() const { return m_wild; }
284 wxString GetDir() const { return m_dirName; }
285
286 void OnListDeleteItem( wxListEvent &event );
287 void OnListDeleteAllItems( wxListEvent &event );
288 void OnListEndLabelEdit( wxListEvent &event );
289 void OnListColClick( wxListEvent &event );
290
291 virtual void SortItems(wxFileData::fileListFieldType field, bool foward);
292 bool GetSortDirection() const { return m_sort_foward; }
293 wxFileData::fileListFieldType GetSortField() const { return m_sort_field; }
294
295 protected:
296 void FreeItemData(wxListItem& item);
297 void FreeAllItemsData();
298
299 wxString m_dirName;
300 bool m_showHidden;
301 wxString m_wild;
302
303 bool m_sort_foward;
304 wxFileData::fileListFieldType m_sort_field;
305
306 private:
307 DECLARE_DYNAMIC_CLASS(wxFileCtrl)
308 DECLARE_EVENT_TABLE()
309 };
310
311 #endif // _WX_FILEDLGG_H_