summaryrefslogtreecommitdiff
path: root/indra/llui/lltexteditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/lltexteditor.cpp')
-rw-r--r--indra/llui/lltexteditor.cpp88
1 files changed, 71 insertions, 17 deletions
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index a626a7a1bc..7928887d4b 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -57,6 +57,7 @@
#include "llcontrol.h"
#include "llimagegl.h"
#include "llwindow.h"
+#include "lltextparser.h"
#include <queue>
//
@@ -300,7 +301,7 @@ LLTextEditor::LLTextEditor(
}
else
{
- mGLFont = LLFontGL::sSansSerif;
+ mGLFont = LLFontGL::getFontSansSerif();
}
updateTextRect();
@@ -383,7 +384,7 @@ void LLTextEditor::updateLineStartList(S32 startpos)
{
updateSegments();
- bindEmbeddedChars( const_cast<LLFontGL*>(mGLFont) );
+ bindEmbeddedChars(mGLFont);
S32 seg_num = mSegments.size();
S32 seg_idx = 0;
@@ -461,7 +462,7 @@ void LLTextEditor::updateLineStartList(S32 startpos)
}
}
- unbindEmbeddedChars(const_cast<LLFontGL*>(mGLFont));
+ unbindEmbeddedChars(mGLFont);
mScrollbar->setDocSize( getLineCount() );
@@ -852,13 +853,13 @@ S32 LLTextEditor::getCursorPosFromLocalCoord( S32 local_x, S32 local_y, BOOL rou
if (mAllowEmbeddedItems)
{
// Figure out which character we're nearest to.
- bindEmbeddedChars(const_cast<LLFontGL*>(mGLFont));
+ bindEmbeddedChars(mGLFont);
pos = mGLFont->charFromPixelOffset(mWText.c_str(), line_start,
(F32)(local_x - mTextRect.mLeft),
(F32)(mTextRect.getWidth()),
line_len,
round, TRUE);
- unbindEmbeddedChars(const_cast<LLFontGL*>(mGLFont));
+ unbindEmbeddedChars(mGLFont);
}
else
{
@@ -2931,7 +2932,7 @@ void LLTextEditor::drawText()
// draw the line numbers
if( mShowLineNumbers && !cur_line_is_continuation)
{
- const LLFontGL *num_font = LLFontGL::sMonospace;
+ const LLFontGL *num_font = LLFontGL::getFontMonospace();
F32 y_top = text_y + ((F32)llround(num_font->getLineHeight()) / 2);
const LLWString ltext = utf8str_to_wstring(llformat("%*d", UI_TEXTEDITOR_LINE_NUMBER_DIGITS, cur_line_num ));
BOOL is_cur_line = getCurrentLine() == cur_line_num;
@@ -3116,7 +3117,7 @@ void LLTextEditor::draw()
{
LLLocalClipRect clip(LLRect(0, getRect().getHeight(), getRect().getWidth() - (mScrollbar->getVisible() ? SCROLLBAR_SIZE : 0), 0));
- bindEmbeddedChars( const_cast<LLFontGL*>(mGLFont) );
+ bindEmbeddedChars(mGLFont);
drawBackground();
drawSelectionBackground();
@@ -3124,7 +3125,7 @@ void LLTextEditor::draw()
drawText();
drawCursor();
- unbindEmbeddedChars( const_cast<LLFontGL*>(mGLFont) );
+ unbindEmbeddedChars(mGLFont);
//RN: the decision was made to always show the orange border for keyboard focus but do not put an insertion caret
// when in readonly mode
@@ -3245,7 +3246,7 @@ void LLTextEditor::changePage( S32 delta )
void LLTextEditor::changeLine( S32 delta )
{
- bindEmbeddedChars( const_cast<LLFontGL*>(mGLFont) );
+ bindEmbeddedChars(mGLFont);
S32 line, offset;
getLineAndOffset( mCursorPos, &line, &offset );
@@ -3272,7 +3273,7 @@ void LLTextEditor::changeLine( S32 delta )
}
else
{
- unbindEmbeddedChars( const_cast<LLFontGL*>(mGLFont) );
+ unbindEmbeddedChars(mGLFont);
return;
}
@@ -3297,7 +3298,7 @@ void LLTextEditor::changeLine( S32 delta )
// put desired position into remember-buffer after setCursorPos()
mDesiredXPixel = desired_x_pixel;
- unbindEmbeddedChars( const_cast<LLFontGL*>(mGLFont) );
+ unbindEmbeddedChars(mGLFont);
}
BOOL LLTextEditor::isScrolledToTop()
@@ -3519,9 +3520,16 @@ void LLTextEditor::appendColoredText(const std::string &new_text,
const LLColor4 &color,
const std::string& font_name)
{
+ LLColor4 lcolor=color;
+ if (mParseHighlights)
+ {
+ LLTextParser* highlight = LLTextParser::getInstance();
+ highlight->parseFullLineHighlights(new_text, &lcolor);
+ }
+
LLStyleSP style(new LLStyle);
style->setVisible(true);
- style->setColor(color);
+ style->setColor(lcolor);
style->setFontName(font_name);
appendStyledText(new_text, allow_undo, prepend_newline, style);
}
@@ -3529,8 +3537,9 @@ void LLTextEditor::appendColoredText(const std::string &new_text,
void LLTextEditor::appendStyledText(const std::string &new_text,
bool allow_undo,
bool prepend_newline,
- const LLStyleSP stylep)
+ LLStyleSP stylep)
{
+ S32 part = (S32)LLTextParser::WHOLE;
if(mParseHTML)
{
@@ -3547,27 +3556,73 @@ void LLTextEditor::appendStyledText(const std::string &new_text,
}
html->mUnderline = TRUE;
- if (start > 0) appendText(text.substr(0,start),allow_undo, prepend_newline, stylep);
+ if (start > 0)
+ {
+ if (part == (S32)LLTextParser::WHOLE ||
+ part == (S32)LLTextParser::START)
+ {
+ part = (S32)LLTextParser::START;
+ }
+ else
+ {
+ part = (S32)LLTextParser::MIDDLE;
+ }
+ std::string subtext=text.substr(0,start);
+ appendHighlightedText(subtext,allow_undo, prepend_newline, part, stylep);
+ }
+
html->setLinkHREF(text.substr(start,end-start));
appendText(text.substr(start, end-start),allow_undo, prepend_newline, html);
if (end < (S32)text.length())
{
text = text.substr(end,text.length() - end);
end=0;
+ part=(S32)LLTextParser::END;
}
else
{
break;
}
}
- if (end < (S32)text.length()) appendText(text,allow_undo, prepend_newline, stylep);
+ if (part != (S32)LLTextParser::WHOLE) part=(S32)LLTextParser::END;
+ if (end < (S32)text.length()) appendHighlightedText(text,allow_undo, prepend_newline, part, stylep);
}
else
{
- appendText(new_text, allow_undo, prepend_newline, stylep);
+ appendHighlightedText(new_text, allow_undo, prepend_newline, part, stylep);
}
}
+void LLTextEditor::appendHighlightedText(const std::string &new_text,
+ bool allow_undo,
+ bool prepend_newline,
+ S32 highlight_part,
+ LLStyleSP stylep)
+{
+ if (mParseHighlights)
+ {
+ LLTextParser* highlight = LLTextParser::getInstance();
+
+ if (highlight && stylep)
+ {
+ LLSD pieces = highlight->parsePartialLineHighlights(new_text, stylep->getColor(), highlight_part);
+ bool lprepend=prepend_newline;
+ for (S32 i=0;i<pieces.size();i++)
+ {
+ LLSD color_llsd = pieces[i]["color"];
+ LLColor4 lcolor;
+ lcolor.setValue(color_llsd);
+ LLStyleSP lstylep(new LLStyle(*stylep));
+ lstylep->setColor(lcolor);
+ if (i != 0 && (pieces.size() > 1) ) lprepend=FALSE;
+ appendText((std::string)pieces[i]["text"], allow_undo, lprepend, lstylep);
+ }
+ return;
+ }
+ }
+ appendText(new_text, allow_undo, prepend_newline, stylep);
+}
+
// Appends new text to end of document
void LLTextEditor::appendText(const std::string &new_text, bool allow_undo, bool prepend_newline,
const LLStyleSP stylep)
@@ -4275,7 +4330,6 @@ S32 LLTextEditor::findHTMLToken(const std::string &line, S32 pos, BOOL reverse)
}
else
{
-
for (int index=pos; index<(S32)line.length(); index++)
{
char c = line[index];