code cleanup
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36388 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -206,6 +206,30 @@ void wxFileDialog::DoMoveWindow(int x, int y, int WXUNUSED(width), int WXUNUSED(
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper used below in ShowModal(): style is used to determine whether to show
|
||||||
|
// the "Save file" dialog (if it contains wxSAVE bit) or "Open file" one;
|
||||||
|
// returns true on success or false on failure in which case err is filled with
|
||||||
|
// the CDERR_XXX constant
|
||||||
|
static bool DoShowCommFileDialog(OPENFILENAME *of, long style, DWORD *err)
|
||||||
|
{
|
||||||
|
if ( style & wxSAVE ? GetSaveFileName(of) : GetOpenFileName(of) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if ( err )
|
||||||
|
{
|
||||||
|
#ifdef __WXWINCE__
|
||||||
|
// according to MSDN, CommDlgExtendedError() should work under CE as
|
||||||
|
// well but apparently in practice it doesn't (anybody has more
|
||||||
|
// details?)
|
||||||
|
*err = GetLastError();
|
||||||
|
#else
|
||||||
|
*err = CommDlgExtendedError();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int wxFileDialog::ShowModal()
|
int wxFileDialog::ShowModal()
|
||||||
{
|
{
|
||||||
HWND hWnd = 0;
|
HWND hWnd = 0;
|
||||||
@@ -393,50 +417,40 @@ int wxFileDialog::ShowModal()
|
|||||||
|
|
||||||
//== Execute FileDialog >>=================================================
|
//== Execute FileDialog >>=================================================
|
||||||
|
|
||||||
bool success = (m_dialogStyle & wxSAVE ? GetSaveFileName(&of)
|
DWORD errCode;
|
||||||
: GetOpenFileName(&of)) != 0;
|
bool success = DoShowCommFileDialog(&of, m_dialogStyle, &errCode);
|
||||||
|
|
||||||
#ifdef __WXWINCE__
|
// sometimes we may have a mismatch between the headers used to compile the
|
||||||
DWORD errCode = GetLastError();
|
// library and the run-time version of comdlg32.dll, try to account for it
|
||||||
#else
|
#ifndef __WXWINCE__
|
||||||
DWORD errCode = CommDlgExtendedError();
|
if ( !success && errCode == CDERR_STRUCTSIZE )
|
||||||
|
|
||||||
// GetOpenFileName will always change the current working directory on
|
|
||||||
// (according to MSDN) "Windows NT 4.0/2000/XP" because the flag
|
|
||||||
// OFN_NOCHANGEDIR has no effect. If the user did not specify wxCHANGE_DIR
|
|
||||||
// let's restore the current working directory to what it was before the
|
|
||||||
// dialog was shown (assuming this behavior extends to Windows Server 2003
|
|
||||||
// seems safe).
|
|
||||||
if ( success &&
|
|
||||||
(msw_flags & OFN_NOCHANGEDIR) &&
|
|
||||||
wxGetOsVersion() == wxWINDOWS_NT )
|
|
||||||
{
|
|
||||||
wxSetWorkingDirectory(cwdOrig);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __WIN32__
|
|
||||||
if (!success && (errCode == CDERR_STRUCTSIZE))
|
|
||||||
{
|
{
|
||||||
// The struct size has changed so try a smaller or bigger size
|
// The struct size has changed so try a smaller or bigger size
|
||||||
|
const int oldStructSize = of.lStructSize;
|
||||||
|
of.lStructSize = oldStructSize - (sizeof(void *) + 2*sizeof(DWORD));
|
||||||
|
success = DoShowCommFileDialog(&of, m_dialogStyle, &errCode);
|
||||||
|
|
||||||
int oldStructSize = of.lStructSize;
|
if ( !success && (errCode == CDERR_STRUCTSIZE) )
|
||||||
of.lStructSize = oldStructSize - (sizeof(void *) + 2*sizeof(DWORD));
|
|
||||||
success = (m_dialogStyle & wxSAVE) ? (GetSaveFileName(&of) != 0)
|
|
||||||
: (GetOpenFileName(&of) != 0);
|
|
||||||
errCode = CommDlgExtendedError();
|
|
||||||
|
|
||||||
if (!success && (errCode == CDERR_STRUCTSIZE))
|
|
||||||
{
|
{
|
||||||
of.lStructSize = oldStructSize + (sizeof(void *) + 2*sizeof(DWORD));
|
// try to adjust in the other direction
|
||||||
success = (m_dialogStyle & wxSAVE) ? (GetSaveFileName(&of) != 0)
|
of.lStructSize = oldStructSize + (sizeof(void *) + 2*sizeof(DWORD));
|
||||||
: (GetOpenFileName(&of) != 0);
|
success = DoShowCommFileDialog(&of, m_dialogStyle, &errCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // __WIN32__
|
#endif // !__WXWINCE__
|
||||||
#endif // __WXWINCE__
|
|
||||||
|
|
||||||
if ( success )
|
if ( success )
|
||||||
{
|
{
|
||||||
|
// GetOpenFileName will always change the current working directory on
|
||||||
|
// (according to MSDN) "Windows NT 4.0/2000/XP" because the flag
|
||||||
|
// OFN_NOCHANGEDIR has no effect. If the user did not specify
|
||||||
|
// wxCHANGE_DIR let's restore the current working directory to what it
|
||||||
|
// was before the dialog was shown.
|
||||||
|
if ( msw_flags & OFN_NOCHANGEDIR )
|
||||||
|
{
|
||||||
|
wxSetWorkingDirectory(cwdOrig);
|
||||||
|
}
|
||||||
|
|
||||||
m_fileNames.Empty();
|
m_fileNames.Empty();
|
||||||
|
|
||||||
if ( ( m_dialogStyle & wxMULTIPLE ) &&
|
if ( ( m_dialogStyle & wxMULTIPLE ) &&
|
||||||
@@ -503,43 +517,19 @@ int wxFileDialog::ShowModal()
|
|||||||
m_dir = wxPathOnly(fileNameBuffer);
|
m_dir = wxPathOnly(fileNameBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef __WXDEBUG__
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// common dialog failed - why?
|
// common dialog failed - why?
|
||||||
#ifdef __WXDEBUG__
|
if ( errCode != 0 )
|
||||||
#ifdef __WXWINCE__
|
|
||||||
if (errCode == 0)
|
|
||||||
{
|
{
|
||||||
// OK, user cancelled the dialog
|
// this msg is only for developers so don't translate it
|
||||||
}
|
|
||||||
else if (errCode == ERROR_INVALID_PARAMETER)
|
|
||||||
{
|
|
||||||
wxLogError(wxT("Invalid parameter passed to file dialog function."));
|
|
||||||
}
|
|
||||||
else if (errCode == ERROR_OUTOFMEMORY)
|
|
||||||
{
|
|
||||||
wxLogError(wxT("Out of memory when calling file dialog function."));
|
|
||||||
}
|
|
||||||
else if (errCode == ERROR_CALL_NOT_IMPLEMENTED)
|
|
||||||
{
|
|
||||||
wxLogError(wxT("Call not implemented when calling file dialog function."));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxLogError(wxT("Unknown error %d when calling file dialog function."), errCode);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
DWORD dwErr = CommDlgExtendedError();
|
|
||||||
if ( dwErr != 0 )
|
|
||||||
{
|
|
||||||
// this msg is only for developers
|
|
||||||
wxLogError(wxT("Common dialog failed with error code %0lx."),
|
wxLogError(wxT("Common dialog failed with error code %0lx."),
|
||||||
dwErr);
|
errCode);
|
||||||
}
|
}
|
||||||
//else: it was just cancelled
|
//else: it was just cancelled
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif // __WXDEBUG__
|
||||||
|
|
||||||
return success ? wxID_OK : wxID_CANCEL;
|
return success ? wxID_OK : wxID_CANCEL;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user