#include "wx/generic/imaglist.h"
#include "wx/notebook.h"
#include "wx/dcclient.h"
+#include "wx/generic/tabg.h"
// ----------------------------------------------------------------------------
// macros
// implementation
// ============================================================================
+// ============================================================================
+// Private class
+// ============================================================================
+
+// This reuses wxTabView to draw the tabs.
+class WXDLLEXPORT wxNotebookTabView: public wxTabView
+{
+DECLARE_DYNAMIC_CLASS(wxNotebookTabView)
+public:
+ wxNotebookTabView(wxNotebook* notebook, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
+ ~wxNotebookTabView(void);
+
+ // Called when a tab is activated
+ virtual void OnTabActivate(int activateId, int deactivateId);
+ // Allows vetoing
+ virtual bool OnTabPreActivate(int activateId, int deactivateId);
+
+protected:
+ wxNotebook* m_notebook;
+};
+
// ----------------------------------------------------------------------------
// wxNotebook construction
// ----------------------------------------------------------------------------
void wxNotebook::Init()
{
m_tabView = (wxNotebookTabView*) NULL;
- m_pImageList = NULL;
m_nSelection = -1;
}
if (!wxWindow::Create(parent, id, pos, size, style|wxNO_BORDER, name))
return FALSE;
- SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
SetTabView(new wxNotebookTabView(this));
// ----------------------------------------------------------------------------
// wxNotebook accessors
// ----------------------------------------------------------------------------
-int wxNotebook::GetPageCount() const
-{
- return m_aPages.Count();
-}
-
int wxNotebook::GetRowCount() const
{
// TODO
return 0;
}
+#if 0
void wxNotebook::AdvanceSelection(bool bForward)
{
int nSel = GetSelection();
else
SetSelection(nSel == 0 ? nMax : nSel - 1);
}
+#endif
bool wxNotebook::SetPageText(int nPage, const wxString& strText)
{
return FALSE;
}
-void wxNotebook::SetImageList(wxImageList* imageList)
+// set the size (the same for all pages)
+void wxNotebook::SetPageSize(const wxSize& size)
+{
+ // TODO
+}
+
+// set the padding between tabs (in pixels)
+void wxNotebook::SetPadding(const wxSize& padding)
+{
+ // TODO
+}
+
+// set the size of the tabs for wxNB_FIXEDWIDTH controls
+void wxNotebook::SetTabSize(const wxSize& sz)
{
- m_pImageList = imageList;
// TODO
}
if (m_nSelection != -1)
{
- m_aPages[m_nSelection]->Show(FALSE);
- m_aPages[m_nSelection]->Lower();
+ m_pages[m_nSelection]->Show(FALSE);
+ m_pages[m_nSelection]->Lower();
}
wxNotebookPage* pPage = GetPage(nPage);
m_tabView->RemoveTab((int) (long) pPage);
#endif
- delete m_aPages[nPage];
- m_aPages.Remove(nPage);
+ m_pages.Remove(pPage);
+ delete pPage;
- if (m_aPages.GetCount() == 0)
+ if (m_pages.GetCount() == 0)
{
m_nSelection = -1;
m_tabView->SetTabSelection(-1, FALSE);
{
wxCHECK( IS_VALID_PAGE(nPage), FALSE );
- m_aPages[nPage]->Show(FALSE);
- // m_aPages[nPage]->Lower();
+ m_pages[nPage]->Show(FALSE);
+ // m_pages[nPage]->Lower();
wxNotebookPage* pPage = GetPage(nPage);
#if defined (__WIN16__)
m_tabView->RemoveTab((int) (long) pPage);
#endif
- m_aPages.Remove(nPage);
+ m_pages.Remove(pPage);
- if (m_aPages.GetCount() == 0)
+ if (m_pages.GetCount() == 0)
{
m_nSelection = -1;
m_tabView->SetTabSelection(-1, TRUE);
int nPageCount = GetPageCount();
int nPage;
for ( nPage = 0; nPage < nPageCount; nPage++ )
- if (m_aPages[nPage] == page)
+ if (m_pages[nPage] == page)
return nPage;
return -1;
}
int nPageCount = GetPageCount();
int nPage;
for ( nPage = 0; nPage < nPageCount; nPage++ )
- delete m_aPages[nPage];
+ delete m_pages[nPage];
- m_aPages.Clear();
+ m_pages.Clear();
return TRUE;
}
-// add a page to the notebook
-bool wxNotebook::AddPage(wxNotebookPage *pPage,
- const wxString& strText,
- bool bSelect,
- int imageId)
-{
- return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
-}
-
// same as AddPage() but does it at given position
bool wxNotebook::InsertPage(int nPage,
wxNotebookPage *pPage,
pPage->Show(FALSE);
// save the pointer to the page
- m_aPages.Insert(pPage, nPage);
+ m_pages.Insert(pPage, nPage);
if (bSelect)
{
// fit the notebook page to the tab control's display area
- unsigned int nCount = m_aPages.Count();
+ unsigned int nCount = m_pages.Count();
for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) {
- wxNotebookPage *pPage = m_aPages[nPage];
+ wxNotebookPage *pPage = m_pages[nPage];
+ wxRect clientRect = GetAvailableClientSize();
if (pPage->IsShown())
{
- wxRect clientRect = GetAvailableClientSize();
pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
if ( pPage->GetAutoLayout() )
pPage->Layout();
}
+ // MBN: this is probably just hiding a problem under the carpet,
+ // but: with OpenMotif 2.2 (not Lesstif), not moving the window
+ // may cause the tabs to be not clickable.
+ else
+ {
+ pPage->Move(clientRect.x, clientRect.y);
+ }
}
Refresh();
}
{
// set focus to the currently selected page if any
if ( m_nSelection != -1 )
- m_aPages[m_nSelection]->SetFocus();
+ m_pages[m_nSelection]->SetFocus();
event.Skip();
}
wxASSERT( nOldSel != nSel ); // impossible
if ( nOldSel != -1 ) {
- m_aPages[nOldSel]->Show(FALSE);
- m_aPages[nOldSel]->Lower();
+ m_pages[nOldSel]->Show(FALSE);
+ m_pages[nOldSel]->Lower();
}
- wxNotebookPage *pPage = m_aPages[nSel];
+ wxNotebookPage *pPage = m_pages[nSel];
wxRect clientRect = GetAvailableClientSize();
pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
m_notebook->GetEventHandler()->ProcessEvent(event);
}
+// Allows Vetoing
+bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId)
+{
+ bool retval = TRUE;
+
+ if (m_notebook)
+ {
+ wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId());
+
+#if defined (__WIN16__)
+ int activatePos = activateId;
+ int deactivatePos = deactivateId;
+#else
+ // Translate from wxTabView's ids (which aren't position-dependent)
+ // to wxNotebook's (which are).
+ wxNotebookPage* pActive = (wxNotebookPage*) activateId;
+ wxNotebookPage* pDeactive = (wxNotebookPage*) deactivateId;
+
+ int activatePos = m_notebook->FindPagePosition(pActive);
+ int deactivatePos = m_notebook->FindPagePosition(pDeactive);
+
+#endif
+ event.SetEventObject(m_notebook);
+ event.SetSelection(activatePos);
+ event.SetOldSelection(deactivatePos);
+ if (m_notebook->GetEventHandler()->ProcessEvent(event))
+ {
+ retval = event.IsAllowed();
+ }
+ }
+ return retval;
+}