PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "lltoastimpanel.h"
  28. #include "llagent.h"
  29. #include "llfloaterreg.h"
  30. #include "llgroupactions.h"
  31. #include "llgroupiconctrl.h"
  32. #include "llimview.h"
  33. #include "llnotifications.h"
  34. #include "llinstantmessage.h"
  35. #include "lltooltip.h"
  36. #include "llviewerchat.h"
  37. const S32 LLToastIMPanel::DEFAULT_MESSAGE_MAX_LINE_COUNT = 6;
  38. //--------------------------------------------------------------------------
  39. LLToastIMPanel::LLToastIMPanel(LLToastIMPanel::Params &p) : LLToastPanel(p.notification),
  40. mAvatarIcon(NULL), mAvatarName(NULL),
  41. mTime(NULL), mMessage(NULL), mGroupIcon(NULL)
  42. {
  43. buildFromFile( "panel_instant_message.xml");
  44. mGroupIcon = getChild<LLGroupIconCtrl>("group_icon");
  45. mAvatarIcon = getChild<LLAvatarIconCtrl>("avatar_icon");
  46. mAdhocIcon = getChild<LLAvatarIconCtrl>("adhoc_icon");
  47. mAvatarName = getChild<LLTextBox>("user_name");
  48. mTime = getChild<LLTextBox>("time_box");
  49. mMessage = getChild<LLTextBox>("message");
  50. LLStyle::Params style_params;
  51. LLFontGL* fontp = LLViewerChat::getChatFont();
  52. std::string font_name = LLFontGL::nameFromFont(fontp);
  53. std::string font_size = LLFontGL::sizeFromFont(fontp);
  54. style_params.font.name(font_name);
  55. style_params.font.size(font_size);
  56. //Handle IRC styled /me messages.
  57. std::string prefix = p.message.substr(0, 4);
  58. if (prefix == "/me " || prefix == "/me'")
  59. {
  60. //style_params.font.style = "UNDERLINE";
  61. mMessage->clear();
  62. style_params.font.style ="ITALIC";
  63. mMessage->appendText(p.from, FALSE, style_params);
  64. style_params.font.style = "ITALIC";
  65. mMessage->appendText(p.message.substr(3), FALSE, style_params);
  66. }
  67. else
  68. {
  69. style_params.font.style = "NORMAL";
  70. mMessage->setText(p.message, style_params);
  71. }
  72. mAvatarName->setValue(p.from);
  73. mTime->setValue(p.time);
  74. mSessionID = p.session_id;
  75. mAvatarID = p.avatar_id;
  76. mNotification = p.notification;
  77. initIcon();
  78. S32 maxLinesCount;
  79. std::istringstream ss( getString("message_max_lines_count") );
  80. if (!(ss >> maxLinesCount))
  81. {
  82. maxLinesCount = DEFAULT_MESSAGE_MAX_LINE_COUNT;
  83. }
  84. snapToMessageHeight(mMessage, maxLinesCount);
  85. }
  86. //--------------------------------------------------------------------------
  87. LLToastIMPanel::~LLToastIMPanel()
  88. {
  89. }
  90. //virtual
  91. BOOL LLToastIMPanel::handleMouseDown(S32 x, S32 y, MASK mask)
  92. {
  93. if (LLPanel::handleMouseDown(x,y,mask) == FALSE)
  94. {
  95. mNotification->respond(mNotification->getResponseTemplate());
  96. }
  97. return TRUE;
  98. }
  99. //virtual
  100. BOOL LLToastIMPanel::handleToolTip(S32 x, S32 y, MASK mask)
  101. {
  102. // It's not our direct child, so parentPointInView() doesn't work.
  103. LLRect ctrl_rect;
  104. mAvatarName->localRectToOtherView(mAvatarName->getLocalRect(), &ctrl_rect, this);
  105. if (ctrl_rect.pointInRect(x, y))
  106. {
  107. spawnNameToolTip();
  108. return TRUE;
  109. }
  110. mGroupIcon->localRectToOtherView(mGroupIcon->getLocalRect(), &ctrl_rect, this);
  111. if(mGroupIcon->getVisible() && ctrl_rect.pointInRect(x, y))
  112. {
  113. spawnGroupIconToolTip();
  114. return TRUE;
  115. }
  116. return LLToastPanel::handleToolTip(x, y, mask);
  117. }
  118. void LLToastIMPanel::spawnNameToolTip()
  119. {
  120. // Spawn at right side of the name textbox.
  121. LLRect sticky_rect = mAvatarName->calcScreenRect();
  122. S32 icon_x =
  123. llmin(sticky_rect.mLeft + mAvatarName->getTextPixelWidth() + 3, sticky_rect.mRight);
  124. LLCoordGL pos(icon_x, sticky_rect.mTop);
  125. LLToolTip::Params params;
  126. params.background_visible(false);
  127. params.click_callback(boost::bind(&LLFloaterReg::showInstance, "inspect_avatar", LLSD().with("avatar_id", mAvatarID), FALSE));
  128. params.delay_time(0.0f); // spawn instantly on hover
  129. params.image(LLUI::getUIImage("Info_Small"));
  130. params.message("");
  131. params.padding(0);
  132. params.pos(pos);
  133. params.sticky_rect(sticky_rect);
  134. LLToolTipMgr::getInstance()->show(params);
  135. }
  136. void LLToastIMPanel::spawnGroupIconToolTip()
  137. {
  138. // Spawn at right bottom side of group icon.
  139. LLRect sticky_rect = mGroupIcon->calcScreenRect();
  140. LLCoordGL pos(sticky_rect.mRight, sticky_rect.mBottom);
  141. LLGroupData g_data;
  142. if(!gAgent.getGroupData(mSessionID, g_data))
  143. {
  144. llwarns << "Error getting group data" << llendl;
  145. }
  146. LLInspector::Params params;
  147. params.fillFrom(LLUICtrlFactory::instance().getDefaultParams<LLInspector>());
  148. params.click_callback(boost::bind(&LLFloaterReg::showInstance, "inspect_group", LLSD().with("group_id", mSessionID), FALSE));
  149. params.delay_time(0.100f);
  150. params.image(LLUI::getUIImage("Info_Small"));
  151. params.message(g_data.mName);
  152. params.padding(3);
  153. params.pos(pos);
  154. params.max_width(300);
  155. LLToolTipMgr::getInstance()->show(params);
  156. }
  157. void LLToastIMPanel::initIcon()
  158. {
  159. mAvatarIcon->setVisible(FALSE);
  160. mGroupIcon->setVisible(FALSE);
  161. mAdhocIcon->setVisible(FALSE);
  162. if(mAvatarName->getValue().asString() == SYSTEM_FROM)
  163. {
  164. // "sys_msg_icon" was disabled by Erica in the changeset: 5109 (85181bc92cbe)
  165. // and "dummy widget" warnings appeared in log.
  166. // It does not make sense to have such image with empty name. Removed for EXT-5057.
  167. }
  168. else
  169. {
  170. LLIMModel::LLIMSession* im_session = LLIMModel::getInstance()->findIMSession(mSessionID);
  171. if(!im_session)
  172. {
  173. llwarns << "Invalid IM session" << llendl;
  174. return;
  175. }
  176. switch(im_session->mSessionType)
  177. {
  178. case LLIMModel::LLIMSession::P2P_SESSION:
  179. mAvatarIcon->setVisible(TRUE);
  180. mAvatarIcon->setValue(mAvatarID);
  181. break;
  182. case LLIMModel::LLIMSession::GROUP_SESSION:
  183. mGroupIcon->setVisible(TRUE);
  184. mGroupIcon->setValue(mSessionID);
  185. break;
  186. case LLIMModel::LLIMSession::ADHOC_SESSION:
  187. mAdhocIcon->setVisible(TRUE);
  188. mAdhocIcon->setValue(im_session->mOtherParticipantID);
  189. mAdhocIcon->setToolTip(im_session->mName);
  190. break;
  191. default:
  192. llwarns << "Unknown IM session type" << llendl;
  193. break;
  194. }
  195. }
  196. }
  197. // EOF