X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8b5d5223d164a3b7fbacc5e69808cadd25163b1b..eb7350290f690dd3e4d92bcf0515027678b3374f:/src/univ/notebook.cpp diff --git a/src/univ/notebook.cpp b/src/univ/notebook.cpp index 2b9e19f9ff..1376222d9b 100644 --- a/src/univ/notebook.cpp +++ b/src/univ/notebook.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: univ/notebook.cpp +// Name: src/univ/notebook.cpp // Purpose: wxNotebook implementation // Author: Vadim Zeitlin // Modified by: @@ -17,14 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "univnotebook.h" -#endif - -#ifdef __VMS -#pragma message disable unscomzer -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ @@ -33,13 +25,40 @@ #if wxUSE_NOTEBOOK -#include "wx/imaglist.h" #include "wx/notebook.h" + +#ifndef WX_PRECOMP + #include "wx/dcmemory.h" +#endif + +#include "wx/imaglist.h" #include "wx/spinbutt.h" -#include "wx/dcmemory.h" #include "wx/univ/renderer.h" +// ---------------------------------------------------------------------------- +// wxStdNotebookInputHandler: translates SPACE and ENTER keys and the left mouse +// click into button press/release actions +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxStdNotebookInputHandler : public wxStdInputHandler +{ +public: + wxStdNotebookInputHandler(wxInputHandler *inphand); + + virtual bool HandleKey(wxInputConsumer *consumer, + const wxKeyEvent& event, + bool pressed); + virtual bool HandleMouse(wxInputConsumer *consumer, + const wxMouseEvent& event); + virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event); + virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event); + virtual bool HandleActivation(wxInputConsumer *consumer, bool activated); + +protected: + void HandleFocusChange(wxInputConsumer *consumer); +}; + // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- @@ -57,9 +76,6 @@ static const size_t INVALID_PAGE = (size_t)-1; -DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) - // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -95,8 +111,7 @@ END_EVENT_TABLE() // implementation // ============================================================================ -IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) -IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) +IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase) // ---------------------------------------------------------------------------- // wxNotebook creation @@ -125,13 +140,16 @@ bool wxNotebook::Create(wxWindow *parent, long style, const wxString& name) { + if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT ) + style |= wxBK_TOP; + if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) return false; m_sizePad = GetRenderer()->GetTabPadding(); - SetBestSize(size); + SetInitialSize(size); CreateInputHandler(wxINP_HANDLER_NOTEBOOK); @@ -144,14 +162,14 @@ bool wxNotebook::Create(wxWindow *parent, wxString wxNotebook::GetPageText(size_t nPage) const { - wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, _T("invalid notebook page") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("invalid notebook page") ); return m_titles[nPage]; } bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), false, _T("invalid notebook page") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("invalid notebook page") ); if ( strText != m_titles[nPage] ) { @@ -174,17 +192,17 @@ bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) int wxNotebook::GetPageImage(size_t nPage) const { - wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("invalid notebook page") ); return m_images[nPage]; } bool wxNotebook::SetPageImage(size_t nPage, int nImage) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), false, _T("invalid notebook page") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("invalid notebook page") ); wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), false, - _T("invalid image index in SetPageImage()") ); + wxT("invalid image index in SetPageImage()") ); if ( nImage != m_images[nPage] ) { @@ -211,9 +229,9 @@ wxNotebook::~wxNotebook() // wxNotebook page switching // ---------------------------------------------------------------------------- -int wxNotebook::SetSelection(size_t nPage) +int wxNotebook::DoSetSelection(size_t nPage, int flags) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("invalid notebook page") ); if ( (size_t)nPage == m_sel ) { @@ -221,15 +239,13 @@ int wxNotebook::SetSelection(size_t nPage) return m_sel; } - // event handling - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); - event.SetSelection(nPage); - event.SetOldSelection(m_sel); - event.SetEventObject(this); - if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() ) + if ( flags & SetSelection_SendEvent ) { - // program doesn't allow the page change - return m_sel; + if ( !SendPageChangingEvent(nPage) ) + { + // program doesn't allow the page change + return m_sel; + } } // we need to change m_sel first, before calling RefreshTab() below as @@ -275,9 +291,11 @@ int wxNotebook::SetSelection(size_t nPage) m_pages[m_sel]->Show(); } - // event handling - event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); - GetEventHandler()->ProcessEvent(event); + if ( flags & SetSelection_SendEvent ) + { + // event handling + SendPageChangedEvent(selOld); + } return selOld; } @@ -294,7 +312,7 @@ bool wxNotebook::InsertPage(size_t nPage, { size_t nPages = GetPageCount(); wxCHECK_MSG( nPage == nPages || IS_VALID_PAGE(nPage), false, - _T("invalid notebook page in InsertPage()") ); + wxT("invalid notebook page in InsertPage()") ); // modify the data m_pages.Insert(pPage, nPage); @@ -371,7 +389,7 @@ bool wxNotebook::DeleteAllPages() wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage) { - wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, _T("invalid notebook page") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, wxT("invalid notebook page") ); wxNotebookPage *page = m_pages[nPage]; m_pages.RemoveAt(nPage); @@ -432,7 +450,7 @@ void wxNotebook::RefreshCurrent() void wxNotebook::RefreshTab(int page, bool forceSelected) { - wxCHECK_RET( IS_VALID_PAGE(page), _T("invalid notebook page") ); + wxCHECK_RET( IS_VALID_PAGE(page), wxT("invalid notebook page") ); wxRect rect = GetTabRect(page); if ( forceSelected || ((size_t)page == m_sel) ) @@ -473,7 +491,7 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n) m_imageList->Draw(image, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL, true); dc.SelectObject(wxNullBitmap); #else - bmp = *m_imageList->GetBitmap(image); + bmp = m_imageList->GetBitmap(image); #endif } @@ -586,10 +604,10 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer) int wxNotebook::HitTest(const wxPoint& pt, long *flags) const { if ( flags ) - *flags = wxNB_HITTEST_NOWHERE; + *flags = wxBK_HITTEST_NOWHERE; // first check that it is in this window at all - if ( !GetClientRect().Inside(pt) ) + if ( !GetClientRect().Contains(pt) ) { return -1; } @@ -599,7 +617,7 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const switch ( GetTabOrientation() ) { default: - wxFAIL_MSG(_T("unknown tab orientation")); + wxFAIL_MSG(wxT("unknown tab orientation")); // fall through case wxTOP: @@ -627,12 +645,12 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const { GetTabSize(n, &rectTabs.width, &rectTabs.height); - if ( rectTabs.Inside(pt) ) + if ( rectTabs.Contains(pt) ) { if ( flags ) { // TODO: be more precise - *flags = wxNB_HITTEST_ONITEM; + *flags = wxBK_HITTEST_ONITEM; } return n; @@ -658,21 +676,21 @@ bool wxNotebook::IsVertical() const wxDirection wxNotebook::GetTabOrientation() const { long style = GetWindowStyle(); - if ( style & wxNB_BOTTOM ) + if ( style & wxBK_BOTTOM ) return wxBOTTOM; - else if ( style & wxNB_RIGHT ) + else if ( style & wxBK_RIGHT ) return wxRIGHT; - else if ( style & wxNB_LEFT ) + else if ( style & wxBK_LEFT ) return wxLEFT; - // wxNB_TOP == 0 so we don't have to test for it + // wxBK_TOP == 0 so we don't have to test for it return wxTOP; } wxRect wxNotebook::GetTabRect(int page) const { wxRect rect; - wxCHECK_MSG( IS_VALID_PAGE(page), rect, _T("invalid notebook page") ); + wxCHECK_MSG( IS_VALID_PAGE(page), rect, wxT("invalid notebook page") ); // calc the size of this tab and of the preceding ones wxCoord widthThis, widthBefore; @@ -775,7 +793,7 @@ wxRect wxNotebook::GetTabsPart() const void wxNotebook::GetTabSize(int page, wxCoord *w, wxCoord *h) const { - wxCHECK_RET( w && h, _T("NULL pointer in GetTabSize") ); + wxCHECK_RET( w && h, wxT("NULL pointer in GetTabSize") ); if ( IsVertical() ) { @@ -794,7 +812,7 @@ void wxNotebook::GetTabSize(int page, wxCoord *w, wxCoord *h) const void wxNotebook::SetTabSize(const wxSize& sz) { - wxCHECK_RET( FixedSizeTabs(), _T("SetTabSize() ignored") ); + wxCHECK_RET( FixedSizeTabs(), wxT("SetTabSize() ignored") ); if ( IsVertical() ) { @@ -815,7 +833,7 @@ wxSize wxNotebook::CalcTabSize(int page) const wxSize size; - wxCHECK_MSG( IS_VALID_PAGE(page), size, _T("invalid notebook page") ); + wxCHECK_MSG( IS_VALID_PAGE(page), size, wxT("invalid notebook page") ); GetTextExtent(m_titles[page], &size.x, &size.y); @@ -1156,7 +1174,7 @@ void wxNotebook::PositionSpinBtn() switch ( GetTabOrientation() ) { default: - wxFAIL_MSG(_T("unknown tab orientation")); + wxFAIL_MSG(wxT("unknown tab orientation")); // fall through case wxTOP: @@ -1189,7 +1207,7 @@ void wxNotebook::PositionSpinBtn() void wxNotebook::ScrollTo(int page) { - wxCHECK_RET( IS_VALID_PAGE(page), _T("invalid notebook page") ); + wxCHECK_RET( IS_VALID_PAGE(page), wxT("invalid notebook page") ); // set the first visible tab and offset (easy) m_firstVisible = (size_t)page; @@ -1207,7 +1225,7 @@ void wxNotebook::ScrollTo(int page) void wxNotebook::ScrollLastTo(int page) { - wxCHECK_RET( IS_VALID_PAGE(page), _T("invalid notebook page") ); + wxCHECK_RET( IS_VALID_PAGE(page), wxT("invalid notebook page") ); // go backwards until we find the first tab which can be made visible // without hiding the given one @@ -1243,7 +1261,7 @@ void wxNotebook::ScrollLastTo(int page) ScrollTo(m_firstVisible); // consitency check: the page we were asked to show should be shown - wxASSERT_MSG( (size_t)page < m_lastVisible, _T("bug in ScrollLastTo") ); + wxASSERT_MSG( (size_t)page < m_lastVisible, wxT("bug in ScrollLastTo") ); } // ---------------------------------------------------------------------------- @@ -1320,6 +1338,14 @@ bool wxNotebook::PerformAction(const wxControlAction& action, return true; } +/* static */ +wxInputHandler *wxNotebook::GetStdInputHandler(wxInputHandler *handlerDef) +{ + static wxStdNotebookInputHandler s_handler(handlerDef); + + return &s_handler; +} + // ---------------------------------------------------------------------------- // wxStdNotebookInputHandler // ---------------------------------------------------------------------------- @@ -1431,4 +1457,3 @@ void wxStdNotebookInputHandler::HandleFocusChange(wxInputConsumer *consumer) } #endif // wxUSE_NOTEBOOK -