1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFileDialog
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/msgdlg.h"
24 #include "wx/dialog.h"
25 #include "wx/filedlg.h"
33 #include "wx/os2/private.h"
39 IMPLEMENT_CLASS(wxFileDialog
, wxDialog
)
41 wxString
wxFileSelector( const char* title
42 ,const char* defaultDir
43 ,const char* defaultFileName
44 ,const char* defaultExtension
52 // If there's a default extension specified but no filter, we create a suitable
56 if ( defaultExtension
&& !filter
)
57 filter2
= wxString("*.") + wxString(defaultExtension
) ;
61 wxString defaultDirString
;
63 defaultDirString
= defaultDir
;
65 defaultDirString
= "";
67 wxString defaultFilenameString
;
69 defaultFilenameString
= defaultFileName
;
71 defaultFilenameString
= "";
73 wxFileDialog
fileDialog(parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
));
75 if ( fileDialog
.ShowModal() == wxID_OK
)
77 return fileDialog
.GetPath();
99 wxString
wxFileSelectorEx( const char* title
100 ,const char* defaultDir
101 ,const char* defaultFileName
102 ,int* defaultFilterIndex
110 wxFileDialog
fileDialog(parent
, title
? title
: "", defaultDir
? defaultDir
: "",
111 defaultFileName
? defaultFileName
: "", filter
? filter
: "", flags
, wxPoint(x
, y
));
113 if ( fileDialog
.ShowModal() == wxID_OK
)
115 *defaultFilterIndex
= fileDialog
.GetFilterIndex();
116 return fileDialog
.GetPath();
119 return wxEmptyString
;
122 wxFileDialog::wxFileDialog( wxWindow
* parent
123 ,const wxString
& message
124 ,const wxString
& defaultDir
125 ,const wxString
& defaultFileName
126 ,const wxString
& wildCard
132 m_dialogStyle
= style
;
135 m_fileName
= defaultFileName
;
137 m_wildCard
= wildCard
;
141 int wxFileDialog::ShowModal()
147 // Generic file load/save dialog
148 static wxString
wxDefaultFileSelector( bool load
150 ,const char* extension
151 ,const char* default_name
155 char *ext
= (char *)extension
;
160 str
= "Load %s file";
162 str
= "Save %s file";
163 sprintf(prompt
, wxGetTranslation(str
), what
);
165 if (*ext
== '.') ext
++;
167 sprintf(wild
, "*.%s", ext
);
169 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);
172 // Generic file load dialog
173 wxString
wxLoadFileSelector( const char* what
174 ,const char* extension
175 ,const char* default_name
179 return wxDefaultFileSelector(TRUE
, what
, extension
, default_name
, parent
);
183 // Generic file save dialog
184 wxString
wxSaveFileSelector( const char* what
185 ,const char* extension
186 ,const char* default_name
190 return wxDefaultFileSelector(FALSE
, what
, extension
, default_name
, parent
);