llscreenchannel.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:22k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llscreenchannel.cpp
  3.  * @brief Class implements a channel on a screen in which appropriate toasts may appear.
  4.  *
  5.  * $LicenseInfo:firstyear=2000&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2000-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h" // must be first include
  33. #include "lliconctrl.h"
  34. #include "lltextbox.h"
  35. #include "llscreenchannel.h"
  36. #include "lltoastpanel.h"
  37. #include "llviewercontrol.h"
  38. #include "llviewerwindow.h"
  39. #include "llfloaterreg.h"
  40. #include "lltrans.h"
  41. #include "lldockablefloater.h"
  42. #include "llsyswellwindow.h"
  43. #include "llimfloater.h"
  44. #include "llscriptfloater.h"
  45. #include "llfontgl.h"
  46. #include <algorithm>
  47. using namespace LLNotificationsUI;
  48. bool LLScreenChannel::mWasStartUpToastShown = false;
  49. //--------------------------------------------------------------------------
  50. //////////////////////
  51. // LLScreenChannelBase
  52. //////////////////////
  53. LLScreenChannelBase::LLScreenChannelBase(const LLUUID& id) :
  54. mToastAlignment(NA_BOTTOM)
  55. ,mCanStoreToasts(true)
  56. ,mHiddenToastsNum(0)
  57. ,mHoveredToast(NULL)
  58. ,mControlHovering(false)
  59. ,mShowToasts(true)
  60. {
  61. mID = id;
  62. mWorldViewRectConnection = gViewerWindow->setOnWorldViewRectUpdated(boost::bind(&LLScreenChannelBase::updatePositionAndSize, this, _1, _2));
  63. setMouseOpaque( false );
  64. setVisible(FALSE);
  65. }
  66. LLScreenChannelBase::~LLScreenChannelBase()
  67. {
  68. mWorldViewRectConnection.disconnect();
  69. }
  70. bool  LLScreenChannelBase::isHovering()
  71. {
  72. if (!mHoveredToast)
  73. {
  74. return false;
  75. }
  76. return mHoveredToast->isHovered();
  77. }
  78. void LLScreenChannelBase::updatePositionAndSize(LLRect old_world_rect, LLRect new_world_rect)
  79. {
  80. S32 top_delta = old_world_rect.mTop - new_world_rect.mTop;
  81. S32 right_delta = old_world_rect.mRight - new_world_rect.mRight;
  82. LLRect this_rect = getRect();
  83. this_rect.mTop -= top_delta;
  84. switch(mChannelAlignment)
  85. {
  86. case CA_LEFT :
  87. break;
  88. case CA_CENTRE :
  89. this_rect.setCenterAndSize(new_world_rect.getWidth() / 2, new_world_rect.getHeight() / 2, this_rect.getWidth(), this_rect.getHeight());
  90. break;
  91. case CA_RIGHT :
  92. this_rect.mLeft -= right_delta;
  93. this_rect.mRight -= right_delta;
  94. }
  95. setRect(this_rect);
  96. redrawToasts();
  97. }
  98. void LLScreenChannelBase::init(S32 channel_left, S32 channel_right)
  99. {
  100. S32 channel_top = gViewerWindow->getWorldViewRectScaled().getHeight();
  101. S32 channel_bottom = gViewerWindow->getWorldViewRectScaled().mBottom + gSavedSettings.getS32("ChannelBottomPanelMargin");
  102. setRect(LLRect(channel_left, channel_top, channel_right, channel_bottom));
  103. setVisible(TRUE);
  104. }
  105. //--------------------------------------------------------------------------
  106. //////////////////////
  107. // LLScreenChannel
  108. //////////////////////
  109. //--------------------------------------------------------------------------
  110. LLScreenChannel::LLScreenChannel(LLUUID& id):
  111. LLScreenChannelBase(id)
  112. ,mStartUpToastPanel(NULL)
  113. {
  114. }
  115. //--------------------------------------------------------------------------
  116. void LLScreenChannel::init(S32 channel_left, S32 channel_right)
  117. {
  118. LLScreenChannelBase::init(channel_left, channel_right);
  119. LLRect world_rect = gViewerWindow->getWorldViewRectScaled();
  120. updatePositionAndSize(world_rect, world_rect);
  121. }
  122. //--------------------------------------------------------------------------
  123. LLScreenChannel::~LLScreenChannel() 
  124. {
  125. }
  126. std::list<LLToast*> LLScreenChannel::findToasts(const Matcher& matcher)
  127. {
  128. std::list<LLToast*> res;
  129. // collect stored toasts
  130. for (std::vector<ToastElem>::iterator it = mStoredToastList.begin(); it
  131. != mStoredToastList.end(); it++)
  132. {
  133. if (matcher.matches(it->toast->getNotification()))
  134. {
  135. res.push_back(it->toast);
  136. }
  137. }
  138. // collect displayed toasts
  139. for (std::vector<ToastElem>::iterator it = mToastList.begin(); it
  140. != mToastList.end(); it++)
  141. {
  142. if (matcher.matches(it->toast->getNotification()))
  143. {
  144. res.push_back(it->toast);
  145. }
  146. }
  147. return res;
  148. }
  149. //--------------------------------------------------------------------------
  150. void LLScreenChannel::updatePositionAndSize(LLRect old_world_rect, LLRect new_world_rect)
  151. {
  152. S32 right_delta = old_world_rect.mRight - new_world_rect.mRight;
  153. LLRect this_rect = getRect();
  154. switch(mChannelAlignment)
  155. {
  156. case CA_LEFT :
  157. this_rect.mTop = (S32) (new_world_rect.getHeight() * getHeightRatio());
  158. break;
  159. case CA_CENTRE :
  160. LLScreenChannelBase::updatePositionAndSize(old_world_rect, new_world_rect);
  161. return;
  162. case CA_RIGHT :
  163. this_rect.mTop = (S32) (new_world_rect.getHeight() * getHeightRatio());
  164. this_rect.mLeft -= right_delta;
  165. this_rect.mRight -= right_delta;
  166. }
  167. setRect(this_rect);
  168. redrawToasts();
  169. }
  170. //--------------------------------------------------------------------------
  171. void LLScreenChannel::addToast(const LLToast::Params& p)
  172. {
  173. bool store_toast = false, show_toast = false;
  174. mDisplayToastsAlways ? show_toast = true : show_toast = mWasStartUpToastShown && (mShowToasts || p.force_show);
  175. store_toast = !show_toast && p.can_be_stored && mCanStoreToasts;
  176. if(!show_toast && !store_toast)
  177. {
  178. mRejectToastSignal(p.notif_id);
  179. return;
  180. }
  181. ToastElem new_toast_elem(p);
  182. new_toast_elem.toast->setOnFadeCallback(boost::bind(&LLScreenChannel::onToastFade, this, _1));
  183. new_toast_elem.toast->setOnToastDestroyedCallback(boost::bind(&LLScreenChannel::onToastDestroyed, this, _1));
  184. if(mControlHovering)
  185. {
  186. new_toast_elem.toast->setOnToastHoverCallback(boost::bind(&LLScreenChannel::onToastHover, this, _1, _2));
  187. new_toast_elem.toast->setMouseEnterCallback(boost::bind(&LLScreenChannel::stopFadingToasts, this));
  188. new_toast_elem.toast->setMouseLeaveCallback(boost::bind(&LLScreenChannel::startFadingToasts, this));
  189. }
  190. if(show_toast)
  191. {
  192. mToastList.push_back(new_toast_elem);
  193. if(p.can_be_stored)
  194. {
  195. // store toasts immediately - EXT-3762
  196. storeToast(new_toast_elem);
  197. }
  198. updateShowToastsState();
  199. redrawToasts();
  200. }
  201. else // store_toast
  202. {
  203. mHiddenToastsNum++;
  204. storeToast(new_toast_elem);
  205. }
  206. }
  207. //--------------------------------------------------------------------------
  208. void LLScreenChannel::onToastDestroyed(LLToast* toast)
  209. {
  210. std::vector<ToastElem>::iterator it = find(mToastList.begin(), mToastList.end(), static_cast<LLPanel*>(toast));
  211. if(it != mToastList.end())
  212. {
  213. mToastList.erase(it);
  214. }
  215. it = find(mStoredToastList.begin(), mStoredToastList.end(), static_cast<LLPanel*>(toast));
  216. if(it != mStoredToastList.end())
  217. {
  218. mStoredToastList.erase(it);
  219. }
  220. }
  221. //--------------------------------------------------------------------------
  222. void LLScreenChannel::onToastFade(LLToast* toast)
  223. {
  224. std::vector<ToastElem>::iterator it = find(mToastList.begin(), mToastList.end(), static_cast<LLPanel*>(toast));
  225. if(it != mToastList.end())
  226. {
  227. bool delete_toast = !mCanStoreToasts || !toast->getCanBeStored();
  228. if(delete_toast)
  229. {
  230. mToastList.erase(it);
  231. deleteToast(toast);
  232. }
  233. else
  234. {
  235. storeToast((*it));
  236. mToastList.erase(it);
  237. }
  238. redrawToasts();
  239. }
  240. }
  241. //--------------------------------------------------------------------------
  242. void LLScreenChannel::deleteToast(LLToast* toast)
  243. {
  244. if (toast->isDead())
  245. {
  246. return;
  247. }
  248. // send signal to observers about destroying of a toast
  249. toast->mOnDeleteToastSignal(toast);
  250. // update channel's Hovering state
  251. // turning hovering off manually because onMouseLeave won't happen if a toast was closed using a keyboard
  252. if(mHoveredToast == toast)
  253. {
  254. mHoveredToast  = NULL;
  255. startFadingToasts();
  256. }
  257. // close the toast
  258. toast->closeFloater();
  259. }
  260. //--------------------------------------------------------------------------
  261. void LLScreenChannel::storeToast(ToastElem& toast_elem)
  262. {
  263. // do not store clones
  264. std::vector<ToastElem>::iterator it = find(mStoredToastList.begin(), mStoredToastList.end(), toast_elem.id);
  265. if( it != mStoredToastList.end() )
  266. return;
  267. mStoredToastList.push_back(toast_elem);
  268. mOnStoreToast(toast_elem.toast->getPanel(), toast_elem.id);
  269. }
  270. //--------------------------------------------------------------------------
  271. void LLScreenChannel::loadStoredToastsToChannel()
  272. {
  273. std::vector<ToastElem>::iterator it;
  274. if(mStoredToastList.size() == 0)
  275. return;
  276. for(it = mStoredToastList.begin(); it != mStoredToastList.end(); ++it)
  277. {
  278. (*it).toast->setIsHidden(false);
  279. (*it).toast->resetTimer();
  280. mToastList.push_back((*it));
  281. }
  282. mStoredToastList.clear();
  283. redrawToasts();
  284. }
  285. //--------------------------------------------------------------------------
  286. void LLScreenChannel::loadStoredToastByNotificationIDToChannel(LLUUID id)
  287. {
  288. std::vector<ToastElem>::iterator it = find(mStoredToastList.begin(), mStoredToastList.end(), id);
  289. if( it == mStoredToastList.end() )
  290. return;
  291. LLToast* toast = (*it).toast;
  292. if(toast->getVisible())
  293. {
  294. // toast is already in channel
  295. return;
  296. }
  297. toast->setIsHidden(false);
  298. toast->resetTimer();
  299. mToastList.push_back((*it));
  300. redrawToasts();
  301. }
  302. //--------------------------------------------------------------------------
  303. void LLScreenChannel::removeStoredToastByNotificationID(LLUUID id)
  304. {
  305. // *TODO: may be remove this function
  306. std::vector<ToastElem>::iterator it = find(mStoredToastList.begin(), mStoredToastList.end(), id);
  307. if( it == mStoredToastList.end() )
  308. return;
  309. LLToast* toast = (*it).toast;
  310. mStoredToastList.erase(it);
  311. mRejectToastSignal(toast->getNotificationID());
  312. }
  313. //--------------------------------------------------------------------------
  314. void LLScreenChannel::killToastByNotificationID(LLUUID id)
  315. {
  316. // searching among toasts on a screen
  317. std::vector<ToastElem>::iterator it = find(mToastList.begin(), mToastList.end(), id);
  318. if( it != mToastList.end())
  319. {
  320. LLToast* toast = (*it).toast;
  321. // if it is a notification toast and notification is UnResponded - then respond on it
  322. // else - simply destroy a toast
  323. //
  324. // NOTE: if a notification is unresponded this function will be called twice for the same toast.
  325. // At first, the notification will be discarded, at second (it will be caused by discarding),
  326. // the toast will be destroyed.
  327. if(toast->isNotificationValid())
  328. {
  329. mRejectToastSignal(toast->getNotificationID());
  330. }
  331. else
  332. {
  333. mToastList.erase(it);
  334. deleteToast(toast);
  335. redrawToasts();
  336. }
  337. return;
  338. }
  339. // searching among stored toasts
  340. it = find(mStoredToastList.begin(), mStoredToastList.end(), id);
  341. if( it != mStoredToastList.end() )
  342. {
  343. LLToast* toast = (*it).toast;
  344. mStoredToastList.erase(it);
  345. // send signal to a listener to let him perform some action on toast rejecting
  346. mRejectToastSignal(toast->getNotificationID());
  347. deleteToast(toast);
  348. }
  349. }
  350. void LLScreenChannel::killMatchedToasts(const Matcher& matcher)
  351. {
  352. std::list<LLToast*> to_delete = findToasts(matcher);
  353. for (std::list<LLToast*>::iterator it = to_delete.begin(); it
  354. != to_delete.end(); it++)
  355. {
  356. killToastByNotificationID((*it)-> getNotificationID());
  357. }
  358. }
  359. //--------------------------------------------------------------------------
  360. void LLScreenChannel::modifyToastByNotificationID(LLUUID id, LLPanel* panel)
  361. {
  362. std::vector<ToastElem>::iterator it = find(mToastList.begin(), mToastList.end(), id);
  363. if( it != mToastList.end() && panel)
  364. {
  365. LLToast* toast = (*it).toast;
  366. LLPanel* old_panel = toast->getPanel();
  367. toast->removeChild(old_panel);
  368. delete old_panel;
  369. toast->insertPanel(panel);
  370. toast->resetTimer();
  371. redrawToasts();
  372. }
  373. }
  374. //--------------------------------------------------------------------------
  375. void LLScreenChannel::redrawToasts()
  376. {
  377. if(mToastList.size() == 0 || isHovering())
  378. return;
  379. switch(mToastAlignment)
  380. {
  381. case NA_TOP : 
  382. showToastsTop();
  383. break;
  384. case NA_CENTRE :
  385. showToastsCentre();
  386. break;
  387. case NA_BOTTOM :
  388. showToastsBottom();
  389. }
  390. }
  391. //--------------------------------------------------------------------------
  392. void LLScreenChannel::showToastsBottom()
  393. {
  394. LLRect toast_rect;
  395. S32 bottom = getRect().mBottom - gFloaterView->getRect().mBottom;
  396. S32 toast_margin = 0;
  397. std::vector<ToastElem>::reverse_iterator it;
  398. LLDockableFloater* floater = dynamic_cast<LLDockableFloater*>(LLDockableFloater::getInstanceHandle().get());
  399. for(it = mToastList.rbegin(); it != mToastList.rend(); ++it)
  400. {
  401. if(it != mToastList.rbegin())
  402. {
  403. LLToast* toast = (*(it-1)).toast;
  404. bottom = toast->getRect().mTop - toast->getTopPad();
  405. toast_margin = gSavedSettings.getS32("ToastGap");
  406. }
  407. toast_rect = (*it).toast->getRect();
  408. toast_rect.setOriginAndSize(getRect().mLeft, bottom + toast_margin, toast_rect.getWidth() ,toast_rect.getHeight());
  409. (*it).toast->setRect(toast_rect);
  410. if(floater && floater->overlapsScreenChannel())
  411. {
  412. if(it == mToastList.rbegin())
  413. {
  414. // move first toast above docked floater
  415. S32 shift = floater->getRect().getHeight();
  416. if(floater->getDockControl())
  417. {
  418. shift += floater->getDockControl()->getTongueHeight();
  419. }
  420. (*it).toast->translate(0, shift);
  421. }
  422. LLRect world_rect = gViewerWindow->getWorldViewRectScaled();
  423. // don't show toasts if there is not enough space
  424. if(toast_rect.mTop > world_rect.mTop)
  425. {
  426. break;
  427. }
  428. }
  429. bool stop_showing_toasts = (*it).toast->getRect().mTop > getRect().mTop;
  430. if(!stop_showing_toasts)
  431. {
  432. if( it != mToastList.rend()-1)
  433. {
  434. S32 toast_top = (*it).toast->getRect().mTop + gSavedSettings.getS32("ToastGap");
  435. stop_showing_toasts = toast_top > getRect().mTop;
  436. }
  437. // at least one toast should be visible
  438. if(it == mToastList.rbegin())
  439. {
  440. stop_showing_toasts = false;
  441. }
  442. if(stop_showing_toasts)
  443. break;
  444. if( !(*it).toast->getVisible() )
  445. {
  446. // HACK
  447. // EXT-2653: it is necessary to prevent overlapping for secondary showed toasts
  448. (*it).toast->setVisible(TRUE);
  449. }
  450. if(!(*it).toast->hasFocus())
  451. {
  452. // Fixing Z-order of toasts (EXT-4862)
  453. // Next toast will be positioned under this one.
  454. gFloaterView->sendChildToBack((*it).toast);
  455. }
  456. }
  457. if(it != mToastList.rend())
  458. {
  459. mHiddenToastsNum = 0;
  460. for(; it != mToastList.rend(); it++)
  461. {
  462. (*it).toast->stopTimer();
  463. (*it).toast->setVisible(FALSE);
  464. mHiddenToastsNum++;
  465. }
  466. }
  467. else
  468. {
  469. closeOverflowToastPanel();
  470. }
  471. }
  472. //--------------------------------------------------------------------------
  473. void LLScreenChannel::showToastsCentre()
  474. {
  475. LLRect toast_rect;
  476. S32 bottom = (getRect().mTop - getRect().mBottom)/2 + mToastList[0].toast->getRect().getHeight()/2;
  477. std::vector<ToastElem>::reverse_iterator it;
  478. for(it = mToastList.rbegin(); it != mToastList.rend(); ++it)
  479. {
  480. toast_rect = (*it).toast->getRect();
  481. toast_rect.setLeftTopAndSize(getRect().mLeft - toast_rect.getWidth() / 2, bottom + toast_rect.getHeight() / 2 + gSavedSettings.getS32("ToastGap"), toast_rect.getWidth() ,toast_rect.getHeight());
  482. (*it).toast->setRect(toast_rect);
  483. (*it).toast->setVisible(TRUE);
  484. }
  485. }
  486. //--------------------------------------------------------------------------
  487. void LLScreenChannel::showToastsTop()
  488. {
  489. }
  490. //--------------------------------------------------------------------------
  491. void LLScreenChannel::createStartUpToast(S32 notif_num, F32 timer)
  492. {
  493. LLRect toast_rect;
  494. LLRect tbox_rect;
  495. LLToast::Params p;
  496. p.lifetime_secs = timer;
  497. p.enable_hide_btn = false;
  498. mStartUpToastPanel = new LLToast(p);
  499. if(!mStartUpToastPanel)
  500. return;
  501. mStartUpToastPanel->setOnFadeCallback(boost::bind(&LLScreenChannel::onStartUpToastHide, this));
  502. LLTextBox* text_box = mStartUpToastPanel->getChild<LLTextBox>("toast_text");
  503. std::string text = LLTrans::getString("StartUpNotifications");
  504. tbox_rect   = text_box->getRect();
  505. S32 tbox_width  = tbox_rect.getWidth();
  506. S32 tbox_vpad   = text_box->getVPad();
  507. S32 text_width  = text_box->getDefaultFont()->getWidth(text);
  508. S32 text_height = text_box->getTextPixelHeight();
  509. // EXT - 3703 (Startup toast message doesn't fit toast width)
  510. // Calculating TextBox HEIGHT needed to include the whole string according to the given WIDTH of the TextBox.
  511. S32 new_tbox_height = (text_width/tbox_width + 1) * text_height;
  512. // Calculating TOP position of TextBox
  513. S32 new_tbox_top = new_tbox_height + tbox_vpad + gSavedSettings.getS32("ToastGap");
  514. // Calculating toast HEIGHT according to the new TextBox size
  515. S32 toast_height = new_tbox_height + tbox_vpad * 2;
  516. tbox_rect.setLeftTopAndSize(tbox_rect.mLeft, new_tbox_top, tbox_rect.getWidth(), new_tbox_height);
  517. text_box->setRect(tbox_rect);
  518. toast_rect = mStartUpToastPanel->getRect();
  519. mStartUpToastPanel->reshape(getRect().getWidth(), toast_rect.getHeight(), true);
  520. toast_rect.setLeftTopAndSize(0, toast_height + gSavedSettings.getS32("ToastGap"), getRect().getWidth(), toast_height);
  521. mStartUpToastPanel->setRect(toast_rect);
  522. text_box->setValue(text);
  523. text_box->setVisible(TRUE);
  524. addChild(mStartUpToastPanel);
  525. mStartUpToastPanel->setVisible(TRUE);
  526. }
  527. // static --------------------------------------------------------------------------
  528. F32 LLScreenChannel::getHeightRatio()
  529. {
  530. F32 ratio = gSavedSettings.getF32("NotificationChannelHeightRatio");
  531. if(0.0f > ratio)
  532. {
  533. ratio = 0.0f;
  534. }
  535. else if(1.0f < ratio)
  536. {
  537. ratio = 1.0f;
  538. }
  539. return ratio;
  540. }
  541. //--------------------------------------------------------------------------
  542. void LLScreenChannel::updateStartUpString(S32 num)
  543. {
  544. // *TODO: update string if notifications are arriving while the StartUp toast is on a screen
  545. }
  546. //--------------------------------------------------------------------------
  547. void LLScreenChannel::onStartUpToastHide()
  548. {
  549. onCommit();
  550. }
  551. //--------------------------------------------------------------------------
  552. void LLScreenChannel::closeStartUpToast()
  553. {
  554. if(mStartUpToastPanel != NULL)
  555. {
  556. mStartUpToastPanel->setVisible(FALSE);
  557. mStartUpToastPanel = NULL;
  558. }
  559. }
  560. void LLNotificationsUI::LLScreenChannel::stopFadingToasts()
  561. {
  562. if (!mToastList.size()) return;
  563. if (!mHoveredToast) return;
  564. std::vector<ToastElem>::iterator it = mToastList.begin();
  565. while (it != mToastList.end())
  566. {
  567. ToastElem& elem = *it;
  568. elem.toast->stopFading();
  569. ++it;
  570. }
  571. }
  572. void LLNotificationsUI::LLScreenChannel::startFadingToasts()
  573. {
  574. if (!mToastList.size()) return;
  575. //because onMouseLeave is processed after onMouseEnter
  576. if (isHovering()) return;
  577. std::vector<ToastElem>::iterator it = mToastList.begin();
  578. while (it != mToastList.end())
  579. {
  580. ToastElem& elem = *it;
  581. elem.toast->startFading();
  582. ++it;
  583. }
  584. }
  585. //--------------------------------------------------------------------------
  586. void LLScreenChannel::hideToastsFromScreen()
  587. {
  588. closeOverflowToastPanel();
  589. for(std::vector<ToastElem>::iterator it = mToastList.begin(); it != mToastList.end(); it++)
  590. (*it).toast->setVisible(FALSE);
  591. }
  592. //--------------------------------------------------------------------------
  593. void LLScreenChannel::hideToast(const LLUUID& notification_id)
  594. {
  595. std::vector<ToastElem>::iterator it = find(mToastList.begin(), mToastList.end(), notification_id);
  596. if(mToastList.end() != it)
  597. {
  598. ToastElem te = *it;
  599. te.toast->setVisible(FALSE);
  600. te.toast->stopTimer();
  601. mToastList.erase(it);
  602. }
  603. }
  604. //--------------------------------------------------------------------------
  605. void LLScreenChannel::removeToastsFromChannel()
  606. {
  607. hideToastsFromScreen();
  608. for(std::vector<ToastElem>::iterator it = mToastList.begin(); it != mToastList.end(); it++)
  609. {
  610. deleteToast((*it).toast);
  611. }
  612. mToastList.clear();
  613. }
  614. //--------------------------------------------------------------------------
  615. void LLScreenChannel::removeAndStoreAllStorableToasts()
  616. {
  617. if(mToastList.size() == 0)
  618. return;
  619. hideToastsFromScreen();
  620. for(std::vector<ToastElem>::iterator it = mToastList.begin(); it != mToastList.end();)
  621. {
  622. if((*it).toast->getCanBeStored())
  623. {
  624. storeToast(*(it));
  625. it = mToastList.erase(it);
  626. }
  627. else
  628. {
  629. ++it;
  630. }
  631. }
  632. redrawToasts();
  633. }
  634. //--------------------------------------------------------------------------
  635. void LLScreenChannel::removeToastsBySessionID(LLUUID id)
  636. {
  637. if(mToastList.size() == 0)
  638. return;
  639. hideToastsFromScreen();
  640. for(std::vector<ToastElem>::iterator it = mToastList.begin(); it != mToastList.end();)
  641. {
  642. if((*it).toast->getSessionID() == id)
  643. {
  644. deleteToast((*it).toast);
  645. it = mToastList.erase(it);
  646. }
  647. else
  648. {
  649. ++it;
  650. }
  651. }
  652. redrawToasts();
  653. }
  654. //--------------------------------------------------------------------------
  655. void LLScreenChannel::onToastHover(LLToast* toast, bool mouse_enter)
  656. {
  657. // because of LLViewerWindow::updateUI() that NOT ALWAYS calls onMouseEnter BEFORE onMouseLeave
  658. // we must check hovering directly to prevent incorrect setting for hovering in a channel
  659. if (mouse_enter)
  660. {
  661. if (toast->isHovered())
  662. {
  663. mHoveredToast = toast;
  664. }
  665. }
  666. else if (mHoveredToast != NULL)
  667. {
  668. if (!mHoveredToast->isHovered())
  669. {
  670. mHoveredToast = NULL;
  671. }
  672. }
  673. if(!isHovering())
  674. redrawToasts();
  675. }
  676. //--------------------------------------------------------------------------
  677. void LLScreenChannel::updateShowToastsState()
  678. {
  679. LLDockableFloater* floater = dynamic_cast<LLDockableFloater*>(LLDockableFloater::getInstanceHandle().get());
  680. if(!floater)
  681. {
  682. setShowToasts(true);
  683. return;
  684. }
  685. S32 channel_bottom = gViewerWindow->getWorldViewRectScaled().mBottom + gSavedSettings.getS32("ChannelBottomPanelMargin");;
  686. LLRect this_rect = getRect();
  687. if(channel_bottom != this_rect.mBottom)
  688. {
  689. setRect(LLRect(this_rect.mLeft, this_rect.mTop, this_rect.mRight, channel_bottom));
  690. }
  691. }
  692. //--------------------------------------------------------------------------
  693. LLToast* LLScreenChannel::getToastByNotificationID(LLUUID id)
  694. {
  695. std::vector<ToastElem>::iterator it = find(mStoredToastList.begin(),
  696. mStoredToastList.end(), id);
  697. if (it == mStoredToastList.end())
  698. return NULL;
  699. return it->toast;
  700. }