diff options
Diffstat (limited to 'indra/newview/llchatitemscontainerctrl.cpp')
-rwxr-xr-x[-rw-r--r--] | indra/newview/llchatitemscontainerctrl.cpp | 426 |
1 files changed, 257 insertions, 169 deletions
diff --git a/indra/newview/llchatitemscontainerctrl.cpp b/indra/newview/llchatitemscontainerctrl.cpp index 63b9fd8e66..cfc62c07b6 100644..100755 --- a/indra/newview/llchatitemscontainerctrl.cpp +++ b/indra/newview/llchatitemscontainerctrl.cpp @@ -2,31 +2,25 @@ * @file llchatitemscontainer.cpp * @brief chat history scrolling panel implementation * - * $LicenseInfo:firstyear=2009&license=viewergpl$ - * - * Copyright (c) 2009, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2009&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * Copyright (C) 2010, 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. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * 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. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * 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 * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -35,230 +29,314 @@ #include "llchatitemscontainerctrl.h" #include "lltextbox.h" -#include "llchatmsgbox.h" #include "llavatariconctrl.h" +#include "llcommandhandler.h" #include "llfloaterreg.h" #include "lllocalcliprect.h" #include "lltrans.h" +#include "llfloaterimnearbychat.h" #include "llviewercontrol.h" #include "llagentdata.h" -/* -static const S32 BORDER_MARGIN = 2; -static const S32 PARENT_BORDER_MARGIN = 0; +#include "llslurl.h" + +static const S32 msg_left_offset = 10; +static const S32 msg_right_offset = 10; +static const S32 msg_height_pad = 5; -static const S32 HORIZONTAL_MULTIPLE = 8; -static const S32 VERTICAL_MULTIPLE = 16; -static const F32 MIN_AUTO_SCROLL_RATE = 120.f; -static const F32 MAX_AUTO_SCROLL_RATE = 500.f; -static const F32 AUTO_SCROLL_RATE_ACCEL = 120.f; +//******************************************************************************************************************* +// LLObjectHandler +//******************************************************************************************************************* -#define MAX_CHAT_HISTORY 100 -*/ +// handle secondlife:///app/object/<ID>/inspect SLURLs +class LLObjectHandler : public LLCommandHandler +{ +public: + LLObjectHandler() : LLCommandHandler("object", UNTRUSTED_BLOCK) { } -static const S32 msg_left_offset = 30; -static const S32 msg_right_offset = 10; -static const S32 msg_height_pad = 2; + bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web) + { + if (params.size() < 2) return false; -//static LLDefaultChildRegistry::Register<LLChatItemsContainerCtrl> t2("chat_items_container"); + LLUUID object_id; + if (!object_id.set(params[0], FALSE)) + { + return false; + } + + const std::string verb = params[1].asString(); + + if (verb == "inspect") + { + LLFloaterReg::showInstance("inspect_object", LLSD().with("object_id", object_id)); + return true; + } + + return false; + } +}; + +LLObjectHandler gObjectHandler; //******************************************************************************************************************* -//LLChatItemCtrl +//LLFloaterIMNearbyChatToastPanel //******************************************************************************************************************* -LLNearbyChatToastPanel* LLNearbyChatToastPanel::createInstance() +LLFloaterIMNearbyChatToastPanel* LLFloaterIMNearbyChatToastPanel::createInstance() { - LLNearbyChatToastPanel* item = new LLNearbyChatToastPanel(); - LLUICtrlFactory::getInstance()->buildPanel(item, "panel_chat_item.xml"); + LLFloaterIMNearbyChatToastPanel* item = new LLFloaterIMNearbyChatToastPanel(); + item->buildFromFile("panel_chat_item.xml"); item->setFollows(FOLLOWS_NONE); return item; } -void LLNearbyChatToastPanel::reshape (S32 width, S32 height, BOOL called_from_parent ) +void LLFloaterIMNearbyChatToastPanel::reshape (S32 width, S32 height, BOOL called_from_parent ) { LLPanel::reshape(width, height,called_from_parent); - // *NOTE: we must check if child items exist because reshape is called from the - // LLView::initFromParams BEFORE postBuild is called and child controls are not exist yet - LLPanel* caption = findChild<LLPanel>("msg_caption", false); - LLChatMsgBox* msg_text = findChild<LLChatMsgBox>("msg_text" ,false); - if(caption && msg_text) + // reshape() may be called from LLView::initFromParams() before the children are created. + // We call findChild() instead of getChild() here to avoid creating dummy controls. + LLUICtrl* msg_text = findChild<LLUICtrl>("msg_text", false); + LLUICtrl* icon = findChild<LLUICtrl>("avatar_icon", false); + + if (!msg_text || !icon) { - LLRect caption_rect = caption->getRect(); - caption_rect.setLeftTopAndSize( 2, height, width - 4, caption_rect.getHeight()); - caption->reshape( width - 4, caption_rect.getHeight(), 1); - caption->setRect(caption_rect); - - LLRect msg_text_rect = msg_text->getRect(); - msg_text_rect.setLeftTopAndSize( msg_left_offset, height - caption_rect.getHeight() , width - msg_left_offset - msg_right_offset, height - caption_rect.getHeight()); - msg_text->reshape( width - msg_left_offset - msg_right_offset, height - caption_rect.getHeight(), 1); - msg_text->setRect(msg_text_rect); + return; } + + LLRect msg_text_rect = msg_text->getRect(); + LLRect avatar_rect = icon->getRect(); + + avatar_rect.setLeftTopAndSize(2,height-2,avatar_rect.getWidth(),avatar_rect.getHeight()); + icon->setRect(avatar_rect); + + + msg_text_rect.setLeftTopAndSize( avatar_rect.mRight + msg_left_offset, + height - msg_height_pad, + width - avatar_rect.mRight - msg_left_offset - msg_right_offset, + height - 2*msg_height_pad); + msg_text->reshape( msg_text_rect.getWidth(), msg_text_rect.getHeight(), 1); + msg_text->setRect(msg_text_rect); } -BOOL LLNearbyChatToastPanel::postBuild() +BOOL LLFloaterIMNearbyChatToastPanel::postBuild() { return LLPanel::postBuild(); } - -std::string LLNearbyChatToastPanel::appendTime() +void LLFloaterIMNearbyChatToastPanel::addMessage(LLSD& notification) { - time_t utc_time; - utc_time = time_corrected(); - std::string timeStr ="["+ LLTrans::getString("TimeHour")+"]:[" - +LLTrans::getString("TimeMin")+"] "; + std::string messageText = notification["message"].asString(); // UTF-8 line of text - LLSD substitution; - substitution["datetime"] = (S32) utc_time; - LLStringUtil::format (timeStr, substitution); + std::string color_name = notification["text_color"].asString(); + + LLColor4 textColor = LLUIColorTable::instance().getColor(color_name); + textColor.mV[VALPHA] =notification["color_alpha"].asReal(); + + S32 font_size = notification["font_size"].asInteger(); - return timeStr; -} + LLFontGL* messageFont; + switch(font_size) + { + case 0: messageFont = LLFontGL::getFontSansSerifSmall(); break; + default: + case 1: messageFont = LLFontGL::getFontSansSerif(); break; + case 2: messageFont = LLFontGL::getFontSansSerifBig(); break; + } + //append text + { + LLStyle::Params style_params; + style_params.color(textColor); + std::string font_name = LLFontGL::nameFromFont(messageFont); + std::string font_style_size = LLFontGL::sizeFromFont(messageFont); + style_params.font.name(font_name); + style_params.font.size(font_style_size); + + int chat_type = notification["chat_type"].asInteger(); + + if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC) + { + style_params.font.style = "ITALIC"; + } + else if( chat_type == CHAT_TYPE_SHOUT) + { + style_params.font.style = "BOLD"; + } + else if( chat_type == CHAT_TYPE_WHISPER) + { + style_params.font.style = "ITALIC"; + } + mMsgText->appendText(messageText, TRUE, style_params); + } + snapToMessageHeight(); -void LLNearbyChatToastPanel::addText (const std::string& message) -{ - LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false); - msg_text->addText(message); - mMessages.push_back(message); } -void LLNearbyChatToastPanel::init(LLSD& notification) +void LLFloaterIMNearbyChatToastPanel::init(LLSD& notification) { - LLPanel* caption = getChild<LLPanel>("msg_caption", false); - - mText = notification["message"].asString(); // UTF-8 line of text - mFromName = notification["from"].asString(); // agent or object name + std::string messageText = notification["message"].asString(); // UTF-8 line of text + std::string fromName = notification["from"].asString(); // agent or object name mFromID = notification["from_id"].asUUID(); // agent id or object id + mFromName = fromName; + int sType = notification["source"].asInteger(); mSourceType = (EChatSourceType)sType; + + std::string color_name = notification["text_color"].asString(); + + LLColor4 textColor = LLUIColorTable::instance().getColor(color_name); + textColor.mV[VALPHA] =notification["color_alpha"].asReal(); + + S32 font_size = notification["font_size"].asInteger(); - std::string str_sender; - - if(gAgentID != mFromID) - str_sender = mFromName; - else - str_sender = LLTrans::getString("You");; - - caption->getChild<LLTextBox>("sender_name", false)->setText(str_sender); + LLFontGL* messageFont; + switch(font_size) + { + case 0: messageFont = LLFontGL::getFontSansSerifSmall(); break; + default: + case 1: messageFont = LLFontGL::getFontSansSerif(); break; + case 2: messageFont = LLFontGL::getFontSansSerifBig(); break; + } - caption->getChild<LLTextBox>("msg_time", false)->setText(appendTime()); + mMsgText = getChild<LLChatMsgBox>("msg_text", false); + mMsgText->setContentTrusted(false); + mMsgText->setText(std::string("")); - LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false); - msg_text->setText(mText); + if ( notification["chat_style"].asInteger() != CHAT_STYLE_IRC ) + { + std::string str_sender; - LLUICtrl* msg_inspector = caption->getChild<LLUICtrl>("msg_inspector"); - if(mSourceType != CHAT_SOURCE_AGENT) - msg_inspector->setVisible(false); + str_sender = fromName; - mMessages.clear(); + str_sender+=" "; - snapToMessageHeight (); + //append sender name + if (mSourceType == CHAT_SOURCE_AGENT || mSourceType == CHAT_SOURCE_OBJECT) + { + LLStyle::Params style_params_name; - mIsDirty = true;//will set Avatar Icon in draw -} + LLColor4 user_name_color = LLUIColorTable::instance().getColor("HTMLLinkColor"); + style_params_name.color(user_name_color); -void LLNearbyChatToastPanel::setMessage (const LLChat& chat_msg) -{ - LLSD notification; - notification["message"] = chat_msg.mText; - notification["from"] = chat_msg.mFromName; - notification["from_id"] = chat_msg.mFromID; - notification["time"] = chat_msg.mTime; - notification["source"] = (S32)chat_msg.mSourceType; + std::string font_name = LLFontGL::nameFromFont(messageFont); + std::string font_style_size = LLFontGL::sizeFromFont(messageFont); + style_params_name.font.name(font_name); + style_params_name.font.size(font_style_size); - init(notification); + style_params_name.link_href = notification["sender_slurl"].asString(); + style_params_name.is_link = true; -} + mMsgText->appendText(str_sender, FALSE, style_params_name); -void LLNearbyChatToastPanel::snapToMessageHeight () -{ - LLChatMsgBox* text_box = getChild<LLChatMsgBox>("msg_text", false); - S32 new_height = text_box->getTextPixelHeight() + msg_height_pad; - LLRect panel_rect = getRect(); + } + else + { + mMsgText->appendText(str_sender, false); + } + } - S32 caption_height = 0; - LLPanel* caption = getChild<LLPanel>("msg_caption", false); - caption_height = caption->getRect().getHeight(); + //append text + { + LLStyle::Params style_params; + style_params.color(textColor); + std::string font_name = LLFontGL::nameFromFont(messageFont); + std::string font_style_size = LLFontGL::sizeFromFont(messageFont); + style_params.font.name(font_name); + style_params.font.size(font_style_size); + + int chat_type = notification["chat_type"].asInteger(); + + if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC) + { + style_params.font.style = "ITALIC"; + } + else if( chat_type == CHAT_TYPE_SHOUT) + { + style_params.font.style = "BOLD"; + } + else if( chat_type == CHAT_TYPE_WHISPER) + { + style_params.font.style = "ITALIC"; + } + mMsgText->appendText(messageText, FALSE, style_params); + } - panel_rect.setLeftTopAndSize( panel_rect.mLeft, panel_rect.mTop, panel_rect.getWidth(), caption_height + new_height); - - reshape( getRect().getWidth(), caption_height + new_height, 1); - - setRect(panel_rect); -} + snapToMessageHeight(); + mIsDirty = true;//will set Avatar Icon in draw +} -void LLNearbyChatToastPanel::setWidth(S32 width) +void LLFloaterIMNearbyChatToastPanel::snapToMessageHeight () { - LLChatMsgBox* text_box = getChild<LLChatMsgBox>("msg_text", false); - text_box->reshape(width - msg_left_offset - msg_right_offset,100/*its not magic number, we just need any number*/); + S32 new_height = llmax (mMsgText->getTextPixelHeight() + 2*mMsgText->getVPad() + 2*msg_height_pad, 25); + + LLRect panel_rect = getRect(); - LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false); - if(mText.length()) - msg_text->setText(mText); + panel_rect.setLeftTopAndSize( panel_rect.mLeft, panel_rect.mTop, panel_rect.getWidth(), new_height); + + reshape( getRect().getWidth(), getRect().getHeight(), 1); - for(size_t i=0;i<mMessages.size();++i) - msg_text->addText(mMessages[i]); + setRect(panel_rect); - setRect(LLRect(getRect().mLeft, getRect().mTop, getRect().mLeft + width , getRect().mBottom)); - snapToMessageHeight (); } -void LLNearbyChatToastPanel::onMouseLeave (S32 x, S32 y, MASK mask) +void LLFloaterIMNearbyChatToastPanel::onMouseLeave (S32 x, S32 y, MASK mask) { - LLPanel* caption = getChild<LLPanel>("msg_caption", false); - LLUICtrl* msg_inspector = caption->getChild<LLUICtrl>("msg_inspector"); - msg_inspector->setVisible(false); } -void LLNearbyChatToastPanel::onMouseEnter (S32 x, S32 y, MASK mask) +void LLFloaterIMNearbyChatToastPanel::onMouseEnter (S32 x, S32 y, MASK mask) { if(mSourceType != CHAT_SOURCE_AGENT) return; - LLPanel* caption = getChild<LLPanel>("msg_caption", false); - LLUICtrl* msg_inspector = caption->getChild<LLUICtrl>("msg_inspector"); - msg_inspector->setVisible(true); } -BOOL LLNearbyChatToastPanel::handleMouseDown (S32 x, S32 y, MASK mask) +BOOL LLFloaterIMNearbyChatToastPanel::handleMouseDown (S32 x, S32 y, MASK mask) { - if(mSourceType != CHAT_SOURCE_AGENT) - return LLPanel::handleMouseDown(x,y,mask); - LLPanel* caption = getChild<LLPanel>("msg_caption", false); - LLUICtrl* msg_inspector = caption->getChild<LLUICtrl>("msg_inspector"); - S32 local_x = x - msg_inspector->getRect().mLeft - caption->getRect().mLeft; - S32 local_y = y - msg_inspector->getRect().mBottom - caption->getRect().mBottom; - if(msg_inspector->pointInView(local_x, local_y)) - { - LLFloaterReg::showInstance("inspect_avatar", LLSD().insert("avatar_id", mFromID)); - } - else - { - LLFloaterReg::showInstance("nearby_chat",LLSD()); - } return LLPanel::handleMouseDown(x,y,mask); } -void LLNearbyChatToastPanel::setHeaderVisibility(EShowItemHeader e) +BOOL LLFloaterIMNearbyChatToastPanel::handleMouseUp (S32 x, S32 y, MASK mask) { - LLPanel* caption = getChild<LLPanel>("msg_caption", false); + /* + fix for request EXT-4780 + leaving this commented since I don't remember why ew block those messages... + if(mSourceType != CHAT_SOURCE_AGENT) + return LLPanel::handleMouseUp(x,y,mask); + */ - LLUICtrl* icon = caption->getChild<LLUICtrl>("avatar_icon", false); - LLUICtrl* name = caption->getChild<LLUICtrl>("sender_name", false); + S32 local_x = x - mMsgText->getRect().mLeft; + S32 local_y = y - mMsgText->getRect().mBottom; + + //if text_box process mouse up (ussually this is click on url) - we didn't show nearby_chat. + if (mMsgText->pointInView(local_x, local_y) ) + { + if (mMsgText->handleMouseUp(local_x,local_y,mask) == TRUE) + return TRUE; + else + { + LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat")->showHistory(); + return FALSE; + } + } + LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat")->showHistory(); + return LLPanel::handleMouseUp(x,y,mask); +} - icon->setVisible(e == CHATITEMHEADER_SHOW_ONLY_ICON || e==CHATITEMHEADER_SHOW_BOTH); - name->setVisible(e == CHATITEMHEADER_SHOW_ONLY_NAME || e==CHATITEMHEADER_SHOW_BOTH); +void LLFloaterIMNearbyChatToastPanel::setHeaderVisibility(EShowItemHeader e) +{ + LLUICtrl* icon = getChild<LLUICtrl>("avatar_icon", false); + if(icon) + icon->setVisible(e == CHATITEMHEADER_SHOW_ONLY_ICON || e==CHATITEMHEADER_SHOW_BOTH); } -bool LLNearbyChatToastPanel::canAddText () +bool LLFloaterIMNearbyChatToastPanel::canAddText () { LLChatMsgBox* msg_text = findChild<LLChatMsgBox>("msg_text"); if(!msg_text) @@ -266,29 +344,39 @@ bool LLNearbyChatToastPanel::canAddText () return msg_text->getLineCount()<10; } -BOOL LLNearbyChatToastPanel::handleRightMouseDown(S32 x, S32 y, MASK mask) +BOOL LLFloaterIMNearbyChatToastPanel::handleRightMouseDown(S32 x, S32 y, MASK mask) { - LLPanel* caption = getChild<LLPanel>("msg_caption", false); - LLUICtrl* avatar_icon = caption->getChild<LLUICtrl>("avatar_icon", false); + LLUICtrl* avatar_icon = getChild<LLUICtrl>("avatar_icon", false); - S32 local_x = x - avatar_icon->getRect().mLeft - caption->getRect().mLeft; - S32 local_y = y - avatar_icon->getRect().mBottom - caption->getRect().mBottom; + S32 local_x = x - avatar_icon->getRect().mLeft; + S32 local_y = y - avatar_icon->getRect().mBottom; //eat message for avatar icon if msg was from object if(avatar_icon->pointInView(local_x, local_y) && mSourceType != CHAT_SOURCE_AGENT) return TRUE; return LLPanel::handleRightMouseDown(x,y,mask); } -void LLNearbyChatToastPanel::draw() +void LLFloaterIMNearbyChatToastPanel::draw() { + LLPanel::draw(); + if(mIsDirty) { - LLPanel* caption = findChild<LLPanel>("msg_caption", false); - if(caption) - caption->getChild<LLAvatarIconCtrl>("avatar_icon", false)->setValue(mFromID); + LLAvatarIconCtrl* icon = getChild<LLAvatarIconCtrl>("avatar_icon", false); + if(icon) + { + icon->setDrawTooltip(mSourceType == CHAT_SOURCE_AGENT); + if(mSourceType == CHAT_SOURCE_OBJECT) + icon->setValue(LLSD("OBJECT_Icon")); + else if(mSourceType == CHAT_SOURCE_SYSTEM) + icon->setValue(LLSD("SL_Logo")); + else if(mSourceType == CHAT_SOURCE_AGENT) + icon->setValue(mFromID); + else if(!mFromID.isNull()) + icon->setValue(mFromID); + } mIsDirty = false; } - LLToastPanelBase::draw(); } |