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 // ('|'-separated) filters in the file dialog
24 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
25 #define wxHAS_MULTIPLE_FILEDLG_FILTERS
28 //----------------------------------------------------------------------------
30 //----------------------------------------------------------------------------
33 The flags below must coexist with the following flags in m_windowStyle
34 #define wxCAPTION 0x20000000
35 #define wxMAXIMIZE 0x00002000
36 #define wxCLOSE_BOX 0x00001000
37 #define wxSYSTEM_MENU 0x00000800
38 wxBORDER_NONE = 0x00200000
39 #define wxRESIZE_BORDER 0x00000040
46 wxFD_OVERWRITE_PROMPT
= 0x0004,
47 wxFD_FILE_MUST_EXIST
= 0x0010,
48 wxFD_MULTIPLE
= 0x0020,
49 wxFD_CHANGE_DIR
= 0x0080,
53 #if WXWIN_COMPATIBILITY_2_6
58 wxOVERWRITE_PROMPT
= wxFD_OVERWRITE_PROMPT
,
59 wxFILE_MUST_EXIST
= wxFD_FILE_MUST_EXIST
,
60 wxMULTIPLE
= wxFD_MULTIPLE
,
61 wxCHANGE_DIR
= wxFD_CHANGE_DIR
65 #define wxFD_DEFAULT_STYLE wxFD_OPEN
67 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileDialogNameStr
[];
68 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorPromptStr
[];
69 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr
[];
71 //----------------------------------------------------------------------------
73 //----------------------------------------------------------------------------
75 class WXDLLIMPEXP_CORE wxFileDialogBase
: public wxDialog
78 wxFileDialogBase () { Init(); }
80 wxFileDialogBase(wxWindow
*parent
,
81 const wxString
& message
= wxFileSelectorPromptStr
,
82 const wxString
& defaultDir
= wxEmptyString
,
83 const wxString
& defaultFile
= wxEmptyString
,
84 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
85 long style
= wxFD_DEFAULT_STYLE
,
86 const wxPoint
& pos
= wxDefaultPosition
,
87 const wxSize
& sz
= wxDefaultSize
,
88 const wxString
& name
= wxFileDialogNameStr
)
91 Create(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
, sz
, name
);
94 virtual ~wxFileDialogBase() {}
97 bool Create(wxWindow
*parent
,
98 const wxString
& message
= wxFileSelectorPromptStr
,
99 const wxString
& defaultDir
= wxEmptyString
,
100 const wxString
& defaultFile
= wxEmptyString
,
101 const wxString
& wildCard
= wxFileSelectorDefaultWildcardStr
,
102 long style
= wxFD_DEFAULT_STYLE
,
103 const wxPoint
& pos
= wxDefaultPosition
,
104 const wxSize
& sz
= wxDefaultSize
,
105 const wxString
& name
= wxFileDialogNameStr
);
107 bool HasFdFlag(int flag
) const { return HasFlag(flag
); }
109 virtual void SetMessage(const wxString
& message
) { m_message
= message
; }
110 virtual void SetPath(const wxString
& path
);
111 virtual void SetDirectory(const wxString
& dir
);
112 virtual void SetFilename(const wxString
& name
);
113 virtual void SetWildcard(const wxString
& wildCard
) { m_wildCard
= wildCard
; }
114 virtual void SetFilterIndex(int filterIndex
) { m_filterIndex
= filterIndex
; }
116 virtual wxString
GetMessage() const { return m_message
; }
117 virtual wxString
GetPath() const { return m_path
; }
118 virtual void GetPaths(wxArrayString
& paths
) const { paths
.Empty(); paths
.Add(m_path
); }
119 virtual wxString
GetDirectory() const { return m_dir
; }
120 virtual wxString
GetFilename() const { return m_fileName
; }
121 virtual void GetFilenames(wxArrayString
& files
) const { files
.Empty(); files
.Add(m_fileName
); }
122 virtual wxString
GetWildcard() const { return m_wildCard
; }
123 virtual int GetFilterIndex() const { return m_filterIndex
; }
125 virtual wxString
GetCurrentlySelectedFilename() const
126 { return m_currentlySelectedFilename
; }
128 // this function is called with wxFileDialog as parameter and should
129 // create the window containing the extra controls we want to show in it
130 typedef wxWindow
*(*ExtraControlCreatorFunction
)(wxWindow
*);
132 virtual bool SupportsExtraControl() const { return false; }
134 bool SetExtraControlCreator(ExtraControlCreatorFunction creator
);
135 wxWindow
*GetExtraControl() const { return m_extraControl
; }
139 #if WXWIN_COMPATIBILITY_2_6
141 wxDEPRECATED( long GetStyle() const );
142 wxDEPRECATED( void SetStyle(long style
) );
144 #endif // WXWIN_COMPATIBILITY_2_6
147 // Append first extension to filePath from a ';' separated extensionList
148 // if filePath = "path/foo.bar" just return it as is
149 // if filePath = "foo[.]" and extensionList = "*.jpg;*.png" return "foo.jpg"
150 // if the extension is "*.j?g" (has wildcards) or "jpg" then return filePath
151 static wxString
AppendExtension(const wxString
&filePath
,
152 const wxString
&extensionList
);
157 wxString m_path
; // Full path
162 // Currently selected, but not yet necessarily accepted by the user, file.
163 // This should be updated whenever the selection in the control changes by
164 // the platform-specific code to provide a useful implementation of
165 // GetCurrentlySelectedFilename().
166 wxString m_currentlySelectedFilename
;
168 wxWindow
* m_extraControl
;
170 // returns true if control is created (if it already exists returns false)
171 bool CreateExtraControl();
172 // return true if SetExtraControlCreator() was called
173 bool HasExtraControlCreator() const
174 { return m_extraControlCreator
!= NULL
; }
175 // get the size of the extra control by creating and deleting it
176 wxSize
GetExtraControlSize();
179 ExtraControlCreatorFunction m_extraControlCreator
;
182 DECLARE_DYNAMIC_CLASS(wxFileDialogBase
)
183 wxDECLARE_NO_COPY_CLASS(wxFileDialogBase
);
187 //----------------------------------------------------------------------------
188 // wxFileDialog convenience functions
189 //----------------------------------------------------------------------------
191 // File selector - backward compatibility
192 WXDLLIMPEXP_CORE wxString
193 wxFileSelector(const wxString
& message
= wxFileSelectorPromptStr
,
194 const wxString
& default_path
= wxEmptyString
,
195 const wxString
& default_filename
= wxEmptyString
,
196 const wxString
& default_extension
= wxEmptyString
,
197 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
199 wxWindow
*parent
= NULL
,
200 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
202 // An extended version of wxFileSelector
203 WXDLLIMPEXP_CORE wxString
204 wxFileSelectorEx(const wxString
& message
= wxFileSelectorPromptStr
,
205 const wxString
& default_path
= wxEmptyString
,
206 const wxString
& default_filename
= wxEmptyString
,
207 int *indexDefaultExtension
= NULL
,
208 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
210 wxWindow
*parent
= NULL
,
211 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
213 // Ask for filename to load
214 WXDLLIMPEXP_CORE wxString
215 wxLoadFileSelector(const wxString
& what
,
216 const wxString
& extension
,
217 const wxString
& default_name
= wxEmptyString
,
218 wxWindow
*parent
= NULL
);
220 // Ask for filename to save
221 WXDLLIMPEXP_CORE wxString
222 wxSaveFileSelector(const wxString
& what
,
223 const wxString
& extension
,
224 const wxString
& default_name
= wxEmptyString
,
225 wxWindow
*parent
= NULL
);
228 #if defined (__WXUNIVERSAL__)
229 #define wxHAS_GENERIC_FILEDIALOG
230 #include "wx/generic/filedlgg.h"
231 #elif defined(__WXMSW__)
232 #include "wx/msw/filedlg.h"
233 #elif defined(__WXMOTIF__)
234 #include "wx/motif/filedlg.h"
235 #elif defined(__WXGTK20__)
236 #include "wx/gtk/filedlg.h" // GTK+ > 2.4 has native version
237 #elif defined(__WXGTK__)
238 #include "wx/gtk1/filedlg.h"
239 #elif defined(__WXMAC__)
240 #include "wx/osx/filedlg.h"
241 #elif defined(__WXCOCOA__)
242 #include "wx/cocoa/filedlg.h"
243 #elif defined(__WXPM__)
244 #include "wx/os2/filedlg.h"
247 #endif // wxUSE_FILEDLG
249 #endif // _WX_FILEDLG_H_BASE_