From 2d19b297a98d8be87c487f6b93e098dce9ca908c Mon Sep 17 00:00:00 2001 From: Paul ProductEngine Date: Fri, 13 May 2011 18:23:11 +0300 Subject: STORM-1202 FIXED Time spin control Implemented time spin control which is like spin control, but shows and allows to edit time string in "hh:mm PM/AM" format. Implemented according to the WLRS spec. --- indra/llui/lllineeditor.cpp | 106 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 85 insertions(+), 21 deletions(-) (limited to 'indra/llui/lllineeditor.cpp') diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index d99ee5a545..66c607e988 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -81,6 +81,7 @@ LLLineEditor::Params::Params() : max_length(""), keystroke_callback("keystroke_callback"), prevalidate_callback("prevalidate_callback"), + prevalidate_input_callback("prevalidate_input_callback"), background_image("background_image"), background_image_disabled("background_image_disabled"), background_image_focused("background_image_focused"), @@ -173,6 +174,7 @@ LLLineEditor::LLLineEditor(const LLLineEditor::Params& p) updateTextPadding(); setCursor(mText.length()); + setPrevalidate(p.prevalidate_input_callback()); setPrevalidate(p.prevalidate_callback()); LLContextMenu* menu = LLUICtrlFactory::instance().createFromFile @@ -401,23 +403,16 @@ void LLLineEditor::setText(const LLStringExplicit &new_text) // Picks a new cursor position based on the actual screen size of text being drawn. void LLLineEditor::setCursorAtLocalPos( S32 local_mouse_x ) { - const llwchar* wtext = mText.getWString().c_str(); - LLWString asterix_text; - if (mDrawAsterixes) - { - for (S32 i = 0; i < mText.length(); i++) - { - asterix_text += utf8str_to_wstring(PASSWORD_ASTERISK); - } - wtext = asterix_text.c_str(); - } + S32 cursor_pos = calcCursorPos(local_mouse_x); + + S32 left_pos = llmin( mSelectionStart, cursor_pos ); + S32 selection_length = llabs( mSelectionStart - cursor_pos ); + const LLWString& text = mText.getWString(); + const LLWString& substr = text.substr(left_pos, selection_length); + + if (mPrevalidateInputFunc && mIsSelecting && !mPrevalidateInputFunc(substr)) + return; - S32 cursor_pos = - mScrollHPos + - mGLFont->charFromPixelOffset( - wtext, mScrollHPos, - (F32)(local_mouse_x - mTextLeftEdge), - (F32)(mTextRightEdge - mTextLeftEdge + 1)); // min-max range is inclusive setCursor(cursor_pos); } @@ -501,6 +496,9 @@ BOOL LLLineEditor::canSelectAll() const void LLLineEditor::selectAll() { + if (mPrevalidateInputFunc && !mPrevalidateInputFunc(mText.getWString())) + return; + mSelectionStart = mText.length(); mSelectionEnd = 0; setCursor(mSelectionEnd); @@ -586,6 +584,9 @@ BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask) if (mask & MASK_SHIFT) { + // assume we're starting a drag select + mIsSelecting = TRUE; + // Handle selection extension S32 old_cursor_pos = getCursor(); setCursorAtLocalPos(x); @@ -620,8 +621,6 @@ BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask) mSelectionStart = old_cursor_pos; mSelectionEnd = getCursor(); } - // assume we're starting a drag select - mIsSelecting = TRUE; } else { @@ -792,6 +791,9 @@ void LLLineEditor::removeChar() { if( getCursor() > 0 ) { + if (mPrevalidateInputFunc && !mPrevalidateInputFunc(mText.getWString().substr(getCursor()-1, 1))) + return; + mText.erase(getCursor() - 1, 1); setCursor(getCursor() - 1); @@ -812,6 +814,9 @@ void LLLineEditor::addChar(const llwchar uni_char) } else if (LL_KIM_OVERWRITE == gKeyboard->getInsertMode()) { + if (mPrevalidateInputFunc && !mPrevalidateInputFunc(mText.getWString().substr(getCursor(), 1))) + return; + mText.erase(getCursor(), 1); } @@ -860,6 +865,13 @@ void LLLineEditor::extendSelection( S32 new_cursor_pos ) startSelection(); } + S32 left_pos = llmin( mSelectionStart, new_cursor_pos ); + S32 selection_length = llabs( mSelectionStart - new_cursor_pos ); + const LLWString& selection = mText.getWString(); + + if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(selection.substr(left_pos, selection_length))) + return; + setCursor(new_cursor_pos); mSelectionEnd = getCursor(); } @@ -992,6 +1004,10 @@ void LLLineEditor::deleteSelection() { S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); S32 selection_length = llabs( mSelectionStart - mSelectionEnd ); + const LLWString& selection = mText.getWString(); + + if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(selection.substr(left_pos, selection_length))) + return; mText.erase(left_pos, selection_length); deselect(); @@ -1009,12 +1025,16 @@ void LLLineEditor::cut() { if( canCut() ) { + S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); + S32 length = llabs( mSelectionStart - mSelectionEnd ); + const LLWString& selection = mText.getWString(); + + if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(selection.substr(left_pos, length))) + return; + // Prepare for possible rollback LLLineEditorRollback rollback( this ); - - S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); - S32 length = llabs( mSelectionStart - mSelectionEnd ); gClipboard.copyFromSubstring( mText.getWString(), left_pos, length ); deleteSelection(); @@ -1094,6 +1114,9 @@ void LLLineEditor::pasteHelper(bool is_primary) if (!paste.empty()) { + if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(paste) ) + return; + // Prepare for possible rollback LLLineEditorRollback rollback(this); @@ -1441,6 +1464,11 @@ BOOL LLLineEditor::handleUnicodeCharHere(llwchar uni_char) LLLineEditorRollback rollback( this ); + LLWString u_char; + u_char.assign(1, uni_char); + if (mPrevalidateInputFunc && !mPrevalidateInputFunc(u_char)) + return handled; + addChar(uni_char); mKeystrokeTimer.reset(); @@ -1492,6 +1520,15 @@ void LLLineEditor::doDelete() } else if ( getCursor() < mText.length()) { + const LLWString& selection = mText.getWString(); + + if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(selection.substr(getCursor(), 1))) + { + if( mKeystrokeCallback ) + mKeystrokeCallback( this ); + + return; + } setCursor(getCursor() + 1); removeChar(); } @@ -1839,6 +1876,27 @@ S32 LLLineEditor::findPixelNearestPos(const S32 cursor_offset) const return result; } +S32 LLLineEditor::calcCursorPos(S32 mouse_x) +{ + const llwchar* wtext = mText.getWString().c_str(); + LLWString asterix_text; + if (mDrawAsterixes) + { + for (S32 i = 0; i < mText.length(); i++) + { + asterix_text += utf8str_to_wstring(PASSWORD_ASTERISK); + } + wtext = asterix_text.c_str(); + } + + S32 cur_pos = mScrollHPos + + mGLFont->charFromPixelOffset( + wtext, mScrollHPos, + (F32)(mouse_x - mTextLeftEdge), + (F32)(mTextRightEdge - mTextLeftEdge + 1)); // min-max range is inclusive + + return cur_pos; +} //virtual void LLLineEditor::clear() { @@ -1932,6 +1990,12 @@ void LLLineEditor::setPrevalidate(LLTextValidate::validate_func_t func) updateAllowingLanguageInput(); } +void LLLineEditor::setPrevalidateInputText(LLTextValidate::validate_func_t func) +{ + mPrevalidateInputFunc = func; + updateAllowingLanguageInput(); +} + // static BOOL LLLineEditor::postvalidateFloat(const std::string &str) { -- cgit v1.2.3 From 5daeefd35e1e105f403f99184ad866e8823767d4 Mon Sep 17 00:00:00 2001 From: Paul ProductEngine Date: Mon, 16 May 2011 17:59:05 +0300 Subject: STORM-1202 Code cleanup for LLLineEditor - Removed code duplication - Renamed prevalidateInputText to prevalidateInput --- indra/llui/lllineeditor.cpp | 65 +++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'indra/llui/lllineeditor.cpp') diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index 66c607e988..2527a608bf 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -174,7 +174,7 @@ LLLineEditor::LLLineEditor(const LLLineEditor::Params& p) updateTextPadding(); setCursor(mText.length()); - setPrevalidate(p.prevalidate_input_callback()); + setPrevalidateInput(p.prevalidate_input_callback()); setPrevalidate(p.prevalidate_callback()); LLContextMenu* menu = LLUICtrlFactory::instance().createFromFile @@ -406,11 +406,10 @@ void LLLineEditor::setCursorAtLocalPos( S32 local_mouse_x ) S32 cursor_pos = calcCursorPos(local_mouse_x); S32 left_pos = llmin( mSelectionStart, cursor_pos ); - S32 selection_length = llabs( mSelectionStart - cursor_pos ); - const LLWString& text = mText.getWString(); - const LLWString& substr = text.substr(left_pos, selection_length); + S32 length = llabs( mSelectionStart - cursor_pos ); + const LLWString& substr = mText.getWString().substr(left_pos, length); - if (mPrevalidateInputFunc && mIsSelecting && !mPrevalidateInputFunc(substr)) + if (mIsSelecting && !prevalidateInput(substr)) return; setCursor(cursor_pos); @@ -496,8 +495,10 @@ BOOL LLLineEditor::canSelectAll() const void LLLineEditor::selectAll() { - if (mPrevalidateInputFunc && !mPrevalidateInputFunc(mText.getWString())) + if (!prevalidateInput(mText.getWString())) + { return; + } mSelectionStart = mText.length(); mSelectionEnd = 0; @@ -791,7 +792,7 @@ void LLLineEditor::removeChar() { if( getCursor() > 0 ) { - if (mPrevalidateInputFunc && !mPrevalidateInputFunc(mText.getWString().substr(getCursor()-1, 1))) + if (!prevalidateInput(mText.getWString().substr(getCursor()-1, 1))) return; mText.erase(getCursor() - 1, 1); @@ -814,7 +815,7 @@ void LLLineEditor::addChar(const llwchar uni_char) } else if (LL_KIM_OVERWRITE == gKeyboard->getInsertMode()) { - if (mPrevalidateInputFunc && !mPrevalidateInputFunc(mText.getWString().substr(getCursor(), 1))) + if (!prevalidateInput(mText.getWString().substr(getCursor(), 1))) return; mText.erase(getCursor(), 1); @@ -867,9 +868,9 @@ void LLLineEditor::extendSelection( S32 new_cursor_pos ) S32 left_pos = llmin( mSelectionStart, new_cursor_pos ); S32 selection_length = llabs( mSelectionStart - new_cursor_pos ); - const LLWString& selection = mText.getWString(); + const LLWString& selection = mText.getWString().substr(left_pos, selection_length); - if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(selection.substr(left_pos, selection_length))) + if (!prevalidateInput(selection)) return; setCursor(new_cursor_pos); @@ -1002,11 +1003,11 @@ void LLLineEditor::deleteSelection() { if( !mReadOnly && hasSelection() ) { - S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); - S32 selection_length = llabs( mSelectionStart - mSelectionEnd ); - const LLWString& selection = mText.getWString(); + S32 left_pos, selection_length; + getSelectionRange(&left_pos, &selection_length); + const LLWString& selection = mText.getWString().substr(left_pos, selection_length); - if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(selection.substr(left_pos, selection_length))) + if (!prevalidateInput(selection)) return; mText.erase(left_pos, selection_length); @@ -1025,11 +1026,11 @@ void LLLineEditor::cut() { if( canCut() ) { - S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); - S32 length = llabs( mSelectionStart - mSelectionEnd ); - const LLWString& selection = mText.getWString(); + S32 left_pos, length; + getSelectionRange(&left_pos, &length); + const LLWString& selection = mText.getWString().substr(left_pos, length); - if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(selection.substr(left_pos, length))) + if (!prevalidateInput(selection)) return; // Prepare for possible rollback @@ -1114,7 +1115,7 @@ void LLLineEditor::pasteHelper(bool is_primary) if (!paste.empty()) { - if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(paste) ) + if (!prevalidateInput(paste)) return; // Prepare for possible rollback @@ -1464,10 +1465,12 @@ BOOL LLLineEditor::handleUnicodeCharHere(llwchar uni_char) LLLineEditorRollback rollback( this ); - LLWString u_char; - u_char.assign(1, uni_char); - if (mPrevalidateInputFunc && !mPrevalidateInputFunc(u_char)) - return handled; + { + LLWString u_char; + u_char.assign(1, uni_char); + if (!prevalidateInput(u_char)) + return handled; + } addChar(uni_char); @@ -1520,9 +1523,9 @@ void LLLineEditor::doDelete() } else if ( getCursor() < mText.length()) { - const LLWString& selection = mText.getWString(); + const LLWString& text_to_delete = mText.getWString().substr(getCursor(), 1); - if ( mPrevalidateInputFunc && !mPrevalidateInputFunc(selection.substr(getCursor(), 1))) + if (!prevalidateInput(text_to_delete)) { if( mKeystrokeCallback ) mKeystrokeCallback( this ); @@ -1990,12 +1993,22 @@ void LLLineEditor::setPrevalidate(LLTextValidate::validate_func_t func) updateAllowingLanguageInput(); } -void LLLineEditor::setPrevalidateInputText(LLTextValidate::validate_func_t func) +void LLLineEditor::setPrevalidateInput(LLTextValidate::validate_func_t func) { mPrevalidateInputFunc = func; updateAllowingLanguageInput(); } +bool LLLineEditor::prevalidateInput(const LLWString& wstr) +{ + if (mPrevalidateInputFunc && !mPrevalidateInputFunc(wstr)) + { + return false; + } + + return true; +} + // static BOOL LLLineEditor::postvalidateFloat(const std::string &str) { -- cgit v1.2.3