1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFileDialog
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "filedlg.h"
18 #include "wx/dialog.h"
19 #include "wx/filedlg.h"
22 IMPLEMENT_CLASS(wxFileDialog
, wxDialog
)
24 wxString
wxFileSelector(const char *title
,
25 const char *defaultDir
, const char *defaultFileName
,
26 const char *defaultExtension
, const char *filter
, int flags
,
27 wxWindow
*parent
, int x
, int y
)
29 // If there's a default extension specified but no filter, we create a suitable
33 if ( defaultExtension
&& !filter
)
34 filter2
= wxString("*.") + wxString(defaultExtension
) ;
38 wxString defaultDirString
;
40 defaultDirString
= defaultDir
;
42 defaultDirString
= "";
44 wxString defaultFilenameString
;
46 defaultFilenameString
= defaultFileName
;
48 defaultFilenameString
= "";
50 wxFileDialog
fileDialog(parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
));
52 if ( fileDialog
.ShowModal() == wxID_OK
)
54 return fileDialog
.GetPath();
60 wxString
wxFileSelectorEx(const char *title
,
61 const char *defaultDir
,
62 const char *defaultFileName
,
63 int* defaultFilterIndex
,
71 wxFileDialog
fileDialog(parent
, title
? title
: "", defaultDir
? defaultDir
: "",
72 defaultFileName
? defaultFileName
: "", filter
? filter
: "", flags
, wxPoint(x
, y
));
74 if ( fileDialog
.ShowModal() == wxID_OK
)
76 *defaultFilterIndex
= fileDialog
.GetFilterIndex();
77 return fileDialog
.GetPath();
83 wxFileDialog::wxFileDialog(wxWindow
*parent
, const wxString
& message
,
84 const wxString
& defaultDir
, const wxString
& defaultFileName
, const wxString
& wildCard
,
85 long style
, const wxPoint
& pos
)
88 m_dialogStyle
= style
;
91 m_fileName
= defaultFileName
;
93 m_wildCard
= wildCard
;
97 int wxFileDialog::ShowModal()
103 // Generic file load/save dialog
104 static wxString
wxDefaultFileSelector(bool load
, const char *what
, const char *extension
, const char *default_name
, wxWindow
*parent
)
106 char *ext
= (char *)extension
;
111 str
= "Load %s file";
113 str
= "Save %s file";
114 sprintf(prompt
, wxGetTranslation(str
), what
);
116 if (*ext
== '.') ext
++;
118 sprintf(wild
, "*.%s", ext
);
120 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);
123 // Generic file load dialog
124 wxString
wxLoadFileSelector(const char *what
, const char *extension
, const char *default_name
, wxWindow
*parent
)
126 return wxDefaultFileSelector(TRUE
, what
, extension
, default_name
, parent
);
130 // Generic file save dialog
131 wxString
wxSaveFileSelector(const char *what
, const char *extension
, const char *default_name
, wxWindow
*parent
)
133 return wxDefaultFileSelector(FALSE
, what
, extension
, default_name
, parent
);