X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4b5f3fe655deeb91d5d3abe8fad30c4a1cae63dc..b9fc7b7fddcfd8673235ac09aba2da632d884f5b:/src/motif/notebook.cpp diff --git a/src/motif/notebook.cpp b/src/motif/notebook.cpp index 7b520792b9..fd0e099d65 100644 --- a/src/motif/notebook.cpp +++ b/src/motif/notebook.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include + // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- @@ -96,16 +99,9 @@ bool wxNotebook::Create(wxWindow *parent, { // base init SetName(name); - SetParent(parent); m_windowId = id == -1 ? NewControlId() : id; - // style - m_windowStyle = style; - - if ( parent != NULL ) - parent->AddChild(this); - // It's like a normal window... if (!wxWindow::Create(parent, id, pos, size, style, name)) return FALSE; @@ -137,9 +133,15 @@ int wxNotebook::GetRowCount() const int wxNotebook::SetSelection(int nPage) { + if (nPage == -1) + return 0; + wxASSERT( IS_VALID_PAGE(nPage) ); - ChangePage(m_nSelection, nPage); + wxNotebookPage* pPage = GetPage(nPage); + + m_tabView->SetTabSelection((int) (long) pPage); + // ChangePage(m_nSelection, nPage); // TODO return 0; @@ -197,22 +199,96 @@ void wxNotebook::SetImageList(wxImageList* imageList) // 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 > 0) + { + m_nSelection = -1; + m_tabView->SetTabSelection((int) (long) GetPage(0), FALSE); + ChangePage(-1, 0); + } + + 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 ); + + 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); + + m_aPages.Remove(nPage); + + if (m_aPages.GetCount() == 0) + { + m_nSelection = -1; + m_tabView->SetTabSelection(-1, FALSE); + } + else if (m_nSelection > 0) + { + m_nSelection = -1; + m_tabView->SetTabSelection((int) (long) GetPage(0), FALSE); + ChangePage(-1, 0); + } + 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 @@ -249,22 +325,23 @@ bool wxNotebook::InsertPage(int nPage, wxASSERT( pPage != NULL ); wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE ); - m_tabView->AddTab(nPage, strText); - -/* - 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); return TRUE; } @@ -311,21 +388,26 @@ void wxNotebook::OnSize(wxSizeEvent& event) m_tabView->SetViewRect(rect); 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); + */ // fit the notebook page to the tab control's display area unsigned int nCount = m_aPages.Count(); for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) { wxNotebookPage *pPage = m_aPages[nPage]; - pPage->SetSize(rect.x + 2, rect.y + 2, rect.width - 2, rect.height - 2); - if ( pPage->GetAutoLayout() ) - pPage->Layout(); + if (pPage->IsShown()) + { + wxRect clientRect = GetAvailableClientSize(); + pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height); + if ( pPage->GetAutoLayout() ) + pPage->Layout(); + } } Refresh(); } @@ -401,12 +483,20 @@ void wxNotebook::ChangePage(int nOldSel, int nSel) if ( nOldSel != -1 ) { m_aPages[nOldSel]->Show(FALSE); + m_aPages[nOldSel]->Lower(); } wxNotebookPage *pPage = m_aPages[nSel]; + + wxRect clientRect = GetAvailableClientSize(); + pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height); + pPage->Show(TRUE); + pPage->Raise(); pPage->SetFocus(); + Refresh(); + m_nSelection = nSel; } @@ -438,6 +528,23 @@ void wxNotebook::OnPaint(wxPaintEvent& WXUNUSED(event) ) m_tabView->Draw(dc); } +wxRect wxNotebook::GetAvailableClientSize() +{ + int cw, ch; + GetClientSize(& cw, & ch); + + int tabHeight = m_tabView->GetTotalTabHeight(); + + // TODO: these margins should be configurable. + wxRect rect; + rect.x = 6; + rect.y = tabHeight + 6; + rect.width = cw - 12; + rect.height = ch - 4 - rect.y ; + + return rect; +} + /* * wxNotebookTabView */ @@ -448,8 +555,6 @@ wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style): wxTabVie { m_notebook = notebook; -// m_currentWindow = (wxWindow *) NULL; - m_notebook->SetTabView(this); SetWindow(m_notebook); @@ -457,7 +562,6 @@ wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style): wxTabVie wxNotebookTabView::~wxNotebookTabView(void) { -// ClearWindows(TRUE); } // Called when a tab is activated @@ -465,50 +569,21 @@ void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId) { if (!m_notebook) return; - - wxWindow *oldWindow = ((deactivateId == -1) ? 0 : m_notebook->GetPage(deactivateId)); - wxWindow *newWindow = m_notebook->GetPage(activateId); - if (oldWindow) - oldWindow->Show(FALSE); - if (newWindow) - newWindow->Show(TRUE); - - m_notebook->Refresh(); -} + wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId()); -#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