]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/filedlgg.h
fixed compilation breakage in 1.24 commit
[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 #include "wx/filefn.h"
18
19 //-----------------------------------------------------------------------------
20 // classes
21 //-----------------------------------------------------------------------------
22
23 class WXDLLEXPORT wxBitmapButton;
24 class WXDLLEXPORT wxCheckBox;
25 class WXDLLEXPORT wxChoice;
26 class WXDLLEXPORT wxFileData;
27 class WXDLLEXPORT wxFileCtrl;
28 class WXDLLEXPORT wxGenericFileDialog;
29 class WXDLLEXPORT wxListEvent;
30 class WXDLLEXPORT wxListItem;
31 class WXDLLEXPORT wxStaticText;
32 class WXDLLEXPORT wxTextCtrl;
33
34 #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
35 #define USE_GENERIC_FILEDIALOG
36 #endif
37
38 //-------------------------------------------------------------------------
39 // wxGenericFileDialog
40 //-------------------------------------------------------------------------
41
42 class WXDLLEXPORT wxGenericFileDialog: public wxFileDialogBase
43 {
44 public:
45 wxGenericFileDialog() : wxFileDialogBase() { Init(); }
46
47 wxGenericFileDialog(wxWindow *parent,
48 const wxString& message = wxFileSelectorPromptStr,
49 const wxString& defaultDir = wxEmptyString,
50 const wxString& defaultFile = wxEmptyString,
51 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
52 long style = 0,
53 const wxPoint& pos = wxDefaultPosition,
54 bool bypassGenericImpl = false );
55
56 bool Create( wxWindow *parent,
57 const wxString& message = wxFileSelectorPromptStr,
58 const wxString& defaultDir = wxEmptyString,
59 const wxString& defaultFile = wxEmptyString,
60 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
61 long style = 0,
62 const wxPoint& pos = wxDefaultPosition,
63 bool bypassGenericImpl = false );
64
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 void Init();
118 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog)
119 DECLARE_EVENT_TABLE()
120
121 // these variables are preserved between wxGenericFileDialog calls
122 static long ms_lastViewStyle; // list or report?
123 static bool ms_lastShowHidden; // did we show hidden files?
124 };
125
126 #ifdef USE_GENERIC_FILEDIALOG
127
128 class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog
129 {
130 public:
131 wxFileDialog() {}
132
133 wxFileDialog(wxWindow *parent,
134 const wxString& message = wxFileSelectorPromptStr,
135 const wxString& defaultDir = wxEmptyString,
136 const wxString& defaultFile = wxEmptyString,
137 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
138 long style = 0,
139 const wxPoint& pos = wxDefaultPosition)
140 :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos)
141 {
142 }
143
144 private:
145 DECLARE_DYNAMIC_CLASS(wxFileDialog)
146 };
147
148 #endif // USE_GENERIC_FILEDIALOG
149
150 //-----------------------------------------------------------------------------
151 // wxFileData - a class to hold the file info for the wxFileCtrl
152 //-----------------------------------------------------------------------------
153
154 class WXDLLEXPORT wxFileData
155 {
156 public:
157 enum fileType
158 {
159 is_file = 0x0000,
160 is_dir = 0x0001,
161 is_link = 0x0002,
162 is_exe = 0x0004,
163 is_drive = 0x0008
164 };
165
166 wxFileData() { Init(); }
167 // Full copy constructor
168 wxFileData( const wxFileData& fileData ) { Copy(fileData); }
169 // Create a filedata from this information
170 wxFileData( const wxString &filePath, const wxString &fileName,
171 fileType type, int image_id );
172
173 // make a full copy of the other wxFileData
174 void Copy( const wxFileData &other );
175
176 // (re)read the extra data about the file from the system
177 void ReadData();
178
179 // get the name of the file, dir, drive
180 wxString GetFileName() const { return m_fileName; }
181 // get the full path + name of the file, dir, path
182 wxString GetFilePath() const { return m_filePath; }
183 // Set the path + name and name of the item
184 void SetNewName( const wxString &filePath, const wxString &fileName );
185
186 // Get the size of the file in bytes
187 wxFileOffset GetSize() const { return m_size; }
188 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
189 wxString GetFileType() const;
190 // get the last modification time
191 wxDateTime GetDateTime() const { return m_dateTime; }
192 // Get the time as a formatted string
193 wxString GetModificationTime() const;
194 // in UNIX get rwx for file, in MSW get attributes ARHS
195 wxString GetPermissions() const { return m_permissions; }
196 // Get the id of the image used in a wxImageList
197 int GetImageId() const { return m_image; }
198
199 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
200 bool IsDir() const { return (m_type & is_dir ) != 0; }
201 bool IsLink() const { return (m_type & is_link ) != 0; }
202 bool IsExe() const { return (m_type & is_exe ) != 0; }
203 bool IsDrive() const { return (m_type & is_drive) != 0; }
204
205 // Get/Set the type of file, file/dir/drive/link
206 int GetType() const { return m_type; }
207
208 // the wxFileCtrl fields in report view
209 enum fileListFieldType
210 {
211 FileList_Name,
212 FileList_Size,
213 FileList_Type,
214 FileList_Time,
215 #if defined(__UNIX__) || defined(__WIN32__)
216 FileList_Perm,
217 #endif // defined(__UNIX__) || defined(__WIN32__)
218 FileList_Max
219 };
220
221 // Get the entry for report view of wxFileCtrl
222 wxString GetEntry( fileListFieldType num ) const;
223
224 // Get a string representation of the file info
225 wxString GetHint() const;
226 // initialize a wxListItem attributes
227 void MakeItem( wxListItem &item );
228
229 // operators
230 wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; }
231
232 protected:
233 wxString m_fileName;
234 wxString m_filePath;
235 wxFileOffset m_size;
236 wxDateTime m_dateTime;
237 wxString m_permissions;
238 int m_type;
239 int m_image;
240
241 private:
242 void Init();
243 };
244
245 //-----------------------------------------------------------------------------
246 // wxFileCtrl
247 //-----------------------------------------------------------------------------
248
249 class WXDLLEXPORT wxFileCtrl : public wxListCtrl
250 {
251 public:
252 wxFileCtrl();
253 wxFileCtrl( wxWindow *win,
254 wxWindowID id,
255 const wxString &wild,
256 bool showHidden,
257 const wxPoint &pos = wxDefaultPosition,
258 const wxSize &size = wxDefaultSize,
259 long style = wxLC_LIST,
260 const wxValidator &validator = wxDefaultValidator,
261 const wxString &name = wxT("filelist") );
262 virtual ~wxFileCtrl();
263
264 virtual void ChangeToListMode();
265 virtual void ChangeToReportMode();
266 virtual void ChangeToSmallIconMode();
267 virtual void ShowHidden( bool show = true );
268 bool GetShowHidden() const { return m_showHidden; }
269
270 virtual long Add( wxFileData *fd, wxListItem &item );
271 virtual void UpdateItem(const wxListItem &item);
272 virtual void UpdateFiles();
273 virtual void MakeDir();
274 virtual void GoToParentDir();
275 virtual void GoToHomeDir();
276 virtual void GoToDir( const wxString &dir );
277 virtual void SetWild( const wxString &wild );
278 wxString GetWild() const { return m_wild; }
279 wxString GetDir() const { return m_dirName; }
280
281 void OnListDeleteItem( wxListEvent &event );
282 void OnListDeleteAllItems( wxListEvent &event );
283 void OnListEndLabelEdit( wxListEvent &event );
284 void OnListColClick( wxListEvent &event );
285
286 virtual void SortItems(wxFileData::fileListFieldType field, bool foward);
287 bool GetSortDirection() const { return m_sort_foward; }
288 wxFileData::fileListFieldType GetSortField() const { return m_sort_field; }
289
290 protected:
291 void FreeItemData(wxListItem& item);
292 void FreeAllItemsData();
293
294 wxString m_dirName;
295 bool m_showHidden;
296 wxString m_wild;
297
298 bool m_sort_foward;
299 wxFileData::fileListFieldType m_sort_field;
300
301 private:
302 DECLARE_DYNAMIC_CLASS(wxFileCtrl)
303 DECLARE_EVENT_TABLE()
304 };
305
306 #endif // _WX_FILEDLGG_H_
307