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