diff options
Diffstat (limited to 'indra/llui/lltextbase.cpp')
-rw-r--r-- | indra/llui/lltextbase.cpp | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp index e220013274..ed03645944 100644 --- a/indra/llui/lltextbase.cpp +++ b/indra/llui/lltextbase.cpp @@ -66,7 +66,10 @@ bool LLTextBase::compare_segment_end::operator()(const LLTextSegmentPtr& a, cons { return a->getStart() < b->getStart(); } - return a->getEnd() < b->getEnd(); + else + { + return a->getEnd() < b->getEnd(); + } } @@ -174,7 +177,7 @@ LLTextBase::Params::Params() LLTextBase::LLTextBase(const LLTextBase::Params &p) : LLUICtrl(p, LLTextViewModelPtr(new LLTextViewModel)), - mURLClickSignal(), + mURLClickSignal(NULL), mMaxTextByteLength( p.max_text_length ), mDefaultFont(p.font), mFontShadow(p.font_shadow), @@ -209,7 +212,8 @@ LLTextBase::LLTextBase(const LLTextBase::Params &p) mParseHTML(p.allow_html), mParseHighlights(p.parse_highlights), mBGVisible(p.bg_visible), - mScroller(NULL) + mScroller(NULL), + mStyleDirty(true) { if(p.allow_scroll) { @@ -248,9 +252,8 @@ LLTextBase::LLTextBase(const LLTextBase::Params &p) LLTextBase::~LLTextBase() { - // Menu, like any other LLUICtrl, is deleted by its parent - gMenuHolder - mSegments.clear(); + delete mURLClickSignal; } void LLTextBase::initFromParams(const LLTextBase::Params& p) @@ -296,13 +299,18 @@ bool LLTextBase::truncate() return did_truncate; } -LLStyle::Params LLTextBase::getDefaultStyleParams() +const LLStyle::Params& LLTextBase::getDefaultStyleParams() { - return LLStyle::Params() - .color(LLUIColor(&mFgColor)) - .readonly_color(LLUIColor(&mReadOnlyFgColor)) - .font(mDefaultFont) - .drop_shadow(mFontShadow); + if (mStyleDirty) + { + mDefaultStyle + .color(LLUIColor(&mFgColor)) + .readonly_color(LLUIColor(&mReadOnlyFgColor)) + .font(mDefaultFont) + .drop_shadow(mFontShadow); + mStyleDirty = false; + } + return mDefaultStyle; } void LLTextBase::onValueChange(S32 start, S32 end) @@ -861,11 +869,12 @@ BOOL LLTextBase::handleMouseUp(S32 x, S32 y, MASK mask) if (cur_segment && cur_segment->handleMouseUp(x, y, mask)) { // Did we just click on a link? - if (cur_segment->getStyle() + if (mURLClickSignal + && cur_segment->getStyle() && cur_segment->getStyle()->isLink()) { // *TODO: send URL here? - mURLClickSignal(this, LLSD() ); + (*mURLClickSignal)(this, LLSD() ); } return TRUE; } @@ -1039,12 +1048,14 @@ void LLTextBase::draw() void LLTextBase::setColor( const LLColor4& c ) { mFgColor = c; + mStyleDirty = true; } //virtual void LLTextBase::setReadOnlyColor(const LLColor4 &c) { mReadOnlyFgColor = c; + mStyleDirty = true; } //virtual @@ -1488,12 +1499,22 @@ void LLTextBase::getSegmentAndOffset( S32 startpos, segment_set_t::iterator* seg LLTextBase::segment_set_t::iterator LLTextBase::getSegIterContaining(S32 index) { + if (index > getLength()) { return mSegments.end(); } + + // when there are no segments, we return the end iterator, which must be checked by caller + if (mSegments.size() <= 1) { return mSegments.begin(); } + segment_set_t::iterator it = mSegments.upper_bound(new LLIndexSegment(index)); return it; } LLTextBase::segment_set_t::const_iterator LLTextBase::getSegIterContaining(S32 index) const { + if (index > getLength()) { return mSegments.end(); } + + // when there are no segments, we return the end iterator, which must be checked by caller + if (mSegments.size() <= 1) { return mSegments.begin(); } + LLTextBase::segment_set_t::const_iterator it = mSegments.upper_bound(new LLIndexSegment(index)); return it; } @@ -2261,12 +2282,6 @@ void LLTextBase::updateRects() ? llmax(mVisibleTextRect.getWidth(), mTextBoundingRect.mRight) : mVisibleTextRect.getWidth(); - if (!mScroller) - { - // push doc rect to top of text widget - doc_rect.translate(0, mVisibleTextRect.getHeight() - doc_rect.mTop); - } - mDocumentView->setShape(doc_rect); //update mVisibleTextRect *after* mDocumentView has been resized @@ -2330,6 +2345,15 @@ LLRect LLTextBase::getVisibleDocumentRect() const } } +boost::signals2::connection LLTextBase::setURLClickedCallback(const commit_signal_t::slot_type& cb) +{ + if (!mURLClickSignal) + { + mURLClickSignal = new commit_signal_t(); + } + return mURLClickSignal->connect(cb); +} + // // LLTextSegment // @@ -2762,9 +2786,9 @@ F32 LLLineBreakTextSegment::draw(S32 start, S32 end, S32 selection_start, S32 se } LLImageTextSegment::LLImageTextSegment(LLStyleConstSP style,S32 pos,class LLTextBase& editor) -: LLTextSegment(pos,pos+1), - mStyle( style ), - mEditor(editor) + :LLTextSegment(pos,pos+1) + ,mStyle( style ) + ,mEditor(editor) { } |