X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/71908213057690d5452f72b2b9c8e62b53357170..894d74dcc233b7f9a936767558f3e061593dd062:/src/univ/notebook.cpp diff --git a/src/univ/notebook.cpp b/src/univ/notebook.cpp index f5757e953b..8326d62016 100644 --- a/src/univ/notebook.cpp +++ b/src/univ/notebook.cpp @@ -17,8 +17,12 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "notebook.h" +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) + #pragma implementation "univnotebook.h" +#endif + +#ifdef __VMS +#pragma message disable unscomzer #endif #include "wx/wxprec.h" @@ -40,7 +44,12 @@ // 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 +68,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 +88,7 @@ private: }; BEGIN_EVENT_TABLE(wxNotebookSpinBtn, wxSpinButton) - EVT_SPIN(-1, wxNotebookSpinBtn::OnSpin) + EVT_SPIN(wxID_ANY, wxNotebookSpinBtn::OnSpin) END_EVENT_TABLE() // ============================================================================ @@ -118,7 +127,7 @@ bool wxNotebook::Create(wxWindow *parent, { if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) - return FALSE; + return false; m_sizePad = GetRenderer()->GetTabPadding(); @@ -126,23 +135,23 @@ bool wxNotebook::Create(wxWindow *parent, 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 +169,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") ); 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 +200,7 @@ bool wxNotebook::SetPageImage(int nPage, int nImage) RefreshTab(nPage); } - return TRUE; + return true; } wxNotebook::~wxNotebook() @@ -202,7 +211,7 @@ wxNotebook::~wxNotebook() // wxNotebook page switching // ---------------------------------------------------------------------------- -int wxNotebook::SetSelection(int nPage) +int wxNotebook::SetSelection(size_t nPage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") ); @@ -212,15 +221,32 @@ int wxNotebook::SetSelection(int nPage) return m_sel; } - if ( m_sel != INVALID_PAGE ) + // 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() ) { - RefreshTab(m_sel); - - m_pages[m_sel]->Hide(); + // program doesn't allow the page change + return m_sel; } + // we need to change m_sel first, before calling RefreshTab() below as + // otherwise the previously selected tab wouldn't be redrawn properly under + // wxGTK which calls Refresh() immediately and not during the next event + // loop iteration as wxMSW does and as it should + size_t selOld = m_sel; + m_sel = nPage; + if ( selOld != INVALID_PAGE ) + { + RefreshTab(selOld, true /* this tab was selected */); + + m_pages[selOld]->Hide(); + } + if ( m_sel != INVALID_PAGE ) // this is impossible - but test nevertheless { if ( HasSpinBtn() ) @@ -249,47 +275,25 @@ int wxNotebook::SetSelection(int nPage) m_pages[m_sel]->Show(); } - return m_sel; -} - -void wxNotebook::ChangePage(int nPage) -{ - wxCHECK_RET( IS_VALID_PAGE(nPage), _T("invalid notebook page") ); - - if ( (size_t)nPage == m_sel ) - { - // nothing to do - return; - } - - 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() ) - { - // program doesn't allow the page change - return; - } - - SetSelection(nPage); - + // event handling event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); GetEventHandler()->ProcessEvent(event); + + return selOld; } // ---------------------------------------------------------------------------- // 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 @@ -321,9 +325,10 @@ 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(); } else // not the first tab { @@ -339,13 +344,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(); @@ -361,10 +366,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") ); @@ -376,12 +381,16 @@ wxNotebookPage *wxNotebook::DoRemovePage(int nPage) m_images.RemoveAt(nPage); // the spin button might not be needed any more - if ( HasSpinBtn() ) + // 2002-08-12 'if' commented out by JACS on behalf + // of Hans Van Leemputten who + // points out that UpdateSpinBtn should always be called, + // to ensure m_lastVisible is up to date. + // if ( HasSpinBtn() ) { UpdateSpinBtn(); } - int count = GetPageCount(); + size_t count = GetPageCount(); if ( count ) { if ( m_sel == (size_t)nPage ) @@ -421,12 +430,12 @@ void wxNotebook::RefreshCurrent() } } -void wxNotebook::RefreshTab(int page) +void wxNotebook::RefreshTab(int page, bool forceSelected) { wxCHECK_RET( IS_VALID_PAGE(page), _T("invalid notebook page") ); wxRect rect = GetTabRect(page); - if ( (size_t)page == m_sel ) + if ( forceSelected || ((size_t)page == m_sel) ) { const wxSize indent = GetRenderer()->GetTabIndent(); rect.Inflate(indent.x, indent.y); @@ -452,16 +461,19 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n) { int image = m_images[n]; -#ifdef __WXMSW__ // FIXME + // Not needed now that wxGenericImageList is being + // used for wxUniversal under MSW +#if 0 // def __WXMSW__ // FIXME int w, h; m_imageList->GetSize(n, w, h); bmp.Create(w, h); 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 } @@ -505,10 +517,20 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer) wxSize sizeSpinBtn = m_spinbtn->GetSize(); if ( IsVertical() ) + { rectTabs.height -= sizeSpinBtn.y; + + // Allow for erasing the line under selected tab + rectTabs.width += 2; + } else + { rectTabs.width -= sizeSpinBtn.x; + // Allow for erasing the line under selected tab + rectTabs.height += 2; + } + dc.SetClippingRegion(rectTabs); } @@ -553,14 +575,19 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer) { DoDrawTab(dc, rectSel, m_sel); } + + dc.DestroyClippingRegion(); } // ---------------------------------------------------------------------------- // wxNotebook geometry // ---------------------------------------------------------------------------- -int wxNotebook::HitTest(const wxPoint& pt) const +int wxNotebook::HitTest(const wxPoint& pt, long *flags) const { + if ( flags ) + *flags = wxNB_HITTEST_NOWHERE; + // first check that it is in this window at all if ( !GetClientRect().Inside(pt) ) { @@ -601,7 +628,15 @@ int wxNotebook::HitTest(const wxPoint& pt) const GetTabSize(n, &rectTabs.width, &rectTabs.height); if ( rectTabs.Inside(pt) ) + { + if ( flags ) + { + // TODO: be more precise + *flags = wxNB_HITTEST_ONITEM; + } + return n; + } // move the rectTabs to the next tab if ( IsVertical() ) @@ -710,8 +745,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 { @@ -798,7 +841,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() ) { @@ -810,7 +853,7 @@ void wxNotebook::ResizeTab(int page) if ( sizeTab.y > m_heightTab ) { - needsRelayout = TRUE; + needsRelayout = true; m_heightTab = sizeTab.y; } @@ -936,7 +979,7 @@ void wxNotebook::SetPageSize(const wxSize& size) SetClientSize(GetSizeForPage(size)); } -wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) +wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const { return AdjustSize(GetSizeForPage(sizePage)); } @@ -1036,7 +1079,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 = @@ -1092,7 +1135,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(); } @@ -1210,7 +1253,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 ) @@ -1247,9 +1290,14 @@ void wxNotebook::DoSetSize(int x, int y, int width, int height, int sizeFlags) { + wxSize old_client_size = GetClientSize(); + wxControl::DoSetSize(x, y, width, height, sizeFlags); - Relayout(); + wxSize new_client_size = GetClientSize(); + + if (old_client_size != new_client_size) + Relayout(); } // ---------------------------------------------------------------------------- @@ -1261,15 +1309,15 @@ bool wxNotebook::PerformAction(const wxControlAction& action, const wxString& strArg) { if ( action == wxACTION_NOTEBOOK_NEXT ) - ChangePage(GetNextPage(TRUE)); + SetSelection(GetNextPage(true)); else if ( action == wxACTION_NOTEBOOK_PREV ) - ChangePage(GetNextPage(FALSE)); + SetSelection(GetNextPage(false)); else if ( action == wxACTION_NOTEBOOK_GOTO ) - ChangePage((int)numArg); + SetSelection((int)numArg); else return wxControl::PerformAction(action, numArg, strArg); - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -1281,14 +1329,14 @@ wxStdNotebookInputHandler::wxStdNotebookInputHandler(wxInputHandler *inphand) { } -bool wxStdNotebookInputHandler::HandleKey(wxControl *control, +bool wxStdNotebookInputHandler::HandleKey(wxInputConsumer *consumer, const wxKeyEvent& event, bool pressed) { // ignore the key releases if ( pressed ) { - wxNotebook *notebook = wxStaticCast(control, wxNotebook); + wxNotebook *notebook = wxStaticCast(consumer->GetInputWindow(), wxNotebook); int page = 0; wxControlAction action; @@ -1325,59 +1373,60 @@ bool wxStdNotebookInputHandler::HandleKey(wxControl *control, break; } - if ( !!action ) + if ( !action.IsEmpty() ) { - return control->PerformAction(action, page); + return consumer->PerformAction(action, page); } } - return wxStdInputHandler::HandleKey(control, event, pressed); + return wxStdInputHandler::HandleKey(consumer, event, pressed); } -bool wxStdNotebookInputHandler::HandleMouse(wxControl *control, +bool wxStdNotebookInputHandler::HandleMouse(wxInputConsumer *consumer, const wxMouseEvent& event) { if ( event.ButtonDown(1) ) { - wxNotebook *notebook = wxStaticCast(control, wxNotebook); + wxNotebook *notebook = wxStaticCast(consumer->GetInputWindow(), wxNotebook); int page = notebook->HitTest(event.GetPosition()); if ( page != -1 ) { - control->PerformAction(wxACTION_NOTEBOOK_GOTO, page); + consumer->PerformAction(wxACTION_NOTEBOOK_GOTO, page); - return FALSE; + return false; } } - return wxStdInputHandler::HandleMouse(control, event); + return wxStdInputHandler::HandleMouse(consumer, event); } -bool wxStdNotebookInputHandler::HandleMouseMove(wxControl *control, +bool wxStdNotebookInputHandler::HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event) { - return wxStdInputHandler::HandleMouseMove(control, event); + return wxStdInputHandler::HandleMouseMove(consumer, event); } -bool wxStdNotebookInputHandler::HandleFocus(wxControl *control, - const wxFocusEvent& event) +bool +wxStdNotebookInputHandler::HandleFocus(wxInputConsumer *consumer, + const wxFocusEvent& WXUNUSED(event)) { - HandleFocusChange(control); + HandleFocusChange(consumer); - return FALSE; + return false; } -bool wxStdNotebookInputHandler::HandleActivation(wxControl *control, +bool wxStdNotebookInputHandler::HandleActivation(wxInputConsumer *consumer, bool WXUNUSED(activated)) { // we react to the focus change in the same way as to the [de]activation - HandleFocusChange(control); + HandleFocusChange(consumer); - return FALSE; + return false; } -void wxStdNotebookInputHandler::HandleFocusChange(wxControl *control) +void wxStdNotebookInputHandler::HandleFocusChange(wxInputConsumer *consumer) { - wxNotebook *notebook = wxStaticCast(control, wxNotebook); + wxNotebook *notebook = wxStaticCast(consumer->GetInputWindow(), wxNotebook); notebook->RefreshCurrent(); }