Update the currently selected file when using IFileDialog too

Implement IFileDialogEvents::OnSelectionChange() to react to the changes
in the dialog selection.
This commit is contained in:
Vadim Zeitlin
2022-05-25 18:46:32 +01:00
parent 5bd765355b
commit a137145a44
2 changed files with 38 additions and 14 deletions

View File

@@ -54,8 +54,8 @@ private:
// called from the hook procedure on CDN_INITDONE reception
void MSWOnInitDone(WXHWND hDlg);
// called from the hook procedure on CDN_SELCHANGE.
void MSWOnSelChange(WXHWND hDlg);
// called when the currently selected file changes in the dialog
void MSWOnSelChange(const wxString& selectedFilename);
// called when the currently selected type of files changes in the dialog
void MSWOnTypeChange(int nFilterIndex);

View File

@@ -241,7 +241,24 @@ public:
wxSTDMETHODIMP OnFileOk(IFileDialog*) wxOVERRIDE { return E_NOTIMPL; }
wxSTDMETHODIMP OnFolderChanging(IFileDialog*, IShellItem*) wxOVERRIDE { return E_NOTIMPL; }
wxSTDMETHODIMP OnFolderChange(IFileDialog*) wxOVERRIDE { return E_NOTIMPL; }
wxSTDMETHODIMP OnSelectionChange(IFileDialog*) wxOVERRIDE { return E_NOTIMPL; }
wxSTDMETHODIMP OnSelectionChange(IFileDialog* pfd) wxOVERRIDE
{
wxCOMPtr<IShellItem> item;
HRESULT hr = pfd->GetCurrentSelection(&item);
if ( FAILED(hr) )
return hr;
wxString path;
hr = wxMSWImpl::GetFSPathFromShellItem(item, path);
if ( FAILED(hr) )
return hr;
m_fileDialog->MSWOnSelChange(path);
return S_OK;
}
wxSTDMETHODIMP OnShareViolation(IFileDialog*, IShellItem*, FDE_SHAREVIOLATION_RESPONSE*) wxOVERRIDE { return E_NOTIMPL; }
wxSTDMETHODIMP OnTypeChange(IFileDialog* pfd) wxOVERRIDE
@@ -306,7 +323,21 @@ wxFileDialogMSWData::HookFunction(HWND hDlg,
break;
case CDN_SELCHANGE:
dialog->MSWOnSelChange((WXHWND)hDlg);
{
TCHAR buf[MAX_PATH];
LRESULT len = SendMessage
(
::GetParent(hDlg),
CDM_GETFILEPATH,
MAX_PATH,
reinterpret_cast<LPARAM>(buf)
);
wxString str;
if ( len )
str = buf;
dialog->MSWOnSelChange(str);
}
break;
case CDN_TYPECHANGE:
@@ -486,19 +517,12 @@ void wxFileDialog::MSWOnInitDone(WXHWND hDlg)
// Call selection change handler so that update handler will be
// called once with no selection.
MSWOnSelChange(hDlg);
MSWOnSelChange(wxString());
}
void wxFileDialog::MSWOnSelChange(WXHWND hDlg)
void wxFileDialog::MSWOnSelChange(const wxString& selectedFilename)
{
TCHAR buf[MAX_PATH];
LRESULT len = SendMessage(::GetParent(hDlg), CDM_GETFILEPATH,
MAX_PATH, reinterpret_cast<LPARAM>(buf));
if ( len > 0 )
m_currentlySelectedFilename = buf;
else
m_currentlySelectedFilename.clear();
m_currentlySelectedFilename = selectedFilename;
UpdateExtraControlUI();
}