X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df91131cb0f90ee8bfb194926a13b1a108ca3c6e..3e1924dd5f5744c3e2a8973de9b3e4f372b7fd85:/src/generic/notebook.cpp?ds=inline diff --git a/src/generic/notebook.cpp b/src/generic/notebook.cpp index b7891ecc37..3b0b6d2382 100644 --- a/src/generic/notebook.cpp +++ b/src/generic/notebook.cpp @@ -24,16 +24,18 @@ #pragma hdrstop #endif +#if wxUSE_NOTEBOOK + #include "wx/notebook.h" #ifndef WX_PRECOMP #include "wx/string.h" + #include "wx/log.h" + #include "wx/dcclient.h" + #include "wx/settings.h" #endif -#include "wx/log.h" -#include "wx/settings.h" -#include "wx/generic/imaglist.h" -#include "wx/dcclient.h" +#include "wx/imaglist.h" #include "wx/generic/tabg.h" // ---------------------------------------------------------------------------- @@ -50,7 +52,7 @@ 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) @@ -59,7 +61,7 @@ BEGIN_EVENT_TABLE(wxNotebook, wxControl) EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) END_EVENT_TABLE() -IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase) IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) // ============================================================================ @@ -70,23 +72,43 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) // 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 wx_static_cast(wxNotebookTabView*, tabview)->GetId(page); +} + // ---------------------------------------------------------------------------- // wxNotebook construction // ---------------------------------------------------------------------------- @@ -128,13 +150,14 @@ bool wxNotebook::Create(wxWindow *parent, // 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; @@ -161,12 +184,18 @@ int wxNotebook::SetSelection(size_t nPage) 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) { @@ -186,7 +215,7 @@ bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) wxNotebookPage* page = GetPage(nPage); if (page) { - m_tabView->SetTabText((int) (long) page, strText); + m_tabView->SetTabText(GetPageId(m_tabView, page), strText); Refresh(); return true; } @@ -200,7 +229,7 @@ wxString wxNotebook::GetPageText(size_t nPage) const 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; } @@ -257,24 +286,24 @@ bool wxNotebook::DeletePage(size_t nPage) 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_nSelection = -1; + m_tabView->SetTabSelection(-1, false); } else if (m_nSelection > -1) { - m_nSelection = -1; + m_nSelection = -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_nSelection != 0) + ChangePage(-1, 0); } RefreshLayout(false); @@ -306,7 +335,7 @@ wxWindow* wxNotebook::DoRemovePage(size_t nPage) wxNotebookPage* pPage = GetPage(nPage); - m_tabView->RemoveTab((int) (long) pPage); + m_tabView->RemoveTab(GetPageId(m_tabView, pPage)); m_pages.Remove(pPage); @@ -385,7 +414,7 @@ bool wxNotebook::InsertPage(size_t nPage, 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); @@ -397,7 +426,7 @@ bool wxNotebook::InsertPage(size_t nPage, { // 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 @@ -651,7 +680,8 @@ wxRect wxNotebook::GetAvailableClientSize() 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; @@ -664,6 +694,19 @@ wxNotebookTabView::~wxNotebookTabView(void) { } +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) { @@ -674,8 +717,8 @@ void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId) // 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); @@ -697,8 +740,8 @@ bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId) // 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); @@ -713,3 +756,5 @@ bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId) } return retval; } + +#endif // wxUSE_NOTEBOOK