X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..aa57eeea83fac24e9d188fa800bdc96c95f5bbeb:/src/generic/notebook.cpp diff --git a/src/generic/notebook.cpp b/src/generic/notebook.cpp index 97019ea950..719d8bba0d 100644 --- a/src/generic/notebook.cpp +++ b/src/generic/notebook.cpp @@ -16,10 +16,14 @@ // ---------------------------------------------------------------------------- // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "notebook.h" #endif +#ifdef __VMS +#pragma message disable unscomzer +#endif + // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -33,6 +37,7 @@ #include "wx/generic/imaglist.h" #include "wx/notebook.h" #include "wx/dcclient.h" +#include "wx/generic/tabg.h" // ---------------------------------------------------------------------------- // macros @@ -45,6 +50,9 @@ // event table // ---------------------------------------------------------------------------- +DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) + BEGIN_EVENT_TABLE(wxNotebook, wxControl) EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) EVT_SIZE(wxNotebook::OnSize) @@ -52,7 +60,6 @@ BEGIN_EVENT_TABLE(wxNotebook, wxControl) EVT_MOUSE_EVENTS(wxNotebook::OnMouseEvent) EVT_SET_FOCUS(wxNotebook::OnSetFocus) EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) -// EVT_IDLE(wxNotebook::OnIdle) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) @@ -62,6 +69,27 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) // 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 // ---------------------------------------------------------------------------- @@ -70,7 +98,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) void wxNotebook::Init() { m_tabView = (wxNotebookTabView*) NULL; - m_pImageList = NULL; m_nSelection = -1; } @@ -106,11 +133,10 @@ bool wxNotebook::Create(wxWindow *parent, m_windowId = id == -1 ? NewControlId() : id; - // It's like a normal window... - if (!wxWindow::Create(parent, id, pos, size, style|wxNO_BORDER, name)) + if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name)) return FALSE; - SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); SetTabView(new wxNotebookTabView(this)); @@ -126,35 +152,25 @@ wxNotebook::~wxNotebook() // ---------------------------------------------------------------------------- // wxNotebook accessors // ---------------------------------------------------------------------------- -int wxNotebook::GetPageCount() const -{ - return m_aPages.Count(); -} - int wxNotebook::GetRowCount() const { // TODO return 0; } -int wxNotebook::SetSelection(int nPage) +int wxNotebook::SetSelection(size_t nPage) { - if (nPage == -1) - return 0; - wxASSERT( IS_VALID_PAGE(nPage) ); -#if defined (__WIN16__) - m_tabView->SetTabSelection(nPage); -#else wxNotebookPage* pPage = GetPage(nPage); m_tabView->SetTabSelection((int) (long) pPage); -#endif + // TODO return 0; } +#if 0 void wxNotebook::AdvanceSelection(bool bForward) { int nSel = GetSelection(); @@ -164,15 +180,12 @@ void wxNotebook::AdvanceSelection(bool bForward) else SetSelection(nSel == 0 ? nMax : nSel - 1); } +#endif -bool wxNotebook::SetPageText(int nPage, const wxString& strText) +bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) { wxASSERT( IS_VALID_PAGE(nPage) ); -#if defined (__WIN16__) - m_tabView->SetTabText(nPage, strText); - Refresh(); - return TRUE; -#else + wxNotebookPage* page = GetPage(nPage); if (page) { @@ -180,26 +193,22 @@ bool wxNotebook::SetPageText(int nPage, const wxString& strText) Refresh(); return TRUE; } -#endif + return FALSE; } -wxString wxNotebook::GetPageText(int nPage) const +wxString wxNotebook::GetPageText(size_t nPage) const { wxASSERT( IS_VALID_PAGE(nPage) ); -#if defined (__WIN16__) - return m_tabView->GetTabText(nPage); -#else wxNotebookPage* page = ((wxNotebook*)this)->GetPage(nPage); if (page) return m_tabView->GetTabText((int) (long) page); else return wxEmptyString; -#endif } -int wxNotebook::GetPageImage(int nPage) const +int wxNotebook::GetPageImage(size_t nPage) const { wxASSERT( IS_VALID_PAGE(nPage) ); @@ -207,7 +216,7 @@ int wxNotebook::GetPageImage(int nPage) const return 0; } -bool wxNotebook::SetPageImage(int nPage, int nImage) +bool wxNotebook::SetPageImage(size_t nPage, int nImage) { wxASSERT( IS_VALID_PAGE(nPage) ); @@ -215,9 +224,21 @@ bool wxNotebook::SetPageImage(int nPage, int nImage) return FALSE; } -void wxNotebook::SetImageList(wxImageList* imageList) -{ - m_pImageList = 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) +{ // TODO } @@ -226,27 +247,24 @@ void wxNotebook::SetImageList(wxImageList* imageList) // ---------------------------------------------------------------------------- // remove one page from the notebook and delete it -bool wxNotebook::DeletePage(int nPage) +bool wxNotebook::DeletePage(size_t nPage) { wxCHECK( IS_VALID_PAGE(nPage), FALSE ); 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); -#if defined (__WIN16__) - m_tabView->RemoveTab(nPage); -#else + 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); @@ -254,11 +272,9 @@ bool wxNotebook::DeletePage(int nPage) else if (m_nSelection > -1) { m_nSelection = -1; -#if defined (__WIN16__) - m_tabView->SetTabSelection(0, FALSE); -#else + m_tabView->SetTabSelection((int) (long) GetPage(0), FALSE); -#endif + if (m_nSelection != 0) ChangePage(-1, 0); } @@ -277,24 +293,26 @@ bool wxNotebook::DeletePage(wxNotebookPage* page) return FALSE; } +bool wxNotebook::RemovePage(size_t nPage) +{ + return DoRemovePage(nPage) != NULL; +} + // remove one page from the notebook -bool wxNotebook::RemovePage(int nPage) +wxWindow* wxNotebook::DoRemovePage(size_t nPage) { 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(nPage); -#else + 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); @@ -303,25 +321,25 @@ bool wxNotebook::RemovePage(int nPage) { // Only change the selection if the page we // deleted was the selection. - if (nPage == m_nSelection) + if (nPage == (size_t)m_nSelection) { m_nSelection = -1; // Select the first tab. Generates a ChangePage. - m_tabView->SetTabSelection((int) (long) GetPage(0), TRUE); + m_tabView->SetTabSelection(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) + if (size_t(m_nSelection) > nPage) m_nSelection -- ; } } RefreshLayout(FALSE); - return TRUE; + return pPage; } bool wxNotebook::RemovePage(wxNotebookPage* page) @@ -336,10 +354,10 @@ bool wxNotebook::RemovePage(wxNotebookPage* page) // Find the position of the wxNotebookPage, -1 if not found. int wxNotebook::FindPagePosition(wxNotebookPage* page) const { - int nPageCount = GetPageCount(); - int nPage; + size_t nPageCount = GetPageCount(); + size_t nPage; for ( nPage = 0; nPage < nPageCount; nPage++ ) - if (m_aPages[nPage] == page) + if (m_pages[nPage] == page) return nPage; return -1; } @@ -349,27 +367,18 @@ bool wxNotebook::DeleteAllPages() { m_tabView->ClearTabs(TRUE); - int nPageCount = GetPageCount(); - int nPage; + size_t nPageCount = GetPageCount(); + size_t 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, +bool wxNotebook::InsertPage(size_t nPage, wxNotebookPage *pPage, const wxString& strText, bool bSelect, @@ -378,26 +387,19 @@ bool wxNotebook::InsertPage(int nPage, wxASSERT( pPage != NULL ); wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE ); -// For 16 bit integers (tabs limited to 32768) -#if defined (__WIN16__) - m_tabView->AddTab(nPage, strText); -#else m_tabView->AddTab((int) (long) pPage, strText); -#endif + if (!bSelect) pPage->Show(FALSE); // save the pointer to the page - m_aPages.Insert(pPage, nPage); + m_pages.Insert(pPage, nPage); if (bSelect) { // This will cause ChangePage to be called, via OnSelPage -#if defined (__WIN16__) - m_tabView->SetTabSelection(nPage, TRUE); -#else + m_tabView->SetTabSelection((int) (long) pPage, TRUE); -#endif } // some page must be selected: either this one or the first one if there is @@ -433,8 +435,11 @@ void wxNotebook::OnSize(wxSizeEvent& event) // This was supposed to cure the non-display of the notebook // until the user resizes the window. // What's going on? -void wxNotebook::OnIdle(wxIdleEvent& event) +void wxNotebook::OnInternalIdle() { + wxWindow::OnInternalIdle(); + +#if 0 static bool s_bFirstTime = TRUE; if ( s_bFirstTime ) { /* @@ -454,7 +459,7 @@ void wxNotebook::OnIdle(wxIdleEvent& event) */ s_bFirstTime = FALSE; } - event.Skip(); +#endif } // Implementation: calculate the layout of the view rect @@ -474,7 +479,7 @@ bool wxNotebook::RefreshLayout(bool force) rect.y = tabHeight + 4; rect.width = cw - 8; rect.height = ch - 4 - rect.y ; - + m_tabView->SetViewRect(rect); m_tabView->LayoutTabs(); @@ -487,7 +492,7 @@ bool wxNotebook::RefreshLayout(bool force) rect.y = tabHeight + 4; rect.width = cw - 8; rect.height = ch - 4 - rect.y ; - + m_tabView->SetViewRect(rect); m_tabView->LayoutTabs(); @@ -497,12 +502,12 @@ bool wxNotebook::RefreshLayout(bool force) // 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]; + size_t nCount = m_pages.Count(); + for ( size_t nPage = 0; nPage < nCount; 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(); @@ -530,7 +535,7 @@ void wxNotebook::OnSetFocus(wxFocusEvent& event) { // 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(); } @@ -569,7 +574,7 @@ bool wxNotebook::DoPhase(int /* nPhase */) void wxNotebook::Command(wxCommandEvent& WXUNUSED(event)) { - wxFAIL_MSG("wxNotebook::Command not implemented"); + wxFAIL_MSG(wxT("wxNotebook::Command not implemented")); } // ---------------------------------------------------------------------------- @@ -583,11 +588,11 @@ void wxNotebook::ChangePage(int nOldSel, int nSel) 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); @@ -634,7 +639,7 @@ wxRect wxNotebook::GetAvailableClientSize() /* * wxNotebookTabView */ - + IMPLEMENT_CLASS(wxNotebookTabView, wxTabView) wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style): wxTabView(style) @@ -656,17 +661,8 @@ void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId) if (!m_notebook) return; -// Because of name truncation! -#if defined(__BORLANDC__) && defined(__WIN16__) - wxNotebookEvent event(wxEVT_COMMAND_NB_PAGE_CHANGED, m_notebook->GetId()); -#else wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId()); -#endif -#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; @@ -675,11 +671,37 @@ void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId) int activatePos = m_notebook->FindPagePosition(pActive); int deactivatePos = m_notebook->FindPagePosition(pDeactive); -#endif event.SetEventObject(m_notebook); event.SetSelection(activatePos); event.SetOldSelection(deactivatePos); 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()); + + // 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); + + event.SetEventObject(m_notebook); + event.SetSelection(activatePos); + event.SetOldSelection(deactivatePos); + if (m_notebook->GetEventHandler()->ProcessEvent(event)) + { + retval = event.IsAllowed(); + } + } + return retval; +}