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 //----------------------------------------------------------------------------
24 //----------------------------------------------------------------------------
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
40 wxFD_OVERWRITE_PROMPT
= 0x0004,
41 wxFD_FILE_MUST_EXIST
= 0x0010,
42 wxFD_MULTIPLE
= 0x0020,
43 wxFD_CHANGE_DIR
= 0x0080,
47 #if WXWIN_COMPATIBILITY_2_6
52 wxOVERWRITE_PROMPT
= wxFD_OVERWRITE_PROMPT
,
53 wxFILE_MUST_EXIST
= wxFD_FILE_MUST_EXIST
,
54 wxMULTIPLE
= wxFD_MULTIPLE
,
55 wxCHANGE_DIR
= wxFD_CHANGE_DIR
59 #define wxFD_DEFAULT_STYLE wxFD_OPEN
61 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileDialogNameStr
[];
62 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorPromptStr
[];
63 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr
[];
65 //----------------------------------------------------------------------------
67 //----------------------------------------------------------------------------
69 class WXDLLIMPEXP_CORE wxFileDialogBase
: public wxDialog
72 wxFileDialogBase () { Init(); }
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
)
85 Create(parent
, message
, defaultDir
, defaultFile
, wildCard
, style
, pos
, sz
, name
);
88 virtual ~wxFileDialogBase() {}
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
);
101 bool HasFdFlag(int flag
) const { return HasFlag(flag
); }
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
; }
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
; }
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
*);
123 virtual bool SupportsExtraControl() const { return false; }
125 bool SetExtraControlCreator(ExtraControlCreatorFunction
WXUNUSED(c
));
126 wxWindow
*GetExtraControl() const { return m_extraControl
; }
130 #if WXWIN_COMPATIBILITY_2_6
132 wxDEPRECATED( long GetStyle() const );
133 wxDEPRECATED( void SetStyle(long style
) );
135 #endif // WXWIN_COMPATIBILITY_2_6
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
);
148 wxString m_path
; // Full path
152 wxWindow
* m_extraControl
;
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();
163 ExtraControlCreatorFunction m_extraControlCreator
;
166 DECLARE_DYNAMIC_CLASS(wxFileDialogBase
)
167 DECLARE_NO_COPY_CLASS(wxFileDialogBase
)
171 //----------------------------------------------------------------------------
172 // wxFileDialog convenience functions
173 //----------------------------------------------------------------------------
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
,
183 wxWindow
*parent
= NULL
,
184 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
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
,
194 wxWindow
*parent
= NULL
,
195 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
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
);
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
);
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"
234 #endif // wxUSE_FILEDLG
236 #endif // _WX_FILEDLG_H_BASE_