]>
Commit | Line | Data |
---|---|---|
8b17ba72 | 1 | ///////////////////////////////////////////////////////////////////////////// |
d022d364 | 2 | // Name: wx/generic/filedlgg.h |
23254b13 | 3 | // Purpose: wxGenericFileDialog |
8b17ba72 RR |
4 | // Author: Robert Roebling |
5 | // Modified by: | |
6 | // Created: 8/17/99 | |
7 | // Copyright: (c) Robert Roebling | |
8 | // RCS-ID: $Id$ | |
65571936 | 9 | // Licence: wxWindows licence |
8b17ba72 RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_FILEDLGG_H_ | |
13 | #define _WX_FILEDLGG_H_ | |
14 | ||
23254b13 | 15 | #include "wx/listctrl.h" |
06cc1fb9 | 16 | #include "wx/datetime.h" |
8226a054 | 17 | #include "wx/filefn.h" |
d022d364 | 18 | #include "wx/filedlg.h" |
8b17ba72 RR |
19 | |
20 | //----------------------------------------------------------------------------- | |
21 | // classes | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
06cc1fb9 JS |
24 | class WXDLLEXPORT wxBitmapButton; |
25 | class WXDLLEXPORT wxCheckBox; | |
26 | class WXDLLEXPORT wxChoice; | |
27 | class WXDLLEXPORT wxFileData; | |
28 | class WXDLLEXPORT wxFileCtrl; | |
29 | class WXDLLEXPORT wxGenericFileDialog; | |
30 | class WXDLLEXPORT wxListEvent; | |
31 | class WXDLLEXPORT wxListItem; | |
32 | class WXDLLEXPORT wxStaticText; | |
33 | class WXDLLEXPORT wxTextCtrl; | |
8b17ba72 | 34 | |
4e1901b7 | 35 | #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__) |
23254b13 JS |
36 | #define USE_GENERIC_FILEDIALOG |
37 | #endif | |
38 | ||
8b17ba72 | 39 | //------------------------------------------------------------------------- |
b600ed13 | 40 | // wxGenericFileDialog |
8b17ba72 RR |
41 | //------------------------------------------------------------------------- |
42 | ||
f74172ab | 43 | class WXDLLEXPORT wxGenericFileDialog: public wxFileDialogBase |
8b17ba72 RR |
44 | { |
45 | public: | |
fe6cf128 | 46 | wxGenericFileDialog() : wxFileDialogBase() { Init(); } |
8b17ba72 | 47 | |
23254b13 | 48 | wxGenericFileDialog(wxWindow *parent, |
fe6cf128 | 49 | const wxString& message = wxFileSelectorPromptStr, |
f74172ab VZ |
50 | const wxString& defaultDir = wxEmptyString, |
51 | const wxString& defaultFile = wxEmptyString, | |
fe6cf128 | 52 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, |
ff3e84ff | 53 | long style = wxFD_DEFAULT_STYLE, |
fe6cf128 | 54 | const wxPoint& pos = wxDefaultPosition, |
ff3e84ff VZ |
55 | const wxSize& sz = wxDefaultSize, |
56 | const wxString& name = wxFileDialogNameStr, | |
fe6cf128 VZ |
57 | bool bypassGenericImpl = false ); |
58 | ||
4e1901b7 RR |
59 | bool Create( wxWindow *parent, |
60 | const wxString& message = wxFileSelectorPromptStr, | |
fe6cf128 VZ |
61 | const wxString& defaultDir = wxEmptyString, |
62 | const wxString& defaultFile = wxEmptyString, | |
4e1901b7 | 63 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, |
ff3e84ff | 64 | long style = wxFD_DEFAULT_STYLE, |
fe6cf128 | 65 | const wxPoint& pos = wxDefaultPosition, |
ff3e84ff VZ |
66 | const wxSize& sz = wxDefaultSize, |
67 | const wxString& name = wxFileDialogNameStr, | |
fe6cf128 VZ |
68 | bool bypassGenericImpl = false ); |
69 | ||
23254b13 | 70 | virtual ~wxGenericFileDialog(); |
8b17ba72 | 71 | |
f74172ab VZ |
72 | virtual void SetMessage(const wxString& message) { SetTitle(message); } |
73 | virtual void SetPath(const wxString& path); | |
74 | virtual void SetFilterIndex(int filterIndex); | |
b4cfe261 | 75 | virtual void SetWildcard(const wxString& wildCard); |
c61f4f6d | 76 | |
7941ba11 | 77 | // for multiple file selection |
f74172ab VZ |
78 | virtual void GetPaths(wxArrayString& paths) const; |
79 | virtual void GetFilenames(wxArrayString& files) const; | |
c8c0e54c | 80 | |
9cedab37 VZ |
81 | // implementation only from now on |
82 | // ------------------------------- | |
83 | ||
84 | virtual int ShowModal(); | |
16dce3b3 | 85 | virtual bool Show( bool show = true ); |
9cedab37 | 86 | |
8b17ba72 RR |
87 | void OnSelected( wxListEvent &event ); |
88 | void OnActivated( wxListEvent &event ); | |
89 | void OnList( wxCommandEvent &event ); | |
90 | void OnReport( wxCommandEvent &event ); | |
8b17ba72 RR |
91 | void OnUp( wxCommandEvent &event ); |
92 | void OnHome( wxCommandEvent &event ); | |
93 | void OnListOk( wxCommandEvent &event ); | |
0b855868 | 94 | void OnNew( wxCommandEvent &event ); |
2b5f62a0 | 95 | void OnChoiceFilter( wxCommandEvent &event ); |
cae5359f | 96 | void OnTextEnter( wxCommandEvent &event ); |
df413171 | 97 | void OnTextChange( wxCommandEvent &event ); |
bf9e3e73 | 98 | void OnCheck( wxCommandEvent &event ); |
c61f4f6d | 99 | |
06cc1fb9 JS |
100 | virtual void HandleAction( const wxString &fn ); |
101 | ||
102 | virtual void UpdateControls(); | |
6b99f53e | 103 | |
4e1901b7 RR |
104 | private: |
105 | // Don't use this implementation at all :-) | |
106 | bool m_bypassGenericImpl; | |
c8c0e54c VZ |
107 | |
108 | protected: | |
2b5f62a0 VZ |
109 | // use the filter with the given index |
110 | void DoSetFilterIndex(int filterindex); | |
111 | ||
cefc49fd | 112 | wxString m_filterExtension; |
9c884972 RR |
113 | wxChoice *m_choice; |
114 | wxTextCtrl *m_text; | |
115 | wxFileCtrl *m_list; | |
116 | wxCheckBox *m_check; | |
117 | wxStaticText *m_static; | |
06cc1fb9 JS |
118 | wxBitmapButton *m_upDirButton; |
119 | wxBitmapButton *m_newDirButton; | |
c8c0e54c | 120 | |
8b17ba72 | 121 | private: |
fe6cf128 | 122 | void Init(); |
23254b13 | 123 | DECLARE_DYNAMIC_CLASS(wxGenericFileDialog) |
8b17ba72 | 124 | DECLARE_EVENT_TABLE() |
cefc49fd | 125 | |
23254b13 | 126 | // these variables are preserved between wxGenericFileDialog calls |
9cedab37 VZ |
127 | static long ms_lastViewStyle; // list or report? |
128 | static bool ms_lastShowHidden; // did we show hidden files? | |
8b17ba72 RR |
129 | }; |
130 | ||
23254b13 JS |
131 | #ifdef USE_GENERIC_FILEDIALOG |
132 | ||
133 | class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog | |
134 | { | |
23254b13 | 135 | public: |
6463b9f5 | 136 | wxFileDialog() {} |
23254b13 JS |
137 | |
138 | wxFileDialog(wxWindow *parent, | |
139 | const wxString& message = wxFileSelectorPromptStr, | |
ca65c044 WS |
140 | const wxString& defaultDir = wxEmptyString, |
141 | const wxString& defaultFile = wxEmptyString, | |
23254b13 JS |
142 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, |
143 | long style = 0, | |
6463b9f5 JS |
144 | const wxPoint& pos = wxDefaultPosition) |
145 | :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos) | |
146 | { | |
147 | } | |
6b99f53e | 148 | |
4e1901b7 RR |
149 | private: |
150 | DECLARE_DYNAMIC_CLASS(wxFileDialog) | |
23254b13 JS |
151 | }; |
152 | ||
23254b13 | 153 | #endif // USE_GENERIC_FILEDIALOG |
8b17ba72 | 154 | |
23254b13 | 155 | //----------------------------------------------------------------------------- |
b600ed13 | 156 | // wxFileData - a class to hold the file info for the wxFileCtrl |
23254b13 JS |
157 | //----------------------------------------------------------------------------- |
158 | ||
159 | class WXDLLEXPORT wxFileData | |
160 | { | |
161 | public: | |
162 | enum fileType | |
163 | { | |
06cc1fb9 | 164 | is_file = 0x0000, |
23254b13 JS |
165 | is_dir = 0x0001, |
166 | is_link = 0x0002, | |
167 | is_exe = 0x0004, | |
168 | is_drive = 0x0008 | |
169 | }; | |
170 | ||
ca9fb418 | 171 | wxFileData() { Init(); } |
b600ed13 | 172 | // Full copy constructor |
81169710 | 173 | wxFileData( const wxFileData& fileData ) { Copy(fileData); } |
b600ed13 | 174 | // Create a filedata from this information |
06cc1fb9 JS |
175 | wxFileData( const wxString &filePath, const wxString &fileName, |
176 | fileType type, int image_id ); | |
177 | ||
81169710 VZ |
178 | // make a full copy of the other wxFileData |
179 | void Copy( const wxFileData &other ); | |
180 | ||
b600ed13 VZ |
181 | // (re)read the extra data about the file from the system |
182 | void ReadData(); | |
183 | ||
06cc1fb9 JS |
184 | // get the name of the file, dir, drive |
185 | wxString GetFileName() const { return m_fileName; } | |
186 | // get the full path + name of the file, dir, path | |
187 | wxString GetFilePath() const { return m_filePath; } | |
b600ed13 VZ |
188 | // Set the path + name and name of the item |
189 | void SetNewName( const wxString &filePath, const wxString &fileName ); | |
190 | ||
191 | // Get the size of the file in bytes | |
8226a054 | 192 | wxFileOffset GetSize() const { return m_size; } |
06cc1fb9 | 193 | // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE> |
b600ed13 | 194 | wxString GetFileType() const; |
06cc1fb9 | 195 | // get the last modification time |
b600ed13 VZ |
196 | wxDateTime GetDateTime() const { return m_dateTime; } |
197 | // Get the time as a formatted string | |
06cc1fb9 JS |
198 | wxString GetModificationTime() const; |
199 | // in UNIX get rwx for file, in MSW get attributes ARHS | |
200 | wxString GetPermissions() const { return m_permissions; } | |
b600ed13 | 201 | // Get the id of the image used in a wxImageList |
06cc1fb9 JS |
202 | int GetImageId() const { return m_image; } |
203 | ||
b600ed13 | 204 | bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); } |
06cc1fb9 JS |
205 | bool IsDir() const { return (m_type & is_dir ) != 0; } |
206 | bool IsLink() const { return (m_type & is_link ) != 0; } | |
207 | bool IsExe() const { return (m_type & is_exe ) != 0; } | |
208 | bool IsDrive() const { return (m_type & is_drive) != 0; } | |
209 | ||
b600ed13 VZ |
210 | // Get/Set the type of file, file/dir/drive/link |
211 | int GetType() const { return m_type; } | |
23254b13 JS |
212 | |
213 | // the wxFileCtrl fields in report view | |
214 | enum fileListFieldType | |
215 | { | |
216 | FileList_Name, | |
06cc1fb9 | 217 | FileList_Size, |
23254b13 | 218 | FileList_Type, |
23254b13 | 219 | FileList_Time, |
06cc1fb9 | 220 | #if defined(__UNIX__) || defined(__WIN32__) |
23254b13 | 221 | FileList_Perm, |
06cc1fb9 | 222 | #endif // defined(__UNIX__) || defined(__WIN32__) |
23254b13 JS |
223 | FileList_Max |
224 | }; | |
225 | ||
b600ed13 | 226 | // Get the entry for report view of wxFileCtrl |
23254b13 JS |
227 | wxString GetEntry( fileListFieldType num ) const; |
228 | ||
06cc1fb9 JS |
229 | // Get a string representation of the file info |
230 | wxString GetHint() const; | |
b600ed13 | 231 | // initialize a wxListItem attributes |
23254b13 | 232 | void MakeItem( wxListItem &item ); |
23254b13 | 233 | |
ca9fb418 | 234 | // operators |
81169710 VZ |
235 | wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; } |
236 | ||
ca9fb418 | 237 | protected: |
23254b13 | 238 | wxString m_fileName; |
06cc1fb9 | 239 | wxString m_filePath; |
8226a054 | 240 | wxFileOffset m_size; |
06cc1fb9 | 241 | wxDateTime m_dateTime; |
23254b13 JS |
242 | wxString m_permissions; |
243 | int m_type; | |
8226a054 VZ |
244 | int m_image; |
245 | ||
ca9fb418 VZ |
246 | private: |
247 | void Init(); | |
23254b13 JS |
248 | }; |
249 | ||
250 | //----------------------------------------------------------------------------- | |
251 | // wxFileCtrl | |
252 | //----------------------------------------------------------------------------- | |
253 | ||
254 | class WXDLLEXPORT wxFileCtrl : public wxListCtrl | |
255 | { | |
256 | public: | |
257 | wxFileCtrl(); | |
258 | wxFileCtrl( wxWindow *win, | |
259 | wxWindowID id, | |
260 | const wxString &wild, | |
261 | bool showHidden, | |
262 | const wxPoint &pos = wxDefaultPosition, | |
263 | const wxSize &size = wxDefaultSize, | |
264 | long style = wxLC_LIST, | |
265 | const wxValidator &validator = wxDefaultValidator, | |
266 | const wxString &name = wxT("filelist") ); | |
267 | virtual ~wxFileCtrl(); | |
268 | ||
06cc1fb9 JS |
269 | virtual void ChangeToListMode(); |
270 | virtual void ChangeToReportMode(); | |
271 | virtual void ChangeToSmallIconMode(); | |
ca65c044 | 272 | virtual void ShowHidden( bool show = true ); |
23254b13 JS |
273 | bool GetShowHidden() const { return m_showHidden; } |
274 | ||
06cc1fb9 | 275 | virtual long Add( wxFileData *fd, wxListItem &item ); |
b600ed13 | 276 | virtual void UpdateItem(const wxListItem &item); |
06cc1fb9 JS |
277 | virtual void UpdateFiles(); |
278 | virtual void MakeDir(); | |
279 | virtual void GoToParentDir(); | |
280 | virtual void GoToHomeDir(); | |
281 | virtual void GoToDir( const wxString &dir ); | |
282 | virtual void SetWild( const wxString &wild ); | |
23254b13 | 283 | wxString GetWild() const { return m_wild; } |
23254b13 JS |
284 | wxString GetDir() const { return m_dirName; } |
285 | ||
286 | void OnListDeleteItem( wxListEvent &event ); | |
81169710 | 287 | void OnListDeleteAllItems( wxListEvent &event ); |
23254b13 JS |
288 | void OnListEndLabelEdit( wxListEvent &event ); |
289 | void OnListColClick( wxListEvent &event ); | |
290 | ||
06cc1fb9 JS |
291 | virtual void SortItems(wxFileData::fileListFieldType field, bool foward); |
292 | bool GetSortDirection() const { return m_sort_foward; } | |
23254b13 JS |
293 | wxFileData::fileListFieldType GetSortField() const { return m_sort_field; } |
294 | ||
06cc1fb9 | 295 | protected: |
81169710 | 296 | void FreeItemData(wxListItem& item); |
23254b13 JS |
297 | void FreeAllItemsData(); |
298 | ||
299 | wxString m_dirName; | |
300 | bool m_showHidden; | |
301 | wxString m_wild; | |
302 | ||
06cc1fb9 | 303 | bool m_sort_foward; |
23254b13 JS |
304 | wxFileData::fileListFieldType m_sort_field; |
305 | ||
06cc1fb9 | 306 | private: |
6b99f53e | 307 | DECLARE_DYNAMIC_CLASS(wxFileCtrl) |
23254b13 JS |
308 | DECLARE_EVENT_TABLE() |
309 | }; | |
8b17ba72 | 310 | |
b600ed13 | 311 | #endif // _WX_FILEDLGG_H_ |