From 18aabdfd3d2efc1b5507e2fe001cfc36ee84b710 Mon Sep 17 00:00:00 2001 From: Paul ProductEngine Date: Tue, 19 Jun 2012 09:44:40 +0300 Subject: CHUI-127 FIXED (Make chat field auto resizable) - Replaced LLLineEditor with newly created LLChatEntry - Moved some functionality (such as setting label) to the LLTextBase as it can be useful to the other derived classes --- indra/llui/llchatentry.cpp | 198 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 indra/llui/llchatentry.cpp (limited to 'indra/llui/llchatentry.cpp') diff --git a/indra/llui/llchatentry.cpp b/indra/llui/llchatentry.cpp new file mode 100644 index 0000000000..6f51705b90 --- /dev/null +++ b/indra/llui/llchatentry.cpp @@ -0,0 +1,198 @@ +/** + * @file llchatentry.cpp + * @brief LLChatEntry implementation + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llchatentry.h" + +static LLDefaultChildRegistry::Register r("text_editor"); + +LLChatEntry::LLChatEntry::Params::Params() +: has_history("has_history", true), + is_expandable("is_expandable", false), + expand_lines_count("expand_lines_count", 1) +{} + +LLChatEntry::LLChatEntry(const Params& p) +: LLTextEditor(p), + mTextExpandedSignal(NULL), + mHasHistory(p.has_history), + mIsExpandable(p.is_expandable), + mExpandLinesCount(p.expand_lines_count), + mPrevLinesCount(0) +{ + // Initialize current history line iterator + mCurrentHistoryLine = mLineHistory.begin(); + + mAutoIndent = false; +} + +LLChatEntry::~LLChatEntry() +{ + delete mTextExpandedSignal; +} + +void LLChatEntry::draw() +{ + LLTextEditor::draw(); + + if(mIsExpandable) + { + expandText(); + } +} + +void LLChatEntry::onCommit() +{ + updateHistory(); + LLTextEditor::onCommit(); +} + +boost::signals2::connection LLChatEntry::setTextExpandedCallback(const commit_signal_t::slot_type& cb) +{ + if (!mTextExpandedSignal) + { + mTextExpandedSignal = new commit_signal_t(); + } + return mTextExpandedSignal->connect(cb); +} + +void LLChatEntry::expandText() +{ + int visible_lines_count = llabs(getVisibleLines(true).first - getVisibleLines(true).second); + bool can_expand = getLineCount() <= mExpandLinesCount; + + // true if pasted text has more lines than expand height limit and expand limit is not reached yet + bool text_pasted = (getLineCount() > mExpandLinesCount) && (visible_lines_count < mExpandLinesCount); + + if (mIsExpandable && (can_expand || text_pasted) && getLineCount() != mPrevLinesCount) + { + int lines_height = 0; + if (text_pasted) + { + // text is pasted and now mLineInfoList.size() > mExpandLineCounts and mLineInfoList is not empty, + // so lines_height is the sum of the last 'mExpandLinesCount' lines height + lines_height = (mLineInfoList.end() - mExpandLinesCount)->mRect.mTop - mLineInfoList.back().mRect.mBottom; + } + else + { + lines_height = mLineInfoList.begin()->mRect.mTop - mLineInfoList.back().mRect.mBottom; + } + + int height = mVPad * 2 + lines_height; + + LLRect doc_rect = getRect(); + doc_rect.setOriginAndSize(doc_rect.mLeft, doc_rect.mBottom, doc_rect.getWidth(), height); + setShape(doc_rect); + + mPrevLinesCount = getLineCount(); + + if (mTextExpandedSignal) + { + (*mTextExpandedSignal)(this, LLSD() ); + } + } +} + +// line history support +void LLChatEntry::updateHistory() +{ + // On history enabled, remember committed line and + // reset current history line number. + // Be sure only to remember lines that are not empty and that are + // different from the last on the list. + if (mHasHistory && getLength()) + { + // Add text to history, ignoring duplicates + if (mLineHistory.empty() || getText() != mLineHistory.back()) + { + mLineHistory.push_back(getText()); + } + + mCurrentHistoryLine = mLineHistory.end(); + } +} + +BOOL LLChatEntry::handleSpecialKey(const KEY key, const MASK mask) +{ + BOOL handled = FALSE; + + LLTextEditor::handleSpecialKey(key, mask); + + switch(key) + { + case KEY_RETURN: + if (MASK_NONE == mask) + { + needsReflow(); + } + break; + + case KEY_UP: + if (mHasHistory && MASK_CONTROL == mask) + { + if (!mLineHistory.empty() && mCurrentHistoryLine > mLineHistory.begin()) + { + setText(*(--mCurrentHistoryLine)); + endOfDoc(); + } + else + { + LLUI::reportBadKeystroke(); + } + handled = TRUE; + } + break; + + case KEY_DOWN: + if (mHasHistory && MASK_CONTROL == mask) + { + if (!mLineHistory.empty() && ++mCurrentHistoryLine < mLineHistory.end()) + { + setText(*mCurrentHistoryLine); + endOfDoc(); + } + else if (!mLineHistory.empty() && mCurrentHistoryLine == mLineHistory.end()) + { + std::string empty(""); + setText(empty); + needsReflow(); + endOfDoc(); + } + else + { + LLUI::reportBadKeystroke(); + } + handled = TRUE; + } + break; + + default: + break; + } + + return handled; +} -- cgit v1.2.3 From ad4ae5583534197cb00c13d769e504fcde4d19d5 Mon Sep 17 00:00:00 2001 From: Paul ProductEngine Date: Tue, 19 Jun 2012 20:37:07 +0300 Subject: Win build fix --- indra/llui/llchatentry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llui/llchatentry.cpp') diff --git a/indra/llui/llchatentry.cpp b/indra/llui/llchatentry.cpp index 6f51705b90..1da7900f59 100644 --- a/indra/llui/llchatentry.cpp +++ b/indra/llui/llchatentry.cpp @@ -30,7 +30,7 @@ static LLDefaultChildRegistry::Register r("text_editor"); -LLChatEntry::LLChatEntry::Params::Params() +LLChatEntry::Params::Params() : has_history("has_history", true), is_expandable("is_expandable", false), expand_lines_count("expand_lines_count", 1) -- cgit v1.2.3 From 91be3bf3019581b74a3515c1081aef883c0658fa Mon Sep 17 00:00:00 2001 From: Paul ProductEngine Date: Fri, 22 Jun 2012 16:56:33 +0300 Subject: CHUI-161 FIXED (Text entered in local chat is not visible to other users nearby) - Applied Merov's fix. The problem was that text_editor was registered twice and, depending of the machine you ran, the viewer would pick one or the other. Mac users were unlucky enough to pick the wrong one all the time. --- indra/llui/llchatentry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llui/llchatentry.cpp') diff --git a/indra/llui/llchatentry.cpp b/indra/llui/llchatentry.cpp index 1da7900f59..dea8ff9bb2 100644 --- a/indra/llui/llchatentry.cpp +++ b/indra/llui/llchatentry.cpp @@ -28,7 +28,7 @@ #include "llchatentry.h" -static LLDefaultChildRegistry::Register r("text_editor"); +static LLDefaultChildRegistry::Register r("chat_editor"); LLChatEntry::Params::Params() : has_history("has_history", true), -- cgit v1.2.3 From 47c140b81d868229187f85185e4721946430ad87 Mon Sep 17 00:00:00 2001 From: Paul ProductEngine Date: Fri, 22 Jun 2012 17:04:47 +0300 Subject: CHUI-127 ADDITIONAL FIX (Make chat field auto resizable) - Fixed crash which occurred while navigating through history of sent messages --- indra/llui/llchatentry.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/llui/llchatentry.cpp') diff --git a/indra/llui/llchatentry.cpp b/indra/llui/llchatentry.cpp index dea8ff9bb2..a6ba125406 100644 --- a/indra/llui/llchatentry.cpp +++ b/indra/llui/llchatentry.cpp @@ -170,13 +170,14 @@ BOOL LLChatEntry::handleSpecialKey(const KEY key, const MASK mask) case KEY_DOWN: if (mHasHistory && MASK_CONTROL == mask) { - if (!mLineHistory.empty() && ++mCurrentHistoryLine < mLineHistory.end()) + if (!mLineHistory.empty() && mCurrentHistoryLine < (mLineHistory.end() - 1) ) { - setText(*mCurrentHistoryLine); + setText(*(++mCurrentHistoryLine)); endOfDoc(); } - else if (!mLineHistory.empty() && mCurrentHistoryLine == mLineHistory.end()) + else if (!mLineHistory.empty() && mCurrentHistoryLine == (mLineHistory.end() - 1) ) { + mCurrentHistoryLine++; std::string empty(""); setText(empty); needsReflow(); -- cgit v1.2.3 From 677c205131e695eb5a3b2a190799330b49d636d8 Mon Sep 17 00:00:00 2001 From: Paul ProductEngine Date: Tue, 26 Jun 2012 19:08:27 +0300 Subject: CHUI-182 FIXED (Vertical scrollbar flashes on and off when chat entry text area expands) - To avoid unnecessary appearing of scrollbar, first chat entry must be expanded and only then decision should be taken in the base class whether scrollbar should be shown or not. --- indra/llui/llchatentry.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llui/llchatentry.cpp') diff --git a/indra/llui/llchatentry.cpp b/indra/llui/llchatentry.cpp index a6ba125406..2a6ccc3dc9 100644 --- a/indra/llui/llchatentry.cpp +++ b/indra/llui/llchatentry.cpp @@ -57,12 +57,12 @@ LLChatEntry::~LLChatEntry() void LLChatEntry::draw() { - LLTextEditor::draw(); - if(mIsExpandable) { expandText(); } + + LLTextEditor::draw(); } void LLChatEntry::onCommit() -- cgit v1.2.3 From 05a72687d848c13754039f6e720a137827533fdb Mon Sep 17 00:00:00 2001 From: Gilbert Gonzales Date: Wed, 17 Oct 2012 14:55:36 -0700 Subject: CHUI-410: Now when a converation floater is focused the default text 'To ' displays only when the text input field is empty. --- indra/llui/llchatentry.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'indra/llui/llchatentry.cpp') diff --git a/indra/llui/llchatentry.cpp b/indra/llui/llchatentry.cpp index 2a6ccc3dc9..38e2a8106a 100644 --- a/indra/llui/llchatentry.cpp +++ b/indra/llui/llchatentry.cpp @@ -136,6 +136,34 @@ void LLChatEntry::updateHistory() } } +void LLChatEntry::beforeValueChange() +{ + if(this->getLength() == 0 && !mLabel.empty()) + { + this->clearSegments(); + } +} + +void LLChatEntry::onValueChange(S32 start, S32 end) +{ + resetLabel(); +} + +BOOL LLChatEntry::useLabel() +{ + return !getLength() && !mLabel.empty(); +} + +void LLChatEntry::onFocusReceived() +{ + +} + +void LLChatEntry::onFocusLost() +{ + +} + BOOL LLChatEntry::handleSpecialKey(const KEY key, const MASK mask) { BOOL handled = FALSE; -- cgit v1.2.3 From 49ad7fd4b57cec635c557070be02556094e90ff6 Mon Sep 17 00:00:00 2001 From: Gilbert Gonzales Date: Wed, 17 Oct 2012 17:52:10 -0700 Subject: CHUI-410: Post code review submit, changed useLabel() to return bool instead of BOOL. Adjusted code accordingly. --- indra/llui/llchatentry.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llui/llchatentry.cpp') diff --git a/indra/llui/llchatentry.cpp b/indra/llui/llchatentry.cpp index 38e2a8106a..8e9c6555c3 100644 --- a/indra/llui/llchatentry.cpp +++ b/indra/llui/llchatentry.cpp @@ -146,10 +146,11 @@ void LLChatEntry::beforeValueChange() void LLChatEntry::onValueChange(S32 start, S32 end) { + //Internally resetLabel() must meet a condition before it can reset the label resetLabel(); } -BOOL LLChatEntry::useLabel() +bool LLChatEntry::useLabel() { return !getLength() && !mLabel.empty(); } -- cgit v1.2.3 From e5aa9088f01f8689e19be82e3caa56fffbab85c1 Mon Sep 17 00:00:00 2001 From: merov_linden Date: Mon, 11 Mar 2013 14:59:53 -0700 Subject: CHUI-810 : Merged Marine Kelley's patch on selected text and use of return key in chat --- indra/llui/llchatentry.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'indra/llui/llchatentry.cpp') diff --git a/indra/llui/llchatentry.cpp b/indra/llui/llchatentry.cpp index 8e9c6555c3..9e48dcde7e 100644 --- a/indra/llui/llchatentry.cpp +++ b/indra/llui/llchatentry.cpp @@ -169,6 +169,15 @@ BOOL LLChatEntry::handleSpecialKey(const KEY key, const MASK mask) { BOOL handled = FALSE; + // In the case of a chat entry, pressing RETURN when something is selected + // should NOT erase the selection (unlike a notecard, for example) + if (key == KEY_RETURN) + { + endOfDoc(); + startSelection(); + endSelection(); + } + LLTextEditor::handleSpecialKey(key, mask); switch(key) -- cgit v1.2.3 From da8f2ffb16d6df1ccb9f34ddf6f26d799d2ea127 Mon Sep 17 00:00:00 2001 From: maksymsproductengine Date: Thu, 28 Mar 2013 04:52:24 +0200 Subject: CHUI-855 FIXED Text entry bar auto expand does not resize --- indra/llui/llchatentry.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'indra/llui/llchatentry.cpp') diff --git a/indra/llui/llchatentry.cpp b/indra/llui/llchatentry.cpp index 9e48dcde7e..6a1b48a08a 100644 --- a/indra/llui/llchatentry.cpp +++ b/indra/llui/llchatentry.cpp @@ -25,6 +25,7 @@ */ #include "linden_common.h" +#include "llscrollcontainer.h" #include "llchatentry.h" @@ -42,7 +43,9 @@ LLChatEntry::LLChatEntry(const Params& p) mHasHistory(p.has_history), mIsExpandable(p.is_expandable), mExpandLinesCount(p.expand_lines_count), - mPrevLinesCount(0) + mPrevLinesCount(0), + mSingleLineMode(false), + mPrevExpandedLineCount(S32_MAX) { // Initialize current history line iterator mCurrentHistoryLine = mLineHistory.begin(); @@ -82,20 +85,23 @@ boost::signals2::connection LLChatEntry::setTextExpandedCallback(const commit_si void LLChatEntry::expandText() { + S32 line_count = mSingleLineMode ? 1 : mExpandLinesCount; + int visible_lines_count = llabs(getVisibleLines(true).first - getVisibleLines(true).second); - bool can_expand = getLineCount() <= mExpandLinesCount; + bool can_changed = getLineCount() <= line_count || line_count < mPrevExpandedLineCount ; + mPrevExpandedLineCount = line_count; // true if pasted text has more lines than expand height limit and expand limit is not reached yet - bool text_pasted = (getLineCount() > mExpandLinesCount) && (visible_lines_count < mExpandLinesCount); + bool text_pasted = (getLineCount() > line_count) && (visible_lines_count < line_count); - if (mIsExpandable && (can_expand || text_pasted) && getLineCount() != mPrevLinesCount) + if (mIsExpandable && (can_changed || text_pasted || mSingleLineMode) && getLineCount() != mPrevLinesCount) { int lines_height = 0; if (text_pasted) { // text is pasted and now mLineInfoList.size() > mExpandLineCounts and mLineInfoList is not empty, - // so lines_height is the sum of the last 'mExpandLinesCount' lines height - lines_height = (mLineInfoList.end() - mExpandLinesCount)->mRect.mTop - mLineInfoList.back().mRect.mBottom; + // so lines_height is the sum of the last 'expanded_line_count' lines height + lines_height = (mLineInfoList.end() - line_count)->mRect.mTop - mLineInfoList.back().mRect.mBottom; } else { @@ -114,6 +120,8 @@ void LLChatEntry::expandText() { (*mTextExpandedSignal)(this, LLSD() ); } + + needsReflow(); } } @@ -235,3 +243,15 @@ BOOL LLChatEntry::handleSpecialKey(const KEY key, const MASK mask) return handled; } + +void LLChatEntry::enableSingleLineMode(bool single_line_mode) +{ + if (mScroller) + { + mScroller->setSize(single_line_mode ? 0 : -1); + } + + mSingleLineMode = single_line_mode; + mPrevLinesCount = -1; + setWordWrap(!single_line_mode); +} -- cgit v1.2.3