PageRenderTime 48ms CodeModel.GetById 18ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lltoastimpanel.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 229 lines | 159 code | 32 blank | 38 comment | 14 complexity | 18e8158ed027427ae68d1b18ebed7444 MD5 | raw file
  1/**
  2 * @file lltoastimpanel.cpp
  3 * @brief Panel for IM toasts.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28#include "lltoastimpanel.h"
 29
 30#include "llagent.h"
 31#include "llfloaterreg.h"
 32#include "llgroupactions.h"
 33#include "llgroupiconctrl.h"
 34#include "llimview.h"
 35#include "llnotifications.h"
 36#include "llinstantmessage.h"
 37#include "lltooltip.h"
 38
 39#include "llviewerchat.h"
 40
 41const S32 LLToastIMPanel::DEFAULT_MESSAGE_MAX_LINE_COUNT	= 6;
 42
 43//--------------------------------------------------------------------------
 44LLToastIMPanel::LLToastIMPanel(LLToastIMPanel::Params &p) :	LLToastPanel(p.notification),
 45								mAvatarIcon(NULL), mAvatarName(NULL),
 46								mTime(NULL), mMessage(NULL), mGroupIcon(NULL)
 47{
 48	buildFromFile( "panel_instant_message.xml");
 49
 50	mGroupIcon = getChild<LLGroupIconCtrl>("group_icon");
 51	mAvatarIcon = getChild<LLAvatarIconCtrl>("avatar_icon");
 52	mAdhocIcon = getChild<LLAvatarIconCtrl>("adhoc_icon");
 53	mAvatarName = getChild<LLTextBox>("user_name");
 54	mTime = getChild<LLTextBox>("time_box");
 55	mMessage = getChild<LLTextBox>("message");
 56
 57	LLStyle::Params style_params;
 58	LLFontGL* fontp = LLViewerChat::getChatFont();
 59	std::string font_name = LLFontGL::nameFromFont(fontp);
 60	std::string font_size = LLFontGL::sizeFromFont(fontp);
 61	style_params.font.name(font_name);
 62	style_params.font.size(font_size);
 63	
 64	
 65	//Handle IRC styled /me messages.
 66	std::string prefix = p.message.substr(0, 4);
 67	if (prefix == "/me " || prefix == "/me'")
 68	{
 69		//style_params.font.style = "UNDERLINE";
 70		mMessage->clear();
 71		
 72		style_params.font.style ="ITALIC";
 73		mMessage->appendText(p.from, FALSE, style_params);
 74
 75		style_params.font.style = "ITALIC";
 76		mMessage->appendText(p.message.substr(3), FALSE, style_params);
 77	}
 78	else
 79	{
 80		style_params.font.style =  "NORMAL";
 81		mMessage->setText(p.message, style_params);
 82	}
 83
 84	mAvatarName->setValue(p.from);
 85	mTime->setValue(p.time);
 86	mSessionID = p.session_id;
 87	mAvatarID = p.avatar_id;
 88	mNotification = p.notification;
 89
 90	initIcon();
 91
 92	S32 maxLinesCount;
 93	std::istringstream ss( getString("message_max_lines_count") );
 94	if (!(ss >> maxLinesCount))
 95	{
 96		maxLinesCount = DEFAULT_MESSAGE_MAX_LINE_COUNT;
 97	}
 98	snapToMessageHeight(mMessage, maxLinesCount);
 99}
100
101//--------------------------------------------------------------------------
102LLToastIMPanel::~LLToastIMPanel()
103{
104}
105
106//virtual
107BOOL LLToastIMPanel::handleMouseDown(S32 x, S32 y, MASK mask)
108{
109	if (LLPanel::handleMouseDown(x,y,mask) == FALSE)
110	{
111		mNotification->respond(mNotification->getResponseTemplate());
112	}
113
114	return TRUE;
115}
116
117//virtual
118BOOL LLToastIMPanel::handleToolTip(S32 x, S32 y, MASK mask)
119{
120	// It's not our direct child, so parentPointInView() doesn't work.
121	LLRect ctrl_rect;
122
123	mAvatarName->localRectToOtherView(mAvatarName->getLocalRect(), &ctrl_rect, this);
124	if (ctrl_rect.pointInRect(x, y))
125	{
126		spawnNameToolTip();
127		return TRUE;
128	}
129
130	mGroupIcon->localRectToOtherView(mGroupIcon->getLocalRect(), &ctrl_rect, this);
131	if(mGroupIcon->getVisible() && ctrl_rect.pointInRect(x, y))
132	{
133		spawnGroupIconToolTip();
134		return TRUE;
135	}
136
137	return LLToastPanel::handleToolTip(x, y, mask);
138}
139
140void LLToastIMPanel::spawnNameToolTip()
141{
142	// Spawn at right side of the name textbox.
143	LLRect sticky_rect = mAvatarName->calcScreenRect();
144	S32 icon_x =
145		llmin(sticky_rect.mLeft + mAvatarName->getTextPixelWidth() + 3, sticky_rect.mRight);
146	LLCoordGL pos(icon_x, sticky_rect.mTop);
147
148	LLToolTip::Params params;
149	params.background_visible(false);
150	params.click_callback(boost::bind(&LLFloaterReg::showInstance, "inspect_avatar", LLSD().with("avatar_id", mAvatarID), FALSE));
151	params.delay_time(0.0f);		// spawn instantly on hover
152	params.image(LLUI::getUIImage("Info_Small"));
153	params.message("");
154	params.padding(0);
155	params.pos(pos);
156	params.sticky_rect(sticky_rect);
157
158	LLToolTipMgr::getInstance()->show(params);
159}
160
161void LLToastIMPanel::spawnGroupIconToolTip()
162{
163	// Spawn at right bottom side of group icon.
164	LLRect sticky_rect = mGroupIcon->calcScreenRect();
165	LLCoordGL pos(sticky_rect.mRight, sticky_rect.mBottom);
166
167	LLGroupData g_data;
168	if(!gAgent.getGroupData(mSessionID, g_data))
169	{
170		llwarns << "Error getting group data" << llendl;
171	}
172
173	LLInspector::Params params;
174	params.fillFrom(LLUICtrlFactory::instance().getDefaultParams<LLInspector>());
175	params.click_callback(boost::bind(&LLFloaterReg::showInstance, "inspect_group", LLSD().with("group_id", mSessionID), FALSE));
176	params.delay_time(0.100f);
177	params.image(LLUI::getUIImage("Info_Small"));
178	params.message(g_data.mName);
179	params.padding(3);
180	params.pos(pos);
181	params.max_width(300);
182
183	LLToolTipMgr::getInstance()->show(params);
184}
185
186void LLToastIMPanel::initIcon()
187{
188	mAvatarIcon->setVisible(FALSE);
189	mGroupIcon->setVisible(FALSE);
190	mAdhocIcon->setVisible(FALSE);
191
192	if(mAvatarName->getValue().asString() == SYSTEM_FROM)
193	{
194		// "sys_msg_icon" was disabled by Erica in the changeset: 5109 (85181bc92cbe)
195		// and "dummy widget" warnings appeared in log.
196		// It does not make sense to have such image with empty name. Removed for EXT-5057.
197	}
198	else
199	{
200		LLIMModel::LLIMSession* im_session = LLIMModel::getInstance()->findIMSession(mSessionID);
201		if(!im_session)
202		{
203			llwarns << "Invalid IM session" << llendl;
204			return;
205		}
206
207		switch(im_session->mSessionType)
208		{
209		case LLIMModel::LLIMSession::P2P_SESSION:
210			mAvatarIcon->setVisible(TRUE);
211			mAvatarIcon->setValue(mAvatarID);
212			break;
213		case LLIMModel::LLIMSession::GROUP_SESSION:
214			mGroupIcon->setVisible(TRUE);
215			mGroupIcon->setValue(mSessionID);
216			break;
217		case LLIMModel::LLIMSession::ADHOC_SESSION:
218			mAdhocIcon->setVisible(TRUE);
219			mAdhocIcon->setValue(im_session->mOtherParticipantID);
220			mAdhocIcon->setToolTip(im_session->mName);
221			break;
222		default:
223			llwarns << "Unknown IM session type" << llendl;
224			break;
225		}
226	}
227}
228
229// EOF