aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/lltexteditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llui/lltexteditor.cpp')
-rw-r--r--linden/indra/llui/lltexteditor.cpp57
1 files changed, 40 insertions, 17 deletions
diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp
index ba991c2..80205d3 100644
--- a/linden/indra/llui/lltexteditor.cpp
+++ b/linden/indra/llui/lltexteditor.cpp
@@ -309,6 +309,9 @@ LLTextEditor::LLTextEditor(
309{ 309{
310 mSourceID.generate(); 310 mSourceID.generate();
311 311
312 // reset desired x cursor position
313 mDesiredXPixel = -1;
314
312 if (font) 315 if (font)
313 { 316 {
314 mGLFont = font; 317 mGLFont = font;
@@ -348,7 +351,7 @@ LLTextEditor::LLTextEditor(
348 mBorder = new LLViewBorder( "text ed border", LLRect(0, mRect.getHeight(), mRect.getWidth(), 0), LLViewBorder::BEVEL_IN, LLViewBorder::STYLE_LINE, UI_TEXTEDITOR_BORDER ); 351 mBorder = new LLViewBorder( "text ed border", LLRect(0, mRect.getHeight(), mRect.getWidth(), 0), LLViewBorder::BEVEL_IN, LLViewBorder::STYLE_LINE, UI_TEXTEDITOR_BORDER );
349 addChild( mBorder ); 352 addChild( mBorder );
350 353
351 setText(default_text); 354 appendText(default_text, FALSE, FALSE);
352 355
353 mParseHTML=FALSE; 356 mParseHTML=FALSE;
354 mHTML=""; 357 mHTML="";
@@ -914,6 +917,8 @@ void LLTextEditor::setCursorPos(S32 offset)
914{ 917{
915 mCursorPos = llclamp(offset, 0, (S32)getLength()); 918 mCursorPos = llclamp(offset, 0, (S32)getLength());
916 updateScrollFromCursor(); 919 updateScrollFromCursor();
920 // reset desired x cursor position
921 mDesiredXPixel = -1;
917} 922}
918 923
919 924
@@ -2645,7 +2650,8 @@ void LLTextEditor::drawSelectionBackground()
2645 { 2650 {
2646 LLGLSNoTexture no_texture; 2651 LLGLSNoTexture no_texture;
2647 const LLColor4& color = mReadOnly ? mReadOnlyBgColor : mWriteableBgColor; 2652 const LLColor4& color = mReadOnly ? mReadOnlyBgColor : mWriteableBgColor;
2648 glColor3f( 1.f - color.mV[0], 1.f - color.mV[1], 1.f - color.mV[2] ); 2653 F32 alpha = hasFocus() ? 1.f : 0.5f;
2654 glColor4f( 1.f - color.mV[0], 1.f - color.mV[1], 1.f - color.mV[2], alpha );
2649 2655
2650 if( selection_left_y == selection_right_y ) 2656 if( selection_left_y == selection_right_y )
2651 { 2657 {
@@ -3098,6 +3104,9 @@ void LLTextEditor::changePage( S32 delta )
3098 S32 line, offset; 3104 S32 line, offset;
3099 getLineAndOffset( mCursorPos, &line, &offset ); 3105 getLineAndOffset( mCursorPos, &line, &offset );
3100 3106
3107 // get desired x position to remember previous position
3108 S32 desired_x_pixel = mDesiredXPixel;
3109
3101 // allow one line overlap 3110 // allow one line overlap
3102 S32 page_size = mScrollbar->getPageSize() - 1; 3111 S32 page_size = mScrollbar->getPageSize() - 1;
3103 if( delta == -1 ) 3112 if( delta == -1 )
@@ -3112,6 +3121,10 @@ void LLTextEditor::changePage( S32 delta )
3112 setCursorPos(getPos( line + page_size, offset )); 3121 setCursorPos(getPos( line + page_size, offset ));
3113 mScrollbar->setDocPos( mScrollbar->getDocPos() + page_size ); 3122 mScrollbar->setDocPos( mScrollbar->getDocPos() + page_size );
3114 } 3123 }
3124
3125 // put desired position into remember-buffer after setCursorPos()
3126 mDesiredXPixel = desired_x_pixel;
3127
3115 if (mOnScrollEndCallback && mOnScrollEndData && (mScrollbar->getDocPos() == mScrollbar->getDocPosMax())) 3128 if (mOnScrollEndCallback && mOnScrollEndData && (mScrollbar->getDocPos() == mScrollbar->getDocPosMax()))
3116 { 3129 {
3117 mOnScrollEndCallback(mOnScrollEndData); 3130 mOnScrollEndCallback(mOnScrollEndData);
@@ -3127,9 +3140,13 @@ void LLTextEditor::changeLine( S32 delta )
3127 3140
3128 S32 line_start = getLineStart(line); 3141 S32 line_start = getLineStart(line);
3129 3142
3130 S32 desired_x_pixel; 3143 // set desired x position to remembered previous position
3131 3144 S32 desired_x_pixel = mDesiredXPixel;
3132 desired_x_pixel = mGLFont->getWidth(mWText.c_str(), line_start, offset, mAllowEmbeddedItems ); 3145 // if remembered position was reset (thus -1), calculate new one here
3146 if( desired_x_pixel == -1 )
3147 {
3148 desired_x_pixel = mGLFont->getWidth(mWText.c_str(), line_start, offset, mAllowEmbeddedItems );
3149 }
3133 3150
3134 S32 new_line = 0; 3151 S32 new_line = 0;
3135 if( (delta < 0) && (line > 0 ) ) 3152 if( (delta < 0) && (line > 0 ) )
@@ -3165,6 +3182,9 @@ void LLTextEditor::changeLine( S32 delta )
3165 mAllowEmbeddedItems); 3182 mAllowEmbeddedItems);
3166 3183
3167 setCursorPos (getPos( new_line, new_offset )); 3184 setCursorPos (getPos( new_line, new_offset ));
3185
3186 // put desired position into remember-buffer after setCursorPos()
3187 mDesiredXPixel = desired_x_pixel;
3168 unbindEmbeddedChars( mGLFont ); 3188 unbindEmbeddedChars( mGLFont );
3169} 3189}
3170 3190
@@ -3358,6 +3378,14 @@ void LLTextEditor::appendColoredText(const LLString &new_text,
3358 style.setVisible(true); 3378 style.setVisible(true);
3359 style.setColor(color); 3379 style.setColor(color);
3360 style.setFontName(font_name); 3380 style.setFontName(font_name);
3381 appendStyledText(new_text, allow_undo, prepend_newline, &style);
3382}
3383
3384void LLTextEditor::appendStyledText(const LLString &new_text,
3385 bool allow_undo,
3386 bool prepend_newline,
3387 const LLStyle* style)
3388{
3361 if(mParseHTML) 3389 if(mParseHTML)
3362 { 3390 {
3363 3391
@@ -3368,10 +3396,13 @@ void LLTextEditor::appendColoredText(const LLString &new_text,
3368 LLStyle html; 3396 LLStyle html;
3369 html.setVisible(true); 3397 html.setVisible(true);
3370 html.setColor(mLinkColor); 3398 html.setColor(mLinkColor);
3371 html.setFontName(font_name); 3399 if (style)
3400 {
3401 html.setFontName(style->getFontString());
3402 }
3372 html.mUnderline = TRUE; 3403 html.mUnderline = TRUE;
3373 3404
3374 if (start > 0) appendText(text.substr(0,start),allow_undo, prepend_newline, &style); 3405 if (start > 0) appendText(text.substr(0,start),allow_undo, prepend_newline, style);
3375 html.setLinkHREF(text.substr(start,end-start)); 3406 html.setLinkHREF(text.substr(start,end-start));
3376 appendText(text.substr(start, end-start),allow_undo, prepend_newline, &html); 3407 appendText(text.substr(start, end-start),allow_undo, prepend_newline, &html);
3377 if (end < (S32)text.length()) 3408 if (end < (S32)text.length())
@@ -3384,22 +3415,14 @@ void LLTextEditor::appendColoredText(const LLString &new_text,
3384 break; 3415 break;
3385 } 3416 }
3386 } 3417 }
3387 if (end < (S32)text.length()) appendText(text,allow_undo, prepend_newline, &style); 3418 if (end < (S32)text.length()) appendText(text,allow_undo, prepend_newline, style);
3388 } 3419 }
3389 else 3420 else
3390 { 3421 {
3391 appendText(new_text, allow_undo, prepend_newline, &style); 3422 appendText(new_text, allow_undo, prepend_newline, style);
3392 } 3423 }
3393} 3424}
3394 3425
3395void LLTextEditor::appendStyledText(const LLString &new_text,
3396 bool allow_undo,
3397 bool prepend_newline,
3398 const LLStyle &style)
3399{
3400 appendText(new_text, allow_undo, prepend_newline, &style);
3401}
3402
3403// Appends new text to end of document 3426// Appends new text to end of document
3404void LLTextEditor::appendText(const LLString &new_text, bool allow_undo, bool prepend_newline, 3427void LLTextEditor::appendText(const LLString &new_text, bool allow_undo, bool prepend_newline,
3405 const LLStyle* segment_style) 3428 const LLStyle* segment_style)