]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/filedlgg.h
added wxprec.h
[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(__APPLE__)
16 #pragma interface "filedlgg.h"
17 #endif
18
19 #include "wx/dialog.h"
20 #include "wx/listctrl.h"
21 #include "wx/datetime.h"
22
23 //-----------------------------------------------------------------------------
24 // classes
25 //-----------------------------------------------------------------------------
26
27 class WXDLLEXPORT wxBitmapButton;
28 class WXDLLEXPORT wxCheckBox;
29 class WXDLLEXPORT wxChoice;
30 class WXDLLEXPORT wxFileData;
31 class WXDLLEXPORT wxFileCtrl;
32 class WXDLLEXPORT wxGenericFileDialog;
33 class WXDLLEXPORT wxListEvent;
34 class WXDLLEXPORT wxListItem;
35 class WXDLLEXPORT wxStaticText;
36 class WXDLLEXPORT wxTextCtrl;
37
38 #if defined(__WXUNIVERSAL__)||defined(__WXGTK__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
39 #define USE_GENERIC_FILEDIALOG
40 #endif
41
42 //-------------------------------------------------------------------------
43 // wxGenericFileDialog
44 //-------------------------------------------------------------------------
45
46 class WXDLLEXPORT wxGenericFileDialog: public wxDialog
47 {
48 public:
49 wxGenericFileDialog() { }
50
51 wxGenericFileDialog(wxWindow *parent,
52 const wxString& message = wxFileSelectorPromptStr,
53 const wxString& defaultDir = _T(""),
54 const wxString& defaultFile = _T(""),
55 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
56 long style = 0,
57 const wxPoint& pos = wxDefaultPosition);
58 virtual ~wxGenericFileDialog();
59
60 void SetMessage(const wxString& message) { SetTitle(message); }
61 void SetPath(const wxString& path);
62 void SetDirectory(const wxString& dir) { m_dir = dir; }
63 void SetFilename(const wxString& name) { m_fileName = name; }
64 void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
65 void SetStyle(long style) { m_dialogStyle = style; }
66 void SetFilterIndex(int filterIndex);
67
68 wxString GetMessage() const { return m_message; }
69 wxString GetPath() const { return m_path; }
70 wxString GetDirectory() const { return m_dir; }
71 wxString GetFilename() const { return m_fileName; }
72 wxString GetWildcard() const { return m_wildCard; }
73 long GetStyle() const { return m_dialogStyle; }
74 int GetFilterIndex() const { return m_filterIndex; }
75
76 // for multiple file selection
77 void GetPaths(wxArrayString& paths) const;
78 void GetFilenames(wxArrayString& files) const;
79
80 // implementation only from now on
81 // -------------------------------
82
83 virtual int ShowModal();
84
85 void OnSelected( wxListEvent &event );
86 void OnActivated( wxListEvent &event );
87 void OnList( wxCommandEvent &event );
88 void OnReport( wxCommandEvent &event );
89 void OnUp( wxCommandEvent &event );
90 void OnHome( wxCommandEvent &event );
91 void OnListOk( wxCommandEvent &event );
92 void OnNew( wxCommandEvent &event );
93 void OnChoiceFilter( wxCommandEvent &event );
94 void OnTextEnter( wxCommandEvent &event );
95 void OnTextChange( wxCommandEvent &event );
96 void OnCheck( wxCommandEvent &event );
97
98 virtual void HandleAction( const wxString &fn );
99
100 virtual void UpdateControls();
101
102 protected:
103 // use the filter with the given index
104 void DoSetFilterIndex(int filterindex);
105
106 wxString m_message;
107 long m_dialogStyle;
108 wxString m_dir;
109 wxString m_path; // Full path
110 wxString m_fileName;
111 wxString m_wildCard;
112 int m_filterIndex;
113 wxString m_filterExtension;
114 wxChoice *m_choice;
115 wxTextCtrl *m_text;
116 wxFileCtrl *m_list;
117 wxCheckBox *m_check;
118 wxStaticText *m_static;
119 wxBitmapButton *m_upDirButton;
120 wxBitmapButton *m_newDirButton;
121
122 private:
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 DECLARE_DYNAMIC_CLASS(wxFileDialog)
136
137 public:
138 wxFileDialog() {}
139
140 wxFileDialog(wxWindow *parent,
141 const wxString& message = wxFileSelectorPromptStr,
142 const wxString& defaultDir = _T(""),
143 const wxString& defaultFile = _T(""),
144 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
145 long style = 0,
146 const wxPoint& pos = wxDefaultPosition)
147 :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos)
148 {
149 }
150 };
151
152 #endif // USE_GENERIC_FILEDIALOG
153
154 //-----------------------------------------------------------------------------
155 // wxFileData - a class to hold the file info for the wxFileCtrl
156 //-----------------------------------------------------------------------------
157
158 class WXDLLEXPORT wxFileData
159 {
160 public:
161 enum fileType
162 {
163 is_file = 0x0000,
164 is_dir = 0x0001,
165 is_link = 0x0002,
166 is_exe = 0x0004,
167 is_drive = 0x0008
168 };
169
170 // Full copy constructor
171 wxFileData( const wxFileData& fileData );
172 // Create a filedata from this information
173 wxFileData( const wxString &filePath, const wxString &fileName,
174 fileType type, int image_id );
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 long 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 private:
230 wxString m_fileName;
231 wxString m_filePath;
232 long m_size;
233 wxDateTime m_dateTime;
234 wxString m_permissions;
235 int m_type;
236 int m_image;
237 };
238
239 //-----------------------------------------------------------------------------
240 // wxFileCtrl
241 //-----------------------------------------------------------------------------
242
243 class WXDLLEXPORT wxFileCtrl : public wxListCtrl
244 {
245 public:
246 wxFileCtrl();
247 wxFileCtrl( wxWindow *win,
248 wxWindowID id,
249 const wxString &wild,
250 bool showHidden,
251 const wxPoint &pos = wxDefaultPosition,
252 const wxSize &size = wxDefaultSize,
253 long style = wxLC_LIST,
254 const wxValidator &validator = wxDefaultValidator,
255 const wxString &name = wxT("filelist") );
256 virtual ~wxFileCtrl();
257
258 virtual void ChangeToListMode();
259 virtual void ChangeToReportMode();
260 virtual void ChangeToSmallIconMode();
261 virtual void ShowHidden( bool show = TRUE );
262 bool GetShowHidden() const { return m_showHidden; }
263
264 virtual long Add( wxFileData *fd, wxListItem &item );
265 virtual void UpdateItem(const wxListItem &item);
266 virtual void UpdateFiles();
267 virtual void MakeDir();
268 virtual void GoToParentDir();
269 virtual void GoToHomeDir();
270 virtual void GoToDir( const wxString &dir );
271 virtual void SetWild( const wxString &wild );
272 wxString GetWild() const { return m_wild; }
273 wxString GetDir() const { return m_dirName; }
274
275 void OnListDeleteItem( wxListEvent &event );
276 void OnListEndLabelEdit( wxListEvent &event );
277 void OnListColClick( wxListEvent &event );
278
279 virtual void SortItems(wxFileData::fileListFieldType field, bool foward);
280 bool GetSortDirection() const { return m_sort_foward; }
281 wxFileData::fileListFieldType GetSortField() const { return m_sort_field; }
282
283 protected:
284 void FreeItemData(const wxListItem& item);
285 void FreeAllItemsData();
286
287 wxString m_dirName;
288 bool m_showHidden;
289 wxString m_wild;
290
291 bool m_sort_foward;
292 wxFileData::fileListFieldType m_sort_field;
293
294 private:
295 DECLARE_DYNAMIC_CLASS(wxFileCtrl);
296 DECLARE_EVENT_TABLE()
297 };
298
299 #endif // _WX_FILEDLGG_H_
300