diff options
Diffstat (limited to 'indra/llui/lllineeditor.cpp')
-rw-r--r-- | indra/llui/lllineeditor.cpp | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index 50edc3e8e7..3eb58e1aec 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -78,7 +78,7 @@ template class LLLineEditor* LLView::getChild<class LLLineEditor>( // LLLineEditor::Params::Params() -: max_length_bytes("max_length", 254), +: max_length(""), keystroke_callback("keystroke_callback"), prevalidate_callback("prevalidate_callback"), background_image("background_image"), @@ -108,7 +108,8 @@ LLLineEditor::Params::Params() LLLineEditor::LLLineEditor(const LLLineEditor::Params& p) : LLUICtrl(p), - mMaxLengthBytes(p.max_length_bytes), + mMaxLengthBytes(p.max_length.bytes), + mMaxLengthChars(p.max_length.chars), mCursorPos( 0 ), mScrollHPos( 0 ), mTextPadLeft(p.text_pad_left), @@ -313,6 +314,12 @@ void LLLineEditor::setMaxTextLength(S32 max_text_length) mMaxLengthBytes = max_len; } +void LLLineEditor::setMaxTextChars(S32 max_text_chars) +{ + S32 max_chars = llmax(0, max_text_chars); + mMaxLengthChars = max_chars; +} + void LLLineEditor::getTextPadding(S32 *left, S32 *right) { *left = mTextPadLeft; @@ -358,6 +365,16 @@ void LLLineEditor::setText(const LLStringExplicit &new_text) } mText.assign(truncated_utf8); + if (mMaxLengthChars) + { + LLWString truncated_wstring = utf8str_to_wstring(truncated_utf8); + if (truncated_wstring.size() > (U32)mMaxLengthChars) + { + truncated_wstring = truncated_wstring.substr(0, mMaxLengthChars); + } + mText.assign(wstring_to_utf8str(truncated_wstring)); + } + if (all_selected) { // ...keep whole thing selected @@ -798,6 +815,7 @@ void LLLineEditor::addChar(const llwchar uni_char) } S32 cur_bytes = mText.getString().size(); + S32 new_bytes = wchar_utf8_length(new_c); BOOL allow_char = TRUE; @@ -807,6 +825,14 @@ void LLLineEditor::addChar(const llwchar uni_char) { allow_char = FALSE; } + else if (mMaxLengthChars) + { + S32 wide_chars = mText.getWString().size(); + if ((wide_chars + 1) > mMaxLengthChars) + { + allow_char = FALSE; + } + } if (allow_char) { @@ -1107,7 +1133,19 @@ void LLLineEditor::pasteHelper(bool is_primary) clean_string = clean_string.substr(0, wchars_that_fit); LLUI::reportBadKeystroke(); } - + + if (mMaxLengthChars) + { + U32 available_chars = mMaxLengthChars - mText.getWString().size(); + + if (available_chars < clean_string.size()) + { + clean_string = clean_string.substr(0, available_chars); + } + + LLUI::reportBadKeystroke(); + } + mText.insert(getCursor(), clean_string); setCursor( getCursor() + (S32)clean_string.length() ); deselect(); |