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