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