From 4ca30c7d65acbe5db364ab85753e06cc2aad63ae Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 10 Nov 2012 00:53:17 +0000 Subject: [PATCH] Simplify wxEVT_PAINT handling in wxScrollHelperBase. Just always call the virtual OnDraw() if wxEVT_PAINT wasn't handled. This is much simpler than connecting our own special handler just to set a flag saying whether the event was processed which was very complicated and didn't work anyhow for the statically connected wxEVT_PAINT handlers. See #14757. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72939 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/scrolwin.h | 16 ------------ src/generic/scrlwing.cpp | 55 +++++++++++----------------------------- 2 files changed, 15 insertions(+), 56 deletions(-) diff --git a/include/wx/scrolwin.h b/include/wx/scrolwin.h index 53883f2ae2..c4bd4dfa93 100644 --- a/include/wx/scrolwin.h +++ b/include/wx/scrolwin.h @@ -252,10 +252,6 @@ protected: // delete the event handler we installed void DeleteEvtHandler(); - // calls wxScrollHelperEvtHandler::ResetDrawnFlag(), see explanation - // in wxScrollHelperEvtHandler::ProcessEvent() - void ResetDrawnFlag(); - // this function should be overridden to return the size available for // m_targetWindow inside m_win of the given size // @@ -376,8 +372,6 @@ public: this->MacSetClipChildren(true); #endif - this->Connect(wxEVT_PAINT, wxPaintEventHandler(wxScrolled::OnPaint)); - // by default, we're scrollable in both directions (but if one of the // styles is specified explicitly, we shouldn't add the other one // automatically) @@ -408,16 +402,6 @@ protected: } private: - // this is needed for wxEVT_PAINT processing hack described in - // wxScrollHelperEvtHandler::ProcessEvent() - void OnPaint(wxPaintEvent& event) - { - // the user code didn't really draw the window if we got here, so set - // this flag to try to call OnDraw() later - ResetDrawnFlag(); - event.Skip(); - } - // VC++ 6 gives warning for the declaration of template member function // without definition #ifndef __VISUALC6__ diff --git a/src/generic/scrlwing.cpp b/src/generic/scrlwing.cpp index 7f77aa8f0b..200608475c 100644 --- a/src/generic/scrlwing.cpp +++ b/src/generic/scrlwing.cpp @@ -79,13 +79,9 @@ public: virtual bool ProcessEvent(wxEvent& event); - void ResetDrawnFlag() { m_hasDrawnWindow = false; } - private: wxScrollHelperBase *m_scrollHelper; - bool m_hasDrawnWindow; - wxDECLARE_NO_COPY_CLASS(wxScrollHelperEvtHandler); }; @@ -186,24 +182,6 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event) { wxEventType evType = event.GetEventType(); - // the explanation of wxEVT_PAINT processing hack: for historic reasons - // there are 2 ways to process this event in classes deriving from - // wxScrolledWindow. The user code may - // - // 1. override wxScrolledWindow::OnDraw(dc) - // 2. define its own OnPaint() handler - // - // In addition, in wxUniversal wxWindow defines OnPaint() itself and - // always processes the draw event, so we can't just try the window - // OnPaint() first and call our HandleOnPaint() if it doesn't process it - // (the latter would never be called in wxUniversal). - // - // So the solution is to have a flag telling us whether the user code drew - // anything in the window. We set it to true here but reset it to false in - // wxScrolledWindow::OnPaint() handler (which wouldn't be called if the - // user code defined OnPaint() in the derived class) - m_hasDrawnWindow = true; - // 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 @@ -222,22 +200,25 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event) if ( evType == wxEVT_SIZE ) { m_scrollHelper->HandleOnSize((wxSizeEvent &)event); - return true; } - if ( processed ) - { - // normally, nothing more to do here - except if it was a paint event - // which wasn't really processed, then we'll try to call our - // OnDraw() below (from HandleOnPaint) - if ( m_hasDrawnWindow || event.IsCommandEvent() ) - { - return true; - } - } + if ( processed && event.IsCommandEvent()) + return true; - if ( evType == wxEVT_PAINT ) + // 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 ) { m_scrollHelper->HandleOnPaint((wxPaintEvent &)event); return true; @@ -462,12 +443,6 @@ void wxScrollHelperBase::DeleteEvtHandler() } } -void wxScrollHelperBase::ResetDrawnFlag() -{ - wxCHECK_RET( m_handler, "invalid use of ResetDrawnFlag - no handler?" ); - m_handler->ResetDrawnFlag(); -} - void wxScrollHelperBase::DoSetTargetWindow(wxWindow *target) { m_targetWindow = target; -- 2.45.2