1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFileDialog base header
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FILEDLG_H_BASE_
13 #define _WX_FILEDLG_H_BASE_
19 #include "wx/dialog.h"
20 #include "wx/arrstr.h"
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
27 //----------------------------------------------------------------------------
29 //----------------------------------------------------------------------------
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
45 wxFD_OVERWRITE_PROMPT
= 0x0004,
46 wxFD_FILE_MUST_EXIST
= 0x0010,
47 wxFD_MULTIPLE
= 0x0020,
48 wxFD_CHANGE_DIR
= 0x0080,
52 #if WXWIN_COMPATIBILITY_2_6
57 wxOVERWRITE_PROMPT
= wxFD_OVERWRITE_PROMPT
,
58 wxFILE_MUST_EXIST
= wxFD_FILE_MUST_EXIST
,
59 wxMULTIPLE
= wxFD_MULTIPLE
,
60 wxCHANGE_DIR
= wxFD_CHANGE_DIR
64 #define wxFD_DEFAULT_STYLE wxFD_OPEN
66 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileDialogNameStr
[];
67 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorPromptStr
[];
68 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr
[];
70 //----------------------------------------------------------------------------
72 //----------------------------------------------------------------------------
74 class WXDLLIMPEXP_CORE wxFileDialogBase
: public wxDialog
77 wxFileDialogBase () { Init(); }
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
)
90 Create(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
, sz
, name
);
93 virtual ~wxFileDialogBase() {}
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
);
106 bool HasFdFlag(int flag
) const { return HasFlag(flag
); }
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
; }
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
; }
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
*);
128 virtual bool SupportsExtraControl() const { return false; }
130 bool SetExtraControlCreator(ExtraControlCreatorFunction creator
);
131 wxWindow
*GetExtraControl() const { return m_extraControl
; }
135 #if WXWIN_COMPATIBILITY_2_6
137 wxDEPRECATED( long GetStyle() const );
138 wxDEPRECATED( void SetStyle(long style
) );
140 #endif // WXWIN_COMPATIBILITY_2_6
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
);
153 wxString m_path
; // Full path
157 wxWindow
* m_extraControl
;
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();
168 ExtraControlCreatorFunction m_extraControlCreator
;
171 DECLARE_DYNAMIC_CLASS(wxFileDialogBase
)
172 DECLARE_NO_COPY_CLASS(wxFileDialogBase
)
176 //----------------------------------------------------------------------------
177 // wxFileDialog convenience functions
178 //----------------------------------------------------------------------------
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
,
188 wxWindow
*parent
= NULL
,
189 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
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
,
199 wxWindow
*parent
= NULL
,
200 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
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
);
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
);
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"
239 #endif // wxUSE_FILEDLG
241 #endif // _WX_FILEDLG_H_BASE_