]>
Commit | Line | Data |
---|---|---|
8b17ba72 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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$ | |
c8c0e54c | 9 | // Licence: wxWindows licence |
8b17ba72 RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_FILEDLGG_H_ | |
13 | #define _WX_FILEDLGG_H_ | |
14 | ||
af49c4b8 | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
8b17ba72 RR |
16 | #pragma interface "filedlgg.h" |
17 | #endif | |
18 | ||
8b17ba72 | 19 | #include "wx/dialog.h" |
23254b13 | 20 | #include "wx/listctrl.h" |
06cc1fb9 | 21 | #include "wx/datetime.h" |
8b17ba72 RR |
22 | |
23 | //----------------------------------------------------------------------------- | |
24 | // classes | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
06cc1fb9 JS |
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; | |
8b17ba72 | 37 | |
c29e2743 | 38 | #if defined(__WXUNIVERSAL__)||defined(__WXGTK__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__) |
23254b13 JS |
39 | #define USE_GENERIC_FILEDIALOG |
40 | #endif | |
41 | ||
8b17ba72 | 42 | //------------------------------------------------------------------------- |
b600ed13 | 43 | // wxGenericFileDialog |
8b17ba72 RR |
44 | //------------------------------------------------------------------------- |
45 | ||
23254b13 | 46 | class WXDLLEXPORT wxGenericFileDialog: public wxDialog |
8b17ba72 RR |
47 | { |
48 | public: | |
23254b13 | 49 | wxGenericFileDialog() { } |
8b17ba72 | 50 | |
23254b13 | 51 | wxGenericFileDialog(wxWindow *parent, |
8b17ba72 | 52 | const wxString& message = wxFileSelectorPromptStr, |
9cedab37 VZ |
53 | const wxString& defaultDir = _T(""), |
54 | const wxString& defaultFile = _T(""), | |
8b17ba72 RR |
55 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, |
56 | long style = 0, | |
57 | const wxPoint& pos = wxDefaultPosition); | |
23254b13 | 58 | virtual ~wxGenericFileDialog(); |
8b17ba72 | 59 | |
9cedab37 | 60 | void SetMessage(const wxString& message) { SetTitle(message); } |
8b17ba72 RR |
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; } | |
f6b66bc2 | 66 | void SetFilterIndex(int filterIndex); |
8b17ba72 RR |
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; } | |
7941ba11 | 74 | int GetFilterIndex() const { return m_filterIndex; } |
c61f4f6d | 75 | |
7941ba11 RR |
76 | // for multiple file selection |
77 | void GetPaths(wxArrayString& paths) const; | |
78 | void GetFilenames(wxArrayString& files) const; | |
c8c0e54c | 79 | |
9cedab37 VZ |
80 | // implementation only from now on |
81 | // ------------------------------- | |
82 | ||
83 | virtual int ShowModal(); | |
84 | ||
8b17ba72 RR |
85 | void OnSelected( wxListEvent &event ); |
86 | void OnActivated( wxListEvent &event ); | |
87 | void OnList( wxCommandEvent &event ); | |
88 | void OnReport( wxCommandEvent &event ); | |
8b17ba72 RR |
89 | void OnUp( wxCommandEvent &event ); |
90 | void OnHome( wxCommandEvent &event ); | |
91 | void OnListOk( wxCommandEvent &event ); | |
0b855868 | 92 | void OnNew( wxCommandEvent &event ); |
2b5f62a0 | 93 | void OnChoiceFilter( wxCommandEvent &event ); |
cae5359f | 94 | void OnTextEnter( wxCommandEvent &event ); |
df413171 | 95 | void OnTextChange( wxCommandEvent &event ); |
bf9e3e73 | 96 | void OnCheck( wxCommandEvent &event ); |
c61f4f6d | 97 | |
06cc1fb9 JS |
98 | virtual void HandleAction( const wxString &fn ); |
99 | ||
100 | virtual void UpdateControls(); | |
c8c0e54c VZ |
101 | |
102 | protected: | |
2b5f62a0 VZ |
103 | // use the filter with the given index |
104 | void DoSetFilterIndex(int filterindex); | |
105 | ||
9c884972 RR |
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; | |
cefc49fd | 113 | wxString m_filterExtension; |
9c884972 RR |
114 | wxChoice *m_choice; |
115 | wxTextCtrl *m_text; | |
116 | wxFileCtrl *m_list; | |
117 | wxCheckBox *m_check; | |
118 | wxStaticText *m_static; | |
06cc1fb9 JS |
119 | wxBitmapButton *m_upDirButton; |
120 | wxBitmapButton *m_newDirButton; | |
c8c0e54c | 121 | |
8b17ba72 | 122 | private: |
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 | { | |
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 | ||
23254b13 | 152 | #endif // USE_GENERIC_FILEDIALOG |
8b17ba72 | 153 | |
23254b13 | 154 | //----------------------------------------------------------------------------- |
b600ed13 | 155 | // wxFileData - a class to hold the file info for the wxFileCtrl |
23254b13 JS |
156 | //----------------------------------------------------------------------------- |
157 | ||
158 | class WXDLLEXPORT wxFileData | |
159 | { | |
160 | public: | |
161 | enum fileType | |
162 | { | |
06cc1fb9 | 163 | is_file = 0x0000, |
23254b13 JS |
164 | is_dir = 0x0001, |
165 | is_link = 0x0002, | |
166 | is_exe = 0x0004, | |
167 | is_drive = 0x0008 | |
168 | }; | |
169 | ||
b600ed13 VZ |
170 | // Full copy constructor |
171 | wxFileData( const wxFileData& fileData ); | |
172 | // Create a filedata from this information | |
06cc1fb9 JS |
173 | wxFileData( const wxString &filePath, const wxString &fileName, |
174 | fileType type, int image_id ); | |
175 | ||
b600ed13 VZ |
176 | // (re)read the extra data about the file from the system |
177 | void ReadData(); | |
178 | ||
06cc1fb9 JS |
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; } | |
b600ed13 VZ |
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 | |
06cc1fb9 JS |
187 | long GetSize() const { return m_size; } |
188 | // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE> | |
b600ed13 | 189 | wxString GetFileType() const; |
06cc1fb9 | 190 | // get the last modification time |
b600ed13 VZ |
191 | wxDateTime GetDateTime() const { return m_dateTime; } |
192 | // Get the time as a formatted string | |
06cc1fb9 JS |
193 | wxString GetModificationTime() const; |
194 | // in UNIX get rwx for file, in MSW get attributes ARHS | |
195 | wxString GetPermissions() const { return m_permissions; } | |
b600ed13 | 196 | // Get the id of the image used in a wxImageList |
06cc1fb9 JS |
197 | int GetImageId() const { return m_image; } |
198 | ||
b600ed13 | 199 | bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); } |
06cc1fb9 JS |
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 | ||
b600ed13 VZ |
205 | // Get/Set the type of file, file/dir/drive/link |
206 | int GetType() const { return m_type; } | |
23254b13 JS |
207 | |
208 | // the wxFileCtrl fields in report view | |
209 | enum fileListFieldType | |
210 | { | |
211 | FileList_Name, | |
06cc1fb9 | 212 | FileList_Size, |
23254b13 | 213 | FileList_Type, |
23254b13 | 214 | FileList_Time, |
06cc1fb9 | 215 | #if defined(__UNIX__) || defined(__WIN32__) |
23254b13 | 216 | FileList_Perm, |
06cc1fb9 | 217 | #endif // defined(__UNIX__) || defined(__WIN32__) |
23254b13 JS |
218 | FileList_Max |
219 | }; | |
220 | ||
b600ed13 | 221 | // Get the entry for report view of wxFileCtrl |
23254b13 JS |
222 | wxString GetEntry( fileListFieldType num ) const; |
223 | ||
06cc1fb9 JS |
224 | // Get a string representation of the file info |
225 | wxString GetHint() const; | |
b600ed13 | 226 | // initialize a wxListItem attributes |
23254b13 | 227 | void MakeItem( wxListItem &item ); |
23254b13 JS |
228 | |
229 | private: | |
23254b13 | 230 | wxString m_fileName; |
06cc1fb9 | 231 | wxString m_filePath; |
23254b13 | 232 | long m_size; |
06cc1fb9 | 233 | wxDateTime m_dateTime; |
23254b13 JS |
234 | wxString m_permissions; |
235 | int m_type; | |
06cc1fb9 | 236 | int m_image; |
23254b13 JS |
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 | ||
06cc1fb9 JS |
258 | virtual void ChangeToListMode(); |
259 | virtual void ChangeToReportMode(); | |
260 | virtual void ChangeToSmallIconMode(); | |
261 | virtual void ShowHidden( bool show = TRUE ); | |
23254b13 JS |
262 | bool GetShowHidden() const { return m_showHidden; } |
263 | ||
06cc1fb9 | 264 | virtual long Add( wxFileData *fd, wxListItem &item ); |
b600ed13 | 265 | virtual void UpdateItem(const wxListItem &item); |
06cc1fb9 JS |
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 ); | |
23254b13 | 272 | wxString GetWild() const { return m_wild; } |
23254b13 JS |
273 | wxString GetDir() const { return m_dirName; } |
274 | ||
275 | void OnListDeleteItem( wxListEvent &event ); | |
276 | void OnListEndLabelEdit( wxListEvent &event ); | |
277 | void OnListColClick( wxListEvent &event ); | |
278 | ||
06cc1fb9 JS |
279 | virtual void SortItems(wxFileData::fileListFieldType field, bool foward); |
280 | bool GetSortDirection() const { return m_sort_foward; } | |
23254b13 JS |
281 | wxFileData::fileListFieldType GetSortField() const { return m_sort_field; } |
282 | ||
06cc1fb9 | 283 | protected: |
23254b13 JS |
284 | void FreeItemData(const wxListItem& item); |
285 | void FreeAllItemsData(); | |
286 | ||
287 | wxString m_dirName; | |
288 | bool m_showHidden; | |
289 | wxString m_wild; | |
290 | ||
06cc1fb9 | 291 | bool m_sort_foward; |
23254b13 JS |
292 | wxFileData::fileListFieldType m_sort_field; |
293 | ||
06cc1fb9 | 294 | private: |
23254b13 JS |
295 | DECLARE_DYNAMIC_CLASS(wxFileCtrl); |
296 | DECLARE_EVENT_TABLE() | |
297 | }; | |
8b17ba72 | 298 | |
b600ed13 | 299 | #endif // _WX_FILEDLGG_H_ |
9cedab37 | 300 |