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