]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filedlg.h
no real changes, just minor refactoring and cleanup
[wxWidgets.git] / include / wx / filedlg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/filedlg.h
3 // Purpose: wxFileDialog base header
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_FILEDLG_H_BASE_
13 #define _WX_FILEDLG_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_FILEDLG
18
19 #include "wx/dialog.h"
20 #include "wx/arrstr.h"
21
22 // this symbol is defined for the platforms which support multiple
23 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
24 #define wxHAS_MULTIPLE_FILEDLG_FILTERS
25 #endif
26
27 //----------------------------------------------------------------------------
28 // wxFileDialog data
29 //----------------------------------------------------------------------------
30
31 /*
32 The flags below must coexist with the following flags in m_windowStyle
33 #define wxCAPTION 0x20000000
34 #define wxMAXIMIZE 0x00002000
35 #define wxCLOSE_BOX 0x00001000
36 #define wxSYSTEM_MENU 0x00000800
37 wxBORDER_NONE = 0x00200000
38 #define wxRESIZE_BORDER 0x00000040
39 */
40
41 enum
42 {
43 wxFD_OPEN = 0x0001,
44 wxFD_SAVE = 0x0002,
45 wxFD_OVERWRITE_PROMPT = 0x0004,
46 wxFD_FILE_MUST_EXIST = 0x0010,
47 wxFD_MULTIPLE = 0x0020,
48 wxFD_CHANGE_DIR = 0x0080,
49 wxFD_PREVIEW = 0x0100
50 };
51
52 #if WXWIN_COMPATIBILITY_2_6
53 enum
54 {
55 wxOPEN = wxFD_OPEN,
56 wxSAVE = wxFD_SAVE,
57 wxOVERWRITE_PROMPT = wxFD_OVERWRITE_PROMPT,
58 wxFILE_MUST_EXIST = wxFD_FILE_MUST_EXIST,
59 wxMULTIPLE = wxFD_MULTIPLE,
60 wxCHANGE_DIR = wxFD_CHANGE_DIR
61 };
62 #endif
63
64 #define wxFD_DEFAULT_STYLE wxFD_OPEN
65
66 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileDialogNameStr[];
67 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorPromptStr[];
68 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr[];
69
70 //----------------------------------------------------------------------------
71 // wxFileDialogBase
72 //----------------------------------------------------------------------------
73
74 class WXDLLIMPEXP_CORE wxFileDialogBase: public wxDialog
75 {
76 public:
77 wxFileDialogBase () { Init(); }
78
79 wxFileDialogBase(wxWindow *parent,
80 const wxString& message = wxFileSelectorPromptStr,
81 const wxString& defaultDir = wxEmptyString,
82 const wxString& defaultFile = wxEmptyString,
83 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
84 long style = wxFD_DEFAULT_STYLE,
85 const wxPoint& pos = wxDefaultPosition,
86 const wxSize& sz = wxDefaultSize,
87 const wxString& name = wxFileDialogNameStr)
88 {
89 Init();
90 Create(parent, message, defaultDir, defaultFile, wildCard, style, pos, sz, name);
91 }
92
93 virtual ~wxFileDialogBase() {}
94
95
96 bool Create(wxWindow *parent,
97 const wxString& message = wxFileSelectorPromptStr,
98 const wxString& defaultDir = wxEmptyString,
99 const wxString& defaultFile = wxEmptyString,
100 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
101 long style = wxFD_DEFAULT_STYLE,
102 const wxPoint& pos = wxDefaultPosition,
103 const wxSize& sz = wxDefaultSize,
104 const wxString& name = wxFileDialogNameStr);
105
106 bool HasFdFlag(int flag) const { return HasFlag(flag); }
107
108 virtual void SetMessage(const wxString& message) { m_message = message; }
109 virtual void SetPath(const wxString& path) { m_path = path; }
110 virtual void SetDirectory(const wxString& dir) { m_dir = dir; }
111 virtual void SetFilename(const wxString& name) { m_fileName = name; }
112 virtual void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
113 virtual void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
114
115 virtual wxString GetMessage() const { return m_message; }
116 virtual wxString GetPath() const { return m_path; }
117 virtual void GetPaths(wxArrayString& paths) const { paths.Empty(); paths.Add(m_path); }
118 virtual wxString GetDirectory() const { return m_dir; }
119 virtual wxString GetFilename() const { return m_fileName; }
120 virtual void GetFilenames(wxArrayString& files) const { files.Empty(); files.Add(m_fileName); }
121 virtual wxString GetWildcard() const { return m_wildCard; }
122 virtual int GetFilterIndex() const { return m_filterIndex; }
123
124 // this function is called with wxFileDialog as parameter and should
125 // create the window containing the extra controls we want to show in it
126 typedef wxWindow *(*ExtraControlCreatorFunction)(wxWindow*);
127
128 virtual bool SupportsExtraControl() const { return false; }
129
130 bool SetExtraControlCreator(ExtraControlCreatorFunction creator);
131 wxWindow *GetExtraControl() const { return m_extraControl; }
132
133 // Utility functions
134
135 #if WXWIN_COMPATIBILITY_2_6
136
137 wxDEPRECATED( long GetStyle() const );
138 wxDEPRECATED( void SetStyle(long style) );
139
140 #endif // WXWIN_COMPATIBILITY_2_6
141
142
143 // Append first extension to filePath from a ';' separated extensionList
144 // if filePath = "path/foo.bar" just return it as is
145 // if filePath = "foo[.]" and extensionList = "*.jpg;*.png" return "foo.jpg"
146 // if the extension is "*.j?g" (has wildcards) or "jpg" then return filePath
147 static wxString AppendExtension(const wxString &filePath,
148 const wxString &extensionList);
149
150 protected:
151 wxString m_message;
152 wxString m_dir;
153 wxString m_path; // Full path
154 wxString m_fileName;
155 wxString m_wildCard;
156 int m_filterIndex;
157 wxWindow* m_extraControl;
158
159 // returns true if control is created (if it already exists returns false)
160 bool CreateExtraControl();
161 // return true if SetExtraControlCreator() was called
162 bool HasExtraControlCreator() const
163 { return m_extraControlCreator != NULL; }
164 // get the size of the extra control by creating and deleting it
165 wxSize GetExtraControlSize();
166
167 private:
168 ExtraControlCreatorFunction m_extraControlCreator;
169
170 void Init();
171 DECLARE_DYNAMIC_CLASS(wxFileDialogBase)
172 DECLARE_NO_COPY_CLASS(wxFileDialogBase)
173 };
174
175
176 //----------------------------------------------------------------------------
177 // wxFileDialog convenience functions
178 //----------------------------------------------------------------------------
179
180 // File selector - backward compatibility
181 WXDLLIMPEXP_CORE wxString
182 wxFileSelector(const wxString& message = wxFileSelectorPromptStr,
183 const wxString& default_path = wxEmptyString,
184 const wxString& default_filename = wxEmptyString,
185 const wxString& default_extension = wxEmptyString,
186 const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
187 int flags = 0,
188 wxWindow *parent = NULL,
189 int x = wxDefaultCoord, int y = wxDefaultCoord);
190
191 // An extended version of wxFileSelector
192 WXDLLIMPEXP_CORE wxString
193 wxFileSelectorEx(const wxString& message = wxFileSelectorPromptStr,
194 const wxString& default_path = wxEmptyString,
195 const wxString& default_filename = wxEmptyString,
196 int *indexDefaultExtension = NULL,
197 const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
198 int flags = 0,
199 wxWindow *parent = NULL,
200 int x = wxDefaultCoord, int y = wxDefaultCoord);
201
202 // Ask for filename to load
203 WXDLLIMPEXP_CORE wxString
204 wxLoadFileSelector(const wxString& what,
205 const wxString& extension,
206 const wxString& default_name = wxEmptyString,
207 wxWindow *parent = NULL);
208
209 // Ask for filename to save
210 WXDLLIMPEXP_CORE wxString
211 wxSaveFileSelector(const wxString& what,
212 const wxString& extension,
213 const wxString& default_name = wxEmptyString,
214 wxWindow *parent = NULL);
215
216
217 #if defined (__WXUNIVERSAL__)
218 #define wxHAS_GENERIC_FILEDIALOG
219 #include "wx/generic/filedlgg.h"
220 #elif defined(__WXMSW__)
221 #include "wx/msw/filedlg.h"
222 #elif defined(__WXMOTIF__)
223 #include "wx/motif/filedlg.h"
224 #elif defined(__WXGTK20__)
225 #include "wx/gtk/filedlg.h" // GTK+ > 2.4 has native version
226 #elif defined(__WXGTK__)
227 #include "wx/gtk1/filedlg.h"
228 #elif defined(__WXMAC__)
229 #include "wx/osx/filedlg.h"
230 #elif defined(__WXCOCOA__)
231 #include "wx/cocoa/filedlg.h"
232 #elif defined(__WXPM__)
233 #include "wx/os2/filedlg.h"
234 #elif defined(__WXPALMOS__)
235 #define wxHAS_GENERIC_FILEDIALOG
236 #include "wx/generic/filedlgg.h"
237 #endif
238
239 #endif // wxUSE_FILEDLG
240
241 #endif // _WX_FILEDLG_H_BASE_