From d01b42b97058e0cb5145a5b6599a0479d71e7f13 Mon Sep 17 00:00:00 2001 From: Aleksas Pantechovskis Date: Mon, 19 Dec 2011 22:49:18 +0100 Subject: [PATCH] Correct update of TextView text run on font change. * Fixes #4698 - font preference changes were not applied on the next message; * The source of problem is resetting of the text run array after applying new font with SetFontAndColor function. Proposed solution updates the text run array items fonts directly without resetting it them and without loosing any styling and color quiting information; * This is result of completing GCI 2011 task. Signed-off-by: Siarzhuk Zharski --- src/apps/mail/Content.cpp | 17 ++++++++++++++++- src/apps/mail/Content.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/apps/mail/Content.cpp b/src/apps/mail/Content.cpp index ef75d1990d..4d76c79487 100644 --- a/src/apps/mail/Content.cpp +++ b/src/apps/mail/Content.cpp @@ -680,7 +680,7 @@ TContentView::MessageReceived(BMessage *msg) { BFont *font; msg->FindPointer("font", (void **)&font); - fTextView->SetFontAndColor(0, LONG_MAX, font); + fTextView->UpdateFont(font); fTextView->Invalidate(Bounds()); break; } @@ -919,6 +919,21 @@ TTextView::~TTextView() } +void +TTextView::UpdateFont(const BFont* newFont) +{ + fFont = *newFont; + + // update the text run array safely with new font + text_run_array *runArray = RunArray(0, LONG_MAX); + for (int i = 0; i < runArray->count; i++) + runArray->runs[i].font = *newFont; + + SetRunArray(0, LONG_MAX, runArray); + FreeRunArray(runArray); +} + + void TTextView::AttachedToWindow() { diff --git a/src/apps/mail/Content.h b/src/apps/mail/Content.h index dd4f88b2c1..7317b4308f 100644 --- a/src/apps/mail/Content.h +++ b/src/apps/mail/Content.h @@ -177,6 +177,7 @@ class TTextView : public BTextView { void AddQuote(int32 start, int32 finish); void RemoveQuote(int32 start, int32 finish); + void UpdateFont(const BFont* newFont); void WindowActivated(bool flag); void Undo(BClipboard *clipboard);