PageRenderTime 42ms CodeModel.GetById 12ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llchatitemscontainerctrl.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 378 lines | 257 code | 78 blank | 43 comment | 49 complexity | 8c48af9fb3d2d6b1cda057709971283b MD5 | raw file
  1/** 
  2 * @file llchatitemscontainer.cpp
  3 * @brief chat history scrolling panel implementation
  4 *
  5 * $LicenseInfo:firstyear=2009&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
 29#include "llchatitemscontainerctrl.h"
 30#include "lltextbox.h"
 31
 32#include "llchatmsgbox.h"
 33#include "llavatariconctrl.h"
 34#include "llcommandhandler.h"
 35#include "llfloaterreg.h"
 36#include "lllocalcliprect.h"
 37#include "lltrans.h"
 38#include "llnearbychatbar.h"
 39
 40#include "llviewercontrol.h"
 41#include "llagentdata.h"
 42
 43#include "llslurl.h"
 44
 45static const S32 msg_left_offset = 10;
 46static const S32 msg_right_offset = 10;
 47static const S32 msg_height_pad = 5;
 48
 49//*******************************************************************************************************************
 50// LLObjectHandler
 51//*******************************************************************************************************************
 52
 53// handle secondlife:///app/object/<ID>/inspect SLURLs
 54class LLObjectHandler : public LLCommandHandler
 55{
 56public:
 57	LLObjectHandler() : LLCommandHandler("object", UNTRUSTED_BLOCK) { }
 58
 59	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
 60	{
 61		if (params.size() < 2) return false;
 62
 63		LLUUID object_id;
 64		if (!object_id.set(params[0], FALSE))
 65		{
 66			return false;
 67		}
 68
 69		const std::string verb = params[1].asString();
 70
 71		if (verb == "inspect")
 72		{
 73			LLFloaterReg::showInstance("inspect_object", LLSD().with("object_id", object_id));
 74			return true;
 75		}
 76
 77		return false;
 78	}
 79};
 80
 81LLObjectHandler gObjectHandler;
 82
 83//*******************************************************************************************************************
 84//LLNearbyChatToastPanel
 85//*******************************************************************************************************************
 86
 87LLNearbyChatToastPanel* LLNearbyChatToastPanel::createInstance()
 88{
 89	LLNearbyChatToastPanel* item = new LLNearbyChatToastPanel();
 90	item->buildFromFile("panel_chat_item.xml");
 91	item->setFollows(FOLLOWS_NONE);
 92	return item;
 93}
 94
 95void	LLNearbyChatToastPanel::reshape		(S32 width, S32 height, BOOL called_from_parent )
 96{
 97	LLPanel::reshape(width, height,called_from_parent);
 98
 99	LLUICtrl* msg_text = getChild<LLUICtrl>("msg_text", false);
100	LLUICtrl* icon = getChild<LLUICtrl>("avatar_icon", false);
101
102	LLRect msg_text_rect = msg_text->getRect();
103	LLRect avatar_rect = icon->getRect();
104	
105	avatar_rect.setLeftTopAndSize(2,height-2,avatar_rect.getWidth(),avatar_rect.getHeight());
106	icon->setRect(avatar_rect);
107
108
109	msg_text_rect.setLeftTopAndSize( avatar_rect.mRight + msg_left_offset, 
110		height - msg_height_pad, 
111		width - avatar_rect.mRight  - msg_left_offset - msg_right_offset, 
112		height - 2*msg_height_pad);
113	msg_text->reshape( msg_text_rect.getWidth(), msg_text_rect.getHeight(), 1);
114	msg_text->setRect(msg_text_rect);
115}
116
117BOOL LLNearbyChatToastPanel::postBuild()
118{
119	return LLPanel::postBuild();
120}
121
122void LLNearbyChatToastPanel::addMessage(LLSD& notification)
123{
124	std::string		messageText = notification["message"].asString();		// UTF-8 line of text
125
126	LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false);
127
128	std::string color_name = notification["text_color"].asString();
129	
130	LLColor4 textColor = LLUIColorTable::instance().getColor(color_name);
131	textColor.mV[VALPHA] =notification["color_alpha"].asReal();
132	
133	S32 font_size = notification["font_size"].asInteger();
134
135	LLFontGL*       messageFont;
136	switch(font_size)
137	{
138		case 0:	messageFont = LLFontGL::getFontSansSerifSmall(); break;
139		default:
140		case 1: messageFont = LLFontGL::getFontSansSerif();	    break;
141		case 2:	messageFont = LLFontGL::getFontSansSerifBig();	break;
142	}
143
144	//append text
145	{
146		LLStyle::Params style_params;
147		style_params.color(textColor);
148		std::string font_name = LLFontGL::nameFromFont(messageFont);
149		std::string font_style_size = LLFontGL::sizeFromFont(messageFont);
150		style_params.font.name(font_name);
151		style_params.font.size(font_style_size);
152
153		int chat_type = notification["chat_type"].asInteger();
154
155		if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC)
156		{
157			style_params.font.style = "ITALIC";
158		}
159		else if( chat_type == CHAT_TYPE_SHOUT)
160		{
161			style_params.font.style = "BOLD";
162		}
163		else if( chat_type == CHAT_TYPE_WHISPER)
164		{
165			style_params.font.style = "ITALIC";
166		}
167		msg_text->appendText(messageText, TRUE, style_params);
168	}
169
170	snapToMessageHeight();
171
172}
173
174void LLNearbyChatToastPanel::init(LLSD& notification)
175{
176	std::string		messageText = notification["message"].asString();		// UTF-8 line of text
177	std::string		fromName = notification["from"].asString();	// agent or object name
178	mFromID = notification["from_id"].asUUID();		// agent id or object id
179	mFromName = fromName;
180	
181	int sType = notification["source"].asInteger();
182    mSourceType = (EChatSourceType)sType;
183	
184	std::string color_name = notification["text_color"].asString();
185	
186	LLColor4 textColor = LLUIColorTable::instance().getColor(color_name);
187	textColor.mV[VALPHA] =notification["color_alpha"].asReal();
188	
189	S32 font_size = notification["font_size"].asInteger();
190
191	LLFontGL*       messageFont;
192	switch(font_size)
193	{
194		case 0:	messageFont = LLFontGL::getFontSansSerifSmall(); break;
195		default:
196		case 1: messageFont = LLFontGL::getFontSansSerif();	    break;
197		case 2:	messageFont = LLFontGL::getFontSansSerifBig();	break;
198	}
199	
200	LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false);
201
202	msg_text->setText(std::string(""));
203
204	if ( notification["chat_style"].asInteger() != CHAT_STYLE_IRC )
205	{
206		std::string str_sender;
207
208		str_sender = fromName;
209
210		str_sender+=" ";
211
212		//append sender name
213		if (mSourceType == CHAT_SOURCE_AGENT || mSourceType == CHAT_SOURCE_OBJECT)
214		{
215			LLStyle::Params style_params_name;
216
217			LLColor4 user_name_color = LLUIColorTable::instance().getColor("HTMLLinkColor");
218			style_params_name.color(user_name_color);
219
220			std::string font_name = LLFontGL::nameFromFont(messageFont);
221			std::string font_style_size = LLFontGL::sizeFromFont(messageFont);
222			style_params_name.font.name(font_name);
223			style_params_name.font.size(font_style_size);
224
225			style_params_name.link_href = notification["sender_slurl"].asString();
226			style_params_name.is_link = true;
227
228			msg_text->appendText(str_sender, FALSE, style_params_name);
229
230		}
231		else
232		{
233			msg_text->appendText(str_sender, false);
234		}
235	}
236
237	//append text
238	{
239		LLStyle::Params style_params;
240		style_params.color(textColor);
241		std::string font_name = LLFontGL::nameFromFont(messageFont);
242		std::string font_style_size = LLFontGL::sizeFromFont(messageFont);
243		style_params.font.name(font_name);
244		style_params.font.size(font_style_size);
245
246		int chat_type = notification["chat_type"].asInteger();
247
248		if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC)
249		{
250			style_params.font.style = "ITALIC";
251		}
252		else if( chat_type == CHAT_TYPE_SHOUT)
253		{
254			style_params.font.style = "BOLD";
255		}
256		else if( chat_type == CHAT_TYPE_WHISPER)
257		{
258			style_params.font.style = "ITALIC";
259		}
260		msg_text->appendText(messageText, FALSE, style_params);
261	}
262
263
264	snapToMessageHeight();
265
266	mIsDirty = true;//will set Avatar Icon in draw
267}
268
269void	LLNearbyChatToastPanel::snapToMessageHeight	()
270{
271	LLChatMsgBox* text_box = getChild<LLChatMsgBox>("msg_text", false);
272	S32 new_height = llmax (text_box->getTextPixelHeight() + 2*text_box->getVPad() + 2*msg_height_pad, 25);
273	
274	LLRect panel_rect = getRect();
275
276	panel_rect.setLeftTopAndSize( panel_rect.mLeft, panel_rect.mTop, panel_rect.getWidth(), new_height);
277	
278	reshape( getRect().getWidth(), getRect().getHeight(), 1);
279	
280	setRect(panel_rect);
281
282}
283
284void LLNearbyChatToastPanel::onMouseLeave			(S32 x, S32 y, MASK mask)
285{
286	
287}
288void LLNearbyChatToastPanel::onMouseEnter				(S32 x, S32 y, MASK mask)
289{
290	if(mSourceType != CHAT_SOURCE_AGENT)
291		return;
292}
293
294BOOL	LLNearbyChatToastPanel::handleMouseDown	(S32 x, S32 y, MASK mask)
295{
296	return LLPanel::handleMouseDown(x,y,mask);
297}
298
299BOOL	LLNearbyChatToastPanel::handleMouseUp	(S32 x, S32 y, MASK mask)
300{
301	/*
302	fix for request  EXT-4780
303	leaving this commented since I don't remember why ew block those messages...
304	if(mSourceType != CHAT_SOURCE_AGENT)
305		return LLPanel::handleMouseUp(x,y,mask);
306    */
307
308	LLChatMsgBox* text_box = getChild<LLChatMsgBox>("msg_text", false);
309	S32 local_x = x - text_box->getRect().mLeft;
310	S32 local_y = y - text_box->getRect().mBottom;
311	
312	//if text_box process mouse up (ussually this is click on url) - we didn't show nearby_chat.
313	if (text_box->pointInView(local_x, local_y) )
314	{
315		if (text_box->handleMouseUp(local_x,local_y,mask) == TRUE)
316			return TRUE;
317		else
318		{
319			LLNearbyChatBar::getInstance()->showHistory();
320			return FALSE;
321		}
322	}
323
324	LLNearbyChatBar::getInstance()->showHistory();
325	return LLPanel::handleMouseUp(x,y,mask);
326}
327
328void	LLNearbyChatToastPanel::setHeaderVisibility(EShowItemHeader e)
329{
330	LLUICtrl* icon = getChild<LLUICtrl>("avatar_icon", false);
331	if(icon)
332		icon->setVisible(e == CHATITEMHEADER_SHOW_ONLY_ICON || e==CHATITEMHEADER_SHOW_BOTH);
333
334}
335
336bool	LLNearbyChatToastPanel::canAddText	()
337{
338	LLChatMsgBox* msg_text = findChild<LLChatMsgBox>("msg_text");
339	if(!msg_text)
340		return false;
341	return msg_text->getLineCount()<10;
342}
343
344BOOL	LLNearbyChatToastPanel::handleRightMouseDown(S32 x, S32 y, MASK mask)
345{
346	LLUICtrl* avatar_icon = getChild<LLUICtrl>("avatar_icon", false);
347
348	S32 local_x = x - avatar_icon->getRect().mLeft;
349	S32 local_y = y - avatar_icon->getRect().mBottom;
350
351	//eat message for avatar icon if msg was from object
352	if(avatar_icon->pointInView(local_x, local_y) && mSourceType != CHAT_SOURCE_AGENT)
353		return TRUE;
354	return LLPanel::handleRightMouseDown(x,y,mask);
355}
356void LLNearbyChatToastPanel::draw()
357{
358	if(mIsDirty)
359	{
360		LLAvatarIconCtrl* icon = getChild<LLAvatarIconCtrl>("avatar_icon", false);
361		if(icon)
362		{
363			icon->setDrawTooltip(mSourceType == CHAT_SOURCE_AGENT);
364			if(mSourceType == CHAT_SOURCE_OBJECT)
365				icon->setValue(LLSD("OBJECT_Icon"));
366			else if(mSourceType == CHAT_SOURCE_SYSTEM)
367				icon->setValue(LLSD("SL_Logo"));
368			else if(mSourceType == CHAT_SOURCE_AGENT)
369				icon->setValue(mFromID);
370			else if(!mFromID.isNull())
371				icon->setValue(mFromID);
372		}
373		mIsDirty = false;
374	}
375	LLToastPanelBase::draw();
376}
377
378