X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/14f355c2b5c71fc7c3d680aea366582d2ac60f7b..d51aa8d87ba31181fb51afc507f83ac5240d8147:/src/univ/notebook.cpp diff --git a/src/univ/notebook.cpp b/src/univ/notebook.cpp index 26916b958d..392f13c4aa 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,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "univnotebook.h" -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ @@ -29,18 +25,50 @@ #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 // ---------------------------------------------------------------------------- -#define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount())) +#if 0 +// due to unsigned type nPage is always >= 0 +#define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((size_t(nPage)) < GetPageCount())) +#else +#define IS_VALID_PAGE(nPage) (((size_t)nPage) < GetPageCount()) +#endif // ---------------------------------------------------------------------------- // constants @@ -59,7 +87,7 @@ class wxNotebookSpinBtn : public wxSpinButton { public: wxNotebookSpinBtn(wxNotebook *nb) - : wxSpinButton(nb, -1, + : wxSpinButton(nb, wxID_ANY, wxDefaultPosition, wxDefaultSize, nb->IsVertical() ? wxSP_VERTICAL : wxSP_HORIZONTAL) { @@ -79,7 +107,7 @@ private: }; BEGIN_EVENT_TABLE(wxNotebookSpinBtn, wxSpinButton) - EVT_SPIN(-1, wxNotebookSpinBtn::OnSpin) + EVT_SPIN(wxID_ANY, wxNotebookSpinBtn::OnSpin) END_EVENT_TABLE() // ============================================================================ @@ -116,33 +144,36 @@ 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; + return false; m_sizePad = GetRenderer()->GetTabPadding(); - SetBestSize(size); + SetInitialSize(size); CreateInputHandler(wxINP_HANDLER_NOTEBOOK); - return TRUE; + return true; } // ---------------------------------------------------------------------------- // wxNotebook page titles and images // ---------------------------------------------------------------------------- -wxString wxNotebook::GetPageText(int nPage) const +wxString wxNotebook::GetPageText(size_t nPage) const { - wxCHECK_MSG( IS_VALID_PAGE(nPage), _T(""), _T("invalid notebook page") ); + wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, _T("invalid notebook page") ); return m_titles[nPage]; } -bool wxNotebook::SetPageText(int nPage, const wxString& strText) +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, _T("invalid notebook page") ); if ( strText != m_titles[nPage] ) { @@ -160,21 +191,21 @@ bool wxNotebook::SetPageText(int nPage, const wxString& strText) } } - return TRUE; + return true; } -int wxNotebook::GetPageImage(int nPage) const +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, _T("invalid notebook page") ); return m_images[nPage]; } -bool wxNotebook::SetPageImage(int nPage, int nImage) +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, _T("invalid notebook page") ); - wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), FALSE, + wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), false, _T("invalid image index in SetPageImage()") ); if ( nImage != m_images[nPage] ) @@ -191,7 +222,7 @@ bool wxNotebook::SetPageImage(int nPage, int nImage) RefreshTab(nPage); } - return TRUE; + return true; } wxNotebook::~wxNotebook() @@ -202,9 +233,9 @@ wxNotebook::~wxNotebook() // wxNotebook page switching // ---------------------------------------------------------------------------- -int wxNotebook::SetSelection(int 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, _T("invalid notebook page") ); if ( (size_t)nPage == m_sel ) { @@ -212,15 +243,13 @@ int wxNotebook::SetSelection(int 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 @@ -233,7 +262,7 @@ int wxNotebook::SetSelection(int nPage) if ( selOld != INVALID_PAGE ) { - RefreshTab(selOld, TRUE /* this tab was selected */); + RefreshTab(selOld, true /* this tab was selected */); m_pages[selOld]->Hide(); } @@ -266,9 +295,11 @@ int wxNotebook::SetSelection(int 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; } @@ -277,14 +308,14 @@ int wxNotebook::SetSelection(int nPage) // wxNotebook pages adding/deleting // ---------------------------------------------------------------------------- -bool wxNotebook::InsertPage(int nPage, +bool wxNotebook::InsertPage(size_t nPage, wxNotebookPage *pPage, const wxString& strText, bool bSelect, int imageId) { - int nPages = GetPageCount(); - wxCHECK_MSG( nPage == nPages || IS_VALID_PAGE(nPage), FALSE, + size_t nPages = GetPageCount(); + wxCHECK_MSG( nPage == nPages || IS_VALID_PAGE(nPage), false, _T("invalid notebook page in InsertPage()") ); // modify the data @@ -316,7 +347,7 @@ bool wxNotebook::InsertPage(int nPage, if ( nPages == 0 ) { // always select the first tab to have at least some selection - bSelect = TRUE; + bSelect = true; Relayout(); Refresh(); @@ -335,13 +366,13 @@ bool wxNotebook::InsertPage(int nPage, pPage->Hide(); } - return TRUE; + return true; } bool wxNotebook::DeleteAllPages() { if ( !wxNotebookBase::DeleteAllPages() ) - return FALSE; + return false; // clear the other arrays as well m_titles.Clear(); @@ -357,10 +388,10 @@ bool wxNotebook::DeleteAllPages() Relayout(); - return TRUE; + return true; } -wxNotebookPage *wxNotebook::DoRemovePage(int nPage) +wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, _T("invalid notebook page") ); @@ -381,7 +412,7 @@ wxNotebookPage *wxNotebook::DoRemovePage(int nPage) UpdateSpinBtn(); } - int count = GetPageCount(); + size_t count = GetPageCount(); if ( count ) { if ( m_sel == (size_t)nPage ) @@ -461,10 +492,10 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n) wxMemoryDC dc; dc.SelectObject(bmp); dc.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID)); - m_imageList->Draw(image, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL, TRUE); + 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 } @@ -577,10 +608,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; } @@ -618,12 +649,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; @@ -649,14 +680,14 @@ 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; } @@ -736,8 +767,16 @@ wxRect wxNotebook::GetTabsPart() const const wxSize indent = GetRenderer()->GetTabIndent(); if ( IsVertical() ) { - rect.x += indent.y; rect.y += indent.x; + if ( dir == wxLEFT ) + { + rect.x += indent.y; + rect.width -= indent.y; + } + else // wxRIGHT + { + rect.width -= indent.y; + } } else // horz { @@ -824,7 +863,7 @@ void wxNotebook::ResizeTab(int page) wxSize sizeTab = CalcTabSize(page); // we only need full relayout if the page size changes - bool needsRelayout = FALSE; + bool needsRelayout = false; if ( IsVertical() ) { @@ -836,7 +875,7 @@ void wxNotebook::ResizeTab(int page) if ( sizeTab.y > m_heightTab ) { - needsRelayout = TRUE; + needsRelayout = true; m_heightTab = sizeTab.y; } @@ -1062,7 +1101,7 @@ void wxNotebook::UpdateSpinBtn() { // this case is special, get rid of it immediately: everything is // visible and we don't need any spin buttons - allTabsShown = TRUE; + allTabsShown = true; // have to reset them manually as we don't call CalcLastVisibleTab() m_firstVisible = @@ -1118,7 +1157,7 @@ void wxNotebook::UpdateSpinBtn() } else // all tabs are visible, we don't need spin button { - if ( m_spinbtn ) + if ( m_spinbtn && m_spinbtn -> IsShown() ) { m_spinbtn->Hide(); } @@ -1236,7 +1275,7 @@ void wxNotebook::ScrollLastTo(int page) wxSize wxNotebook::DoGetBestClientSize() const { // calculate the max page size - wxSize size(0, 0); + wxSize size; size_t count = GetPageCount(); if ( count ) @@ -1276,9 +1315,9 @@ void wxNotebook::DoSetSize(int x, int y, wxSize old_client_size = GetClientSize(); wxControl::DoSetSize(x, y, width, height, sizeFlags); - + wxSize new_client_size = GetClientSize(); - + if (old_client_size != new_client_size) Relayout(); } @@ -1292,15 +1331,23 @@ bool wxNotebook::PerformAction(const wxControlAction& action, const wxString& strArg) { if ( action == wxACTION_NOTEBOOK_NEXT ) - SetSelection(GetNextPage(TRUE)); + SetSelection(GetNextPage(true)); else if ( action == wxACTION_NOTEBOOK_PREV ) - SetSelection(GetNextPage(FALSE)); + SetSelection(GetNextPage(false)); else if ( action == wxACTION_NOTEBOOK_GOTO ) SetSelection((int)numArg); else return wxControl::PerformAction(action, numArg, strArg); - return TRUE; + return true; +} + +/* static */ +wxInputHandler *wxNotebook::GetStdInputHandler(wxInputHandler *handlerDef) +{ + static wxStdNotebookInputHandler s_handler(handlerDef); + + return &s_handler; } // ---------------------------------------------------------------------------- @@ -1356,7 +1403,7 @@ bool wxStdNotebookInputHandler::HandleKey(wxInputConsumer *consumer, break; } - if ( !!action ) + if ( !action.IsEmpty() ) { return consumer->PerformAction(action, page); } @@ -1376,7 +1423,7 @@ bool wxStdNotebookInputHandler::HandleMouse(wxInputConsumer *consumer, { consumer->PerformAction(wxACTION_NOTEBOOK_GOTO, page); - return FALSE; + return false; } } @@ -1395,7 +1442,7 @@ wxStdNotebookInputHandler::HandleFocus(wxInputConsumer *consumer, { HandleFocusChange(consumer); - return FALSE; + return false; } bool wxStdNotebookInputHandler::HandleActivation(wxInputConsumer *consumer, @@ -1404,7 +1451,7 @@ bool wxStdNotebookInputHandler::HandleActivation(wxInputConsumer *consumer, // we react to the focus change in the same way as to the [de]activation HandleFocusChange(consumer); - return FALSE; + return false; } void wxStdNotebookInputHandler::HandleFocusChange(wxInputConsumer *consumer) @@ -1414,4 +1461,3 @@ void wxStdNotebookInputHandler::HandleFocusChange(wxInputConsumer *consumer) } #endif // wxUSE_NOTEBOOK -