#include <wx/notebook.h>
#include <wx/dcclient.h>
+#include <Xm/Xm.h>
+#include <wx/motif/private.h>
+
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
{
// 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;
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);
// 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);
-
-/*
- 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
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();
}
-
- // 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 ) {
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;
}
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
*/
{
m_notebook = notebook;
-// m_currentWindow = (wxWindow *) NULL;
-
m_notebook->SetTabView(this);
SetWindow(m_notebook);
wxNotebookTabView::~wxNotebookTabView(void)
{
-// ClearWindows(TRUE);
}
// Called when a tab is activated
{
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