diff options
author | Richard Nelson <richard@lindenlab.com> | 2009-10-05 20:53:51 +0000 |
---|---|---|
committer | Richard Nelson <richard@lindenlab.com> | 2009-10-05 20:53:51 +0000 |
commit | 606311b508c5b13cd995a98d16660e61a58fa3f7 (patch) | |
tree | 76060699e943ce9c305f1c717815f8ad01f4c7ed /indra/newview | |
parent | 9818f158366a0df980a2e4b9251177d9a9209cfb (diff) |
text boxes are now *not* mouse_opaque by default
fixed some textbox and text editor layout problems (getWidth called with wrong index)
EXT-1302 - rewrite LLExpandableTextBox to use new LLTextBase functionality (using custom LLExpanderSegment)
reviewed by James
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llexpandabletextbox.cpp | 322 | ||||
-rw-r--r-- | indra/newview/llexpandabletextbox.h | 36 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/floater_test_widgets.xml | 5 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/panel_profile.xml | 8 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/widgets/expandable_text.xml | 10 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/widgets/text.xml | 1 |
6 files changed, 108 insertions, 274 deletions
diff --git a/indra/newview/llexpandabletextbox.cpp b/indra/newview/llexpandabletextbox.cpp index f8f5db9d7e..28c124d1c6 100644 --- a/indra/newview/llexpandabletextbox.cpp +++ b/indra/newview/llexpandabletextbox.cpp @@ -34,253 +34,121 @@ #include "llexpandabletextbox.h" #include "llscrollcontainer.h" +#include "llwindow.h" static LLDefaultChildRegistry::Register<LLExpandableTextBox> t1("expandable_text"); -LLExpandableTextBox::LLTextBoxEx::Params::Params() -: expand_textbox("expand_textbox") +class LLExpanderSegment : public LLTextSegment { -} +public: + LLExpanderSegment(const LLStyleSP& style, S32 start, S32 end, const std::string& more_text, LLTextBase& editor ) + : LLTextSegment(start, end), + mEditor(editor), + mStyle(style), + mMoreText(more_text) + {} + + /*virtual*/ S32 getWidth(S32 first_char, S32 num_chars) const + { + // more label always spans width of text box + return mEditor.getTextRect().getWidth(); + } + /*virtual*/ S32 getOffset(S32 segment_local_x_coord, S32 start_offset, S32 num_chars, bool round) const + { + return start_offset; + } + /*virtual*/ S32 getNumChars(S32 num_pixels, S32 segment_offset, S32 line_offset, S32 max_chars) const { return getEnd() - getStart(); } + /*virtual*/ F32 draw(S32 start, S32 end, S32 selection_start, S32 selection_end, const LLRect& draw_rect) + { + F32 right_x; + mStyle->getFont()->renderUTF8(mMoreText, start, draw_rect.mRight, draw_rect.mTop, mStyle->getColor(), LLFontGL::RIGHT, LLFontGL::TOP, 0, mStyle->getShadowType(), end - start, draw_rect.getWidth(), &right_x, mEditor.getUseEllipses()); + return right_x; + } + /*virtual*/ S32 getMaxHeight() const { return llceil(mStyle->getFont()->getLineHeight()); } + /*virtual*/ bool canEdit() const { return false; } + /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask) { mEditor.onCommit(); return TRUE; } + /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask) + { + LLUI::getWindow()->setCursor(UI_CURSOR_HAND); + return TRUE; + } +private: + LLTextBase& mEditor; + LLStyleSP mStyle; + std::string mMoreText; +}; + + LLExpandableTextBox::LLTextBoxEx::LLTextBoxEx(const Params& p) -: LLTextBox(p) +: LLTextBox(p), + mExpanded(false) { setIsChrome(TRUE); - LLTextBox::Params params = p.expand_textbox; - mExpandTextBox = LLUICtrlFactory::create<LLTextBox>(params); - addChild(mExpandTextBox); - - LLRect rc = getLocalRect(); - rc.mRight -= getHPad(); - rc.mLeft = rc.mRight - mExpandTextBox->getTextPixelWidth(); - rc.mTop = mExpandTextBox->getTextPixelHeight(); - mExpandTextBox->setRect(rc); } -BOOL LLExpandableTextBox::LLTextBoxEx::handleMouseUp(S32 x, S32 y, MASK mask) +void LLExpandableTextBox::LLTextBoxEx::reshape(S32 width, S32 height, BOOL called_from_parent) { - BOOL ret = LLTextBox::handleMouseUp(x, y, mask); + LLTextBox::reshape(width, height, called_from_parent); - if(mExpandTextBox->getRect().pointInRect(x, y)) + if (getTextPixelHeight() > getRect().getHeight()) { - onCommit(); + showExpandText(); + } + else + { + hideExpandText(); } - - return ret; } -void LLExpandableTextBox::LLTextBoxEx::draw() +void LLExpandableTextBox::LLTextBoxEx::setValue(const LLSD& value) { - // draw text box - LLTextBox::draw(); - // force text box to draw children - LLUICtrl::draw(); -} - -/* LLTextBox has been rewritten, the variables referenced in this code -no longer exist. + LLTextBox::setValue(value); -void LLExpandableTextBox::LLTextBoxEx::drawText( S32 x, S32 y, const LLWString &text, const LLColor4& color ) -{ - // *NOTE:dzaporozhan: - // Copy/paste from LLTextBox::drawText in order to modify last - // line width if needed and who "More" link - F32 alpha = getDrawContext().mAlpha; - if (mSegments.size() > 1) + if (getTextPixelHeight() > getRect().getHeight()) { - // we have Urls (or other multi-styled segments) - drawTextSegments(x, y, text); - } - else if( mLineLengthList.empty() ) - { - // simple case of 1 line of text in one style - mDefaultFont->render(text, 0, (F32)x, (F32)y, color % alpha, - mHAlign, mVAlign, - 0, - mShadowType, - S32_MAX, getRect().getWidth(), NULL, mUseEllipses); - - mExpandTextBox->setVisible(FALSE); + showExpandText(); } else { - // simple case of multiple lines of text, all in the same style - S32 cur_pos = 0; - for (std::vector<S32>::iterator iter = mLineLengthList.begin(); - iter != mLineLengthList.end(); ++iter) - { - S32 line_length = *iter; - S32 line_height = llfloor(mDefaultFont->getLineHeight()) + mLineSpacing; - S32 max_pixels = getRect().getWidth(); - - if(iter + 1 != mLineLengthList.end() - && y - line_height < line_height) - { - max_pixels = getCropTextWidth(); - } - - mDefaultFont->render(text, cur_pos, (F32)x, (F32)y, color % alpha, - mHAlign, mVAlign, - 0, - mShadowType, - line_length, max_pixels, NULL, mUseEllipses ); - - cur_pos += line_length + 1; - - y -= line_height; - if(y < line_height) - { - if( mLineLengthList.end() != iter + 1 ) - { - showExpandText(y); - } - else - { - hideExpandText(); - } - break; - } - } + hideExpandText(); } } -*/ -void LLExpandableTextBox::LLTextBoxEx::showExpandText(S32 y) -{ - LLRect rc = mExpandTextBox->getRect(); - rc.mTop = y + mExpandTextBox->getTextPixelHeight(); - rc.mBottom = y; - mExpandTextBox->setRect(rc); - mExpandTextBox->setVisible(TRUE); -} -void LLExpandableTextBox::LLTextBoxEx::hideExpandText() -{ - mExpandTextBox->setVisible(FALSE); -} - -S32 LLExpandableTextBox::LLTextBoxEx::getCropTextWidth() -{ - return mExpandTextBox->getRect().mLeft - getHPad() * 2; -} - -/* -// *NOTE:James: -// LLTextBox::drawText() has been completely rewritten, as it now handles -// arbitrarily styled segments of text. This needs to be rebuilt. - -void LLExpandableTextBox::LLTextBoxEx::drawTextSegments(S32 init_x, S32 init_y, const LLWString &text) +void LLExpandableTextBox::LLTextBoxEx::showExpandText() { - - // *NOTE:dzaporozhan: - // Copy/paste from LLTextBox::drawTextSegments in order to modify last - // line width if needed and who "More" link - F32 alpha = getDrawContext().mAlpha; - - const S32 text_len = text.length(); - if (text_len <= 0) + if (!mExpanded) { - return; + // get fully visible lines + std::pair<S32, S32> visible_lines = getVisibleLines(true); + S32 last_line = visible_lines.second - 1; + + LLStyle::Params expander_style = getDefaultStyle(); + expander_style.font.name.setIfNotProvided(LLFontGL::nameFromFont(expander_style.font)); + expander_style.font.style = "UNDERLINE"; + expander_style.color = LLUIColorTable::instance().getColor("HTMLLinkColor"); + LLExpanderSegment* expanderp = new LLExpanderSegment(new LLStyle(expander_style), getLineStart(last_line), getLength() + 1, "More", *this); + insertSegment(expanderp); + mExpanded = true; } - S32 cur_line = 0; - S32 num_lines = getLineCount(); - S32 line_start = getLineStart(cur_line); - S32 line_height = llround( mDefaultFont->getLineHeight() ) + mLineSpacing; - F32 text_y = (F32) init_y; - segment_set_t::iterator cur_seg = mSegments.begin(); +} - // render a line of text at a time - const LLRect textRect = getLocalRect(); - while((textRect.mBottom <= text_y) && (cur_line < num_lines)) +//NOTE: obliterates existing styles (including hyperlinks) +void LLExpandableTextBox::LLTextBoxEx::hideExpandText() +{ + if (mExpanded) { - S32 next_start = -1; - S32 line_end = text_len; - - if ((cur_line + 1) < num_lines) - { - next_start = getLineStart(cur_line + 1); - line_end = next_start; - } - if ( text[line_end-1] == '\n' ) - { - --line_end; - } - - // render all segments on this line - F32 text_x = init_x; - S32 seg_start = line_start; - while (seg_start < line_end && cur_seg != mSegments.end()) - { - // move to the next segment (or continue the previous one) - LLTextSegment *cur_segment = *cur_seg; - while (cur_segment->getEnd() <= seg_start) - { - if (++cur_seg == mSegments.end()) - { - return; - } - cur_segment = *cur_seg; - } - - // Draw a segment within the line - S32 clipped_end = llmin( line_end, cur_segment->getEnd() ); - S32 clipped_len = clipped_end - seg_start; - if( clipped_len > 0 ) - { - LLStyleSP style = cur_segment->getStyle(); - if (style && style->isVisible()) - { - // work out the color for the segment - LLColor4 color ; - if (getEnabled()) - { - color = style->isLink() ? mLinkColor.get() : mTextColor.get(); - } - else - { - color = mDisabledColor.get(); - } - color = color % alpha; - - S32 max_pixels = textRect.getWidth(); - - if(cur_line + 1 < num_lines - && text_y - line_height < line_height) - { - max_pixels = getCropTextWidth(); - } - - // render a single line worth for this segment - mDefaultFont->render(text, seg_start, text_x, text_y, color, - mHAlign, mVAlign, 0, mShadowType, clipped_len, - max_pixels, &text_x, mUseEllipses); - } - - seg_start += clipped_len; - } - } - - // move down one line - text_y -= (F32)line_height; - line_start = next_start; - cur_line++; - if(text_y < line_height) - { - if( cur_line < num_lines ) - { - showExpandText((S32)text_y); - } - else - { - hideExpandText(); - } - break; - } + // this will overwrite the expander segment and all text styling with a single style + LLNormalTextSegment* segmentp = new LLNormalTextSegment( + new LLStyle(getDefaultStyle()), 0, getLength() + 1, *this); + insertSegment(segmentp); + + mExpanded = false; } } -*/ S32 LLExpandableTextBox::LLTextBoxEx::getVerticalTextDelta() { @@ -295,24 +163,24 @@ S32 LLExpandableTextBox::LLTextBoxEx::getVerticalTextDelta() ////////////////////////////////////////////////////////////////////////// LLExpandableTextBox::Params::Params() -: textbox("textbox") -, scroll("scroll") -, max_height("max_height", 0) -, bg_visible("bg_visible", false) -, expanded_bg_visible("expanded_bg_visible", true) -, bg_color("bg_color", LLColor4::black) -, expanded_bg_color("expanded_bg_color", LLColor4::black) +: textbox("textbox"), + scroll("scroll"), + max_height("max_height", 0), + bg_visible("bg_visible", false), + expanded_bg_visible("expanded_bg_visible", true), + bg_color("bg_color", LLColor4::black), + expanded_bg_color("expanded_bg_color", LLColor4::black) { } LLExpandableTextBox::LLExpandableTextBox(const Params& p) -: LLUICtrl(p) -, mMaxHeight(p.max_height) -, mBGVisible(p.bg_visible) -, mExpandedBGVisible(p.expanded_bg_visible) -, mBGColor(p.bg_color) -, mExpandedBGColor(p.expanded_bg_color) -, mExpanded(false) +: LLUICtrl(p), + mMaxHeight(p.max_height), + mBGVisible(p.bg_visible), + mExpandedBGVisible(p.expanded_bg_visible), + mBGColor(p.bg_color), + mExpandedBGColor(p.expanded_bg_color), + mExpanded(false) { LLRect rc = getLocalRect(); @@ -474,8 +342,6 @@ void LLExpandableTextBox::collapseTextBox() updateTextBoxRect(); - // Should be handled automatically in reshape above. JC - //mTextBox->setWrappedText(mText); if(gFocusMgr.getTopCtrl() == this) { gFocusMgr.setTopCtrl(NULL); diff --git a/indra/newview/llexpandabletextbox.h b/indra/newview/llexpandabletextbox.h index 0b9c3f7258..b78a4dc674 100644 --- a/indra/newview/llexpandabletextbox.h +++ b/indra/newview/llexpandabletextbox.h @@ -54,27 +54,11 @@ protected: public: struct Params : public LLInitParam::Block<Params, LLTextBox::Params> { - Optional<LLTextBox::Params> expand_textbox; - - Params(); }; - /** - * Draw text box and "More" link - */ - /*virtual*/ void draw(); - -// /** -// * Draws simple text(no urls) line by line, will show or hide "More" link -// * if needed. -// */ -// /*virtual*/ void drawText( S32 x, S32 y, const LLWString &text, const LLColor4& color ); -// -// /** -// * Draws segmented text(with urls) line by line. Will show or hide "More" link -// * if needed -// */ -// void drawTextSegments(S32 x, S32 y, const LLWString &text); + // adds or removes "More" link as needed + /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); + /*virtual*/ void setValue(const LLSD& value); /** * Returns difference between text box height and text height. @@ -92,11 +76,6 @@ protected: */ virtual S32 getHPad() { return mHPad; } - /** - * Broadcasts "commit" signal if user clicked "More" link - */ - /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask); - protected: LLTextBoxEx(const Params& p); @@ -105,21 +84,16 @@ protected: /** * Shows "More" link */ - void showExpandText(S32 y); + void showExpandText(); /** * Hides "More" link */ void hideExpandText(); - /** - * Returns cropped line width - */ - S32 getCropTextWidth(); - private: - LLTextBox* mExpandTextBox; + bool mExpanded; }; public: diff --git a/indra/newview/skins/default/xui/en/floater_test_widgets.xml b/indra/newview/skins/default/xui/en/floater_test_widgets.xml index 5a29c6a319..8ed2047a27 100644 --- a/indra/newview/skins/default/xui/en/floater_test_widgets.xml +++ b/indra/newview/skins/default/xui/en/floater_test_widgets.xml @@ -316,13 +316,16 @@ height="40" follows="top|left|bottom" layout="topleft" - name="test_text_editor" + name="test_text_box" tool_tip="text box" top_pad="5" width="200"> Text box with multiple lines +and too +many +line to actually fit </text> <!-- And a third column --> diff --git a/indra/newview/skins/default/xui/en/panel_profile.xml b/indra/newview/skins/default/xui/en/panel_profile.xml index b4212aaa34..9cf699ad46 100644 --- a/indra/newview/skins/default/xui/en/panel_profile.xml +++ b/indra/newview/skins/default/xui/en/panel_profile.xml @@ -43,7 +43,7 @@ layout="topleft" top="0" left="0" - width="284" + width="300" height="700"> <panel follows="left|top" @@ -52,7 +52,7 @@ left="10" name="second_life_image_panel" top="10" - width="280"> + width="285"> <texture_picker allow_no_texture="true" default_image_name="None" @@ -94,7 +94,7 @@ top_pad="10" left="10" name="first_life_image_panel" - width="280"> + width="285"> <texture_picker allow_no_texture="true" default_image_name="None" @@ -122,7 +122,7 @@ height="90" layout="topleft" name="fl_description_edit" - width="180" + width="170" expanded_bg_visible="true" expanded_bg_color="black"> Lorem ipsum dolor sit amet, consectetur adlkjpiscing elit moose moose. Aenean viverra orci et justo sagittis aliquet. Nullam malesuada mauris sit amet. adipiscing elit. Aenean rigviverra orci et justo sagittis aliquet. Nullam malesuada mauris sit amet sorbet ipsum. adipiscing elit. Aenean viverra orci et justo sagittis aliquet. Nullam malesuada mauris sit amet ipsum. diff --git a/indra/newview/skins/default/xui/en/widgets/expandable_text.xml b/indra/newview/skins/default/xui/en/widgets/expandable_text.xml index bcfc2f6472..e470f42d36 100644 --- a/indra/newview/skins/default/xui/en/widgets/expandable_text.xml +++ b/indra/newview/skins/default/xui/en/widgets/expandable_text.xml @@ -9,16 +9,6 @@ tab_stop="true" v_pad="2" h_pad="3" > - <expand_textbox - name="expand" - follows="bottom|right" - visible="false" - bg_visible="false" - tab_stop="false" - v_pad="0" - h_pad="0" - text="[http://www.DUMMY.com More]" - tool_tip="Click to expand text"/> </textbox> <scroll name="scroll" diff --git a/indra/newview/skins/default/xui/en/widgets/text.xml b/indra/newview/skins/default/xui/en/widgets/text.xml index 7d78a8fa20..f0127a9d5a 100644 --- a/indra/newview/skins/default/xui/en/widgets/text.xml +++ b/indra/newview/skins/default/xui/en/widgets/text.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="utf-8" standalone="yes" ?> <text allow_html="true" clip_to_rect="false" + mouse_opaque="false" name="text_box" font="SansSerifSmall" font_shadow="soft" |