]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/notebook.cpp
Oops, don't cut and paste between ports, and do test compile both states
[wxWidgets.git] / src / msw / notebook.cpp
index 36e50c706b45f8fe8827b7ce35539683fe720814..d492f461cbd026e4791e1930f48bc48c0f8ceab2 100644 (file)
@@ -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)
@@ -304,48 +318,55 @@ void wxNotebook::SetTabSize(const wxSize& sz)
 // wxNotebook operations
 // ----------------------------------------------------------------------------
 
-// remove one page from the notebook
-bool wxNotebook::DeletePage(int nPage)
-{
-  wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
-
-  if ( m_nSelection == nPage ) {
-      // advance selection backwards - the page being deleted shouldn't be left
-      // selected
-      AdvanceSelection(FALSE);
-  }
-
-  TabCtrl_DeleteItem(m_hwnd, nPage);
-
-  delete m_pages[nPage];
-  m_pages.RemoveAt(nPage);
-
-  if ( m_pages.IsEmpty() ) {
-      // no selection if the notebook became empty
-      m_nSelection = -1;
-  }
-  else
-      m_nSelection = TabCtrl_GetCurSel(m_hwnd);
-
-
-  return TRUE;
-}
-
 // remove one page from the notebook, without deleting
 wxNotebookPage *wxNotebook::DoRemovePage(int nPage)
 {
-  wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage);
-  if ( !pageRemoved )
-      return NULL;
+    wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage);
+    if ( !pageRemoved )
+        return NULL;
+
+    TabCtrl_DeleteItem(m_hwnd, nPage);
+
+    if ( m_pages.IsEmpty() )
+    {
+        // no selection any more, the notebook becamse empty
+        m_nSelection = -1;
+    }
+    else // notebook still not empty
+    {
+        // change the selected page if it was deleted or became invalid
+        int selNew;
+        if ( m_nSelection == GetPageCount() )
+        {
+            // 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;
 
-  TabCtrl_DeleteItem(m_hwnd, nPage);
+            // 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 ( m_pages.IsEmpty() )
-    m_nSelection = -1;
-  else
-    m_nSelection = TabCtrl_GetCurSel(m_hwnd);
+        if ( selNew != -1 )
+        {
+            // m_nSelection must be always valid so reset it before calling
+            // SetSelection()
+            m_nSelection = -1;
+            SetSelection(selNew);
+        }
+    }
 
-  return pageRemoved;
+    return pageRemoved;
 }
 
 // remove all pages
@@ -624,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