From 256edfbf118e706daa1b30a017eb5acae0618b29 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 13 Oct 2012 22:49:33 +0000 Subject: [PATCH] Do give focus to the wxNotebook page when switching to it under MSW. Switching to the page but keeping the focus on the notebook itself makes it difficult to use the UI from keyboard and is inconsistent with the behaviour of native property sheets. Do restore the code to set the focus to the page as the bug that resulted in a wrong radio button being selected when we did this was apparently fixed elsewhere in the meanwhile because it doesn't happen any more even with this change. See #2268. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72657 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/notebook.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 2a3a46fe78..1d69e439bb 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -375,17 +375,22 @@ void wxNotebook::UpdateSelection(int selNew) { wxNotebookPage *pPage = m_pages[selNew]; pPage->Show(true); - } - - // Changing the page should give the focus to it but, as per bug report - // http://sf.net/tracker/index.php?func=detail&aid=1150659&group_id=9863&atid=109863, - // we should not set the focus to it directly since it erroneously - // selects radio buttons and breaks keyboard handling for a notebook's - // scroll buttons. So give focus to the notebook and not the page. - // but don't do this is the notebook is hidden - if ( ::IsWindowVisible(GetHwnd()) ) - SetFocus(); + // In addition to showing the page, we also want to give focus to it to + // make it possible to work with it from keyboard easily. However there + // are two exceptions: first, don't touch the focus at all if the + // notebook itself is not currently shown. + if ( ::IsWindowVisible(GetHwnd()) ) + { + // And second, don't give focus away if the tab control itself has + // it, as this is how the native property sheets behave: if you + // explicitly click on the tab label giving it focus, it will + // remain after switching to another page. But if the focus was + // inside the notebook page, it switches to the new page. + if ( !HasFocus() ) + pPage->SetFocus(); + } + } m_selection = selNew; } -- 2.45.2