summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llbutton.cpp4
-rw-r--r--indra/llui/llbutton.h3
-rw-r--r--indra/llui/llfloater.cpp4
-rw-r--r--indra/llui/llscrolllistctrl.cpp4
-rw-r--r--indra/llui/lltextbase.cpp374
-rw-r--r--indra/llui/lltextbase.h34
-rw-r--r--indra/llui/lltexteditor.cpp49
-rw-r--r--indra/llui/lltexteditor.h1
-rw-r--r--indra/llui/lltextparser.cpp40
-rw-r--r--indra/llui/lltextparser.h15
-rw-r--r--indra/llui/llurlentry.h2
-rw-r--r--indra/llui/llurlmatch.cpp6
-rw-r--r--indra/llui/llurlmatch.h6
-rw-r--r--indra/llui/llurlregistry.cpp8
-rw-r--r--indra/llui/tests/llurlmatch_test.cpp30
15 files changed, 383 insertions, 197 deletions
diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp
index a8f72183fd..34f3049f2e 100644
--- a/indra/llui/llbutton.cpp
+++ b/indra/llui/llbutton.cpp
@@ -636,8 +636,8 @@ void LLButton::draw()
if (mFlashing)
{
- // if we have icon for flashing, use it as image for button
- if(flash && mImageFlash->getName() != "FlashIconAbsent")
+ // if button should flash and we have icon for flashing, use it as image for button
+ if(flash && mImageFlash)
{
// setting flash to false to avoid its further influence on glow
flash = false;
diff --git a/indra/llui/llbutton.h b/indra/llui/llbutton.h
index b251c3d65d..9bd566d3c9 100644
--- a/indra/llui/llbutton.h
+++ b/indra/llui/llbutton.h
@@ -314,8 +314,7 @@ private:
/* There are two ways an image can flash- by making changes in color according to flash_color attribute
or by changing icon from current to the one specified in image_flash. Second way is used only if
- the name of flash icon is different from "FlashIconAbsent" which is there by default. First way is used
- otherwise. */
+ flash icon name is set in attributes(by default it isn't). First way is used otherwise. */
LLPointer<LLUIImage> mImageFlash;
LLUIColor mHighlightColor;
diff --git a/indra/llui/llfloater.cpp b/indra/llui/llfloater.cpp
index 6babaf936b..fad98e553f 100644
--- a/indra/llui/llfloater.cpp
+++ b/indra/llui/llfloater.cpp
@@ -330,6 +330,7 @@ void LLFloater::addDragHandle()
addChild(mDragHandle);
}
layoutDragHandle();
+ applyTitle();
}
void LLFloater::layoutDragHandle()
@@ -348,7 +349,6 @@ void LLFloater::layoutDragHandle()
}
mDragHandle->setRect(rect);
updateTitleButtons();
- applyTitle();
}
void LLFloater::addResizeCtrls()
@@ -2519,7 +2519,7 @@ LLFloater *LLFloaterView::getBackmost() const
void LLFloaterView::syncFloaterTabOrder()
{
- // look for a visible modal dialog, starting from first (should be only one)
+ // look for a visible modal dialog, starting from first
LLModalDialog* modal_dialog = NULL;
for ( child_list_const_iter_t child_it = getChildList()->begin(); child_it != getChildList()->end(); ++child_it)
{
diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp
index 94eade06ad..d4d161f2c9 100644
--- a/indra/llui/llscrolllistctrl.cpp
+++ b/indra/llui/llscrolllistctrl.cpp
@@ -2949,7 +2949,6 @@ BOOL LLScrollListCtrl::operateOnAll(EOperation op)
//virtual
void LLScrollListCtrl::setFocus(BOOL b)
{
- mSearchString.clear();
// for tabbing into pristine scroll lists (Finder)
if (!getFirstSelected())
{
@@ -2994,6 +2993,9 @@ void LLScrollListCtrl::onFocusLost()
{
gFocusMgr.setMouseCapture(NULL);
}
+
+ mSearchString.clear();
+
LLUICtrl::onFocusLost();
}
diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index 8fc6f16702..38b35020b5 100644
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -401,11 +401,11 @@ void LLTextBase::drawSelectionBackground()
++rect_it)
{
LLRect selection_rect = *rect_it;
- selection_rect.translate(mVisibleTextRect.mLeft - content_display_rect.mLeft, mVisibleTextRect.mBottom - content_display_rect.mBottom);
- gl_rect_2d(selection_rect, selection_color);
- }
+ selection_rect.translate(mVisibleTextRect.mLeft - content_display_rect.mLeft, mVisibleTextRect.mBottom - content_display_rect.mBottom);
+ gl_rect_2d(selection_rect, selection_color);
}
}
+}
void LLTextBase::drawCursor()
{
@@ -962,17 +962,18 @@ void LLTextBase::reshape(S32 width, S32 height, BOOL called_from_parent)
{
if (width != getRect().getWidth() || height != getRect().getHeight())
{
- //EXT-4288
- //to keep consistance scrolling behaviour
- //when scrolling from top and from bottom...
- bool is_scrolled_to_end = (mScroller!=NULL) && scrolledToEnd();
+ bool scrolled_to_bottom = mScroller ? mScroller->isAtBottom() : false;
LLUICtrl::reshape( width, height, called_from_parent );
- if (is_scrolled_to_end)
+ if (mScroller && scrolled_to_bottom && mTrackEnd)
{
- deselect();
- endOfDoc();
+ // keep bottom of text buffer visible
+ // do this here as well as in reflow to handle case
+ // where shrinking from top, which causes buffer to temporarily
+ // not be scrolled to the bottom, since the scroll index
+ // specified the _top_ of the visible document region
+ mScroller->goToBottom();
}
// do this first after reshape, because other things depend on
@@ -1116,6 +1117,34 @@ void LLTextBase::reflow()
updateSegments();
+ if (mReflowIndex == S32_MAX)
+ {
+ return;
+ }
+
+ bool scrolled_to_bottom = mScroller ? mScroller->isAtBottom() : false;
+
+ LLRect cursor_rect = getLocalRectFromDocIndex(mCursorPos);
+ bool follow_selection = getLocalRect().overlaps(cursor_rect); // cursor is (potentially) visible
+
+ // store in top-left relative coordinates to avoid issues with horizontal scrollbar appearing and disappearing
+ cursor_rect.mTop = mVisibleTextRect.mTop - cursor_rect.mTop;
+ cursor_rect.mBottom = mVisibleTextRect.mTop - cursor_rect.mBottom;
+
+ S32 first_line = getFirstVisibleLine();
+
+ // if scroll anchor not on first line, update it to first character of first line
+ if (!mLineInfoList.empty()
+ && (mScrollIndex < mLineInfoList[first_line].mDocIndexStart
+ || mScrollIndex >= mLineInfoList[first_line].mDocIndexEnd))
+ {
+ mScrollIndex = mLineInfoList[first_line].mDocIndexStart;
+ }
+ LLRect first_char_rect = getLocalRectFromDocIndex(mScrollIndex);
+ // store in top-left relative coordinates to avoid issues with horizontal scrollbar appearing and disappearing
+ first_char_rect.mTop = mVisibleTextRect.mTop - first_char_rect.mTop;
+ first_char_rect.mBottom = mVisibleTextRect.mTop - first_char_rect.mBottom;
+
S32 reflow_count = 0;
while(mReflowIndex < S32_MAX)
{
@@ -1129,6 +1158,7 @@ void LLTextBase::reflow()
lldebugs << "Breaking out of reflow due to possible infinite loop in " << getName() << llendl;
break;
}
+
S32 start_index = mReflowIndex;
mReflowIndex = S32_MAX;
@@ -1136,25 +1166,6 @@ void LLTextBase::reflow()
// to force inlined widgets with follows set to shrink
mDocumentView->reshape(mVisibleTextRect.getWidth(), mDocumentView->getRect().getHeight());
- bool scrolled_to_bottom = mScroller ? mScroller->isAtBottom() : false;
-
- LLRect old_cursor_rect = getLocalRectFromDocIndex(mCursorPos);
- bool follow_selection = mVisibleTextRect.overlaps(old_cursor_rect); // cursor is visible
- old_cursor_rect.translate(-mVisibleTextRect.mLeft, -mVisibleTextRect.mBottom);
-
- S32 first_line = getFirstVisibleLine();
-
- // if scroll anchor not on first line, update it to first character of first line
- if (!mLineInfoList.empty()
- && (mScrollIndex < mLineInfoList[first_line].mDocIndexStart
- || mScrollIndex >= mLineInfoList[first_line].mDocIndexEnd))
- {
- mScrollIndex = mLineInfoList[first_line].mDocIndexStart;
- }
- LLRect first_char_rect = getLocalRectFromDocIndex(mScrollIndex);
- // subtract off effect of horizontal scrollbar from local position of first char
- first_char_rect.translate(-mVisibleTextRect.mLeft, -mVisibleTextRect.mBottom);
-
S32 cur_top = 0;
segment_set_t::iterator seg_iter = mSegments.begin();
@@ -1275,6 +1286,7 @@ void LLTextBase::reflow()
segmentp->updateLayout(*this);
}
+ }
// apply scroll constraints after reflowing text
if (!hasMouseCapture() && mScroller)
@@ -1288,20 +1300,29 @@ void LLTextBase::reflow()
{
// keep cursor in same vertical position on screen when selecting text
LLRect new_cursor_rect_doc = getDocRectFromDocIndex(mCursorPos);
+ LLRect old_cursor_rect = cursor_rect;
+ old_cursor_rect.mTop = mVisibleTextRect.mTop - cursor_rect.mTop;
+ old_cursor_rect.mBottom = mVisibleTextRect.mTop - cursor_rect.mBottom;
+
mScroller->scrollToShowRect(new_cursor_rect_doc, old_cursor_rect);
}
else
{
// keep first line of text visible
LLRect new_first_char_rect = getDocRectFromDocIndex(mScrollIndex);
- mScroller->scrollToShowRect(new_first_char_rect, first_char_rect);
+
+ // pass in desired rect in the coordinate frame of the document viewport
+ LLRect old_first_char_rect = first_char_rect;
+ old_first_char_rect.mTop = mVisibleTextRect.mTop - first_char_rect.mTop;
+ old_first_char_rect.mBottom = mVisibleTextRect.mTop - first_char_rect.mBottom;
+
+ mScroller->scrollToShowRect(new_first_char_rect, old_first_char_rect);
}
}
// reset desired x cursor position
updateCursorXPos();
}
-}
LLRect LLTextBase::getTextBoundingRect()
{
@@ -1576,7 +1597,7 @@ static LLUIImagePtr image_from_icon_name(const std::string& icon_name)
}
}
-void LLTextBase::appendText(const std::string &new_text, bool prepend_newline, const LLStyle::Params& input_params)
+void LLTextBase::appendTextImpl(const std::string &new_text, bool prepend_newline, const LLStyle::Params& input_params)
{
LLStyle::Params style_params(input_params);
style_params.fillFrom(getDefaultStyleParams());
@@ -1609,8 +1630,7 @@ void LLTextBase::appendText(const std::string &new_text, bool prepend_newline, c
part = (S32)LLTextParser::MIDDLE;
}
std::string subtext=text.substr(0,start);
- appendAndHighlightText(subtext, prepend_newline, part, style_params);
- prepend_newline = false;
+ appendAndHighlightTextImpl(subtext, part, style_params);
}
// output an optional icon before the Url
@@ -1627,13 +1647,12 @@ void LLTextBase::appendText(const std::string &new_text, bool prepend_newline, c
// Text will be replaced during rendering with the icon,
// but string cannot be empty or the segment won't be
// added (or drawn).
- appendAndHighlightText(" ", prepend_newline, part, icon_params);
- prepend_newline = false;
+ appendImageSegment(part, icon);
}
}
- // output the styled Url
- appendAndHighlightText(match.getLabel(), prepend_newline, part, link_params);
+ // output the styled Url
+ appendAndHighlightTextImpl(match.getLabel(), part, link_params);
// set the tooltip for the Url label
if (! match.getTooltip().empty())
@@ -1645,8 +1664,6 @@ void LLTextBase::appendText(const std::string &new_text, bool prepend_newline, c
segment->setToolTip(match.getTooltip());
}
}
-
- prepend_newline = false;
// move on to the rest of the text after the Url
if (end < (S32)text.length())
@@ -1660,13 +1677,41 @@ void LLTextBase::appendText(const std::string &new_text, bool prepend_newline, c
break;
}
}
- if (part != (S32)LLTextParser::WHOLE) part=(S32)LLTextParser::END;
- if (end < (S32)text.length()) appendAndHighlightText(text, prepend_newline, part, style_params);
+ if (part != (S32)LLTextParser::WHOLE)
+ part=(S32)LLTextParser::END;
+ if (end < (S32)text.length())
+ appendAndHighlightTextImpl(text, part, style_params);
}
else
{
- appendAndHighlightText(new_text, prepend_newline, part, style_params);
+ appendAndHighlightTextImpl(new_text, part, style_params);
+ }
+}
+
+void LLTextBase::appendText(const std::string &new_text, bool prepend_newline, const LLStyle::Params& input_params)
+{
+ if (new_text.empty())
+ return;
+
+ if(prepend_newline)
+ appendLineBreakSegment(input_params);
+ std::string::size_type start = 0;
+ std::string::size_type pos = new_text.find("\n",start);
+
+ while(pos!=-1)
+ {
+ if(pos!=start)
+ {
+ std::string str = std::string(new_text,start,pos-start);
+ appendTextImpl(str,input_params);
+ }
+ appendLineBreakSegment(input_params);
+ start = pos+1;
+ pos = new_text.find("\n",start);
}
+
+ std::string str = std::string(new_text,start,new_text.length()-start);
+ appendTextImpl(str,input_params);
}
void LLTextBase::needsReflow(S32 index)
@@ -1675,10 +1720,28 @@ void LLTextBase::needsReflow(S32 index)
mReflowIndex = llmin(mReflowIndex, index);
}
-void LLTextBase::appendAndHighlightText(const std::string &new_text, bool prepend_newline, S32 highlight_part, const LLStyle::Params& style_params)
+void LLTextBase::appendLineBreakSegment(const LLStyle::Params& style_params)
{
- if (new_text.empty()) return;
+ segment_vec_t segments;
+ LLStyleConstSP sp(new LLStyle(style_params));
+ segments.push_back(new LLLineBreakTextSegment(sp, getLength()));
+
+ insertStringNoUndo(getLength(), utf8str_to_wstring("\n"), &segments);
+}
+
+void LLTextBase::appendImageSegment(S32 highlight_part, const LLStyle::Params& style_params)
+{
+ segment_vec_t segments;
+ LLStyleConstSP sp(new LLStyle(style_params));
+ segments.push_back(new LLImageTextSegment(sp, getLength(),*this));
+
+ insertStringNoUndo(getLength(), utf8str_to_wstring(" "), &segments);
+}
+
+
+void LLTextBase::appendAndHighlightTextImpl(const std::string &new_text, S32 highlight_part, const LLStyle::Params& style_params)
+{
// Save old state
S32 selection_start = mSelectionStart;
S32 selection_end = mSelectionEnd;
@@ -1691,13 +1754,11 @@ void LLTextBase::appendAndHighlightText(const std::string &new_text, bool prepen
setCursorPos(old_length);
- LLTextParser* highlight = LLTextParser::getInstance();
-
- if (mParseHighlights && highlight)
+ if (mParseHighlights)
{
LLStyle::Params highlight_params(style_params);
- LLSD pieces = highlight->parsePartialLineHighlights(new_text, highlight_params.color(), (LLTextParser::EHighlightPosition)highlight_part);
+ LLSD pieces = LLTextParser::instance().parsePartialLineHighlights(new_text, highlight_params.color(), (LLTextParser::EHighlightPosition)highlight_part);
for (S32 i = 0; i < pieces.size(); i++)
{
LLSD color_llsd = pieces[i]["color"];
@@ -1706,14 +1767,8 @@ void LLTextBase::appendAndHighlightText(const std::string &new_text, bool prepen
highlight_params.color = lcolor;
LLWString wide_text;
- if (prepend_newline && (i == 0 || pieces.size() <= 1 ))
- {
- wide_text = utf8str_to_wstring(std::string("\n") + pieces[i]["text"].asString());
- }
- else
- {
wide_text = utf8str_to_wstring(pieces[i]["text"].asString());
- }
+
S32 cur_length = getLength();
LLStyleConstSP sp(new LLStyle(highlight_params));
LLTextSegmentPtr segmentp = new LLNormalTextSegment(sp, cur_length, cur_length + wide_text.size(), *this);
@@ -1725,17 +1780,7 @@ void LLTextBase::appendAndHighlightText(const std::string &new_text, bool prepen
else
{
LLWString wide_text;
-
- // Add carriage return if not first line
- if (getLength() != 0
- && prepend_newline)
- {
- wide_text = utf8str_to_wstring(std::string("\n") + new_text);
- }
- else
- {
wide_text = utf8str_to_wstring(new_text);
- }
segment_vec_t segments;
S32 segment_start = old_length;
@@ -1763,11 +1808,32 @@ void LLTextBase::appendAndHighlightText(const std::string &new_text, bool prepen
{
setCursorPos(cursor_pos);
}
+}
- //if( !allow_undo )
- //{
- // blockUndo();
- //}
+void LLTextBase::appendAndHighlightText(const std::string &new_text, bool prepend_newline, S32 highlight_part, const LLStyle::Params& style_params)
+{
+ if (new_text.empty()) return;
+
+ if(prepend_newline)
+ appendLineBreakSegment(style_params);
+
+ std::string::size_type start = 0;
+ std::string::size_type pos = new_text.find("\n",start);
+
+ while(pos!=-1)
+ {
+ if(pos!=start)
+ {
+ std::string str = std::string(new_text,start,pos-start);
+ appendAndHighlightTextImpl(str,highlight_part, style_params);
+ }
+ appendLineBreakSegment(style_params);
+ start = pos+1;
+ pos = new_text.find("\n",start);
+ }
+
+ std::string str = std::string(new_text,start,new_text.length()-start);
+ appendAndHighlightTextImpl(str,highlight_part, style_params);
}
@@ -1876,14 +1942,19 @@ S32 LLTextBase::getDocIndexFromLocalCoord( S32 local_x, S32 local_y, BOOL round,
S32 text_width, text_height;
bool newline = segmentp->getDimensions(line_seg_offset, segment_line_length, text_width, text_height);
+ if(newline)
+ {
+ pos = segment_line_start + segmentp->getOffset(local_x - start_x, line_seg_offset, segment_line_length, round);
+ break;
+ }
+
// if we've reached a line of text *below* the mouse cursor, doc index is first character on that line
if (hit_past_end_of_line && local_y - mVisibleTextRect.mBottom + visible_region.mBottom > line_iter->mRect.mTop)
{
pos = segment_line_start;
break;
}
- if (local_x < start_x + text_width // cursor to left of right edge of text
- || newline) // or this line ends with a newline, set doc pos to newline char
+ if (local_x < start_x + text_width) // cursor to left of right edge of text
{
// Figure out which character we're nearest to.
S32 offset;
@@ -1907,13 +1978,13 @@ S32 LLTextBase::getDocIndexFromLocalCoord( S32 local_x, S32 local_y, BOOL round,
pos = segment_line_start + offset;
break;
}
- else if (hit_past_end_of_line && segmentp->getEnd() >= line_iter->mDocIndexEnd - 1)
+ else if (hit_past_end_of_line && segmentp->getEnd() > line_iter->mDocIndexEnd - 1)
{
+ // segment wraps to next line, so just set doc pos to the end of the line
// segment wraps to next line, so just set doc pos to start of next line (represented by mDocIndexEnd)
pos = llmin(getLength(), line_iter->mDocIndexEnd);
break;
}
-
start_x += text_width;
}
@@ -1982,11 +2053,18 @@ LLRect LLTextBase::getDocRectFromDocIndex(S32 pos) const
LLRect LLTextBase::getLocalRectFromDocIndex(S32 pos) const
{
+ LLRect content_window_rect = mScroller ? mScroller->getContentWindowRect() : getLocalRect();
+ if (mBorderVisible)
+ {
+ content_window_rect.stretch(-1);
+ }
+
LLRect local_rect;
+
if (mLineInfoList.empty())
{
// return default height rect in upper left
- local_rect = mVisibleTextRect;
+ local_rect = content_window_rect;
local_rect.mBottom = local_rect.mTop - (S32)(mDefaultFont->getLineHeight());
return local_rect;
}
@@ -1997,8 +2075,8 @@ LLRect LLTextBase::getLocalRectFromDocIndex(S32 pos) const
// compensate for scrolled, inset view of doc
LLRect scrolled_view_rect = getVisibleDocumentRect();
local_rect = doc_rect;
- local_rect.translate(mVisibleTextRect.mLeft - scrolled_view_rect.mLeft,
- mVisibleTextRect.mBottom - scrolled_view_rect.mBottom);
+ local_rect.translate(content_window_rect.mLeft - scrolled_view_rect.mLeft,
+ content_window_rect.mBottom - scrolled_view_rect.mBottom);
return local_rect;
}
@@ -2370,25 +2448,6 @@ F32 LLNormalTextSegment::draw(S32 start, S32 end, S32 selection_start, S32 selec
{
if( end - start > 0 )
{
- if ( mStyle->isImage() && (start >= 0) && (end <= mEnd - mStart))
- {
- // ...for images, only render the image, not the underlying text,
- // which is only a placeholder space
- LLColor4 color = LLColor4::white % mEditor.getDrawContext().mAlpha;
- LLUIImagePtr image = mStyle->getImage();
- S32 style_image_height = image->getHeight();
- S32 style_image_width = image->getWidth();
- // Text is drawn from the top of the draw_rect downward
- S32 text_center = draw_rect.mTop - (mFontHeight / 2);
- // Align image to center of text
- S32 image_bottom = text_center - (style_image_height / 2);
- image->draw(draw_rect.mLeft, image_bottom,
- style_image_width, style_image_height, color);
-
- const S32 IMAGE_HPAD = 3;
- return draw_rect.mLeft + style_image_width + IMAGE_HPAD;
- }
-
return drawClippedSegment( getStart() + start, getStart() + end, selection_start, selection_end, draw_rect);
}
return draw_rect.mLeft;
@@ -2401,11 +2460,6 @@ 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())
{
@@ -2564,33 +2618,14 @@ bool LLNormalTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& widt
{
height = 0;
width = 0;
- bool force_newline = false;
if (num_chars > 0)
{
height = mFontHeight;
const LLWString &text = mEditor.getWText();
// if last character is a newline, then return true, forcing line break
- llwchar last_char = text[mStart + first_char + num_chars - 1];
- if (last_char == '\n')
- {
- force_newline = true;
- // don't count newline in font width
- width = mStyle->getFont()->getWidth(text.c_str(), mStart + first_char, num_chars - 1);
- }
- else
- {
width = mStyle->getFont()->getWidth(text.c_str(), mStart + first_char, num_chars);
}
- }
-
- LLUIImagePtr image = mStyle->getImage();
- if( image.notNull())
- {
- width += image->getWidth();
- height = llmax(height, image->getHeight());
- }
-
- return force_newline;
+ return false;
}
S32 LLNormalTextSegment::getOffset(S32 segment_local_x_coord, S32 start_offset, S32 num_chars, bool round) const
@@ -2613,15 +2648,7 @@ S32 LLNormalTextSegment::getNumChars(S32 num_pixels, S32 segment_offset, S32 lin
num_pixels = llmax(0, num_pixels - image->getWidth());
}
- // search for newline and if found, truncate there
- S32 last_char = mStart + segment_offset;
- for (; last_char != mEnd; ++last_char)
- {
- if (text[last_char] == '\n')
- {
- break;
- }
- }
+ S32 last_char = mEnd;
// set max characters to length of segment, or to first newline
max_chars = llmin(max_chars, last_char - (mStart + segment_offset));
@@ -2649,8 +2676,7 @@ S32 LLNormalTextSegment::getNumChars(S32 num_pixels, S32 segment_offset, S32 lin
S32 last_char_in_run = mStart + segment_offset + num_chars;
// check length first to avoid indexing off end of string
if (last_char_in_run < mEnd
- && (last_char_in_run >= mEditor.getLength()
- || text[last_char_in_run] == '\n'))
+ && (last_char_in_run >= mEditor.getLength() ))
{
num_chars++;
}
@@ -2745,3 +2771,87 @@ void LLInlineViewSegment::linkToDocument(LLTextBase* editor)
{
editor->addDocumentChild(mView);
}
+
+LLLineBreakTextSegment::LLLineBreakTextSegment(LLStyleConstSP style,S32 pos):LLTextSegment(pos,pos+1)
+{
+ mFontHeight = llceil(style->getFont()->getLineHeight());
+}
+LLLineBreakTextSegment::~LLLineBreakTextSegment()
+{
+}
+bool LLLineBreakTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& width, S32& height) const
+{
+ width = 0;
+ height = mFontHeight;
+
+ return true;
+}
+S32 LLLineBreakTextSegment::getNumChars(S32 num_pixels, S32 segment_offset, S32 line_offset, S32 max_chars) const
+{
+ return 1;
+}
+F32 LLLineBreakTextSegment::draw(S32 start, S32 end, S32 selection_start, S32 selection_end, const LLRect& draw_rect)
+{
+ return draw_rect.mLeft;
+}
+
+LLImageTextSegment::LLImageTextSegment(LLStyleConstSP style,S32 pos,class LLTextBase& editor)
+ :LLTextSegment(pos,pos+1)
+ ,mStyle( style )
+ ,mEditor(editor)
+{
+}
+
+LLImageTextSegment::~LLImageTextSegment()
+{
+}
+
+static const S32 IMAGE_HPAD = 3;
+
+bool LLImageTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& width, S32& height) const
+{
+ width = 0;
+ height = llceil(mStyle->getFont()->getLineHeight());;
+
+ LLUIImagePtr image = mStyle->getImage();
+ if( image.notNull())
+ {
+ width += image->getWidth() + IMAGE_HPAD;
+ height = llmax(height, image->getHeight() + IMAGE_HPAD );
+ }
+ return false;
+}
+
+S32 LLImageTextSegment::getNumChars(S32 num_pixels, S32 segment_offset, S32 line_offset, S32 max_chars) const
+{
+ LLUIImagePtr image = mStyle->getImage();
+ S32 image_width = image->getWidth();
+ if(num_pixels>image_width + IMAGE_HPAD)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+F32 LLImageTextSegment::draw(S32 start, S32 end, S32 selection_start, S32 selection_end, const LLRect& draw_rect)
+{
+ if ( (start >= 0) && (end <= mEnd - mStart))
+ {
+ LLColor4 color = LLColor4::white % mEditor.getDrawContext().mAlpha;
+ LLUIImagePtr image = mStyle->getImage();
+ S32 style_image_height = image->getHeight();
+ S32 style_image_width = image->getWidth();
+ // Text is drawn from the top of the draw_rect downward
+
+ S32 text_center = draw_rect.mTop - (draw_rect.getHeight() / 2);
+ // Align image to center of draw rect
+ S32 image_bottom = text_center - (style_image_height / 2);
+ image->draw(draw_rect.mLeft, image_bottom,
+ style_image_width, style_image_height, color);
+
+ const S32 IMAGE_HPAD = 3;
+ return draw_rect.mLeft + style_image_width + IMAGE_HPAD;
+ }
+ return 0.0;
+}
+
diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h
index ddf604c195..7041b9a109 100644
--- a/indra/llui/lltextbase.h
+++ b/indra/llui/lltextbase.h
@@ -320,6 +320,13 @@ protected:
// avatar names are looked up.
void replaceUrl(const std::string &url, const std::string &label, const std::string& icon);
+ void appendLineBreakSegment(const LLStyle::Params& style_params);
+ void appendImageSegment(S32 highlight_part, const LLStyle::Params& style_params);
+
+ void appendTextImpl(const std::string &new_text, const LLStyle::Params& input_params = LLStyle::Params());
+ void appendAndHighlightTextImpl(const std::string &new_text, S32 highlight_part, const LLStyle::Params& style_params);
+
+
protected:
// text segmentation and flow
segment_set_t mSegments;
@@ -511,5 +518,32 @@ private:
bool mForceNewLine;
};
+class LLLineBreakTextSegment : public LLTextSegment
+{
+public:
+
+ LLLineBreakTextSegment(LLStyleConstSP style,S32 pos);
+ ~LLLineBreakTextSegment();
+ bool getDimensions(S32 first_char, S32 num_chars, S32& width, S32& height) const;
+ S32 getNumChars(S32 num_pixels, S32 segment_offset, S32 line_offset, S32 max_chars) const;
+ F32 draw(S32 start, S32 end, S32 selection_start, S32 selection_end, const LLRect& draw_rect);
+
+private:
+ S32 mFontHeight;
+};
+
+class LLImageTextSegment : public LLTextSegment
+{
+public:
+ LLImageTextSegment(LLStyleConstSP style,S32 pos,class LLTextBase& editor);
+ ~LLImageTextSegment();
+ bool getDimensions(S32 first_char, S32 num_chars, S32& width, S32& height) const;
+ S32 getNumChars(S32 num_pixels, S32 segment_offset, S32 line_offset, S32 max_chars) const;
+ F32 draw(S32 start, S32 end, S32 selection_start, S32 selection_end, const LLRect& draw_rect);
+
+private:
+ class LLTextBase& mEditor;
+ LLStyleConstSP mStyle;
+};
#endif
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index 4fd62045e8..c9474d66b7 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -1083,6 +1083,28 @@ void LLTextEditor::addChar(llwchar wc)
setCursorPos(mCursorPos + addChar( mCursorPos, wc ));
}
+void LLTextEditor::addLineBreakChar()
+{
+ if( !getEnabled() )
+ {
+ return;
+ }
+ if( hasSelection() )
+ {
+ deleteSelection(TRUE);
+ }
+ else if (LL_KIM_OVERWRITE == gKeyboard->getInsertMode())
+ {
+ removeChar(mCursorPos);
+ }
+
+ LLStyleConstSP sp(new LLStyle(LLStyle::Params()));
+ LLTextSegmentPtr segment = new LLLineBreakTextSegment(sp, mCursorPos);
+
+ S32 pos = execute(new TextCmdAddChar(mCursorPos, FALSE, '\n', segment));
+
+ setCursorPos(mCursorPos + pos);
+}
BOOL LLTextEditor::handleSelectionKey(const KEY key, const MASK mask)
@@ -1404,7 +1426,27 @@ void LLTextEditor::pasteHelper(bool is_primary)
}
// Insert the new text into the existing text.
- setCursorPos(mCursorPos + insert(mCursorPos, clean_string, FALSE, LLTextSegmentPtr()));
+
+ //paste text with linebreaks.
+ std::basic_string<llwchar>::size_type start = 0;
+ std::basic_string<llwchar>::size_type pos = clean_string.find('\n',start);
+
+ while(pos!=-1)
+ {
+ if(pos!=start)
+ {
+ std::basic_string<llwchar> str = std::basic_string<llwchar>(clean_string,start,pos-start);
+ setCursorPos(mCursorPos + insert(mCursorPos, str, FALSE, LLTextSegmentPtr()));
+ }
+ addLineBreakChar();
+
+ start = pos+1;
+ pos = clean_string.find('\n',start);
+ }
+
+ std::basic_string<llwchar> str = std::basic_string<llwchar>(clean_string,start,clean_string.length()-start);
+ setCursorPos(mCursorPos + insert(mCursorPos, str, FALSE, LLTextSegmentPtr()));
+
deselect();
onKeyStroke();
@@ -2169,7 +2211,10 @@ void LLTextEditor::autoIndent()
}
// Insert that number of spaces on the new line
- addChar( '\n' );
+
+ //appendLineBreakSegment(LLStyle::Params());//addChar( '\n' );
+ addLineBreakChar();
+
for( i = 0; i < space_count; i++ )
{
addChar( ' ' );
diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h
index 9b3ab9414c..7b68974fd8 100644
--- a/indra/llui/lltexteditor.h
+++ b/indra/llui/lltexteditor.h
@@ -240,6 +240,7 @@ protected:
// Undoable operations
void addChar(llwchar c); // at mCursorPos
S32 addChar(S32 pos, llwchar wc);
+ void addLineBreakChar();
S32 overwriteChar(S32 pos, llwchar wc);
void removeChar();
S32 removeChar(S32 pos);
diff --git a/indra/llui/lltextparser.cpp b/indra/llui/lltextparser.cpp
index 76a39e3094..2493afcb5d 100644
--- a/indra/llui/lltextparser.cpp
+++ b/indra/llui/lltextparser.cpp
@@ -43,29 +43,14 @@
#include "v4color.h"
#include "lldir.h"
-// Routines used for parsing text for TextParsers and html
-
-LLTextParser* LLTextParser::sInstance = NULL;
-
//
// Member Functions
//
-LLTextParser::~LLTextParser()
-{
- sInstance=NULL;
-}
+LLTextParser::LLTextParser()
+: mLoaded(false)
+{}
-// static
-LLTextParser* LLTextParser::getInstance()
-{
- if (!sInstance)
- {
- sInstance = new LLTextParser();
- sInstance->loadFromDisk();
- }
- return sInstance;
-}
// Moved triggerAlerts() to llfloaterchat.cpp to break llui/llaudio library dependency.
@@ -105,6 +90,8 @@ S32 LLTextParser::findPattern(const std::string &text, LLSD highlight)
LLSD LLTextParser::parsePartialLineHighlights(const std::string &text, const LLColor4 &color, EHighlightPosition part, S32 index)
{
+ loadKeywords();
+
//evil recursive string atomizer.
LLSD ret_llsd, start_llsd, middle_llsd, end_llsd;
@@ -195,6 +182,8 @@ LLSD LLTextParser::parsePartialLineHighlights(const std::string &text, const LLC
bool LLTextParser::parseFullLineHighlights(const std::string &text, LLColor4 *color)
{
+ loadKeywords();
+
for (S32 i=0;i<mHighlights.size();i++)
{
if ((S32)mHighlights[i]["highlight"]==ALL || (S32)mHighlights[i]["condition"]==MATCHES)
@@ -221,14 +210,14 @@ std::string LLTextParser::getFileName()
return path;
}
-LLSD LLTextParser::loadFromDisk()
+void LLTextParser::loadKeywords()
{
- std::string filename=getFileName();
- if (filename.empty())
- {
- llwarns << "LLTextParser::loadFromDisk() no valid user directory." << llendl;
+ if (mLoaded)
+ {// keywords already loaded
+ return;
}
- else
+ std::string filename=getFileName();
+ if (!filename.empty())
{
llifstream file;
file.open(filename.c_str());
@@ -237,9 +226,8 @@ LLSD LLTextParser::loadFromDisk()
LLSDSerialize::fromXML(mHighlights, file);
}
file.close();
+ mLoaded = true;
}
-
- return mHighlights;
}
bool LLTextParser::saveToDisk(LLSD highlights)
diff --git a/indra/llui/lltextparser.h b/indra/llui/lltextparser.h
index 072ac0f300..3005822f43 100644
--- a/indra/llui/lltextparser.h
+++ b/indra/llui/lltextparser.h
@@ -35,12 +35,13 @@
#define LL_LLTEXTPARSER_H
#include "llsd.h"
+#include "llsingleton.h"
class LLUUID;
class LLVector3d;
class LLColor4;
-class LLTextParser
+class LLTextParser : public LLSingleton<LLTextParser>
{
public:
typedef enum e_condition_type { CONTAINS, MATCHES, STARTS_WITH, ENDS_WITH } EConditionType;
@@ -48,22 +49,20 @@ public:
typedef enum e_highlight_position { WHOLE, START, MIDDLE, END } EHighlightPosition;
typedef enum e_dialog_action { ACTION_NONE, ACTION_CLOSE, ACTION_ADD, ACTION_COPY, ACTION_UPDATE } EDialogAction;
- static LLTextParser* getInstance();
- LLTextParser(){};
- ~LLTextParser();
+ LLTextParser();
- S32 findPattern(const std::string &text, LLSD highlight);
LLSD parsePartialLineHighlights(const std::string &text,const LLColor4 &color, EHighlightPosition part=WHOLE, S32 index=0);
bool parseFullLineHighlights(const std::string &text, LLColor4 *color);
+private:
+ S32 findPattern(const std::string &text, LLSD highlight);
std::string getFileName();
- LLSD loadFromDisk();
+ void loadKeywords();
bool saveToDisk(LLSD highlights);
public:
LLSD mHighlights;
-private:
- static LLTextParser* sInstance;
+ bool mLoaded;
};
#endif
diff --git a/indra/llui/llurlentry.h b/indra/llui/llurlentry.h
index 5be3c6a45b..04423a81a3 100644
--- a/indra/llui/llurlentry.h
+++ b/indra/llui/llurlentry.h
@@ -95,6 +95,8 @@ public:
/// Return the name of a SL location described by this Url, if any
virtual std::string getLocation(const std::string &url) const { return ""; }
+ virtual LLUUID getID(const std::string &string) const { return LLUUID::null; }
+
protected:
std::string getIDStringFromUrl(const std::string &url) const;
std::string escapeUrl(const std::string &url) const;
diff --git a/indra/llui/llurlmatch.cpp b/indra/llui/llurlmatch.cpp
index 51fca6d7c0..73d880522b 100644
--- a/indra/llui/llurlmatch.cpp
+++ b/indra/llui/llurlmatch.cpp
@@ -48,8 +48,9 @@ LLUrlMatch::LLUrlMatch() :
void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url,
const std::string &label, const std::string &tooltip,
- const std::string &icon, const LLStyle::Params& style,
- const std::string &menu, const std::string &location)
+ const std::string &icon, const LLUIColor& color,
+ const std::string &menu, const std::string &location,
+ bool disabled_link)
{
mStart = start;
mEnd = end;
@@ -61,4 +62,5 @@ void LLUrlMatch::setValues(U32 start, U32 end, const std::string &url,
mStyle.link_href = url;
mMenuName = menu;
mLocation = location;
+ mID = id;
}
diff --git a/indra/llui/llurlmatch.h b/indra/llui/llurlmatch.h
index 3b15a156a8..458a27d01f 100644
--- a/indra/llui/llurlmatch.h
+++ b/indra/llui/llurlmatch.h
@@ -86,9 +86,10 @@ public:
/// Change the contents of this match object (used by LLUrlRegistry)
void setValues(U32 start, U32 end, const std::string &url, const std::string &label,
const std::string &tooltip, const std::string &icon,
- const LLStyle::Params& style, const std::string &menu,
- const std::string &location);
+ const LLUIColor& color, const std::string &menu,
+ const std::string &location, const LLUUID& id);
+ const LLUUID& getID() const { return mID; }
private:
U32 mStart;
U32 mEnd;
@@ -98,6 +99,7 @@ private:
std::string mIcon;
std::string mMenuName;
std::string mLocation;
+ LLUUID mID;
LLStyle::Params mStyle;
};
diff --git a/indra/llui/llurlregistry.cpp b/indra/llui/llurlregistry.cpp
index f119233f8f..5de249d994 100644
--- a/indra/llui/llurlregistry.cpp
+++ b/indra/llui/llurlregistry.cpp
@@ -43,7 +43,7 @@ void LLUrlRegistryNullCallback(const std::string &url, const std::string &label,
LLUrlRegistry::LLUrlRegistry()
{
- mUrlEntry.reserve(16);
+ mUrlEntry.reserve(20);
// Urls are matched in the order that they were registered
registerUrl(new LLUrlEntryNoLink());
@@ -192,7 +192,8 @@ bool LLUrlRegistry::findUrl(const std::string &text, LLUrlMatch &match, const LL
match_entry->getIcon(url),
match_entry->getStyle(),
match_entry->getMenuName(),
- match_entry->getLocation(url));
+ match_entry->getLocation(url),
+ match_entry->getID(url));
return true;
}
@@ -225,7 +226,8 @@ bool LLUrlRegistry::findUrl(const LLWString &text, LLUrlMatch &match, const LLUr
match.getIcon(),
match.getStyle(),
match.getMenuName(),
- match.getLocation());
+ match.getLocation(),
+ match.getID());
return true;
}
return false;
diff --git a/indra/llui/tests/llurlmatch_test.cpp b/indra/llui/tests/llurlmatch_test.cpp
index d6ef5132c8..e8e1ea118b 100644
--- a/indra/llui/tests/llurlmatch_test.cpp
+++ b/indra/llui/tests/llurlmatch_test.cpp
@@ -176,7 +176,7 @@ namespace tut
LLUrlMatch match;
ensure("empty()", match.empty());
- match.setValues(0, 1, "http://secondlife.com", "Second Life", "", "", LLStyle::Params(), "", "");
+ match.setValues(0, 1, "http://secondlife.com", "Second Life", "", "", LLUIColor(), "", "", LLUUID::null);
ensure("! empty()", ! match.empty());
}
@@ -189,7 +189,7 @@ namespace tut
LLUrlMatch match;
ensure_equals("getStart() == 0", match.getStart(), 0);
- match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "", "", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getStart() == 10", match.getStart(), 10);
}
@@ -202,7 +202,7 @@ namespace tut
LLUrlMatch match;
ensure_equals("getEnd() == 0", match.getEnd(), 0);
- match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "", "", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getEnd() == 20", match.getEnd(), 20);
}
@@ -215,10 +215,10 @@ namespace tut
LLUrlMatch match;
ensure_equals("getUrl() == ''", match.getUrl(), "");
- match.setValues(10, 20, "http://slurl.com/", "", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "http://slurl.com/", "", "", "", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getUrl() == 'http://slurl.com/'", match.getUrl(), "http://slurl.com/");
- match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "", "", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getUrl() == '' (2)", match.getUrl(), "");
}
@@ -231,10 +231,10 @@ namespace tut
LLUrlMatch match;
ensure_equals("getLabel() == ''", match.getLabel(), "");
- match.setValues(10, 20, "", "Label", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "Label", "", "", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getLabel() == 'Label'", match.getLabel(), "Label");
- match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "", "", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getLabel() == '' (2)", match.getLabel(), "");
}
@@ -247,10 +247,10 @@ namespace tut
LLUrlMatch match;
ensure_equals("getTooltip() == ''", match.getTooltip(), "");
- match.setValues(10, 20, "", "", "Info", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "Info", "", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getTooltip() == 'Info'", match.getTooltip(), "Info");
- match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "", "", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getTooltip() == '' (2)", match.getTooltip(), "");
}
@@ -263,10 +263,10 @@ namespace tut
LLUrlMatch match;
ensure_equals("getIcon() == ''", match.getIcon(), "");
- match.setValues(10, 20, "", "", "", "Icon", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "", "Icon", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getIcon() == 'Icon'", match.getIcon(), "Icon");
- match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "", "", LLUIColor(), "", "", LLUUID::null);
ensure_equals("getIcon() == '' (2)", match.getIcon(), "");
}
@@ -279,10 +279,10 @@ namespace tut
LLUrlMatch match;
ensure("getMenuName() empty", match.getMenuName().empty());
- match.setValues(10, 20, "", "", "", "Icon", LLStyle::Params(), "xui_file.xml", "");
+ match.setValues(10, 20, "", "", "", "Icon", LLUIColor(), "xui_file.xml", "", LLUUID::null);
ensure_equals("getMenuName() == \"xui_file.xml\"", match.getMenuName(), "xui_file.xml");
- match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "", "", LLUIColor(), "", "", LLUUID::null);
ensure("getMenuName() empty (2)", match.getMenuName().empty());
}
@@ -295,10 +295,10 @@ namespace tut
LLUrlMatch match;
ensure("getLocation() empty", match.getLocation().empty());
- match.setValues(10, 20, "", "", "", "Icon", LLStyle::Params(), "xui_file.xml", "Paris");
+ match.setValues(10, 20, "", "", "", "Icon", LLUIColor(), "xui_file.xml", "Paris", LLUUID::null);
ensure_equals("getLocation() == \"Paris\"", match.getLocation(), "Paris");
- match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "");
+ match.setValues(10, 20, "", "", "", "", LLUIColor(), "", "", LLUUID::null);
ensure("getLocation() empty (2)", match.getLocation().empty());
}
}