]>
Commit | Line | Data |
---|---|---|
b600ed13 | 1 | ///////////////////////////////////////////////////////////////////////////// |
e031f1df | 2 | // Name: wx/filedlg.h |
b600ed13 VZ |
3 | // Purpose: wxFileDialog base header |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 8/17/99 | |
7 | // Copyright: (c) Robert Roebling | |
65571936 | 8 | // Licence: wxWindows licence |
b600ed13 VZ |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
34138703 JS |
11 | #ifndef _WX_FILEDLG_H_BASE_ |
12 | #define _WX_FILEDLG_H_BASE_ | |
c801d85f | 13 | |
2ecf902b WS |
14 | #include "wx/defs.h" |
15 | ||
1e6feb95 VZ |
16 | #if wxUSE_FILEDLG |
17 | ||
f74172ab | 18 | #include "wx/dialog.h" |
a9711a4d | 19 | #include "wx/arrstr.h" |
f74172ab | 20 | |
f92ec193 VZ |
21 | // this symbol is defined for the platforms which support multiple |
22 | // ('|'-separated) filters in the file dialog | |
26078494 VZ |
23 | #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__) |
24 | #define wxHAS_MULTIPLE_FILEDLG_FILTERS | |
25 | #endif | |
26 | ||
b600ed13 | 27 | //---------------------------------------------------------------------------- |
f74172ab | 28 | // wxFileDialog data |
b600ed13 VZ |
29 | //---------------------------------------------------------------------------- |
30 | ||
45f4109c RR |
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 | ||
ff3e84ff VZ |
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, | |
45f4109c RR |
48 | wxFD_CHANGE_DIR = 0x0080, |
49 | wxFD_PREVIEW = 0x0100 | |
ff3e84ff VZ |
50 | }; |
51 | ||
e031f1df WS |
52 | #if WXWIN_COMPATIBILITY_2_6 |
53 | enum | |
54 | { | |
55 | wxOPEN = wxFD_OPEN, | |
56 | wxSAVE = wxFD_SAVE, | |
57 | wxOVERWRITE_PROMPT = wxFD_OVERWRITE_PROMPT, | |
e031f1df WS |
58 | wxFILE_MUST_EXIST = wxFD_FILE_MUST_EXIST, |
59 | wxMULTIPLE = wxFD_MULTIPLE, | |
60 | wxCHANGE_DIR = wxFD_CHANGE_DIR | |
61 | }; | |
62 | #endif | |
63 | ||
ff3e84ff VZ |
64 | #define wxFD_DEFAULT_STYLE wxFD_OPEN |
65 | ||
53a2db12 FM |
66 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFileDialogNameStr[]; |
67 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorPromptStr[]; | |
68 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr[]; | |
b600ed13 | 69 | |
f74172ab VZ |
70 | //---------------------------------------------------------------------------- |
71 | // wxFileDialogBase | |
72 | //---------------------------------------------------------------------------- | |
73 | ||
53a2db12 | 74 | class WXDLLIMPEXP_CORE wxFileDialogBase: public wxDialog |
f74172ab VZ |
75 | { |
76 | public: | |
fe6cf128 | 77 | wxFileDialogBase () { Init(); } |
f74172ab VZ |
78 | |
79 | wxFileDialogBase(wxWindow *parent, | |
fe6cf128 VZ |
80 | const wxString& message = wxFileSelectorPromptStr, |
81 | const wxString& defaultDir = wxEmptyString, | |
82 | const wxString& defaultFile = wxEmptyString, | |
83 | const wxString& wildCard = wxFileSelectorDefaultWildcardStr, | |
ff3e84ff VZ |
84 | long style = wxFD_DEFAULT_STYLE, |
85 | const wxPoint& pos = wxDefaultPosition, | |
86 | const wxSize& sz = wxDefaultSize, | |
87 | const wxString& name = wxFileDialogNameStr) | |
fe6cf128 VZ |
88 | { |
89 | Init(); | |
ff3e84ff | 90 | Create(parent, message, defaultDir, defaultFile, wildCard, style, pos, sz, name); |
fe6cf128 VZ |
91 | } |
92 | ||
8ce68f7f VZ |
93 | virtual ~wxFileDialogBase() {} |
94 | ||
95 | ||
fe6cf128 VZ |
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, | |
ff3e84ff VZ |
101 | long style = wxFD_DEFAULT_STYLE, |
102 | const wxPoint& pos = wxDefaultPosition, | |
103 | const wxSize& sz = wxDefaultSize, | |
104 | const wxString& name = wxFileDialogNameStr); | |
f74172ab | 105 | |
45f4109c | 106 | bool HasFdFlag(int flag) const { return HasFlag(flag); } |
b014db05 | 107 | |
f74172ab | 108 | virtual void SetMessage(const wxString& message) { m_message = message; } |
7430a4bb VZ |
109 | virtual void SetPath(const wxString& path); |
110 | virtual void SetDirectory(const wxString& dir); | |
111 | virtual void SetFilename(const wxString& name); | |
f74172ab | 112 | virtual void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; } |
f74172ab VZ |
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; } | |
f74172ab VZ |
122 | virtual int GetFilterIndex() const { return m_filterIndex; } |
123 | ||
926df8a1 VZ |
124 | virtual wxString GetCurrentlySelectedFilename() const |
125 | { return m_currentlySelectedFilename; } | |
126 | ||
8ce68f7f VZ |
127 | // this function is called with wxFileDialog as parameter and should |
128 | // create the window containing the extra controls we want to show in it | |
129 | typedef wxWindow *(*ExtraControlCreatorFunction)(wxWindow*); | |
130 | ||
8ce68f7f VZ |
131 | virtual bool SupportsExtraControl() const { return false; } |
132 | ||
d6dae1b4 | 133 | bool SetExtraControlCreator(ExtraControlCreatorFunction creator); |
8ce68f7f VZ |
134 | wxWindow *GetExtraControl() const { return m_extraControl; } |
135 | ||
f74172ab VZ |
136 | // Utility functions |
137 | ||
cc197ed4 VZ |
138 | #if WXWIN_COMPATIBILITY_2_6 |
139 | ||
140 | wxDEPRECATED( long GetStyle() const ); | |
141 | wxDEPRECATED( void SetStyle(long style) ); | |
142 | ||
143 | #endif // WXWIN_COMPATIBILITY_2_6 | |
144 | ||
145 | ||
f74172ab VZ |
146 | // Append first extension to filePath from a ';' separated extensionList |
147 | // if filePath = "path/foo.bar" just return it as is | |
148 | // if filePath = "foo[.]" and extensionList = "*.jpg;*.png" return "foo.jpg" | |
149 | // if the extension is "*.j?g" (has wildcards) or "jpg" then return filePath | |
150 | static wxString AppendExtension(const wxString &filePath, | |
151 | const wxString &extensionList); | |
152 | ||
153 | protected: | |
154 | wxString m_message; | |
f74172ab VZ |
155 | wxString m_dir; |
156 | wxString m_path; // Full path | |
157 | wxString m_fileName; | |
158 | wxString m_wildCard; | |
159 | int m_filterIndex; | |
926df8a1 VZ |
160 | |
161 | // Currently selected, but not yet necessarily accepted by the user, file. | |
162 | // This should be updated whenever the selection in the control changes by | |
163 | // the platform-specific code to provide a useful implementation of | |
164 | // GetCurrentlySelectedFilename(). | |
165 | wxString m_currentlySelectedFilename; | |
166 | ||
8ce68f7f VZ |
167 | wxWindow* m_extraControl; |
168 | ||
169 | // returns true if control is created (if it already exists returns false) | |
170 | bool CreateExtraControl(); | |
6fa6d659 VZ |
171 | // return true if SetExtraControlCreator() was called |
172 | bool HasExtraControlCreator() const | |
173 | { return m_extraControlCreator != NULL; } | |
174 | // get the size of the extra control by creating and deleting it | |
175 | wxSize GetExtraControlSize(); | |
f74172ab VZ |
176 | |
177 | private: | |
8ce68f7f VZ |
178 | ExtraControlCreatorFunction m_extraControlCreator; |
179 | ||
fe6cf128 | 180 | void Init(); |
f74172ab | 181 | DECLARE_DYNAMIC_CLASS(wxFileDialogBase) |
c0c133e1 | 182 | wxDECLARE_NO_COPY_CLASS(wxFileDialogBase); |
f74172ab VZ |
183 | }; |
184 | ||
8ce68f7f | 185 | |
b600ed13 VZ |
186 | //---------------------------------------------------------------------------- |
187 | // wxFileDialog convenience functions | |
188 | //---------------------------------------------------------------------------- | |
189 | ||
f8bcb37d | 190 | // File selector - backward compatibility |
53a2db12 | 191 | WXDLLIMPEXP_CORE wxString |
6dc2e823 VS |
192 | wxFileSelector(const wxString& message = wxFileSelectorPromptStr, |
193 | const wxString& default_path = wxEmptyString, | |
194 | const wxString& default_filename = wxEmptyString, | |
195 | const wxString& default_extension = wxEmptyString, | |
f8bcb37d | 196 | const wxString& wildcard = wxFileSelectorDefaultWildcardStr, |
b600ed13 VZ |
197 | int flags = 0, |
198 | wxWindow *parent = NULL, | |
6dc2e823 | 199 | int x = wxDefaultCoord, int y = wxDefaultCoord); |
b600ed13 VZ |
200 | |
201 | // An extended version of wxFileSelector | |
53a2db12 | 202 | WXDLLIMPEXP_CORE wxString |
6dc2e823 VS |
203 | wxFileSelectorEx(const wxString& message = wxFileSelectorPromptStr, |
204 | const wxString& default_path = wxEmptyString, | |
205 | const wxString& default_filename = wxEmptyString, | |
b600ed13 | 206 | int *indexDefaultExtension = NULL, |
f8bcb37d | 207 | const wxString& wildcard = wxFileSelectorDefaultWildcardStr, |
b600ed13 VZ |
208 | int flags = 0, |
209 | wxWindow *parent = NULL, | |
6dc2e823 | 210 | int x = wxDefaultCoord, int y = wxDefaultCoord); |
b600ed13 VZ |
211 | |
212 | // Ask for filename to load | |
53a2db12 | 213 | WXDLLIMPEXP_CORE wxString |
6dc2e823 VS |
214 | wxLoadFileSelector(const wxString& what, |
215 | const wxString& extension, | |
216 | const wxString& default_name = wxEmptyString, | |
217 | wxWindow *parent = NULL); | |
b600ed13 VZ |
218 | |
219 | // Ask for filename to save | |
53a2db12 | 220 | WXDLLIMPEXP_CORE wxString |
6dc2e823 VS |
221 | wxSaveFileSelector(const wxString& what, |
222 | const wxString& extension, | |
223 | const wxString& default_name = wxEmptyString, | |
224 | wxWindow *parent = NULL); | |
b600ed13 VZ |
225 | |
226 | ||
099d4217 | 227 | #if defined (__WXUNIVERSAL__) |
0cf3e587 VZ |
228 | #define wxHAS_GENERIC_FILEDIALOG |
229 | #include "wx/generic/filedlgg.h" | |
099d4217 | 230 | #elif defined(__WXMSW__) |
0cf3e587 | 231 | #include "wx/msw/filedlg.h" |
2049ba38 | 232 | #elif defined(__WXMOTIF__) |
0cf3e587 | 233 | #include "wx/motif/filedlg.h" |
ff654490 | 234 | #elif defined(__WXGTK20__) |
0cf3e587 | 235 | #include "wx/gtk/filedlg.h" // GTK+ > 2.4 has native version |
1be7a35c | 236 | #elif defined(__WXGTK__) |
0cf3e587 | 237 | #include "wx/gtk1/filedlg.h" |
34138703 | 238 | #elif defined(__WXMAC__) |
ef0e9220 | 239 | #include "wx/osx/filedlg.h" |
0201182b | 240 | #elif defined(__WXCOCOA__) |
0cf3e587 | 241 | #include "wx/cocoa/filedlg.h" |
1777b9bb | 242 | #elif defined(__WXPM__) |
0cf3e587 | 243 | #include "wx/os2/filedlg.h" |
c801d85f KB |
244 | #endif |
245 | ||
1e6feb95 | 246 | #endif // wxUSE_FILEDLG |
ba681060 | 247 | |
b600ed13 | 248 | #endif // _WX_FILEDLG_H_BASE_ |