@@ -20,6 +20,33 @@ WINE_DEFAULT_DEBUG_CHANNEL(shellfind);
2020#define UNIMPLEMENTED DbgPrint (" %s is UNIMPLEMENTED!\n " , __FUNCTION__)
2121#endif
2222
23+ static BOOL IsWindowChildOf (const HWND hNeedle, const HWND hRoot)
24+ {
25+ if (hNeedle != hRoot)
26+ {
27+ for (HWND hParent = hNeedle; hParent;)
28+ {
29+ hParent = GetParent (hParent);
30+ if (hParent == hRoot)
31+ return TRUE ;
32+ }
33+ }
34+ return FALSE ;
35+ }
36+
37+ static UINT GetShellViewItemCount (IShellView *pSV)
38+ {
39+ int signedCount;
40+ CComQIIDPtr<I_ID (IFolderView)> pFV (pSV);
41+ if (pFV && SUCCEEDED (pFV->ItemCount (SVGIO_ALLVIEW, &signedCount)))
42+ return signedCount;
43+ UINT unsignedCount;
44+ CComQIIDPtr<I_ID (IShellFolderView)> pSFV (pSV);
45+ if (pSFV && SUCCEEDED (pSFV->GetObjectCount (&unsignedCount)))
46+ return unsignedCount;
47+ return 0 ;
48+ }
49+
2350CSearchBar::CSearchBar () :
2451 m_pSite(NULL ),
2552 m_bVisible(FALSE )
@@ -336,6 +363,8 @@ HRESULT STDMETHODCALLTYPE CSearchBar::ShowDW(BOOL fShow)
336363{
337364 m_bVisible = fShow ;
338365 ShowWindow (fShow );
366+ if (fShow )
367+ TrySetFocus (DISPID_WINDOWSTATECHANGED);
339368 return S_OK;
340369}
341370
@@ -562,6 +591,7 @@ HRESULT STDMETHODCALLTYPE CSearchBar::Invoke(DISPID dispIdMember, REFIID riid, L
562591 case DISPID_DOCUMENTCOMPLETE:
563592 {
564593 TrySubscribeToSearchEvents ();
594+ TrySetFocus (DISPID_NAVIGATECOMPLETE2);
565595
566596 // Remove the search results folder from the address box
567597 CComPtr<IDispatch> pDispatch;
@@ -606,8 +636,28 @@ HRESULT STDMETHODCALLTYPE CSearchBar::Invoke(DISPID dispIdMember, REFIID riid, L
606636 case DISPID_SEARCHCOMPLETE:
607637 case DISPID_SEARCHABORT:
608638 SetSearchInProgress (FALSE );
639+ TrySetFocus (DISPID_SEARCHCOMPLETE);
609640 return S_OK;
610641 default :
611642 return E_INVALIDARG;
612643 }
613644}
645+
646+ void CSearchBar::TrySetFocus (UINT Source)
647+ {
648+ CComPtr<IShellBrowser> pBrowser;
649+ CComPtr<IShellView> pResultsSV;
650+ if (SUCCEEDED (GetSearchResultsFolder (&pBrowser, NULL , NULL )))
651+ pBrowser->QueryActiveShellView (&pResultsSV);
652+ UINT cItems = pResultsSV ? GetShellViewItemCount (pResultsSV) : 0 ;
653+
654+ // Attempt to set the focus if we are not in the results folder or if there are no results
655+ HWND hWndFocus = ::GetFocus ();
656+ if (!hWndFocus || !pResultsSV || cItems == 0 )
657+ {
658+ BOOL IsOnButton = GetDlgItem (IDC_SEARCH_BUTTON) == hWndFocus;
659+ BOOL IsOnSelfPane = hWndFocus == m_hWnd;
660+ if (!hWndFocus || IsOnSelfPane || IsOnButton || !IsWindowChildOf (hWndFocus, m_hWnd))
661+ SendMessageW (WM_NEXTDLGCTL, (WPARAM)GetDlgItem (IDC_SEARCH_FILENAME), TRUE );
662+ }
663+ }
0 commit comments