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