-IMPLEMENT_CLASS(wxFileDialog, wxDialog)
-
-// ----------------------------------------------------------------------------
-// global functions
-// ----------------------------------------------------------------------------
-
-wxString wxFileSelector(
- const char* pzTitle
-, const char* pzDefaultDir
-, const char* pzDefaultFileName
-, const char* pzDefaultExtension
-, const char* pzFilter
-, int nFlags
-, wxWindow* pParent
-, int nX
-, int nY
-)
-{
- wxString sFilter("");
- wxString sDefaultDirString;
- wxString sDefaultFilenameString;
-
- //
- // If there's a default extension specified but no filter, we create
- // a suitable filter.
- //
- if (pzDefaultExtension && !pzFilter)
- sFilter = wxString("*.") + wxString(pzDefaultExtension);
- else if (pzFilter)
- sFilter = pzFilter;
-
- if (pzDefaultDir)
- sDefaultDirString = pzDefaultDir;
- else
- sDefaultDirString = "";
-
- if (pzDefaultFileName)
- sDefaultFilenameString = pzDefaultFileName;
- else
- sDefaultFilenameString = "";
-
- wxFileDialog vFileDialog( pParent
- ,pzTitle
- ,sDefaultDirString
- ,sDefaultFilenameString
- ,sFilter
- ,nFlags
- ,wxPoint(nX, nY)
- );
-
- if (wxStrlen(pzDefaultExtension) != 0)
- {
- int nFilterFind = 0;
- int nFilterIndex = 0;
-
- for (unsigned int i = 0; i < sFilter.Len(); i++)
- {
- if (sFilter.GetChar(i) == wxT('|'))
- {
- //
- // Save the start index of the new filter
- unsigned int uIs = i++;
-
- //
- // Find the end of the filter
- //
- for(; i < sFilter.Len(); i++)
- {
- if(sFilter[i] == wxT('|'))
- break;
- }
-
- if( i - uIs - 1 > 0 && uIs + 1 < sFilter.Len() )
- {
- if(sFilter.Mid(uIs + 1, i - uIs - 1).Contains(pzDefaultExtension))
- {
- nFilterFind = nFilterIndex;
- break;
- }
- }
- nFilterIndex++;
- }
- }
- vFileDialog.SetFilterIndex(nFilterFind);
- }
- if (vFileDialog.ShowModal() == wxID_OK)
- {
- return vFileDialog.GetPath();
- }
- else
- return wxEmptyString;
-} // end of wxFileSelector
-
-wxString wxFileSelectorEx (
- const char* pzTitle
-, const char* pzDefaultDir
-, const char* pzDefaultFileName
-, int* pnDefaultFilterIndex
-, const char* pzFilter
-, int nFlags
-, wxWindow* pParent
-, int nX
-, int nY
-)
-{
- wxFileDialog vFileDialog( pParent
- ,pzTitle ? pzTitle : ""
- ,pzDefaultDir ? pzDefaultDir : ""
- ,pzDefaultFileName ? pzDefaultFileName : ""
- ,pzFilter ? pzFilter : ""
- ,nFlags
- ,wxPoint(nX, nY)
- );
-
- if (vFileDialog.ShowModal() == wxID_OK)
- {
- *pnDefaultFilterIndex = vFileDialog.GetFilterIndex();
- return vFileDialog.GetPath();
- }
- else
- return wxEmptyString;
-} // end of wxFileSelectorEx