From a137145a44f67ace4e2a6999715b41b75ea67630 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 25 May 2022 18:46:32 +0100 Subject: [PATCH] Update the currently selected file when using IFileDialog too Implement IFileDialogEvents::OnSelectionChange() to react to the changes in the dialog selection. --- include/wx/msw/filedlg.h | 4 ++-- src/msw/filedlg.cpp | 48 ++++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/include/wx/msw/filedlg.h b/include/wx/msw/filedlg.h index b22eaf9a3d..74a708e9f7 100644 --- a/include/wx/msw/filedlg.h +++ b/include/wx/msw/filedlg.h @@ -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); diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index c665d37da2..35d12da18f 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -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 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(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(buf)); - - if ( len > 0 ) - m_currentlySelectedFilename = buf; - else - m_currentlySelectedFilename.clear(); + m_currentlySelectedFilename = selectedFilename; UpdateExtraControlUI(); }