#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
-#ifndef __WXPALMOS__
+#if wxUSE_NOTEBOOK
-#include "wx/string.h"
-#include "wx/log.h"
-#include "wx/settings.h"
-#include "wx/generic/imaglist.h"
#include "wx/notebook.h"
-#include "wx/dcclient.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/string.h"
+ #include "wx/log.h"
+ #include "wx/dcclient.h"
+ #include "wx/settings.h"
+#endif
+
+#include "wx/imaglist.h"
#include "wx/generic/tabg.h"
// ----------------------------------------------------------------------------
// event table
// ----------------------------------------------------------------------------
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
-
-BEGIN_EVENT_TABLE(wxNotebook, wxControl)
+BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase)
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange)
EVT_SIZE(wxNotebook::OnSize)
EVT_PAINT(wxNotebook::OnPaint)
EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
END_EVENT_TABLE()
-IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
-IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
-
// ============================================================================
// implementation
// ============================================================================
// Private class
// ============================================================================
+WX_DECLARE_HASH_MAP(int, wxNotebookPage*, wxIntegerHash, wxIntegerEqual,
+ wxIntToNotebookPageHashMap);
+
+WX_DECLARE_HASH_MAP(wxNotebookPage*, int, wxPointerHash, wxPointerEqual,
+ wxNotebookPageToIntHashMap);
+
// 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);
+ wxNotebookTabView(wxNotebook* notebook, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
+ virtual ~wxNotebookTabView(void);
- // Called when a tab is activated
- virtual void OnTabActivate(int activateId, int deactivateId);
- // Allows vetoing
- virtual bool OnTabPreActivate(int activateId, int deactivateId);
+ // Called when a tab is activated
+ virtual void OnTabActivate(int activateId, int deactivateId);
+ // Allows vetoing
+ virtual bool OnTabPreActivate(int activateId, int deactivateId);
+
+ // map integer ids used by wxTabView to wxNotebookPage pointers
+ int GetId(wxNotebookPage *page);
+ wxNotebookPage *GetPage(int id) { return m_idToPage[id]; }
protected:
- wxNotebook* m_notebook;
+ wxNotebook* m_notebook;
+
+private:
+ wxIntToNotebookPageHashMap m_idToPage;
+ wxNotebookPageToIntHashMap m_pageToId;
+ int m_nextid;
};
+static int GetPageId(wxTabView *tabview, wxNotebookPage *page)
+{
+ return static_cast<wxNotebookTabView*>(tabview)->GetId(page);
+}
+
// ----------------------------------------------------------------------------
// wxNotebook construction
// ----------------------------------------------------------------------------
// common part of all ctors
void wxNotebook::Init()
{
- m_tabView = (wxNotebookTabView*) NULL;
- m_nSelection = -1;
+ m_tabView = NULL;
+ m_selection = -1;
}
// default for dynamic class
// base init
SetName(name);
+ if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
+ style |= wxBK_TOP;
+
m_windowId = id == wxID_ANY ? NewControlId() : id;
if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name))
return false;
- SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
-
SetTabView(new wxNotebookTabView(this));
return true;
wxNotebookPage* pPage = GetPage(nPage);
- m_tabView->SetTabSelection((int) (long) pPage);
+ m_tabView->SetTabSelection(GetPageId(m_tabView, pPage));
// TODO
return 0;
}
+int wxNotebook::ChangeSelection(size_t nPage)
+{
+ // FIXME: currently it does generate events too
+ return SetSelection(nPage);
+}
+
#if 0
void wxNotebook::AdvanceSelection(bool bForward)
{
wxNotebookPage* page = GetPage(nPage);
if (page)
{
- m_tabView->SetTabText((int) (long) page, strText);
+ m_tabView->SetTabText(GetPageId(m_tabView, page), strText);
Refresh();
return true;
}
wxNotebookPage* page = ((wxNotebook*)this)->GetPage(nPage);
if (page)
- return m_tabView->GetTabText((int) (long) page);
+ return m_tabView->GetTabText(GetPageId(m_tabView, page));
else
return wxEmptyString;
}
{
wxCHECK( IS_VALID_PAGE(nPage), false );
- if (m_nSelection != -1)
+ if (m_selection != -1)
{
- m_pages[m_nSelection]->Show(false);
- m_pages[m_nSelection]->Lower();
+ m_pages[m_selection]->Show(false);
+ m_pages[m_selection]->Lower();
}
wxNotebookPage* pPage = GetPage(nPage);
- m_tabView->RemoveTab((int) (long) pPage);
+ m_tabView->RemoveTab(GetPageId(m_tabView, pPage));
m_pages.Remove(pPage);
delete pPage;
if (m_pages.GetCount() == 0)
{
- m_nSelection = -1;
- m_tabView->SetTabSelection(-1, false);
+ m_selection = -1;
+ m_tabView->SetTabSelection(-1, false);
}
- else if (m_nSelection > -1)
+ else if (m_selection > -1)
{
- m_nSelection = -1;
+ m_selection = -1;
- m_tabView->SetTabSelection((int) (long) GetPage(0), false);
+ m_tabView->SetTabSelection(GetPageId(m_tabView, GetPage(0)), false);
- if (m_nSelection != 0)
- ChangePage(-1, 0);
+ if (m_selection != 0)
+ ChangePage(-1, 0);
}
RefreshLayout(false);
wxNotebookPage* pPage = GetPage(nPage);
- m_tabView->RemoveTab((int) (long) pPage);
+ m_tabView->RemoveTab(GetPageId(m_tabView, pPage));
m_pages.Remove(pPage);
if (m_pages.GetCount() == 0)
{
- m_nSelection = -1;
+ m_selection = -1;
m_tabView->SetTabSelection(-1, true);
}
- else if (m_nSelection > -1)
+ else if (m_selection > -1)
{
// Only change the selection if the page we
// deleted was the selection.
- if (nPage == (size_t)m_nSelection)
+ if (nPage == (size_t)m_selection)
{
- m_nSelection = -1;
+ m_selection = -1;
// Select the first tab. Generates a ChangePage.
m_tabView->SetTabSelection(0, true);
}
// We must adjust which tab we think is selected.
// If greater than the page we deleted, it must be moved down
// a notch.
- if (size_t(m_nSelection) > nPage)
- m_nSelection -- ;
+ if (size_t(m_selection) > nPage)
+ m_selection -- ;
}
}
wxASSERT( pPage != NULL );
wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false );
- m_tabView->AddTab((int) (long) pPage, strText);
+ m_tabView->AddTab(GetPageId(m_tabView, pPage), strText);
if (!bSelect)
pPage->Show(false);
{
// This will cause ChangePage to be called, via OnSelPage
- m_tabView->SetTabSelection((int) (long) pPage, true);
+ m_tabView->SetTabSelection(GetPageId(m_tabView, pPage), true);
}
// some page must be selected: either this one or the first one if there is
// still no selection
- if ( m_nSelection == -1 )
+ if ( m_selection == -1 )
ChangePage(-1, 0);
RefreshLayout(false);
return true;
}
-void wxNotebook::OnSelChange(wxNotebookEvent& event)
+void wxNotebook::OnSelChange(wxBookCtrlEvent& event)
{
// is it our tab control?
if ( event.GetEventObject() == this )
{
- if (event.GetSelection() != m_nSelection)
+ if (event.GetSelection() != m_selection)
ChangePage(event.GetOldSelection(), event.GetSelection());
}
void wxNotebook::OnSetFocus(wxFocusEvent& event)
{
// set focus to the currently selected page if any
- if ( m_nSelection != -1 )
- m_pages[m_nSelection]->SetFocus();
+ if ( m_selection != -1 )
+ m_pages[m_selection]->SetFocus();
event.Skip();
}
void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
{
- if ( event.IsWindowChange() ) {
+ if ( event.IsWindowChange() )
+ {
// change pages
AdvanceSelection(event.GetDirection());
}
else {
// pass to the parent
- if ( GetParent() ) {
+ if ( GetParent() )
+ {
event.SetCurrentFocus(this);
- GetParent()->ProcessEvent(event);
+ GetParent()->ProcessWindowEvent(event);
}
}
}
pPage->Raise();
pPage->SetFocus();
- m_nSelection = nSel;
+ m_selection = nSel;
}
void wxNotebook::OnMouseEvent(wxMouseEvent& event)
IMPLEMENT_CLASS(wxNotebookTabView, wxTabView)
-wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style): wxTabView(style)
+wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style)
+ : wxTabView(style), m_nextid(1)
{
m_notebook = notebook;
{
}
+int wxNotebookTabView::GetId(wxNotebookPage *page)
+{
+ int& id = m_pageToId[page];
+
+ if (!id)
+ {
+ id = m_nextid++;
+ m_idToPage[id] = page;
+ }
+
+ return id;
+}
+
// Called when a tab is activated
void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId)
{
if (!m_notebook)
return;
- wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId());
+ wxBookCtrlEvent event(wxEVT_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId());
// Translate from wxTabView's ids (which aren't position-dependent)
// to wxNotebook's (which are).
- wxNotebookPage* pActive = (wxNotebookPage*) activateId;
- wxNotebookPage* pDeactive = (wxNotebookPage*) deactivateId;
+ wxNotebookPage* pActive = GetPage(activateId);
+ wxNotebookPage* pDeactive = GetPage(deactivateId);
int activatePos = m_notebook->FindPagePosition(pActive);
int deactivatePos = m_notebook->FindPagePosition(pDeactive);
if (m_notebook)
{
- wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId());
+ wxBookCtrlEvent event(wxEVT_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId());
// Translate from wxTabView's ids (which aren't position-dependent)
// to wxNotebook's (which are).
- wxNotebookPage* pActive = (wxNotebookPage*) activateId;
- wxNotebookPage* pDeactive = (wxNotebookPage*) deactivateId;
+ wxNotebookPage* pActive = GetPage(activateId);
+ wxNotebookPage* pDeactive = GetPage(deactivateId);
int activatePos = m_notebook->FindPagePosition(pActive);
int deactivatePos = m_notebook->FindPagePosition(pDeactive);
return retval;
}
-#endif // __WXPALMOS__
+#endif // wxUSE_NOTEBOOK