]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/filedlgg.h
Fix wxMotif build.
[wxWidgets.git] / include / wx / generic / filedlgg.h
CommitLineData
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
27class WXDLLEXPORT wxBitmapButton;
28class WXDLLEXPORT wxCheckBox;
29class WXDLLEXPORT wxChoice;
30class WXDLLEXPORT wxFileData;
31class WXDLLEXPORT wxFileCtrl;
32class WXDLLEXPORT wxGenericFileDialog;
33class WXDLLEXPORT wxListEvent;
34class WXDLLEXPORT wxListItem;
35class WXDLLEXPORT wxStaticText;
36class 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
42#ifdef USE_GENERIC_FILEDIALOG
43
44//-----------------------------------------------------------------------------
45// data
46//-----------------------------------------------------------------------------
47
48WXDLLEXPORT_DATA(extern const wxChar *)wxFileSelectorPromptStr;
49WXDLLEXPORT_DATA(extern const wxChar *)wxFileSelectorDefaultWildcardStr;
50
51#endif // USE_GENERIC_FILEDIALOG
52
8b17ba72
RR
53//-------------------------------------------------------------------------
54// File selector
55//-------------------------------------------------------------------------
56
23254b13 57class WXDLLEXPORT wxGenericFileDialog: public wxDialog
8b17ba72
RR
58{
59public:
23254b13 60 wxGenericFileDialog() { }
8b17ba72 61
23254b13 62 wxGenericFileDialog(wxWindow *parent,
8b17ba72 63 const wxString& message = wxFileSelectorPromptStr,
9cedab37
VZ
64 const wxString& defaultDir = _T(""),
65 const wxString& defaultFile = _T(""),
8b17ba72
RR
66 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
67 long style = 0,
68 const wxPoint& pos = wxDefaultPosition);
23254b13 69 virtual ~wxGenericFileDialog();
8b17ba72 70
9cedab37 71 void SetMessage(const wxString& message) { SetTitle(message); }
8b17ba72
RR
72 void SetPath(const wxString& path);
73 void SetDirectory(const wxString& dir) { m_dir = dir; }
74 void SetFilename(const wxString& name) { m_fileName = name; }
75 void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
76 void SetStyle(long style) { m_dialogStyle = style; }
f6b66bc2 77 void SetFilterIndex(int filterIndex);
8b17ba72
RR
78
79 wxString GetMessage() const { return m_message; }
80 wxString GetPath() const { return m_path; }
81 wxString GetDirectory() const { return m_dir; }
82 wxString GetFilename() const { return m_fileName; }
83 wxString GetWildcard() const { return m_wildCard; }
84 long GetStyle() const { return m_dialogStyle; }
7941ba11 85 int GetFilterIndex() const { return m_filterIndex; }
c61f4f6d 86
7941ba11
RR
87 // for multiple file selection
88 void GetPaths(wxArrayString& paths) const;
89 void GetFilenames(wxArrayString& files) const;
c8c0e54c 90
9cedab37
VZ
91 // implementation only from now on
92 // -------------------------------
93
94 virtual int ShowModal();
95
8b17ba72
RR
96 void OnSelected( wxListEvent &event );
97 void OnActivated( wxListEvent &event );
98 void OnList( wxCommandEvent &event );
99 void OnReport( wxCommandEvent &event );
8b17ba72
RR
100 void OnUp( wxCommandEvent &event );
101 void OnHome( wxCommandEvent &event );
102 void OnListOk( wxCommandEvent &event );
0b855868 103 void OnNew( wxCommandEvent &event );
2b5f62a0 104 void OnChoiceFilter( wxCommandEvent &event );
cae5359f 105 void OnTextEnter( wxCommandEvent &event );
df413171 106 void OnTextChange( wxCommandEvent &event );
bf9e3e73 107 void OnCheck( wxCommandEvent &event );
c61f4f6d 108
06cc1fb9
JS
109 virtual void HandleAction( const wxString &fn );
110
111 virtual void UpdateControls();
c8c0e54c
VZ
112
113protected:
2b5f62a0
VZ
114 // use the filter with the given index
115 void DoSetFilterIndex(int filterindex);
116
9c884972
RR
117 wxString m_message;
118 long m_dialogStyle;
119 wxString m_dir;
120 wxString m_path; // Full path
121 wxString m_fileName;
122 wxString m_wildCard;
123 int m_filterIndex;
cefc49fd 124 wxString m_filterExtension;
9c884972
RR
125 wxChoice *m_choice;
126 wxTextCtrl *m_text;
127 wxFileCtrl *m_list;
128 wxCheckBox *m_check;
129 wxStaticText *m_static;
06cc1fb9
JS
130 wxBitmapButton *m_upDirButton;
131 wxBitmapButton *m_newDirButton;
c8c0e54c 132
8b17ba72 133private:
23254b13 134 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog)
8b17ba72 135 DECLARE_EVENT_TABLE()
cefc49fd 136
23254b13 137 // these variables are preserved between wxGenericFileDialog calls
9cedab37
VZ
138 static long ms_lastViewStyle; // list or report?
139 static bool ms_lastShowHidden; // did we show hidden files?
8b17ba72
RR
140};
141
23254b13
JS
142#ifdef USE_GENERIC_FILEDIALOG
143
144class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog
145{
146 DECLARE_DYNAMIC_CLASS(wxFileDialog)
147
148public:
149 wxFileDialog() {}
150
151 wxFileDialog(wxWindow *parent,
152 const wxString& message = wxFileSelectorPromptStr,
153 const wxString& defaultDir = _T(""),
154 const wxString& defaultFile = _T(""),
155 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
156 long style = 0,
157 const wxPoint& pos = wxDefaultPosition)
158 :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos)
159 {
160 }
161};
162
8b17ba72
RR
163// File selector - backward compatibility
164WXDLLEXPORT wxString
165wxFileSelector(const wxChar *message = wxFileSelectorPromptStr,
166 const wxChar *default_path = NULL,
167 const wxChar *default_filename = NULL,
168 const wxChar *default_extension = NULL,
169 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
170 int flags = 0,
171 wxWindow *parent = NULL,
172 int x = -1, int y = -1);
173
174// An extended version of wxFileSelector
175WXDLLEXPORT wxString
176wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr,
177 const wxChar *default_path = NULL,
178 const wxChar *default_filename = NULL,
179 int *indexDefaultExtension = NULL,
180 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
181 int flags = 0,
182 wxWindow *parent = NULL,
183 int x = -1, int y = -1);
184
185// Ask for filename to load
186WXDLLEXPORT wxString
187wxLoadFileSelector(const wxChar *what,
188 const wxChar *extension,
189 const wxChar *default_name = (const wxChar *)NULL,
190 wxWindow *parent = (wxWindow *) NULL);
191
192// Ask for filename to save
193WXDLLEXPORT wxString
194wxSaveFileSelector(const wxChar *what,
195 const wxChar *extension,
196 const wxChar *default_name = (const wxChar *) NULL,
197 wxWindow *parent = (wxWindow *) NULL);
198
23254b13 199#endif // USE_GENERIC_FILEDIALOG
8b17ba72 200
23254b13
JS
201//-----------------------------------------------------------------------------
202// wxFileData
203//-----------------------------------------------------------------------------
204
205class WXDLLEXPORT wxFileData
206{
207public:
208 enum fileType
209 {
06cc1fb9 210 is_file = 0x0000,
23254b13
JS
211 is_dir = 0x0001,
212 is_link = 0x0002,
213 is_exe = 0x0004,
214 is_drive = 0x0008
215 };
216
06cc1fb9
JS
217 wxFileData( const wxString &filePath, const wxString &fileName,
218 fileType type, int image_id );
219
220 // get the name of the file, dir, drive
221 wxString GetFileName() const { return m_fileName; }
222 // get the full path + name of the file, dir, path
223 wxString GetFilePath() const { return m_filePath; }
224 long GetSize() const { return m_size; }
225 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
226 wxString GetType() const;
227 // get the last modification time
228 wxDateTime GetTime() const { return m_dateTime; }
229 wxString GetModificationTime() const;
230 // in UNIX get rwx for file, in MSW get attributes ARHS
231 wxString GetPermissions() const { return m_permissions; }
232 int GetImageId() const { return m_image; }
233
234 bool IsDir() const { return (m_type & is_dir ) != 0; }
235 bool IsLink() const { return (m_type & is_link ) != 0; }
236 bool IsExe() const { return (m_type & is_exe ) != 0; }
237 bool IsDrive() const { return (m_type & is_drive) != 0; }
238
239 int GetFileType() const { return m_type; }
23254b13
JS
240
241 // the wxFileCtrl fields in report view
242 enum fileListFieldType
243 {
244 FileList_Name,
06cc1fb9 245 FileList_Size,
23254b13 246 FileList_Type,
23254b13 247 FileList_Time,
06cc1fb9 248#if defined(__UNIX__) || defined(__WIN32__)
23254b13 249 FileList_Perm,
06cc1fb9 250#endif // defined(__UNIX__) || defined(__WIN32__)
23254b13
JS
251 FileList_Max
252 };
253
254 wxString GetEntry( fileListFieldType num ) const;
255
06cc1fb9
JS
256 // Get a string representation of the file info
257 wxString GetHint() const;
23254b13 258 void MakeItem( wxListItem &item );
06cc1fb9 259 void SetNewName( const wxString &filePath, const wxString &fileName );
23254b13
JS
260
261private:
23254b13 262 wxString m_fileName;
06cc1fb9 263 wxString m_filePath;
23254b13 264 long m_size;
06cc1fb9 265 wxDateTime m_dateTime;
23254b13
JS
266 wxString m_permissions;
267 int m_type;
06cc1fb9 268 int m_image;
23254b13
JS
269};
270
271//-----------------------------------------------------------------------------
272// wxFileCtrl
273//-----------------------------------------------------------------------------
274
275class WXDLLEXPORT wxFileCtrl : public wxListCtrl
276{
277public:
278 wxFileCtrl();
279 wxFileCtrl( wxWindow *win,
280 wxWindowID id,
281 const wxString &wild,
282 bool showHidden,
283 const wxPoint &pos = wxDefaultPosition,
284 const wxSize &size = wxDefaultSize,
285 long style = wxLC_LIST,
286 const wxValidator &validator = wxDefaultValidator,
287 const wxString &name = wxT("filelist") );
288 virtual ~wxFileCtrl();
289
06cc1fb9
JS
290 virtual void ChangeToListMode();
291 virtual void ChangeToReportMode();
292 virtual void ChangeToSmallIconMode();
293 virtual void ShowHidden( bool show = TRUE );
23254b13
JS
294 bool GetShowHidden() const { return m_showHidden; }
295
06cc1fb9
JS
296 virtual long Add( wxFileData *fd, wxListItem &item );
297 virtual void UpdateFiles();
298 virtual void MakeDir();
299 virtual void GoToParentDir();
300 virtual void GoToHomeDir();
301 virtual void GoToDir( const wxString &dir );
302 virtual void SetWild( const wxString &wild );
23254b13 303 wxString GetWild() const { return m_wild; }
23254b13
JS
304 wxString GetDir() const { return m_dirName; }
305
306 void OnListDeleteItem( wxListEvent &event );
307 void OnListEndLabelEdit( wxListEvent &event );
308 void OnListColClick( wxListEvent &event );
309
06cc1fb9
JS
310 virtual void SortItems(wxFileData::fileListFieldType field, bool foward);
311 bool GetSortDirection() const { return m_sort_foward; }
23254b13
JS
312 wxFileData::fileListFieldType GetSortField() const { return m_sort_field; }
313
06cc1fb9 314protected:
23254b13
JS
315 void FreeItemData(const wxListItem& item);
316 void FreeAllItemsData();
317
318 wxString m_dirName;
319 bool m_showHidden;
320 wxString m_wild;
321
06cc1fb9 322 bool m_sort_foward;
23254b13
JS
323 wxFileData::fileListFieldType m_sort_field;
324
06cc1fb9 325private:
23254b13
JS
326 DECLARE_DYNAMIC_CLASS(wxFileCtrl);
327 DECLARE_EVENT_TABLE()
328};
8b17ba72
RR
329
330#endif
23254b13 331 // _WX_FILEDLGG_H_
8b17ba72 332
9cedab37 333