diff options
Diffstat (limited to 'indra/llui/lltextbase.cpp')
-rw-r--r-- | indra/llui/lltextbase.cpp | 157 |
1 files changed, 80 insertions, 77 deletions
diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp index 22cce755b0..0add3fb500 100644 --- a/indra/llui/lltextbase.cpp +++ b/indra/llui/lltextbase.cpp @@ -232,7 +232,7 @@ LLTextBase::LLTextBase(const LLTextBase::Params &p) createDefaultSegment(); - updateTextRect(); + updateRects(); } LLTextBase::~LLTextBase() @@ -538,10 +538,6 @@ void LLTextBase::drawText() next_start = getLineStart(cur_line + 1); line_end = next_start; } - if ( text[line_end-1] == '\n' ) - { - --line_end; - } LLRect text_rect(line.mRect.mLeft + mTextRect.mLeft - scrolled_view_rect.mLeft, line.mRect.mTop - scrolled_view_rect.mBottom + mTextRect.mBottom, @@ -944,7 +940,7 @@ void LLTextBase::reshape(S32 width, S32 height, BOOL called_from_parent) // do this first after reshape, because other things depend on // up-to-date mTextRect - updateTextRect(); + updateRects(); needsReflow(); } @@ -957,10 +953,20 @@ void LLTextBase::draw() // then update scroll position, as cursor may have moved updateScrollFromCursor(); + LLRect doc_rect; + if (mScroller) + { + mScroller->localRectToOtherView(mScroller->getContentWindowRect(), &doc_rect, this); + } + else + { + doc_rect = getLocalRect(); + } + if (mBGVisible) { // clip background rect against extents, if we support scrolling - LLLocalClipRect clip(getLocalRect(), mScroller != NULL); + LLLocalClipRect clip(doc_rect, mScroller != NULL); LLColor4 bg_color = mReadOnly ? mReadOnlyBgColor.get() @@ -975,7 +981,7 @@ void LLTextBase::draw() { // only clip if we support scrolling (mScroller != NULL) - LLLocalClipRect clip(mTextRect, mScroller != NULL); + LLLocalClipRect clip(doc_rect, mScroller != NULL); drawSelectionBackground(); drawText(); drawCursor(); @@ -1154,60 +1160,8 @@ void LLTextBase::reflow(S32 start_index) } } - if (mLineInfoList.empty()) - { - mContentsRect = LLRect(0, mVPad, mHPad, 0); - } - else - { - - mContentsRect = mLineInfoList.begin()->mRect; - for (line_list_t::const_iterator line_iter = ++mLineInfoList.begin(); - line_iter != mLineInfoList.end(); - ++line_iter) - { - mContentsRect.unionWith(line_iter->mRect); - } - - mContentsRect.mRight += mHPad; - mContentsRect.mTop += mVPad; - // get around rounding errors when clipping text against rectangle - mContentsRect.stretch(1); - } - - // change mDocumentView size to accomodate reflowed text - LLRect document_rect; - if (mScroller) - { - // document is size of scroller or size of text contents, whichever is larger - document_rect.setOriginAndSize(0, 0, - mScroller->getContentWindowRect().getWidth(), - llmax(mScroller->getContentWindowRect().getHeight(), mContentsRect.getHeight())); - } - else - { - // document size is just extents of reflowed text, reset to origin 0,0 - document_rect.set(0, - getLocalRect().getHeight(), - getLocalRect().getWidth(), - llmin(0, getLocalRect().getHeight() - mContentsRect.getHeight())); - } - mDocumentView->setShape(document_rect); - - // after making document big enough to hold all the text, move the text to fit in the document - if (!mLineInfoList.empty()) - { - S32 delta_pos = mDocumentView->getRect().getHeight() - mLineInfoList.begin()->mRect.mTop - mVPad; - // move line segments to fit new document rect - for (line_list_t::iterator it = mLineInfoList.begin(); it != mLineInfoList.end(); ++it) - { - it->mRect.translate(0, delta_pos); - } - mContentsRect.translate(0, delta_pos); - } - // calculate visible region for diplaying text - updateTextRect(); + updateRects(); for (segment_set_t::iterator segment_it = mSegments.begin(); segment_it != mSegments.end(); @@ -2075,8 +2029,30 @@ S32 LLTextBase::getEditableIndex(S32 index, bool increasing_direction) } } -void LLTextBase::updateTextRect() +void LLTextBase::updateRects() { + if (mLineInfoList.empty()) + { + mContentsRect = LLRect(0, mVPad, mHPad, 0); + } + else + { + + mContentsRect = mLineInfoList.begin()->mRect; + for (line_list_t::const_iterator line_iter = ++mLineInfoList.begin(); + line_iter != mLineInfoList.end(); + ++line_iter) + { + mContentsRect.unionWith(line_iter->mRect); + } + + mContentsRect.mRight += mHPad; + mContentsRect.mTop += mVPad; + // get around rounding errors when clipping text against rectangle + mContentsRect.stretch(1); + } + + LLRect old_text_rect = mTextRect; mTextRect = mScroller ? mScroller->getContentWindowRect() : getLocalRect(); //FIXME: replace border with image? @@ -2090,6 +2066,37 @@ void LLTextBase::updateTextRect() { needsReflow(); } + + // change document rect size too + LLRect document_rect; + if (mScroller) + { + // document is size of scroller or size of text contents, whichever is larger + document_rect.setOriginAndSize(0, 0, + mScroller->getContentWindowRect().getWidth(), + llmax(mScroller->getContentWindowRect().getHeight(), mContentsRect.getHeight())); + } + else + { + // document size is just extents of reflowed text, reset to origin 0,0 + document_rect.set(0, + getLocalRect().getHeight(), + getLocalRect().getWidth(), + llmin(0, getLocalRect().getHeight() - mContentsRect.getHeight())); + } + mDocumentView->setShape(document_rect); + + // after making document big enough to hold all the text, move the text to fit in the document + if (!mLineInfoList.empty()) + { + S32 delta_pos = mDocumentView->getRect().getHeight() - mLineInfoList.begin()->mRect.mTop - mVPad; + // move line segments to fit new document rect + for (line_list_t::iterator it = mLineInfoList.begin(); it != mLineInfoList.end(); ++it) + { + it->mRect.translate(0, delta_pos); + } + mContentsRect.translate(0, delta_pos); + } } @@ -2218,6 +2225,11 @@ F32 LLNormalTextSegment::drawClippedSegment(S32 seg_start, S32 seg_end, S32 sele const LLWString &text = mEditor.getWText(); + if ( text[seg_end-1] == '\n' ) + { + --seg_end; + } + F32 right_x = rect.mLeft; if (!mStyle->isVisible()) { @@ -2362,16 +2374,7 @@ void LLNormalTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& widt { LLWString text = mEditor.getWText(); - // look for any printable character, then return the font height - height = 0; - for (S32 index = mStart + first_char; index < mStart + first_char + num_chars; ++index) - { - if (text[index] != '\n') - { - height = mFontHeight; - break; - } - } + height = mFontHeight; width = mStyle->getFont()->getWidth(text.c_str(), mStart + first_char, num_chars); } @@ -2393,7 +2396,11 @@ S32 LLNormalTextSegment::getNumChars(S32 num_pixels, S32 segment_offset, S32 lin S32 last_char = mStart + segment_offset; for (; last_char != mEnd; ++last_char) { - if (text[last_char] == '\n') break; + if (text[last_char] == '\n') + { + last_char++; + break; + } } // set max characters to length of segment, or to first newline @@ -2416,10 +2423,6 @@ S32 LLNormalTextSegment::getNumChars(S32 num_pixels, S32 segment_offset, S32 lin // include terminating NULL num_chars++; } - else if (text[mStart + segment_offset + num_chars] == '\n') - { - num_chars++; - } return num_chars; } |