https://git.reactos.org/?p=reactos.git;a=commitdiff;h=556cc8a7b27c427a94ee2…
commit 556cc8a7b27c427a94ee22364624122f5df006f8
Author: Whindmar Saksit <whindsaks(a)proton.me>
AuthorDate: Fri Feb 28 16:57:08 2025 +0100
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Feb 28 16:57:08 2025 +0100
[BROWSEUI] Set find files pane focus (#7722)
CORE-16424
---
dll/win32/browseui/shellfind/CSearchBar.cpp | 50 +++++++++++++++++++++++++++++
dll/win32/browseui/shellfind/CSearchBar.h | 1 +
2 files changed, 51 insertions(+)
diff --git a/dll/win32/browseui/shellfind/CSearchBar.cpp
b/dll/win32/browseui/shellfind/CSearchBar.cpp
index b7d97123798..2ff47bfaf24 100644
--- a/dll/win32/browseui/shellfind/CSearchBar.cpp
+++ b/dll/win32/browseui/shellfind/CSearchBar.cpp
@@ -20,6 +20,33 @@ WINE_DEFAULT_DEBUG_CHANNEL(shellfind);
#define UNIMPLEMENTED DbgPrint("%s is UNIMPLEMENTED!\n", __FUNCTION__)
#endif
+static BOOL IsWindowChildOf(const HWND hNeedle, const HWND hRoot)
+{
+ if (hNeedle != hRoot)
+ {
+ for (HWND hParent = hNeedle; hParent;)
+ {
+ hParent = GetParent(hParent);
+ if (hParent == hRoot)
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+static UINT GetShellViewItemCount(IShellView *pSV)
+{
+ int signedCount;
+ CComQIIDPtr<I_ID(IFolderView)> pFV(pSV);
+ if (pFV && SUCCEEDED(pFV->ItemCount(SVGIO_ALLVIEW, &signedCount)))
+ return signedCount;
+ UINT unsignedCount;
+ CComQIIDPtr<I_ID(IShellFolderView)> pSFV(pSV);
+ if (pSFV && SUCCEEDED(pSFV->GetObjectCount(&unsignedCount)))
+ return unsignedCount;
+ return 0;
+}
+
CSearchBar::CSearchBar() :
m_pSite(NULL),
m_bVisible(FALSE)
@@ -336,6 +363,8 @@ HRESULT STDMETHODCALLTYPE CSearchBar::ShowDW(BOOL fShow)
{
m_bVisible = fShow;
ShowWindow(fShow);
+ if (fShow)
+ TrySetFocus(DISPID_WINDOWSTATECHANGED);
return S_OK;
}
@@ -562,6 +591,7 @@ HRESULT STDMETHODCALLTYPE CSearchBar::Invoke(DISPID dispIdMember,
REFIID riid, L
case DISPID_DOCUMENTCOMPLETE:
{
TrySubscribeToSearchEvents();
+ TrySetFocus(DISPID_NAVIGATECOMPLETE2);
// Remove the search results folder from the address box
CComPtr<IDispatch> pDispatch;
@@ -606,8 +636,28 @@ HRESULT STDMETHODCALLTYPE CSearchBar::Invoke(DISPID dispIdMember,
REFIID riid, L
case DISPID_SEARCHCOMPLETE:
case DISPID_SEARCHABORT:
SetSearchInProgress(FALSE);
+ TrySetFocus(DISPID_SEARCHCOMPLETE);
return S_OK;
default:
return E_INVALIDARG;
}
}
+
+void CSearchBar::TrySetFocus(UINT Source)
+{
+ CComPtr<IShellBrowser> pBrowser;
+ CComPtr<IShellView> pResultsSV;
+ if (SUCCEEDED(GetSearchResultsFolder(&pBrowser, NULL, NULL)))
+ pBrowser->QueryActiveShellView(&pResultsSV);
+ UINT cItems = pResultsSV ? GetShellViewItemCount(pResultsSV) : 0;
+
+ // Attempt to set the focus if we are not in the results folder or if there are no
results
+ HWND hWndFocus = ::GetFocus();
+ if (!hWndFocus || !pResultsSV || cItems == 0)
+ {
+ BOOL IsOnButton = GetDlgItem(IDC_SEARCH_BUTTON) == hWndFocus;
+ BOOL IsOnSelfPane = hWndFocus == m_hWnd;
+ if (!hWndFocus || IsOnSelfPane || IsOnButton || !IsWindowChildOf(hWndFocus,
m_hWnd))
+ SendMessageW(WM_NEXTDLGCTL, (WPARAM)GetDlgItem(IDC_SEARCH_FILENAME), TRUE);
+ }
+}
diff --git a/dll/win32/browseui/shellfind/CSearchBar.h
b/dll/win32/browseui/shellfind/CSearchBar.h
index a798e368d5c..0a4ead4d307 100644
--- a/dll/win32/browseui/shellfind/CSearchBar.h
+++ b/dll/win32/browseui/shellfind/CSearchBar.h
@@ -30,6 +30,7 @@ private:
BOOL GetAddressEditBoxPath(WCHAR *szPath);
void SetSearchInProgress(BOOL bInProgress);
HRESULT TrySubscribeToSearchEvents();
+ void TrySetFocus(UINT Source);
// *** ATL event handlers ***
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);