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