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 <[email protected]>
This commit is contained in:
committed by
Siarzhuk Zharski
parent
2ba22cc36a
commit
d01b42b970
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user