X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b8bdaa7c2b5050ed81ae6ec4f2f2557554e465f2..8bcf4c86f423035eca565571b4cbafd2e60e4c3d:/src/msw/notebook.cpp?ds=sidebyside diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index f79742abe6..da0ea9377d 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -496,37 +496,35 @@ wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage) } else // notebook still not empty { - // change the selected page if it was deleted or became invalid - int selNew; - if ( m_nSelection == int(GetPageCount()) ) + int selNew = TabCtrl_GetCurSel(m_hwnd); + if (selNew != -1) { - // last page deleted, make the new last page the new selection - selNew = m_nSelection - 1; + // No selection change, just refresh the current selection. + // Because it could be that the slection index changed + // we need to update it. + // Note: this does not mean the selection it self changed. + m_nSelection = selNew; + m_pages[m_nSelection]->Refresh(); } - else if ( int(nPage) <= m_nSelection ) - { - // we must show another page, even if it has the same index - selNew = m_nSelection; - } - else // nothing changes for the currently selected page - { - selNew = -1; - - // we still must refresh the current page: this needs to be done - // for some unknown reason if the tab control shows the up-down - // control (i.e. when there are too many pages) -- otherwise after - // deleting a page nothing at all is shown - if (m_nSelection >= 0) - m_pages[m_nSelection]->Refresh(); - } - - if ( selNew != -1 ) + else if (int(nPage) == m_nSelection) { + // The selection was deleted. + + // Determine new selection. + if (m_nSelection == int(GetPageCount())) + selNew = m_nSelection - 1; + else + selNew = m_nSelection; + // m_nSelection must be always valid so reset it before calling // SetSelection() m_nSelection = -1; SetSelection(selNew); } + else + { + wxFAIL; // Windows did not behave ok. + } } return pageRemoved; @@ -727,6 +725,23 @@ void wxNotebook::OnSelChange(wxNotebookEvent& event) { wxNotebookPage *pPage = m_pages[sel]; pPage->Show(true); + pPage->SetFocus(); + + // If the newly focused window is not a child of the new page, + // SetFocus was not successful and the notebook itself should be + // focused + wxWindow *currentFocus = FindFocus(); + wxWindow *startFocus = currentFocus; + while ( currentFocus && currentFocus != pPage && currentFocus != this ) + currentFocus = currentFocus->GetParent(); + + if ( startFocus == pPage || currentFocus != pPage ) + SetFocus(); + + } + else // no pages in the notebook, give the focus to itself + { + SetFocus(); } m_nSelection = sel; @@ -740,12 +755,14 @@ bool wxNotebook::MSWTranslateMessage(WXMSG *wxmsg) { const MSG * const msg = (MSG *)wxmsg; - // we want to process (simple, i.e. without Shift or Ctrl) TAB to pass it - // to our page for keyboard navigation + // intercept TAB, CTRL+TAB and CTRL+SHIFT+TAB for processing by wxNotebook. + // TAB will be passed to the currently selected page, CTRL+TAB and + // CTRL+SHIFT+TAB will be processed by the notebook itself. do not + // intercept SHIFT+TAB. This goes to the parent of the notebook which will + // process it. if ( msg->message == WM_KEYDOWN && msg->wParam == VK_TAB && msg->hwnd == m_hwnd && - !wxIsCtrlDown() && !wxIsShiftDown() && - m_nSelection != -1 ) + (wxIsCtrlDown() || !wxIsShiftDown()) ) { return MSWProcessMessage(wxmsg); } @@ -957,10 +974,11 @@ void wxNotebook::ApplyThemeBackground(wxWindow*, const wxColour&) #endif } +#if wxUSE_UXTHEME long wxNotebook::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { static bool g_TestedForTheme = false; - static bool g_UseTheme = false; + static bool g_supportsThemes = false; switch ( nMsg ) { case WM_ERASEBKGND: @@ -969,19 +987,25 @@ long wxNotebook::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { int commCtrlVersion = wxTheApp->GetComCtl32Version() ; - g_UseTheme = (commCtrlVersion >= 600); + g_supportsThemes = (commCtrlVersion >= 600); g_TestedForTheme = true; } - // If using XP themes, it seems we can get away + // If currently an XP theme is active, it seems we can get away // with not drawing a background, which reduces flicker. - if (g_UseTheme) - return true; + if (g_supportsThemes) + { + wxUxThemeEngine *p = wxUxThemeEngine::Get(); + if (p && p->IsThemeActive() ) + { + return true; + } + } } } return wxControl::MSWWindowProc(nMsg, wParam, lParam); } - +#endif // #if wxUSE_UXTHEME #endif // wxUSE_NOTEBOOK