From cd45ed362297f7fd7c5ce4956fafa6641e460604 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 4 Jan 2012 14:41:29 +0000 Subject: [PATCH] Possible fix for #13821: wxRichTextCtrl using 100% CPU git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70264 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/richtext/richtextctrl.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index dfd6c701be..83905493a1 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -125,6 +125,9 @@ public: void Notify(); + bool GetRefreshEnabled() const { return m_refreshEnabled; } + void EnableRefresh(bool b) { m_refreshEnabled = b; } + protected: virtual void DoShow(); virtual void DoHide(); @@ -144,6 +147,7 @@ private: bool m_flashOn; wxRichTextCaretTimer m_timer; wxRichTextCtrl* m_richTextCtrl; + bool m_refreshEnabled; }; #endif @@ -406,6 +410,11 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) #if !wxRICHTEXT_USE_OWN_CARET if (GetCaret() && !IsFrozen()) GetCaret()->Hide(); +#else + // Stop the caret refreshing the control from within the + // paint handler + if (GetCaret()) + ((wxRichTextCaret*) GetCaret())->EnableRefresh(false); #endif { @@ -460,6 +469,7 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) #if wxRICHTEXT_USE_OWN_CARET if (GetCaret()->IsVisible()) { + PositionCaret(); ((wxRichTextCaret*) GetCaret())->DoDraw(& dc); } #endif @@ -470,10 +480,8 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) GetCaret()->Show(); PositionCaret(); #else -#if !defined(__WXMAC__) - // Causes caret dropouts on Mac - PositionCaret(); -#endif + if (GetCaret()) + ((wxRichTextCaret*) GetCaret())->EnableRefresh(true); #endif } @@ -4413,6 +4421,7 @@ bool wxRichTextDropSource::GiveFeedback(wxDragResult WXUNUSED(effect)) void wxRichTextCaret::Init() { m_hasFocus = true; + m_refreshEnabled = true; m_xOld = m_yOld = -1; @@ -4457,7 +4466,7 @@ void wxRichTextCaret::DoMove() if (m_xOld != -1 && m_yOld != -1) { - if (m_richTextCtrl) + if (m_richTextCtrl && m_refreshEnabled) { wxRect rect(GetPosition(), GetSize()); m_richTextCtrl->RefreshRect(rect, false); @@ -4508,7 +4517,7 @@ void wxRichTextCaret::OnKillFocus() void wxRichTextCaret::Refresh() { - if (m_richTextCtrl) + if (m_richTextCtrl && m_refreshEnabled) { wxRect rect(GetPosition(), GetSize()); m_richTextCtrl->RefreshRect(rect, false); -- 2.45.2