Applied patch [ 708582 ] wxGenericFileDialog & expose generic wxFileCtrl
[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(__APPLE__)
16 #pragma interface "filedlgg.h"
17 #endif
18
19 #include "wx/dialog.h"
20 #include "wx/listctrl.h"
21
22 //-----------------------------------------------------------------------------
23 // classes
24 //-----------------------------------------------------------------------------
25
26 class wxCheckBox;
27 class wxChoice;
28 class wxFileData;
29 class wxFileCtrl;
30 class wxGenericFileDialog;
31 class wxListEvent;
32 class wxListItem;
33 class wxStaticText;
34 class wxTextCtrl;
35
36 #if defined(__WXUNIVERSAL__)||defined(__WXGTK__)||defined(__WXX11__)||defined(__WXMGL__)
37 #define USE_GENERIC_FILEDIALOG
38 #endif
39
40 #ifdef USE_GENERIC_FILEDIALOG
41
42 //-----------------------------------------------------------------------------
43 // data
44 //-----------------------------------------------------------------------------
45
46 WXDLLEXPORT_DATA(extern const wxChar *)wxFileSelectorPromptStr;
47 WXDLLEXPORT_DATA(extern const wxChar *)wxFileSelectorDefaultWildcardStr;
48
49 #endif // USE_GENERIC_FILEDIALOG
50
51 //-------------------------------------------------------------------------
52 // File selector
53 //-------------------------------------------------------------------------
54
55 class WXDLLEXPORT wxGenericFileDialog: public wxDialog
56 {
57 public:
58 wxGenericFileDialog() { }
59
60 wxGenericFileDialog(wxWindow *parent,
61 const wxString& message = wxFileSelectorPromptStr,
62 const wxString& defaultDir = _T(""),
63 const wxString& defaultFile = _T(""),
64 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
65 long style = 0,
66 const wxPoint& pos = wxDefaultPosition);
67 virtual ~wxGenericFileDialog();
68
69 void SetMessage(const wxString& message) { SetTitle(message); }
70 void SetPath(const wxString& path);
71 void SetDirectory(const wxString& dir) { m_dir = dir; }
72 void SetFilename(const wxString& name) { m_fileName = name; }
73 void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
74 void SetStyle(long style) { m_dialogStyle = style; }
75 void SetFilterIndex(int filterIndex);
76
77 wxString GetMessage() const { return m_message; }
78 wxString GetPath() const { return m_path; }
79 wxString GetDirectory() const { return m_dir; }
80 wxString GetFilename() const { return m_fileName; }
81 wxString GetWildcard() const { return m_wildCard; }
82 long GetStyle() const { return m_dialogStyle; }
83 int GetFilterIndex() const { return m_filterIndex; }
84
85 // for multiple file selection
86 void GetPaths(wxArrayString& paths) const;
87 void GetFilenames(wxArrayString& files) const;
88
89 // implementation only from now on
90 // -------------------------------
91
92 virtual int ShowModal();
93
94 void OnSelected( wxListEvent &event );
95 void OnActivated( wxListEvent &event );
96 void OnList( wxCommandEvent &event );
97 void OnReport( wxCommandEvent &event );
98 void OnUp( wxCommandEvent &event );
99 void OnHome( wxCommandEvent &event );
100 void OnListOk( wxCommandEvent &event );
101 void OnNew( wxCommandEvent &event );
102 void OnChoiceFilter( wxCommandEvent &event );
103 void OnTextEnter( wxCommandEvent &event );
104 void OnTextChange( wxCommandEvent &event );
105 void OnCheck( wxCommandEvent &event );
106
107 void HandleAction( const wxString &fn );
108
109 protected:
110 // use the filter with the given index
111 void DoSetFilterIndex(int filterindex);
112
113 wxString m_message;
114 long m_dialogStyle;
115 wxString m_dir;
116 wxString m_path; // Full path
117 wxString m_fileName;
118 wxString m_wildCard;
119 int m_filterIndex;
120 wxString m_filterExtension;
121 wxChoice *m_choice;
122 wxTextCtrl *m_text;
123 wxFileCtrl *m_list;
124 wxCheckBox *m_check;
125 wxStaticText *m_static;
126
127 private:
128 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog)
129 DECLARE_EVENT_TABLE()
130
131 // these variables are preserved between wxGenericFileDialog calls
132 static long ms_lastViewStyle; // list or report?
133 static bool ms_lastShowHidden; // did we show hidden files?
134 };
135
136 #ifdef USE_GENERIC_FILEDIALOG
137
138 class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog
139 {
140 DECLARE_DYNAMIC_CLASS(wxFileDialog)
141
142 public:
143 wxFileDialog() {}
144
145 wxFileDialog(wxWindow *parent,
146 const wxString& message = wxFileSelectorPromptStr,
147 const wxString& defaultDir = _T(""),
148 const wxString& defaultFile = _T(""),
149 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
150 long style = 0,
151 const wxPoint& pos = wxDefaultPosition)
152 :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos)
153 {
154 }
155 };
156
157 // File selector - backward compatibility
158 WXDLLEXPORT wxString
159 wxFileSelector(const wxChar *message = wxFileSelectorPromptStr,
160 const wxChar *default_path = NULL,
161 const wxChar *default_filename = NULL,
162 const wxChar *default_extension = NULL,
163 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
164 int flags = 0,
165 wxWindow *parent = NULL,
166 int x = -1, int y = -1);
167
168 // An extended version of wxFileSelector
169 WXDLLEXPORT wxString
170 wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr,
171 const wxChar *default_path = NULL,
172 const wxChar *default_filename = NULL,
173 int *indexDefaultExtension = NULL,
174 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
175 int flags = 0,
176 wxWindow *parent = NULL,
177 int x = -1, int y = -1);
178
179 // Ask for filename to load
180 WXDLLEXPORT wxString
181 wxLoadFileSelector(const wxChar *what,
182 const wxChar *extension,
183 const wxChar *default_name = (const wxChar *)NULL,
184 wxWindow *parent = (wxWindow *) NULL);
185
186 // Ask for filename to save
187 WXDLLEXPORT wxString
188 wxSaveFileSelector(const wxChar *what,
189 const wxChar *extension,
190 const wxChar *default_name = (const wxChar *) NULL,
191 wxWindow *parent = (wxWindow *) NULL);
192
193 #endif // USE_GENERIC_FILEDIALOG
194
195 //-----------------------------------------------------------------------------
196 // wxFileData
197 //-----------------------------------------------------------------------------
198
199 class WXDLLEXPORT wxFileData
200 {
201 public:
202 enum fileType
203 {
204 is_file = 0,
205 is_dir = 0x0001,
206 is_link = 0x0002,
207 is_exe = 0x0004,
208 is_drive = 0x0008
209 };
210
211 wxFileData( const wxString &name, const wxString &fname, fileType type );
212 wxString GetName() const;
213 wxString GetFullName() const;
214 wxString GetHint() const;
215
216 // the wxFileCtrl fields in report view
217 enum fileListFieldType
218 {
219 FileList_Name,
220 FileList_Type,
221 FileList_Date,
222 FileList_Time,
223 #ifdef __UNIX__
224 FileList_Perm,
225 #endif // __UNIX__
226 FileList_Max
227 };
228
229 wxString GetEntry( fileListFieldType num ) const;
230
231 bool IsDir() const;
232 bool IsLink() const;
233 bool IsExe() const;
234 bool IsDrive() const;
235 long GetSize() const { return m_size; }
236 int GetHour() const { return m_hour; }
237 int GetMinute() const { return m_minute; }
238 int GetYear() const { return m_year; }
239 int GetMonth() const { return m_month; }
240 int GetDay() const { return m_day; }
241
242 void MakeItem( wxListItem &item );
243 void SetNewName( const wxString &name, const wxString &fname );
244
245 private:
246 wxString m_name;
247 wxString m_fileName;
248 long m_size;
249 int m_hour;
250 int m_minute;
251 int m_year;
252 int m_month;
253 int m_day;
254 wxString m_permissions;
255 int m_type;
256 };
257
258 //-----------------------------------------------------------------------------
259 // wxFileCtrl
260 //-----------------------------------------------------------------------------
261
262 class WXDLLEXPORT wxFileCtrl : public wxListCtrl
263 {
264 public:
265 wxFileCtrl();
266 wxFileCtrl( wxWindow *win,
267 wxWindowID id,
268 const wxString &wild,
269 bool showHidden,
270 const wxPoint &pos = wxDefaultPosition,
271 const wxSize &size = wxDefaultSize,
272 long style = wxLC_LIST,
273 const wxValidator &validator = wxDefaultValidator,
274 const wxString &name = wxT("filelist") );
275 virtual ~wxFileCtrl();
276
277 void ChangeToListMode();
278 void ChangeToReportMode();
279 void ChangeToIconMode();
280 void ShowHidden( bool show = TRUE );
281 bool GetShowHidden() const { return m_showHidden; }
282
283 long Add( wxFileData *fd, wxListItem &item );
284 void UpdateFiles();
285 virtual void StatusbarText( wxChar *WXUNUSED(text) ) {};
286 void MakeDir();
287 void GoToParentDir();
288 void GoToHomeDir();
289 void GoToDir( const wxString &dir );
290 void SetWild( const wxString &wild );
291 wxString GetWild() const { return m_wild; }
292 void GetDir( wxString &dir );
293 wxString GetDir() const { return m_dirName; }
294
295 void OnListDeleteItem( wxListEvent &event );
296 void OnListEndLabelEdit( wxListEvent &event );
297 void OnListColClick( wxListEvent &event );
298
299 // Associate commonly used UI controls with wxFileCtrl so that they can be
300 // disabled when they cannot be used (e.g. can't go to parent directory
301 // if wxFileCtrl already is in the root dir):
302 void SetGoToParentControl(wxWindow *ctrl) { m_goToParentControl = ctrl; }
303 void SetNewDirControl(wxWindow *ctrl) { m_newDirControl = ctrl; }
304
305 void SortItems(wxFileData::fileListFieldType field, bool foward);
306 bool GetSortDirection() const { return m_sort_foward > 0; }
307 wxFileData::fileListFieldType GetSortField() const { return m_sort_field; }
308
309 private:
310 void FreeItemData(const wxListItem& item);
311 void FreeAllItemsData();
312
313 wxString m_dirName;
314 bool m_showHidden;
315 wxString m_wild;
316
317 wxWindow *m_goToParentControl;
318 wxWindow *m_newDirControl;
319
320 int m_sort_foward;
321 wxFileData::fileListFieldType m_sort_field;
322
323 DECLARE_DYNAMIC_CLASS(wxFileCtrl);
324 DECLARE_EVENT_TABLE()
325 };
326
327 #endif
328 // _WX_FILEDLGG_H_
329
330