X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df7145da50005a9f512d8f3329b6ed2166e956d0..66525ca43b1e56837fcf624b5918c837365d8609:/src/msw/notebook.cpp?ds=sidebyside diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 065f983c79..d492f461cb 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -161,7 +161,7 @@ WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const tabStyle |= WS_TABSTOP | TCS_TABS; - if ( style & wxTC_MULTILINE ) + if ( style & wxNB_MULTILINE ) tabStyle |= TCS_MULTILINE; if ( style & wxNB_FIXEDWIDTH ) tabStyle |= TCS_FIXEDWIDTH; @@ -205,9 +205,23 @@ int wxNotebook::SetSelection(int nPage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); - ChangePage(m_nSelection, nPage); + if ( nPage != m_nSelection ) + { + wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); + event.SetSelection(nPage); + event.SetOldSelection(m_nSelection); + event.SetEventObject(this); + if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) + { + // program allows the page change + event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); + (void)GetEventHandler()->ProcessEvent(event); + + TabCtrl_SetCurSel(m_hwnd, nPage); + } + } - return TabCtrl_SetCurSel(m_hwnd, nPage); + return m_nSelection; } bool wxNotebook::SetPageText(int nPage, const wxString& strText) @@ -320,16 +334,36 @@ wxNotebookPage *wxNotebook::DoRemovePage(int nPage) } else // notebook still not empty { - // refresh the selected page and change it if it became invalid + // change the selected page if it was deleted or became invalid + int selNew; if ( m_nSelection == GetPageCount() ) { - m_nSelection--; + // last page deleted, make the new last page the new selection + selNew = m_nSelection - 1; + } + else if ( 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; - // force ChangePage() to really do something - int sel = m_nSelection; - m_nSelection = -1; - SetSelection(sel); + // 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 + m_pages[m_nSelection]->Refresh(); + } + + if ( selNew != -1 ) + { + // m_nSelection must be always valid so reset it before calling + // SetSelection() + m_nSelection = -1; + SetSelection(selNew); + } } return pageRemoved; @@ -611,44 +645,4 @@ bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) return processed; } -// ---------------------------------------------------------------------------- -// wxNotebook helper functions -// ---------------------------------------------------------------------------- - -// generate the page changing and changed events, hide the currently active -// panel and show the new one -void wxNotebook::ChangePage(int nOldSel, int nSel) -{ - // MT-FIXME should use a real semaphore - static bool s_bInsideChangePage = FALSE; - - // when we call ProcessEvent(), our own OnSelChange() is called which calls - // this function - break the infinite loop - if ( s_bInsideChangePage ) - return; - - // it's not an error (the message may be generated by the tab control itself) - // and it may happen - just do nothing - if ( nSel == nOldSel ) - return; - - s_bInsideChangePage = TRUE; - - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); - event.SetSelection(nSel); - event.SetOldSelection(nOldSel); - event.SetEventObject(this); - if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() ) - { - // program doesn't allow the page change - s_bInsideChangePage = FALSE; - return; - } - - event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); - GetEventHandler()->ProcessEvent(event); - - s_bInsideChangePage = FALSE; -} - #endif // wxUSE_NOTEBOOK