From 169adfa9c4b781f737920bc808da91cd926c3e36 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 20 Oct 2005 22:51:57 +0000 Subject: [PATCH] Resets scroll position on load git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35960 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/richtext/richtextctrl.h | 2 +- src/richtext/richtextbuffer.cpp | 19 ++++++++++++------- src/richtext/richtextctrl.cpp | 8 +++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index a1e9c69772..fcd77bd77e 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -561,7 +561,7 @@ public: virtual bool SetFont(const wxFont& font); /// Set up scrollbars, e.g. after a resize - virtual void SetupScrollbars(); + virtual void SetupScrollbars(bool atTop = false); /// Keyboard navigation virtual bool Navigate(int keyCode, int flags); diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index cf57ce9b69..168cac92aa 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -1949,6 +1949,8 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& WXUNUSED(range), /// Lay the item out bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) { + // ClearLines(); + // Increase the size of the paragraph due to spacing int spaceBeforePara = ConvertTenthsMMToPixels(dc, GetAttributes().GetParagraphSpacingBefore()); int spaceAfterPara = ConvertTenthsMMToPixels(dc, GetAttributes().GetParagraphSpacingAfter()); @@ -4859,13 +4861,16 @@ bool wxRichTextPlainTextHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStr { int ch = stream.GetC(); - if (ch == 10 && lastCh != 13) - str += wxT('\n'); - - if (ch > 0 && ch != 10) - str += wxChar(ch); - - lastCh = ch; + if (!stream.Eof()) + { + if (ch == 10 && lastCh != 13) + str += wxT('\n'); + + if (ch > 0 && ch != 10) + str += wxChar(ch); + + lastCh = ch; + } } buffer->Clear(); diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 057deed1fa..272fa94fb3 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -1331,7 +1331,7 @@ void wxRichTextCtrl::OnSize(wxSizeEvent& event) } /// Set up scrollbars, e.g. after a resize -void wxRichTextCtrl::SetupScrollbars() +void wxRichTextCtrl::SetupScrollbars(bool atTop) { if (m_freezeCount) return; @@ -1351,8 +1351,9 @@ void wxRichTextCtrl::SetupScrollbars() int unitsY = maxHeight/pixelsPerUnit; - int startX, startY; - GetViewStart(& startX, & startY); + int startX = 0, startY = 0; + if (!atTop) + GetViewStart(& startX, & startY); int maxPositionX = 0; // wxMax(sz.x - clientSize.x, 0); int maxPositionY = (wxMax(maxHeight - clientSize.y, 0))/pixelsPerUnit; @@ -1413,6 +1414,7 @@ bool wxRichTextCtrl::LoadFile(const wxString& filename, int type) SetInsertionPoint(0); Layout(); PositionCaret(); + SetupScrollbars(true); Refresh(); SendUpdateEvent();