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