summaryrefslogtreecommitdiff
path: root/indra/llui/lllineeditor.cpp
diff options
context:
space:
mode:
authorLeyla Farazha <leyla@lindenlab.com>2010-09-16 09:38:05 -0700
committerLeyla Farazha <leyla@lindenlab.com>2010-09-16 09:38:05 -0700
commitae623c8068145f968f09ccf9bbdd90e993ca4283 (patch)
tree29cffd02ee00b447c07e4cd40a2e0fa9b8cc30a3 /indra/llui/lllineeditor.cpp
parente27ac0abf7bef6e61c2d81911cc0c693206ee401 (diff)
Set display name field now clamps to 31 unicode characters
Added ability to set max length in line editors by characters in addition to bytes left other widgets (comboboxes/spinners) using the bytes, but it can easily be changed over reviewed by Richard
Diffstat (limited to 'indra/llui/lllineeditor.cpp')
-rw-r--r--indra/llui/lllineeditor.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp
index 2759167d04..3646228097 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,6 +1133,13 @@ void LLLineEditor::pasteHelper(bool is_primary)
clean_string = clean_string.substr(0, wchars_that_fit);
LLUI::reportBadKeystroke();
}
+
+ U32 available_chars = mMaxLengthChars - mText.getWString().size();
+
+ if (available_chars < clean_string.size())
+ {
+ clean_string = clean_string.substr(0, available_chars);
+ }
mText.insert(getCursor(), clean_string);
setCursor( getCursor() + (S32)clean_string.length() );