From 9f68f482c145adc5c9a78e6f505e9cbdab888e1f Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Wed, 10 Jul 2024 22:47:02 +0900 Subject: [PATCH] [BROWSEUI] Check focus before opening AutoComplete (#7128) Unexpectedly remaining AutoComplete list is annoying. JIRA issue: CORE-19685 - Add CAutoComplete:: m_bEditHasFocus to watch focus. - Update m_bEditHasFocus on WM_SETFOCUS and WM_KILLFOCUS messages on Edit window procedure. - Don't open AutoComplete list when m_bEditHasFocus was FALSE. --- dll/win32/browseui/CAutoComplete.cpp | 12 +++++++++++- dll/win32/browseui/CAutoComplete.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/dll/win32/browseui/CAutoComplete.cpp b/dll/win32/browseui/CAutoComplete.cpp index 434351c9365..e05c31b8b76 100644 --- a/dll/win32/browseui/CAutoComplete.cpp +++ b/dll/win32/browseui/CAutoComplete.cpp @@ -338,12 +338,14 @@ LRESULT CAutoComplete::EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l return TRUE; // eat break; case WM_SETFOCUS: + m_bEditHasFocus = TRUE; break; case WM_KILLFOCUS: // hide the list if lost focus hwndGotFocus = (HWND)wParam; if (hwndGotFocus != m_hwndEdit && hwndGotFocus != m_hWnd) HideDropDown(); + m_bEditHasFocus = FALSE; break; case WM_IME_NOTIFY: if (wParam == IMN_OPENCANDIDATE) @@ -656,7 +658,7 @@ LRESULT CACSizeBox::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHand // CAutoComplete public methods CAutoComplete::CAutoComplete() - : m_bInSetText(FALSE), m_bInSelectItem(FALSE) + : m_bInSetText(FALSE), m_bInSelectItem(FALSE), m_bEditHasFocus(FALSE) , m_bDowner(TRUE), m_dwOptions(ACO_AUTOAPPEND | ACO_AUTOSUGGEST) , m_bEnabled(TRUE), m_hwndCombo(NULL), m_hFont(NULL), m_bResized(FALSE) , m_hwndEdit(NULL), m_fnOldEditProc(NULL), m_fnOldWordBreakProc(NULL) @@ -1121,6 +1123,7 @@ CAutoComplete::Init(HWND hwndEdit, IUnknown *punkACL, if (!::SetWindowSubclass(hwndEdit, EditSubclassProc, 0, reinterpret_cast(this))) return E_FAIL; m_hwndEdit = hwndEdit; + m_bEditHasFocus = (::GetFocus() == hwndEdit); // add reference to m_hwndEdit AddRef(); // set word break procedure @@ -1387,6 +1390,13 @@ CStringW CAutoComplete::GetQuickEdit(LPCWSTR pszText) const VOID CAutoComplete::RepositionDropDown() { + // If Edit has no focus, don't open auto-complete + if (!m_bEditHasFocus) + { + TRACE("!m_bEditHasFocus\n"); + return; + } + // get nearest monitor from m_hwndEdit HMONITOR hMon = ::MonitorFromWindow(m_hwndEdit, MONITOR_DEFAULTTONEAREST); ATLASSERT(hMon != NULL); diff --git a/dll/win32/browseui/CAutoComplete.h b/dll/win32/browseui/CAutoComplete.h index b8370f899a0..831d592afbc 100644 --- a/dll/win32/browseui/CAutoComplete.h +++ b/dll/win32/browseui/CAutoComplete.h @@ -153,6 +153,7 @@ public: static LPCWSTR GetWndClassName() { return WC_DROPDOWNW; } BOOL m_bInSetText; // this flag avoids subsequent action in WM_SETTEXT BOOL m_bInSelectItem; // this flag avoids subsequent action in LVN_ITEMCHANGED + BOOL m_bEditHasFocus; // public methods CAutoComplete();