Better handling of OFN_NOVALIDATE for win31 style file dialogs.

This commit is contained in:
Huw Davies 2003-05-13 22:06:34 +00:00 committed by Alexandre Julliard
parent 535e0f6238
commit e3924140ca
1 changed files with 22 additions and 5 deletions

View File

@ -328,6 +328,7 @@ static BOOL FILEDLG_ScanDir(HWND hWnd, LPWSTR newPath)
LRESULT lRet = TRUE; LRESULT lRet = TRUE;
HCURSOR hCursorWait, oldCursor; HCURSOR hCursorWait, oldCursor;
TRACE("Trying to change to %s\n", debugstr_w(newPath));
if ( !SetCurrentDirectoryW( newPath )) if ( !SetCurrentDirectoryW( newPath ))
return FALSE; return FALSE;
lstrcpynW(buffer, newPath, sizeof(buffer)/sizeof(WCHAR)); lstrcpynW(buffer, newPath, sizeof(buffer)/sizeof(WCHAR));
@ -646,15 +647,23 @@ void FILEDLG_UpdateResult(LFSPRIVATE lfs, WCHAR *tmpstr)
int lenstr2; int lenstr2;
LPOPENFILENAMEW ofnW = lfs->ofnW; LPOPENFILENAMEW ofnW = lfs->ofnW;
WCHAR tmpstr2[BUFFILE]; WCHAR tmpstr2[BUFFILE];
WCHAR *bs;
GetCurrentDirectoryW(BUFFILE, tmpstr2); TRACE("%s\n", debugstr_w(tmpstr));
if(ofnW->Flags & OFN_NOVALIDATE)
tmpstr2[0] = '\0';
else
GetCurrentDirectoryW(BUFFILE, tmpstr2);
lenstr2 = strlenW(tmpstr2); lenstr2 = strlenW(tmpstr2);
if (lenstr2 > 3) if (lenstr2 > 3)
tmpstr2[lenstr2++]='\\'; tmpstr2[lenstr2++]='\\';
lstrcpynW(tmpstr2+lenstr2, tmpstr, BUFFILE-lenstr2); lstrcpynW(tmpstr2+lenstr2, tmpstr, BUFFILE-lenstr2);
if (ofnW->lpstrFile) if (ofnW->lpstrFile)
lstrcpynW(ofnW->lpstrFile, tmpstr2, ofnW->nMaxFile); lstrcpynW(ofnW->lpstrFile, tmpstr2, ofnW->nMaxFile);
ofnW->nFileOffset = strrchrW(tmpstr2,'\\') - tmpstr2 +1; if((bs = strrchrW(tmpstr2, '\\')) != NULL)
ofnW->nFileOffset = bs - tmpstr2 +1;
else
ofnW->nFileOffset = 0;
ofnW->nFileExtension = 0; ofnW->nFileExtension = 0;
while(tmpstr2[ofnW->nFileExtension] != '.' && tmpstr2[ofnW->nFileExtension] != '\0') while(tmpstr2[ofnW->nFileExtension] != '.' && tmpstr2[ofnW->nFileExtension] != '\0')
ofnW->nFileExtension++; ofnW->nFileExtension++;
@ -668,13 +677,17 @@ void FILEDLG_UpdateResult(LFSPRIVATE lfs, WCHAR *tmpstr)
char tmp[1024]; /* MAX_PATHNAME_LEN */ char tmp[1024]; /* MAX_PATHNAME_LEN */
LPOPENFILENAME16 ofn16 = lfs->ofn16; LPOPENFILENAME16 ofn16 = lfs->ofn16;
char *dest = MapSL(ofn16->lpstrFile); char *dest = MapSL(ofn16->lpstrFile);
char *bs16;
if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1, if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1,
tmp, sizeof(tmp), NULL, NULL )) tmp, sizeof(tmp), NULL, NULL ))
tmp[sizeof(tmp)-1] = 0; tmp[sizeof(tmp)-1] = 0;
GetShortPathNameA(tmp, dest, ofn16->nMaxFile); GetShortPathNameA(tmp, dest, ofn16->nMaxFile);
/* the same procedure as every year... */ /* the same procedure as every year... */
ofn16->nFileOffset = strrchr(dest,'\\') - dest +1; if((bs16 = strrchr(dest, '\\')) != NULL)
ofn16->nFileOffset = bs16 - dest +1;
else
ofn16->nFileOffset = 0;
ofn16->nFileExtension = 0; ofn16->nFileExtension = 0;
while(dest[ofn16->nFileExtension] != '.' && dest[ofn16->nFileExtension] != '\0') while(dest[ofn16->nFileExtension] != '.' && dest[ofn16->nFileExtension] != '\0')
ofn16->nFileExtension++; ofn16->nFileExtension++;
@ -822,13 +835,14 @@ static LRESULT FILEDLG_TestPath( LFSPRIVATE lfs, LPWSTR path )
else else
{ {
strcpyW(tmpstr2, path); strcpyW(tmpstr2, path);
*path = 0; if(!(lfs->ofnW->Flags & OFN_NOVALIDATE))
*path = 0;
} }
TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path), debugstr_w(tmpstr2)); TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path), debugstr_w(tmpstr2));
SetDlgItemTextW( hWnd, edt1, tmpstr2 ); SetDlgItemTextW( hWnd, edt1, tmpstr2 );
FILEDLG_ScanDir(hWnd, path); FILEDLG_ScanDir(hWnd, path);
return FALSE; return (lfs->ofnW->Flags & OFN_NOVALIDATE) ? TRUE : FALSE;
} }
/* no wildcards, we might have a directory or a filename */ /* no wildcards, we might have a directory or a filename */
@ -886,6 +900,7 @@ static LRESULT FILEDLG_Validate( LFSPRIVATE lfs, LPWSTR path, UINT control, INT
else else
GetDlgItemTextW( hWnd, edt1, filename, sizeof(filename)/sizeof(WCHAR)); GetDlgItemTextW( hWnd, edt1, filename, sizeof(filename)/sizeof(WCHAR));
TRACE("got filename = %s\n", debugstr_w(filename));
/* if we did not click in file list to get there */ /* if we did not click in file list to get there */
if (control != lst1) if (control != lst1)
{ {
@ -1018,6 +1033,7 @@ static LRESULT FILEDLG_WMCommand(HWND hWnd, LPARAM lParam, UINT notification,
break; break;
case IDOK: case IDOK:
TRACE("OK pressed\n");
if (FILEDLG_Validate( lfs, NULL, control, 0, FALSE )) if (FILEDLG_Validate( lfs, NULL, control, 0, FALSE ))
EndDialog(hWnd, TRUE); EndDialog(hWnd, TRUE);
return TRUE; return TRUE;
@ -1304,6 +1320,7 @@ BOOL WINAPI GetFileName31A(
if (!lpofn || !FileDlg_Init()) return FALSE; if (!lpofn || !FileDlg_Init()) return FALSE;
TRACE("ofn flags %08lx\n", lpofn->Flags);
lfs = FILEDLG_AllocPrivate((LPARAM) lpofn, LFS32A, dlgType); lfs = FILEDLG_AllocPrivate((LPARAM) lpofn, LFS32A, dlgType);
if (lfs) if (lfs)
{ {