wxFileDialog cleanup, extracted common code to fldlgcmn.cpp (patch 754187)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21149 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-06-14 13:31:49 +00:00
parent 30e671a59f
commit b600ed1362
19 changed files with 458 additions and 1326 deletions

View File

@@ -58,127 +58,6 @@
#endif
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
// ----------------------------------------------------------------------------
// CLASS wxFileDialog
// ----------------------------------------------------------------------------
@@ -443,75 +322,3 @@ int wxFileDialog::ShowModal()
return wxID_CANCEL;
} // end of wxFileDialog::ShowModal
//
// Generic file load/save dialog
//
static wxString wxDefaultFileSelector (
bool bLoad
, const char* pzWhat
, const char* pzExtension
, const char* pzDefaultName
, wxWindow* pParent
)
{
char* pzExt = (char *)pzExtension;
char zPrompt[50];
wxString sStr;
char zWild[60];
if (bLoad)
sStr = "Load %s file";
else
sStr = "Save %s file";
sprintf(zPrompt, wxGetTranslation(sStr), pzWhat);
if (*pzExt == '.')
pzExt++;
sprintf(zWild, "*.%s", pzExt);
return wxFileSelector ( zPrompt
,NULL
,pzDefaultName
,pzExt
,zWild
,0
,pParent
);
} // end of wxDefaultFileSelector
//
// Generic file load dialog
//
wxString wxLoadFileSelector (
const char* pzWhat
, const char* pzExtension
, const char* pzDefaultName
, wxWindow* pParent
)
{
return wxDefaultFileSelector( TRUE
,pzWhat
,pzExtension
,pzDefaultName
,pParent
);
} // end of wxLoadFileSelector
//
// Generic file save dialog
//
wxString wxSaveFileSelector (
const char* pzWhat
, const char* pzExtension
, const char* pzDefaultName
, wxWindow* pParent
)
{
return wxDefaultFileSelector( FALSE
,pzWhat
,pzExtension
,pzDefaultName
,pParent
);
} // end of wxSaveFileSelector