]>
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$ | |
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" |
8b17ba72 RR |
18 | |
19 | //----------------------------------------------------------------------------- | |
20 | // classes | |
21 | //----------------------------------------------------------------------------- | |
22 | ||
06cc1fb9 JS |
23 | class WXDLLEXPORT wxBitmapButton; |
24 | class WXDLLEXPORT wxCheckBox; | |
25 | class WXDLLEXPORT wxChoice; | |
26 | class WXDLLEXPORT wxFileData; | |
27 | class WXDLLEXPORT wxFileCtrl; | |
28 | class WXDLLEXPORT wxGenericFileDialog; | |
29 | class WXDLLEXPORT wxListEvent; | |
30 | class WXDLLEXPORT wxListItem; | |
31 | class WXDLLEXPORT wxStaticText; | |
32 | class WXDLLEXPORT wxTextCtrl; | |
8b17ba72 | 33 | |
4e1901b7 | 34 | #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__) |
23254b13 JS |
35 | #define USE_GENERIC_FILEDIALOG |
36 | #endif | |
37 | ||
8b17ba72 | 38 | //------------------------------------------------------------------------- |
b600ed13 | 39 | // wxGenericFileDialog |
8b17ba72 RR |
40 | //------------------------------------------------------------------------- |
41 | ||
f74172ab | 42 | class WXDLLEXPORT wxGenericFileDialog: public wxFileDialogBase |
8b17ba72 RR |
43 | { |
44 | public: | |
fe6cf128 | 45 | wxGenericFileDialog() : wxFileDialogBase() { Init(); } |
8b17ba72 | 46 | |
23254b13 | 47 | wxGenericFileDialog(wxWindow *parent, |
fe6cf128 | 48 | const wxString& message = wxFileSelectorPromptStr, |
f74172ab VZ |
49 | const wxString& defaultDir = wxEmptyString, |
50 | const wxString& defaultFile = wxEmptyString, | |
fe6cf128 VZ |
51 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, |
52 | long style = 0, | |
53 | const wxPoint& pos = wxDefaultPosition, | |
54 | bool bypassGenericImpl = false ); | |
55 | ||
4e1901b7 RR |
56 | bool Create( wxWindow *parent, |
57 | const wxString& message = wxFileSelectorPromptStr, | |
fe6cf128 VZ |
58 | const wxString& defaultDir = wxEmptyString, |
59 | const wxString& defaultFile = wxEmptyString, | |
4e1901b7 RR |
60 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, |
61 | long style = 0, | |
fe6cf128 VZ |
62 | const wxPoint& pos = wxDefaultPosition, |
63 | bool bypassGenericImpl = false ); | |
64 | ||
23254b13 | 65 | virtual ~wxGenericFileDialog(); |
8b17ba72 | 66 | |
f74172ab VZ |
67 | virtual void SetMessage(const wxString& message) { SetTitle(message); } |
68 | virtual void SetPath(const wxString& path); | |
69 | virtual void SetFilterIndex(int filterIndex); | |
b4cfe261 | 70 | virtual void SetWildcard(const wxString& wildCard); |
c61f4f6d | 71 | |
7941ba11 | 72 | // for multiple file selection |
f74172ab VZ |
73 | virtual void GetPaths(wxArrayString& paths) const; |
74 | virtual void GetFilenames(wxArrayString& files) const; | |
c8c0e54c | 75 | |
9cedab37 VZ |
76 | // implementation only from now on |
77 | // ------------------------------- | |
78 | ||
79 | virtual int ShowModal(); | |
16dce3b3 | 80 | virtual bool Show( bool show = true ); |
9cedab37 | 81 | |
8b17ba72 RR |
82 | void OnSelected( wxListEvent &event ); |
83 | void OnActivated( wxListEvent &event ); | |
84 | void OnList( wxCommandEvent &event ); | |
85 | void OnReport( wxCommandEvent &event ); | |
8b17ba72 RR |
86 | void OnUp( wxCommandEvent &event ); |
87 | void OnHome( wxCommandEvent &event ); | |
88 | void OnListOk( wxCommandEvent &event ); | |
0b855868 | 89 | void OnNew( wxCommandEvent &event ); |
2b5f62a0 | 90 | void OnChoiceFilter( wxCommandEvent &event ); |
cae5359f | 91 | void OnTextEnter( wxCommandEvent &event ); |
df413171 | 92 | void OnTextChange( wxCommandEvent &event ); |
bf9e3e73 | 93 | void OnCheck( wxCommandEvent &event ); |
c61f4f6d | 94 | |
06cc1fb9 JS |
95 | virtual void HandleAction( const wxString &fn ); |
96 | ||
97 | virtual void UpdateControls(); | |
6b99f53e | 98 | |
4e1901b7 RR |
99 | private: |
100 | // Don't use this implementation at all :-) | |
101 | bool m_bypassGenericImpl; | |
c8c0e54c VZ |
102 | |
103 | protected: | |
2b5f62a0 VZ |
104 | // use the filter with the given index |
105 | void DoSetFilterIndex(int filterindex); | |
106 | ||
cefc49fd | 107 | wxString m_filterExtension; |
9c884972 RR |
108 | wxChoice *m_choice; |
109 | wxTextCtrl *m_text; | |
110 | wxFileCtrl *m_list; | |
111 | wxCheckBox *m_check; | |
112 | wxStaticText *m_static; | |
06cc1fb9 JS |
113 | wxBitmapButton *m_upDirButton; |
114 | wxBitmapButton *m_newDirButton; | |
c8c0e54c | 115 | |
8b17ba72 | 116 | private: |
fe6cf128 | 117 | void Init(); |
23254b13 | 118 | DECLARE_DYNAMIC_CLASS(wxGenericFileDialog) |
8b17ba72 | 119 | DECLARE_EVENT_TABLE() |
cefc49fd | 120 | |
23254b13 | 121 | // these variables are preserved between wxGenericFileDialog calls |
9cedab37 VZ |
122 | static long ms_lastViewStyle; // list or report? |
123 | static bool ms_lastShowHidden; // did we show hidden files? | |
8b17ba72 RR |
124 | }; |
125 | ||
23254b13 JS |
126 | #ifdef USE_GENERIC_FILEDIALOG |
127 | ||
128 | class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog | |
129 | { | |
23254b13 | 130 | public: |
6463b9f5 | 131 | wxFileDialog() {} |
23254b13 JS |
132 | |
133 | wxFileDialog(wxWindow *parent, | |
134 | const wxString& message = wxFileSelectorPromptStr, | |
ca65c044 WS |
135 | const wxString& defaultDir = wxEmptyString, |
136 | const wxString& defaultFile = wxEmptyString, | |
23254b13 JS |
137 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, |
138 | long style = 0, | |
6463b9f5 JS |
139 | const wxPoint& pos = wxDefaultPosition) |
140 | :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos) | |
141 | { | |
142 | } | |
6b99f53e | 143 | |
4e1901b7 RR |
144 | private: |
145 | DECLARE_DYNAMIC_CLASS(wxFileDialog) | |
23254b13 JS |
146 | }; |
147 | ||
23254b13 | 148 | #endif // USE_GENERIC_FILEDIALOG |
8b17ba72 | 149 | |
23254b13 | 150 | //----------------------------------------------------------------------------- |
b600ed13 | 151 | // wxFileData - a class to hold the file info for the wxFileCtrl |
23254b13 JS |
152 | //----------------------------------------------------------------------------- |
153 | ||
154 | class WXDLLEXPORT wxFileData | |
155 | { | |
156 | public: | |
157 | enum fileType | |
158 | { | |
06cc1fb9 | 159 | is_file = 0x0000, |
23254b13 JS |
160 | is_dir = 0x0001, |
161 | is_link = 0x0002, | |
162 | is_exe = 0x0004, | |
163 | is_drive = 0x0008 | |
164 | }; | |
165 | ||
ca9fb418 | 166 | wxFileData() { Init(); } |
b600ed13 | 167 | // Full copy constructor |
81169710 | 168 | wxFileData( const wxFileData& fileData ) { Copy(fileData); } |
b600ed13 | 169 | // Create a filedata from this information |
06cc1fb9 JS |
170 | wxFileData( const wxString &filePath, const wxString &fileName, |
171 | fileType type, int image_id ); | |
172 | ||
81169710 VZ |
173 | // make a full copy of the other wxFileData |
174 | void Copy( const wxFileData &other ); | |
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 | |
8226a054 | 187 | wxFileOffset GetSize() const { return m_size; } |
06cc1fb9 | 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 | 228 | |
ca9fb418 | 229 | // operators |
81169710 VZ |
230 | wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; } |
231 | ||
ca9fb418 | 232 | protected: |
23254b13 | 233 | wxString m_fileName; |
06cc1fb9 | 234 | wxString m_filePath; |
8226a054 | 235 | wxFileOffset m_size; |
06cc1fb9 | 236 | wxDateTime m_dateTime; |
23254b13 JS |
237 | wxString m_permissions; |
238 | int m_type; | |
8226a054 VZ |
239 | int m_image; |
240 | ||
ca9fb418 VZ |
241 | private: |
242 | void Init(); | |
23254b13 JS |
243 | }; |
244 | ||
245 | //----------------------------------------------------------------------------- | |
246 | // wxFileCtrl | |
247 | //----------------------------------------------------------------------------- | |
248 | ||
249 | class WXDLLEXPORT wxFileCtrl : public wxListCtrl | |
250 | { | |
251 | public: | |
252 | wxFileCtrl(); | |
253 | wxFileCtrl( wxWindow *win, | |
254 | wxWindowID id, | |
255 | const wxString &wild, | |
256 | bool showHidden, | |
257 | const wxPoint &pos = wxDefaultPosition, | |
258 | const wxSize &size = wxDefaultSize, | |
259 | long style = wxLC_LIST, | |
260 | const wxValidator &validator = wxDefaultValidator, | |
261 | const wxString &name = wxT("filelist") ); | |
262 | virtual ~wxFileCtrl(); | |
263 | ||
06cc1fb9 JS |
264 | virtual void ChangeToListMode(); |
265 | virtual void ChangeToReportMode(); | |
266 | virtual void ChangeToSmallIconMode(); | |
ca65c044 | 267 | virtual void ShowHidden( bool show = true ); |
23254b13 JS |
268 | bool GetShowHidden() const { return m_showHidden; } |
269 | ||
06cc1fb9 | 270 | virtual long Add( wxFileData *fd, wxListItem &item ); |
b600ed13 | 271 | virtual void UpdateItem(const wxListItem &item); |
06cc1fb9 JS |
272 | virtual void UpdateFiles(); |
273 | virtual void MakeDir(); | |
274 | virtual void GoToParentDir(); | |
275 | virtual void GoToHomeDir(); | |
276 | virtual void GoToDir( const wxString &dir ); | |
277 | virtual void SetWild( const wxString &wild ); | |
23254b13 | 278 | wxString GetWild() const { return m_wild; } |
23254b13 JS |
279 | wxString GetDir() const { return m_dirName; } |
280 | ||
281 | void OnListDeleteItem( wxListEvent &event ); | |
81169710 | 282 | void OnListDeleteAllItems( wxListEvent &event ); |
23254b13 JS |
283 | void OnListEndLabelEdit( wxListEvent &event ); |
284 | void OnListColClick( wxListEvent &event ); | |
285 | ||
06cc1fb9 JS |
286 | virtual void SortItems(wxFileData::fileListFieldType field, bool foward); |
287 | bool GetSortDirection() const { return m_sort_foward; } | |
23254b13 JS |
288 | wxFileData::fileListFieldType GetSortField() const { return m_sort_field; } |
289 | ||
06cc1fb9 | 290 | protected: |
81169710 | 291 | void FreeItemData(wxListItem& item); |
23254b13 JS |
292 | void FreeAllItemsData(); |
293 | ||
294 | wxString m_dirName; | |
295 | bool m_showHidden; | |
296 | wxString m_wild; | |
297 | ||
06cc1fb9 | 298 | bool m_sort_foward; |
23254b13 JS |
299 | wxFileData::fileListFieldType m_sort_field; |
300 | ||
06cc1fb9 | 301 | private: |
6b99f53e | 302 | DECLARE_DYNAMIC_CLASS(wxFileCtrl) |
23254b13 JS |
303 | DECLARE_EVENT_TABLE() |
304 | }; | |
8b17ba72 | 305 | |
b600ed13 | 306 | #endif // _WX_FILEDLGG_H_ |
9cedab37 | 307 |