X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8cb172b4f12fae80b06d5936108a1bc7f2521674..05e3a383e0bff29b830f91b6b40e63a3b1a3e72f:/src/univ/notebook.cpp?ds=sidebyside diff --git a/src/univ/notebook.cpp b/src/univ/notebook.cpp index 852d926621..5865b1baf4 100644 --- a/src/univ/notebook.cpp +++ b/src/univ/notebook.cpp @@ -5,7 +5,7 @@ // Modified by: // Created: 01.02.01 // RCS-ID: $Id$ -// Copyright: (c) 2001 Vadim Zeitlin +// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -212,15 +212,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,33 +266,11 @@ 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; } // ---------------------------------------------------------------------------- @@ -324,6 +319,7 @@ bool wxNotebook::InsertPage(int nPage, bSelect = TRUE; Relayout(); + Refresh(); } else // not the first tab { @@ -376,7 +372,11 @@ 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(); } @@ -421,12 +421,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,7 +452,9 @@ 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); @@ -460,6 +462,7 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n) dc.SelectObject(bmp); dc.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID)); m_imageList->Draw(image, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL, TRUE); + dc.SelectObject(wxNullBitmap); #else bmp = *m_imageList->GetBitmap(image); #endif @@ -505,10 +508,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 +566,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 +619,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() ) @@ -936,7 +962,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)); } @@ -1247,9 +1273,14 @@ void wxNotebook::DoSetSize(int x, int y, int width, int height, int sizeFlags) { - wxControl::DoSetSize(x, y, width, height, sizeFlags); + wxSize old_client_size = GetClientSize(); - Relayout(); + wxControl::DoSetSize(x, y, width, height, sizeFlags); + + wxSize new_client_size = GetClientSize(); + + if (old_client_size != new_client_size) + Relayout(); } // ---------------------------------------------------------------------------- @@ -1261,11 +1292,11 @@ 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); @@ -1281,14 +1312,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; @@ -1327,57 +1358,57 @@ bool wxStdNotebookInputHandler::HandleKey(wxControl *control, if ( !!action ) { - 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 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, +bool wxStdNotebookInputHandler::HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event) { - HandleFocusChange(control); + HandleFocusChange(consumer); 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; } -void wxStdNotebookInputHandler::HandleFocusChange(wxControl *control) +void wxStdNotebookInputHandler::HandleFocusChange(wxInputConsumer *consumer) { - wxNotebook *notebook = wxStaticCast(control, wxNotebook); + wxNotebook *notebook = wxStaticCast(consumer->GetInputWindow(), wxNotebook); notebook->RefreshCurrent(); }