X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9806a47c30050b2beeb772f69d4cef4a20dc8745..341baa4c718000e49e632d7293888fc133196f74:/src/generic/notebook.cpp diff --git a/src/generic/notebook.cpp b/src/generic/notebook.cpp index 94170c605e..853fc8ab7d 100644 --- a/src/generic/notebook.cpp +++ b/src/generic/notebook.cpp @@ -33,6 +33,7 @@ #include "wx/generic/imaglist.h" #include "wx/notebook.h" #include "wx/dcclient.h" +#include "wx/generic/tabg.h" // ---------------------------------------------------------------------------- // macros @@ -55,7 +56,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) @@ -65,6 +65,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 // ---------------------------------------------------------------------------- @@ -112,7 +133,7 @@ bool wxNotebook::Create(wxWindow *parent, 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)); @@ -435,8 +456,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 ) { /* @@ -456,7 +480,7 @@ void wxNotebook::OnIdle(wxIdleEvent& event) */ s_bFirstTime = FALSE; } - event.Skip(); +#endif } // Implementation: calculate the layout of the view rect @@ -502,13 +526,20 @@ bool wxNotebook::RefreshLayout(bool force) unsigned int nCount = m_pages.Count(); for ( unsigned int 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(); } + // 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(); } @@ -679,4 +710,36 @@ void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId) 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; +}