1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFileDialog base header
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_FILEDLG_H_BASE_
12 #define _WX_FILEDLG_H_BASE_
18 #include "wx/dialog.h"
19 #include "wx/arrstr.h"
21 // this symbol is defined for the platforms which support multiple
22 // ('|'-separated) filters in the file dialog
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
);
110 virtual void SetDirectory(const wxString
& dir
);
111 virtual void SetFilename(const wxString
& 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 virtual wxString
GetCurrentlySelectedFilename() const
125 { return m_currentlySelectedFilename
; }
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
*);
131 virtual bool SupportsExtraControl() const { return false; }
133 bool SetExtraControlCreator(ExtraControlCreatorFunction creator
);
134 wxWindow
*GetExtraControl() const { return m_extraControl
; }
138 #if WXWIN_COMPATIBILITY_2_6
140 wxDEPRECATED( long GetStyle() const );
141 wxDEPRECATED( void SetStyle(long style
) );
143 #endif // WXWIN_COMPATIBILITY_2_6
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
);
156 wxString m_path
; // Full path
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
;
167 wxWindow
* m_extraControl
;
169 // returns true if control is created (if it already exists returns false)
170 bool CreateExtraControl();
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();
178 ExtraControlCreatorFunction m_extraControlCreator
;
181 DECLARE_DYNAMIC_CLASS(wxFileDialogBase
)
182 wxDECLARE_NO_COPY_CLASS(wxFileDialogBase
);
186 //----------------------------------------------------------------------------
187 // wxFileDialog convenience functions
188 //----------------------------------------------------------------------------
190 // File selector - backward compatibility
191 WXDLLIMPEXP_CORE wxString
192 wxFileSelector(const wxString
& message
= wxFileSelectorPromptStr
,
193 const wxString
& default_path
= wxEmptyString
,
194 const wxString
& default_filename
= wxEmptyString
,
195 const wxString
& default_extension
= wxEmptyString
,
196 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
198 wxWindow
*parent
= NULL
,
199 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
201 // An extended version of wxFileSelector
202 WXDLLIMPEXP_CORE wxString
203 wxFileSelectorEx(const wxString
& message
= wxFileSelectorPromptStr
,
204 const wxString
& default_path
= wxEmptyString
,
205 const wxString
& default_filename
= wxEmptyString
,
206 int *indexDefaultExtension
= NULL
,
207 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
209 wxWindow
*parent
= NULL
,
210 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
212 // Ask for filename to load
213 WXDLLIMPEXP_CORE wxString
214 wxLoadFileSelector(const wxString
& what
,
215 const wxString
& extension
,
216 const wxString
& default_name
= wxEmptyString
,
217 wxWindow
*parent
= NULL
);
219 // Ask for filename to save
220 WXDLLIMPEXP_CORE wxString
221 wxSaveFileSelector(const wxString
& what
,
222 const wxString
& extension
,
223 const wxString
& default_name
= wxEmptyString
,
224 wxWindow
*parent
= NULL
);
227 #if defined (__WXUNIVERSAL__)
228 #define wxHAS_GENERIC_FILEDIALOG
229 #include "wx/generic/filedlgg.h"
230 #elif defined(__WXMSW__)
231 #include "wx/msw/filedlg.h"
232 #elif defined(__WXMOTIF__)
233 #include "wx/motif/filedlg.h"
234 #elif defined(__WXGTK20__)
235 #include "wx/gtk/filedlg.h" // GTK+ > 2.4 has native version
236 #elif defined(__WXGTK__)
237 #include "wx/gtk1/filedlg.h"
238 #elif defined(__WXMAC__)
239 #include "wx/osx/filedlg.h"
240 #elif defined(__WXCOCOA__)
241 #include "wx/cocoa/filedlg.h"
242 #elif defined(__WXPM__)
243 #include "wx/os2/filedlg.h"
246 #endif // wxUSE_FILEDLG
248 #endif // _WX_FILEDLG_H_BASE_