X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a85c15521738cd2951153c3bbab36b6f272bef1e..94e2ed3b8db0220160c0b939782cd46914ec073a:/src/generic/scrlwing.cpp?ds=inline diff --git a/src/generic/scrlwing.cpp b/src/generic/scrlwing.cpp index ff58945bf8..ce07d296b2 100644 --- a/src/generic/scrlwing.cpp +++ b/src/generic/scrlwing.cpp @@ -167,6 +167,13 @@ void wxAutoScrollTimer::Notify() bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event) { + wxEventType evType = event.GetEventType(); + + if ( evType == wxEVT_SIZE ) + { + m_scrollHelper->HandleOnSize((wxSizeEvent &)event); + } + if ( wxEvtHandler::ProcessEvent(event) ) return TRUE; @@ -174,8 +181,6 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event) // ProcessEvent() above event.Skip(FALSE); - wxEventType evType = event.GetEventType(); - if ( evType == wxEVT_PAINT ) { m_scrollHelper->HandleOnPaint((wxPaintEvent &)event); @@ -209,10 +214,6 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event) m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event); } #endif // wxUSE_MOUSEWHEEL - else if ( evType == wxEVT_SIZE ) - { - m_scrollHelper->HandleOnSize((wxSizeEvent &)event); - } else if ( evType == wxEVT_CHAR ) { m_scrollHelper->HandleOnChar((wxKeyEvent &)event); @@ -272,6 +273,8 @@ wxScrollHelper::~wxScrollHelper() if ( m_targetWindow ) m_targetWindow->PopEventHandler(TRUE /* do delete it */); + if ( m_win && m_win != m_targetWindow) + m_win->PopEventHandler(TRUE /* do delete it */); } // ---------------------------------------------------------------------------- @@ -357,7 +360,17 @@ void wxScrollHelper::SetScrollbars(int pixelsPerUnitX, void wxScrollHelper::SetTargetWindow( wxWindow *target ) { wxASSERT_MSG( target, wxT("target window must not be NULL") ); + // FIXME: There is a potential problem with this way of deleting + // event handlers, basically you can not be sure that you delete + // the event handler that was create by this wxScrollHelper. + // Remove the old event handler from the previous target scroll window. + if (m_targetWindow && m_targetWindow != m_win) + m_targetWindow->PopEventHandler(TRUE /* Delete old event handler*/); m_targetWindow = target; + // Install a new event handler, which will intercept the events we're + // interested in from the target scroll window. + if (m_targetWindow != m_win) + m_targetWindow->PushEventHandler(new wxScrollHelperEvtHandler(this)); } wxWindow *wxScrollHelper::GetTargetWindow() const @@ -977,9 +990,24 @@ void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event) { lines *= event.GetLinesPerAction(); - int vsx, vsy; - GetViewStart(&vsx, &vsy); - Scroll(-1, vsy - lines); + wxScrollWinEvent newEvent; + + newEvent.SetPosition(0); + newEvent.SetOrientation(wxVERTICAL); + newEvent.m_eventObject = m_win; + if (lines > 0) + newEvent.m_eventType = wxEVT_SCROLLWIN_LINEUP; + else + newEvent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; + + int times = abs(lines); + for (; times > 0; times --) + m_win->GetEventHandler()->ProcessEvent(newEvent); + + /* Old Way */ + // int vsx, vsy; + // GetViewStart(&vsx, &vsy); + // Scroll(-1, vsy - lines); } }