wxASSERT( IS_VALID_PAGE(nPage) );
- ChangePage(m_nSelection, nPage);
+ wxNotebookPage* pPage = GetPage(nPage);
+
+ m_tabView->SetTabSelection((int) (long) pPage);
// TODO
return 0;
{
wxASSERT( IS_VALID_PAGE(nPage) );
- // TODO
+ wxNotebookPage* page = GetPage(nPage);
+ if (page)
+ {
+ m_tabView->SetTabText((int) (long) page, strText);
+ Refresh();
+ return TRUE;
+ }
+
return FALSE;
}
{
wxASSERT( IS_VALID_PAGE(nPage) );
- // TODO
- return wxString("");
+ wxNotebookPage* page = ((wxNotebook*)this)->GetPage(nPage);
+ if (page)
+ return m_tabView->GetTabText((int) (long) page);
+ else
+ return wxEmptyString;
}
int wxNotebook::GetPageImage(int nPage) const
// wxNotebook operations
// ----------------------------------------------------------------------------
-// remove one page from the notebook
+// remove one page from the notebook and delete it
bool wxNotebook::DeletePage(int nPage)
{
- wxFAIL_MSG("Sorry, DeletePage not implemented for Motif wxNotebook because wxTabView doesn't support it.");
- return FALSE;
-
-/*
wxCHECK( IS_VALID_PAGE(nPage), FALSE );
- // TODO: delete native widget page
+ if (m_nSelection != -1)
+ {
+ m_aPages[m_nSelection]->Show(FALSE);
+ m_aPages[m_nSelection]->Lower();
+ }
+
+ wxNotebookPage* pPage = GetPage(nPage);
+ m_tabView->RemoveTab((int) (long) pPage);
delete m_aPages[nPage];
m_aPages.Remove(nPage);
+ if (m_aPages.GetCount() == 0)
+ {
+ m_nSelection = -1;
+ m_tabView->SetTabSelection(-1, FALSE);
+ }
+ else if (m_nSelection > -1)
+ {
+ m_nSelection = -1;
+ m_tabView->SetTabSelection((int) (long) GetPage(0), FALSE);
+ if (m_nSelection != 0)
+ ChangePage(-1, 0);
+ }
+
+ RefreshLayout(FALSE);
+
return TRUE;
-*/
+}
+
+bool wxNotebook::DeletePage(wxNotebookPage* page)
+{
+ int pagePos = FindPagePosition(page);
+ if (pagePos > -1)
+ return DeletePage(pagePos);
+ else
+ return FALSE;
+}
+
+// remove one page from the notebook
+bool wxNotebook::RemovePage(int nPage)
+{
+ wxCHECK( IS_VALID_PAGE(nPage), FALSE );
+
+ m_aPages[nPage]->Show(FALSE);
+ // m_aPages[nPage]->Lower();
+
+ wxNotebookPage* pPage = GetPage(nPage);
+ m_tabView->RemoveTab((int) (long) pPage);
+
+ m_aPages.Remove(nPage);
+
+ if (m_aPages.GetCount() == 0)
+ {
+ m_nSelection = -1;
+ m_tabView->SetTabSelection(-1, TRUE);
+ }
+ else if (m_nSelection > -1)
+ {
+ // Only change the selection if the page we
+ // deleted was the selection.
+ if (nPage == m_nSelection)
+ {
+ m_nSelection = -1;
+ // Select the first tab. Generates a ChangePage.
+ m_tabView->SetTabSelection((int) (long) GetPage(0), TRUE);
+ }
+ else
+ {
+ // We must adjust which tab we think is selected.
+ // If greater than the page we deleted, it must be moved down
+ // a notch.
+ if (m_nSelection > nPage)
+ m_nSelection -- ;
+ }
+ }
+
+ RefreshLayout(FALSE);
+
+ return TRUE;
+}
+
+bool wxNotebook::RemovePage(wxNotebookPage* page)
+{
+ int pagePos = FindPagePosition(page);
+ if (pagePos > -1)
+ return RemovePage(pagePos);
+ else
+ return FALSE;
+}
+
+// Find the position of the wxNotebookPage, -1 if not found.
+int wxNotebook::FindPagePosition(wxNotebookPage* page) const
+{
+ int nPageCount = GetPageCount();
+ int nPage;
+ for ( nPage = 0; nPage < nPageCount; nPage++ )
+ if (m_aPages[nPage] == page)
+ return nPage;
+ return -1;
}
// remove all pages
wxASSERT( pPage != NULL );
wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
- m_tabView->AddTab(nPage, strText);
- pPage->Show(FALSE);
-
-/*
- if (bSelect)
- m_tabView->SetTabSelection(nPage, TRUE);
-*/
+ m_tabView->AddTab((int) (long) pPage, strText);
+ if (!bSelect)
+ pPage->Show(FALSE);
// save the pointer to the page
m_aPages.Insert(pPage, nPage);
- // some page must be selected: either this one or the first one if there is
+ if (bSelect)
+ {
+ // This will cause ChangePage to be called, via OnSelPage
+ m_tabView->SetTabSelection((int) (long) pPage, TRUE);
+ }
+
+ // some page must be selected: either this one or the first one if there is
// still no selection
- if ( bSelect )
- m_nSelection = nPage;
- else if ( m_nSelection == -1 )
- m_nSelection = 0;
+ if ( m_nSelection == -1 )
+ ChangePage(-1, 0);
+
+ RefreshLayout(FALSE);
return TRUE;
}
s_bFirstTime = FALSE;
}
+ RefreshLayout();
+
+ // Processing continues to next OnSize
+ event.Skip();
+}
+
+// Implementation: calculate the layout of the view rect
+// and resize the children if required
+bool wxNotebook::RefreshLayout(bool force)
+{
if (m_tabView)
{
+ wxRect oldRect = m_tabView->GetViewRect();
+
int cw, ch;
GetClientSize(& cw, & ch);
m_tabView->Layout();
- // emulate page change (it's esp. important to do it first time because
- // otherwise our page would stay invisible)
- int nSel = m_nSelection;
- m_nSelection = -1;
- SetSelection(nSel);
+ if (!force && (rect == oldRect))
+ return FALSE;
// fit the notebook page to the tab control's display area
}
Refresh();
}
-
- // Processing continues to next OnSize
- event.Skip();
+ return TRUE;
}
void wxNotebook::OnSelChange(wxNotebookEvent& event)
{
// is it our tab control?
if ( event.GetEventObject() == this )
- ChangePage(event.GetOldSelection(), event.GetSelection());
+ {
+ if (event.GetSelection() != m_nSelection)
+ ChangePage(event.GetOldSelection(), event.GetSelection());
+ }
// we want to give others a chance to process this message as well
event.Skip();
// hide the currently active panel and show the new one
void wxNotebook::ChangePage(int nOldSel, int nSel)
{
+ // cout << "ChangePage: " << nOldSel << ", " << nSel << "\n";
wxASSERT( nOldSel != nSel ); // impossible
if ( nOldSel != -1 ) {
return;
wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId());
- event.SetEventObject(m_notebook);
- event.SetSelection(activateId);
- event.SetOldSelection(deactivateId);
- m_notebook->GetEventHandler()->ProcessEvent(event);
-
- /*
- wxWindow *oldWindow = ((deactivateId == -1) ? 0 : m_notebook->GetPage(deactivateId));
- wxWindow *newWindow = m_notebook->GetPage(activateId);
-
- if (oldWindow)
- {
- oldWindow->Show(FALSE);
- oldWindow->Lower();
- }
- if (newWindow)
- {
- newWindow->Show(TRUE);
- newWindow->Raise();
-
- int cw, ch;
- m_notebook->GetClientSize(& cw, & ch);
-
- int tabHeight = GetTotalTabHeight();
- wxRect rect;
- rect.x = 4;
- rect.y = tabHeight + 4;
- rect.width = cw - 8;
- rect.height = ch - 4 - rect.y ;
-
- newWindow->SetSize(rect.x + 2, rect.y + 2, rect.width - 2, rect.height - 2);
- newWindow->Refresh();
- }
-
- // TODO: only refresh the tab area.
- m_notebook->Refresh();
-*/
-}
-#if 0
-void wxNotebookTabView::AddTabWindow(int id, wxWindow *window)
-{
- m_tabWindows.Append((long)id, window);
- window->Show(FALSE);
-}
+ // Translate from wxTabView's ids (which aren't position-dependent)
+ // to wxNotebook's (which are).
+ wxNotebookPage* pActive = (wxNotebookPage*) activateId;
+ wxNotebookPage* pDeactive = (wxNotebookPage*) deactivateId;
-wxWindow *wxNotebookTabView::GetTabWindow(int id) const
-{
- wxNode *node = m_tabWindows.Find((long)id);
- if (!node)
- return (wxWindow *) NULL;
- return (wxWindow *)node->Data();
-}
+ int activatePos = m_notebook->FindPagePosition(pActive);
+ int deactivatePos = m_notebook->FindPagePosition(pDeactive);
-void wxNotebookTabView::ClearWindows(bool deleteWindows)
-{
- if (deleteWindows)
- m_tabWindows.DeleteContents(TRUE);
- m_tabWindows.Clear();
- m_tabWindows.DeleteContents(FALSE);
+ event.SetEventObject(m_notebook);
+ event.SetSelection(activatePos);
+ event.SetOldSelection(deactivatePos);
+ m_notebook->GetEventHandler()->ProcessEvent(event);
}
-void wxNotebookTabView::ShowWindowForTab(int id)
-{
- wxWindow *newWindow = GetTabWindow(id);
- if (newWindow == m_currentWindow)
- return;
- if (m_currentWindow)
- m_currentWindow->Show(FALSE);
- newWindow->Show(TRUE);
- newWindow->Refresh();
-}
-#endif