From b12f75cfdc3414fc4a64e5afbff9326819f15658 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 28 Aug 2006 10:06:18 +0000 Subject: [PATCH] More changes to StyleBuffer. Now BTextView::AutoResize() has a minimum size of 3 pixels. To be verified, but seems to work better. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18657 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/BTextView/StyleBuffer.cpp | 25 ++++++++++---------- src/kits/interface/BTextView/StyleBuffer.h | 6 ++--- src/kits/interface/BTextView/TextView.cpp | 4 +++- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/kits/interface/BTextView/StyleBuffer.cpp b/src/kits/interface/BTextView/StyleBuffer.cpp index e54879e8f5..f0c58dd253 100644 --- a/src/kits/interface/BTextView/StyleBuffer.cpp +++ b/src/kits/interface/BTextView/StyleBuffer.cpp @@ -85,8 +85,7 @@ _BStyleRecordBuffer_::_BStyleRecordBuffer_() int32 -_BStyleRecordBuffer_::InsertRecord(const BFont *inFont, - const rgb_color *inColor) +_BStyleRecordBuffer_::InsertRecord(const BFont *inFont, const rgb_color *inColor) { int32 index = 0; @@ -111,14 +110,14 @@ _BStyleRecordBuffer_::InsertRecord(const BFont *inFont, } // no unused space, expand the buffer - index = fItemCount; - STEStyleRecord newRecord; - newRecord.refs = 0; - newRecord.ascent = fh.ascent; - newRecord.descent = fh.descent + fh.leading; - newRecord.style.font = *inFont; - newRecord.style.color = *inColor; - InsertItemsAt(1, index, &newRecord); + const STEStyle style = { *inFont, *inColor }; + const STEStyleRecord newRecord = { + 0, + fh.ascent, + fh.descent + fh.leading, + style + }; + InsertItemsAt(1, fItemCount, &newRecord); return index; } @@ -176,8 +175,9 @@ SetStyleFromMode(uint32 mode, const BFont *fromFont, BFont *toFont, _BStyleBuffer_::_BStyleBuffer_(const BFont *inFont, const rgb_color *inColor) + : + fValidNullStyle(true) { - fValidNullStyle = true; fNullStyle.font = *inFont; fNullStyle.color = *inColor; } @@ -227,8 +227,7 @@ _BStyleBuffer_::SetNullStyle(uint32 inMode, const BFont *inFont, void -_BStyleBuffer_::GetNullStyle(const BFont **font, - const rgb_color **color) const +_BStyleBuffer_::GetNullStyle(const BFont **font, const rgb_color **color) const { if (font) *font = &fNullStyle.font; diff --git a/src/kits/interface/BTextView/StyleBuffer.h b/src/kits/interface/BTextView/StyleBuffer.h index c6125b588d..8d762e41aa 100644 --- a/src/kits/interface/BTextView/StyleBuffer.h +++ b/src/kits/interface/BTextView/StyleBuffer.h @@ -138,9 +138,9 @@ class _BStyleBuffer_ { const _BStyleRunDescBuffer_& RunBuffer() const; const _BStyleRecordBuffer_& RecordBuffer() const; - protected: - _BStyleRunDescBuffer_ fStyleRunDesc; - _BStyleRecordBuffer_ fStyleRecord; + private: + _BStyleRunDescBuffer_ fStyleRunDesc; + _BStyleRecordBuffer_ fStyleRecord; bool fValidNullStyle; STEStyle fNullStyle; }; diff --git a/src/kits/interface/BTextView/TextView.cpp b/src/kits/interface/BTextView/TextView.cpp index 3d494b6d59..438c7a1266 100644 --- a/src/kits/interface/BTextView/TextView.cpp +++ b/src/kits/interface/BTextView/TextView.cpp @@ -4020,7 +4020,9 @@ BTextView::AutoResize(bool redraw) float newWidth = 0; for (int32 i = 0; i < CountLines(); i++) newWidth += LineWidth(i); - + + if (newWidth < 3) + newWidth = 3; BRect newRect(0, 0, ceilf(newWidth) + 1, ceilf(TextHeight(0, 0)) + 1); if (fContainerView != NULL) {