X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7d0cf3f9be68172d67ed1e82975ea5f080989a33..e8481866872d3eec6e0ce1fa7eab856abff26c34:/src/generic/vscroll.cpp diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index 0572b8e07b..efbef67e33 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -4,7 +4,6 @@ // Author: Vadim Zeitlin // Modified by: Brad Anderson, David Warkentin // Created: 30.05.03 -// RCS-ID: $Id$ // Copyright: (c) 2003 Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -62,12 +61,20 @@ private: // wxVarScrollHelperEvtHandler implementation // ============================================================================ +// FIXME: This method totally duplicates a method with the same name in +// wxScrollHelperEvtHandler, we really should merge them by reusing the +// common parts in wxAnyScrollHelperBase. bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event) { wxEventType evType = event.GetEventType(); - // pass it on to the real handler - bool processed = wxEvtHandler::ProcessEvent(event); + // Pass it on to the real handler: notice that we must not call + // ProcessEvent() on this object itself as it wouldn't pass it to the next + // handler (i.e. the real window) if we're called from a previous handler + // (as indicated by "process here only" flag being set) and we do want to + // execute the handler defined in the window we're associated with right + // now, without waiting until TryAfter() is called from wxEvtHandler. + bool processed = m_nextHandler->ProcessEvent(event); // always process the size events ourselves, even if the user code handles // them as well, as we need to AdjustScrollbars() @@ -79,18 +86,28 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event) if ( evType == wxEVT_SIZE ) { m_scrollHelper->HandleOnSize((wxSizeEvent &)event); - - return !event.GetSkipped(); + return true; } - if ( processed ) + if ( processed && event.IsCommandEvent()) + return true; + + // For wxEVT_PAINT the user code can either handle this event as usual or + // override virtual OnDraw(), so if the event hasn't been handled we need + // to call this virtual function ourselves. + if ( +#ifndef __WXUNIVERSAL__ + // in wxUniversal "processed" will always be true, because + // all windows use the paint event to draw themselves. + // In this case we can't use this flag to determine if a custom + // paint event handler already drew our window and we just + // call OnDraw() anyway. + !processed && +#endif // !__WXUNIVERSAL__ + evType == wxEVT_PAINT ) { - // normally, nothing more to do here - except if we have a command - // event - if ( event.IsCommandEvent() ) - { - return true; - } + m_scrollHelper->HandleOnPaint((wxPaintEvent &)event); + return true; } // reset the skipped flag (which might have been set to true in @@ -113,20 +130,45 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event) { // it makes sense to indicate that we processed the message as we // did scroll the window (and also notice that wxAutoScrollTimer - // relies on our return value for continuous scrolling) + // relies on our return value to stop scrolling when we are at top + // or bottom already) processed = true; wasSkipped = false; } } #if wxUSE_MOUSEWHEEL + // Use GTK's own scroll wheel handling in GtkScrolledWindow +#ifndef __WXGTK20__ else if ( evType == wxEVT_MOUSEWHEEL ) { m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event); } +#endif #endif // wxUSE_MOUSEWHEEL + else if ( evType == wxEVT_CHAR && + (m_scrollHelper->GetOrientation() == wxVERTICAL) ) + { + m_scrollHelper->HandleOnChar((wxKeyEvent &)event); + if ( !event.GetSkipped() ) + { + processed = true; + wasSkipped = false; + } + } event.Skip(wasSkipped); + // We called ProcessEvent() on the next handler, meaning that we explicitly + // worked around the request to process the event in this handler only. As + // explained above, this is unfortunately really necessary but the trouble + // is that the event will continue to be post-processed by the previous + // handler resulting in duplicate calls to event handlers. Call the special + // function below to prevent this from happening, base class DoTryChain() + // will check for it and behave accordingly. + // + // And if we're not called from DoTryChain(), this won't do anything anyhow. + event.DidntHonourProcessOnlyIn(); + return processed; } @@ -140,9 +182,8 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event) // ---------------------------------------------------------------------------- wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win) + : wxAnyScrollHelperBase(win) { - wxASSERT_MSG( win, wxT("associated window can't be NULL in wxVarScrollHelperBase") ); - #if wxUSE_MOUSEWHEEL m_sumWheelRotation = 0; #endif @@ -151,17 +192,11 @@ wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win) m_sizeTotal = 0; m_unitFirst = 0; - m_win = - m_targetWindow = NULL; - m_physicalScrolling = true; m_handler = NULL; - m_win = win; - // by default, the associated window is also the target window DoSetTargetWindow(win); - } wxVarScrollHelperBase::~wxVarScrollHelperBase() @@ -487,10 +522,10 @@ void wxVarScrollHelperBase::RefreshUnits(size_t from, size_t to) to = GetVisibleEnd(); // calculate the rect occupied by these units on screen - int orient_size, nonorient_size, orient_pos; - orient_size = nonorient_size = orient_pos = 0; + int orient_size = 0, + orient_pos = 0; - nonorient_size = GetNonOrientationTargetSize(); + int nonorient_size = GetNonOrientationTargetSize(); for ( size_t nBefore = GetVisibleBegin(); nBefore < from;