]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/filedlgg.h
more extra semicolons removed (patch 1303724)
[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 #include "wx/listctrl.h"
16 #include "wx/datetime.h"
17
18 //-----------------------------------------------------------------------------
19 // classes
20 //-----------------------------------------------------------------------------
21
22 class WXDLLEXPORT wxBitmapButton;
23 class WXDLLEXPORT wxCheckBox;
24 class WXDLLEXPORT wxChoice;
25 class WXDLLEXPORT wxFileData;
26 class WXDLLEXPORT wxFileCtrl;
27 class WXDLLEXPORT wxGenericFileDialog;
28 class WXDLLEXPORT wxListEvent;
29 class WXDLLEXPORT wxListItem;
30 class WXDLLEXPORT wxStaticText;
31 class WXDLLEXPORT wxTextCtrl;
32
33 #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
34 #define USE_GENERIC_FILEDIALOG
35 #endif
36
37 //-------------------------------------------------------------------------
38 // wxGenericFileDialog
39 //-------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxGenericFileDialog: public wxFileDialogBase
42 {
43 public:
44 wxGenericFileDialog() : wxFileDialogBase() { Init(); }
45
46 wxGenericFileDialog(wxWindow *parent,
47 const wxString& message = wxFileSelectorPromptStr,
48 const wxString& defaultDir = wxEmptyString,
49 const wxString& defaultFile = wxEmptyString,
50 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
51 long style = 0,
52 const wxPoint& pos = wxDefaultPosition,
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 = 0,
61 const wxPoint& pos = wxDefaultPosition,
62 bool bypassGenericImpl = false );
63
64 virtual ~wxGenericFileDialog();
65
66 virtual void SetMessage(const wxString& message) { SetTitle(message); }
67 virtual void SetPath(const wxString& path);
68 virtual void SetFilterIndex(int filterIndex);
69 virtual void SetWildcard(const wxString& wildCard);
70
71 // for multiple file selection
72 virtual void GetPaths(wxArrayString& paths) const;
73 virtual void GetFilenames(wxArrayString& files) const;
74
75 // implementation only from now on
76 // -------------------------------
77
78 virtual int ShowModal();
79 virtual bool Show( bool show = true );
80
81 void OnSelected( wxListEvent &event );
82 void OnActivated( wxListEvent &event );
83 void OnList( wxCommandEvent &event );
84 void OnReport( wxCommandEvent &event );
85 void OnUp( wxCommandEvent &event );
86 void OnHome( wxCommandEvent &event );
87 void OnListOk( wxCommandEvent &event );
88 void OnNew( wxCommandEvent &event );
89 void OnChoiceFilter( wxCommandEvent &event );
90 void OnTextEnter( wxCommandEvent &event );
91 void OnTextChange( wxCommandEvent &event );
92 void OnCheck( wxCommandEvent &event );
93
94 virtual void HandleAction( const wxString &fn );
95
96 virtual void UpdateControls();
97
98 private:
99 // Don't use this implementation at all :-)
100 bool m_bypassGenericImpl;
101
102 protected:
103 // use the filter with the given index
104 void DoSetFilterIndex(int filterindex);
105
106 wxString m_filterExtension;
107 wxChoice *m_choice;
108 wxTextCtrl *m_text;
109 wxFileCtrl *m_list;
110 wxCheckBox *m_check;
111 wxStaticText *m_static;
112 wxBitmapButton *m_upDirButton;
113 wxBitmapButton *m_newDirButton;
114
115 private:
116 void Init();
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