]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/filedlgg.h
Apply parts of patch #1719888 to fix compilation on Mac and with
[wxWidgets.git] / include / wx / generic / filedlgg.h
CommitLineData
8b17ba72 1/////////////////////////////////////////////////////////////////////////////
d022d364 2// Name: wx/generic/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"
d022d364 18#include "wx/filedlg.h"
8b17ba72
RR
19
20//-----------------------------------------------------------------------------
21// classes
22//-----------------------------------------------------------------------------
23
06cc1fb9
JS
24class WXDLLEXPORT wxBitmapButton;
25class WXDLLEXPORT wxCheckBox;
26class WXDLLEXPORT wxChoice;
27class WXDLLEXPORT wxFileData;
28class WXDLLEXPORT wxFileCtrl;
29class WXDLLEXPORT wxGenericFileDialog;
30class WXDLLEXPORT wxListEvent;
31class WXDLLEXPORT wxListItem;
32class WXDLLEXPORT wxStaticText;
33class WXDLLEXPORT wxTextCtrl;
8b17ba72
RR
34
35//-------------------------------------------------------------------------
b600ed13 36// wxGenericFileDialog
8b17ba72
RR
37//-------------------------------------------------------------------------
38
f74172ab 39class WXDLLEXPORT wxGenericFileDialog: public wxFileDialogBase
8b17ba72
RR
40{
41public:
fe6cf128 42 wxGenericFileDialog() : wxFileDialogBase() { Init(); }
8b17ba72 43
23254b13 44 wxGenericFileDialog(wxWindow *parent,
fe6cf128 45 const wxString& message = wxFileSelectorPromptStr,
f74172ab
VZ
46 const wxString& defaultDir = wxEmptyString,
47 const wxString& defaultFile = wxEmptyString,
fe6cf128 48 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
ff3e84ff 49 long style = wxFD_DEFAULT_STYLE,
fe6cf128 50 const wxPoint& pos = wxDefaultPosition,
ff3e84ff
VZ
51 const wxSize& sz = wxDefaultSize,
52 const wxString& name = wxFileDialogNameStr,
fe6cf128
VZ
53 bool bypassGenericImpl = false );
54
4e1901b7
RR
55 bool Create( wxWindow *parent,
56 const wxString& message = wxFileSelectorPromptStr,
fe6cf128
VZ
57 const wxString& defaultDir = wxEmptyString,
58 const wxString& defaultFile = wxEmptyString,
4e1901b7 59 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
ff3e84ff 60 long style = wxFD_DEFAULT_STYLE,
fe6cf128 61 const wxPoint& pos = wxDefaultPosition,
ff3e84ff
VZ
62 const wxSize& sz = wxDefaultSize,
63 const wxString& name = wxFileDialogNameStr,
fe6cf128
VZ
64 bool bypassGenericImpl = false );
65
23254b13 66 virtual ~wxGenericFileDialog();
8b17ba72 67
f74172ab
VZ
68 virtual void SetMessage(const wxString& message) { SetTitle(message); }
69 virtual void SetPath(const wxString& path);
70 virtual void SetFilterIndex(int filterIndex);
b4cfe261 71 virtual void SetWildcard(const wxString& wildCard);
c61f4f6d 72
7941ba11 73 // for multiple file selection
f74172ab
VZ
74 virtual void GetPaths(wxArrayString& paths) const;
75 virtual void GetFilenames(wxArrayString& files) const;
c8c0e54c 76
9cedab37
VZ
77 // implementation only from now on
78 // -------------------------------
79
80 virtual int ShowModal();
16dce3b3 81 virtual bool Show( bool show = true );
9cedab37 82
8b17ba72
RR
83 void OnSelected( wxListEvent &event );
84 void OnActivated( wxListEvent &event );
85 void OnList( wxCommandEvent &event );
86 void OnReport( wxCommandEvent &event );
8b17ba72
RR
87 void OnUp( wxCommandEvent &event );
88 void OnHome( wxCommandEvent &event );
89 void OnListOk( wxCommandEvent &event );
0b855868 90 void OnNew( wxCommandEvent &event );
2b5f62a0 91 void OnChoiceFilter( wxCommandEvent &event );
cae5359f 92 void OnTextEnter( wxCommandEvent &event );
df413171 93 void OnTextChange( wxCommandEvent &event );
bf9e3e73 94 void OnCheck( wxCommandEvent &event );
c61f4f6d 95
06cc1fb9
JS
96 virtual void HandleAction( const wxString &fn );
97
98 virtual void UpdateControls();
6b99f53e 99
4e1901b7
RR
100private:
101 // Don't use this implementation at all :-)
102 bool m_bypassGenericImpl;
c8c0e54c
VZ
103
104protected:
2b5f62a0
VZ
105 // use the filter with the given index
106 void DoSetFilterIndex(int filterindex);
107
cefc49fd 108 wxString m_filterExtension;
9c884972
RR
109 wxChoice *m_choice;
110 wxTextCtrl *m_text;
111 wxFileCtrl *m_list;
112 wxCheckBox *m_check;
113 wxStaticText *m_static;
06cc1fb9
JS
114 wxBitmapButton *m_upDirButton;
115 wxBitmapButton *m_newDirButton;
c8c0e54c 116
8b17ba72 117private:
fe6cf128 118 void Init();
23254b13 119 DECLARE_DYNAMIC_CLASS(wxGenericFileDialog)
8b17ba72 120 DECLARE_EVENT_TABLE()
cefc49fd 121
23254b13 122 // these variables are preserved between wxGenericFileDialog calls
9cedab37
VZ
123 static long ms_lastViewStyle; // list or report?
124 static bool ms_lastShowHidden; // did we show hidden files?
8b17ba72
RR
125};
126
a84f5f39 127#ifdef wxUSE_GENERIC_FILEDIALOG
23254b13
JS
128
129class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog
130{
23254b13 131public:
6463b9f5 132 wxFileDialog() {}
23254b13
JS
133
134 wxFileDialog(wxWindow *parent,
135 const wxString& message = wxFileSelectorPromptStr,
ca65c044
WS
136 const wxString& defaultDir = wxEmptyString,
137 const wxString& defaultFile = wxEmptyString,
23254b13
JS
138 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
139 long style = 0,
6463b9f5
JS
140 const wxPoint& pos = wxDefaultPosition)
141 :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos)
142 {
143 }
6b99f53e 144
4e1901b7
RR
145private:
146 DECLARE_DYNAMIC_CLASS(wxFileDialog)
23254b13
JS
147};
148
a84f5f39 149#endif // wxUSE_GENERIC_FILEDIALOG
8b17ba72 150
23254b13 151//-----------------------------------------------------------------------------
b600ed13 152// wxFileData - a class to hold the file info for the wxFileCtrl
23254b13
JS
153//-----------------------------------------------------------------------------
154
155class WXDLLEXPORT wxFileData
156{
157public:
158 enum fileType
159 {
06cc1fb9 160 is_file = 0x0000,
23254b13
JS
161 is_dir = 0x0001,
162 is_link = 0x0002,
163 is_exe = 0x0004,
164 is_drive = 0x0008
165 };
166
ca9fb418 167 wxFileData() { Init(); }
b600ed13 168 // Full copy constructor
81169710 169 wxFileData( const wxFileData& fileData ) { Copy(fileData); }
b600ed13 170 // Create a filedata from this information
06cc1fb9
JS
171 wxFileData( const wxString &filePath, const wxString &fileName,
172 fileType type, int image_id );
173
81169710
VZ
174 // make a full copy of the other wxFileData
175 void Copy( const wxFileData &other );
176
b600ed13
VZ
177 // (re)read the extra data about the file from the system
178 void ReadData();
179
06cc1fb9
JS
180 // get the name of the file, dir, drive
181 wxString GetFileName() const { return m_fileName; }
182 // get the full path + name of the file, dir, path
183 wxString GetFilePath() const { return m_filePath; }
b600ed13
VZ
184 // Set the path + name and name of the item
185 void SetNewName( const wxString &filePath, const wxString &fileName );
186
187 // Get the size of the file in bytes
8226a054 188 wxFileOffset GetSize() const { return m_size; }
06cc1fb9 189 // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
b600ed13 190 wxString GetFileType() const;
06cc1fb9 191 // get the last modification time
b600ed13
VZ
192 wxDateTime GetDateTime() const { return m_dateTime; }
193 // Get the time as a formatted string
06cc1fb9
JS
194 wxString GetModificationTime() const;
195 // in UNIX get rwx for file, in MSW get attributes ARHS
196 wxString GetPermissions() const { return m_permissions; }
b600ed13 197 // Get the id of the image used in a wxImageList
06cc1fb9
JS
198 int GetImageId() const { return m_image; }
199
b600ed13 200 bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
06cc1fb9
JS
201 bool IsDir() const { return (m_type & is_dir ) != 0; }
202 bool IsLink() const { return (m_type & is_link ) != 0; }
203 bool IsExe() const { return (m_type & is_exe ) != 0; }
204 bool IsDrive() const { return (m_type & is_drive) != 0; }
205
b600ed13
VZ
206 // Get/Set the type of file, file/dir/drive/link
207 int GetType() const { return m_type; }
23254b13
JS
208
209 // the wxFileCtrl fields in report view
210 enum fileListFieldType
211 {
212 FileList_Name,
06cc1fb9 213 FileList_Size,
23254b13 214 FileList_Type,
23254b13 215 FileList_Time,
06cc1fb9 216#if defined(__UNIX__) || defined(__WIN32__)
23254b13 217 FileList_Perm,
06cc1fb9 218#endif // defined(__UNIX__) || defined(__WIN32__)
23254b13
JS
219 FileList_Max
220 };
221
b600ed13 222 // Get the entry for report view of wxFileCtrl
23254b13
JS
223 wxString GetEntry( fileListFieldType num ) const;
224
06cc1fb9
JS
225 // Get a string representation of the file info
226 wxString GetHint() const;
b600ed13 227 // initialize a wxListItem attributes
23254b13 228 void MakeItem( wxListItem &item );
23254b13 229
ca9fb418 230 // operators
81169710
VZ
231 wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; }
232
ca9fb418 233protected:
23254b13 234 wxString m_fileName;
06cc1fb9 235 wxString m_filePath;
8226a054 236 wxFileOffset m_size;
06cc1fb9 237 wxDateTime m_dateTime;
23254b13
JS
238 wxString m_permissions;
239 int m_type;
8226a054
VZ
240 int m_image;
241
ca9fb418
VZ
242private:
243 void Init();
23254b13
JS
244};
245
246//-----------------------------------------------------------------------------
247// wxFileCtrl
248//-----------------------------------------------------------------------------
249
250class WXDLLEXPORT wxFileCtrl : public wxListCtrl
251{
252public:
253 wxFileCtrl();
254 wxFileCtrl( wxWindow *win,
255 wxWindowID id,
256 const wxString &wild,
257 bool showHidden,
258 const wxPoint &pos = wxDefaultPosition,
259 const wxSize &size = wxDefaultSize,
260 long style = wxLC_LIST,
261 const wxValidator &validator = wxDefaultValidator,
262 const wxString &name = wxT("filelist") );
263 virtual ~wxFileCtrl();
264
06cc1fb9
JS
265 virtual void ChangeToListMode();
266 virtual void ChangeToReportMode();
267 virtual void ChangeToSmallIconMode();
ca65c044 268 virtual void ShowHidden( bool show = true );
23254b13
JS
269 bool GetShowHidden() const { return m_showHidden; }
270
06cc1fb9 271 virtual long Add( wxFileData *fd, wxListItem &item );
b600ed13 272 virtual void UpdateItem(const wxListItem &item);
06cc1fb9
JS
273 virtual void UpdateFiles();
274 virtual void MakeDir();
275 virtual void GoToParentDir();
276 virtual void GoToHomeDir();
277 virtual void GoToDir( const wxString &dir );
278 virtual void SetWild( const wxString &wild );
23254b13 279 wxString GetWild() const { return m_wild; }
23254b13
JS
280 wxString GetDir() const { return m_dirName; }
281
282 void OnListDeleteItem( wxListEvent &event );
81169710 283 void OnListDeleteAllItems( wxListEvent &event );
23254b13
JS
284 void OnListEndLabelEdit( wxListEvent &event );
285 void OnListColClick( wxListEvent &event );
286
06cc1fb9
JS
287 virtual void SortItems(wxFileData::fileListFieldType field, bool foward);
288 bool GetSortDirection() const { return m_sort_foward; }
23254b13
JS
289 wxFileData::fileListFieldType GetSortField() const { return m_sort_field; }
290
06cc1fb9 291protected:
81169710 292 void FreeItemData(wxListItem& item);
23254b13
JS
293 void FreeAllItemsData();
294
295 wxString m_dirName;
296 bool m_showHidden;
297 wxString m_wild;
298
06cc1fb9 299 bool m_sort_foward;
23254b13
JS
300 wxFileData::fileListFieldType m_sort_field;
301
06cc1fb9 302private:
6b99f53e 303 DECLARE_DYNAMIC_CLASS(wxFileCtrl)
23254b13
JS
304 DECLARE_EVENT_TABLE()
305};
8b17ba72 306
b600ed13 307#endif // _WX_FILEDLGG_H_