PageRenderTime 182ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llchiclet.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 1268 lines | 528 code | 274 blank | 466 comment | 18 complexity | 8e2a50594940cbe5df0928b3bd85046d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llchiclet.h
  3. * @brief LLChiclet class header file
  4. *
  5. * $LicenseInfo:firstyear=2002&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. #ifndef LL_LLCHICLET_H
  27. #define LL_LLCHICLET_H
  28. #include "llavatariconctrl.h"
  29. #include "llbutton.h"
  30. #include "llpanel.h"
  31. #include "lltextbox.h"
  32. #include "lloutputmonitorctrl.h"
  33. #include "llgroupmgr.h"
  34. #include "llimview.h"
  35. class LLMenuGL;
  36. class LLIMFloater;
  37. /**
  38. * Class for displaying amount of messages/notifications(unread).
  39. */
  40. class LLChicletNotificationCounterCtrl : public LLTextBox
  41. {
  42. public:
  43. struct Params : public LLInitParam::Block<Params, LLTextBox::Params>
  44. {
  45. /**
  46. * Contains maximum displayed count of unread messages. Default value is 9.
  47. *
  48. * If count is less than "max_unread_count" will be displayed as is.
  49. * Otherwise 9+ will be shown (for default value).
  50. */
  51. Optional<S32> max_displayed_count;
  52. Params();
  53. };
  54. /**
  55. * Sets number of notifications
  56. */
  57. virtual void setCounter(S32 counter);
  58. /**
  59. * Returns number of notifications
  60. */
  61. virtual S32 getCounter() const { return mCounter; }
  62. /**
  63. * Returns width, required to display amount of notifications in text form.
  64. * Width is the only valid value.
  65. */
  66. /*virtual*/ LLRect getRequiredRect();
  67. /**
  68. * Sets number of notifications using LLSD
  69. */
  70. /*virtual*/ void setValue(const LLSD& value);
  71. /**
  72. * Returns number of notifications wrapped in LLSD
  73. */
  74. /*virtual*/ LLSD getValue() const;
  75. protected:
  76. LLChicletNotificationCounterCtrl(const Params& p);
  77. friend class LLUICtrlFactory;
  78. private:
  79. S32 mCounter;
  80. S32 mInitialWidth;
  81. S32 mMaxDisplayedCount;
  82. };
  83. /**
  84. * Class for displaying avatar's icon in P2P chiclet.
  85. */
  86. class LLChicletAvatarIconCtrl : public LLAvatarIconCtrl
  87. {
  88. public:
  89. struct Params : public LLInitParam::Block<Params, LLAvatarIconCtrl::Params>
  90. {
  91. Params()
  92. {
  93. changeDefault(draw_tooltip, FALSE);
  94. changeDefault(mouse_opaque, FALSE);
  95. changeDefault(default_icon_name, "Generic_Person");
  96. };
  97. };
  98. protected:
  99. LLChicletAvatarIconCtrl(const Params& p);
  100. friend class LLUICtrlFactory;
  101. };
  102. /**
  103. * Class for displaying group's icon in Group chiclet.
  104. */
  105. class LLChicletGroupIconCtrl : public LLIconCtrl
  106. {
  107. public:
  108. struct Params : public LLInitParam::Block<Params, LLIconCtrl::Params>
  109. {
  110. Optional<std::string> default_icon;
  111. Params()
  112. : default_icon("default_icon", "Generic_Group")
  113. {}
  114. };
  115. /**
  116. * Sets icon, if value is LLUUID::null - default icon will be set.
  117. */
  118. virtual void setValue(const LLSD& value );
  119. protected:
  120. LLChicletGroupIconCtrl(const Params& p);
  121. friend class LLUICtrlFactory;
  122. std::string mDefaultIcon;
  123. };
  124. /**
  125. * Class for displaying icon in inventory offer chiclet.
  126. */
  127. class LLChicletInvOfferIconCtrl : public LLChicletAvatarIconCtrl
  128. {
  129. public:
  130. struct Params :
  131. public LLInitParam::Block<Params, LLChicletAvatarIconCtrl::Params>
  132. {
  133. Optional<std::string> default_icon;
  134. Params()
  135. : default_icon("default_icon", "Generic_Object_Small")
  136. {
  137. changeDefault(avatar_id, LLUUID::null);
  138. };
  139. };
  140. /**
  141. * Sets icon, if value is LLUUID::null - default icon will be set.
  142. */
  143. virtual void setValue(const LLSD& value );
  144. protected:
  145. LLChicletInvOfferIconCtrl(const Params& p);
  146. friend class LLUICtrlFactory;
  147. private:
  148. std::string mDefaultIcon;
  149. };
  150. /**
  151. * Class for displaying of speaker's voice indicator
  152. */
  153. class LLChicletSpeakerCtrl : public LLOutputMonitorCtrl
  154. {
  155. public:
  156. struct Params : public LLInitParam::Block<Params, LLOutputMonitorCtrl::Params>
  157. {
  158. Params(){};
  159. };
  160. protected:
  161. LLChicletSpeakerCtrl(const Params&p);
  162. friend class LLUICtrlFactory;
  163. };
  164. /**
  165. * Base class for all chiclets.
  166. */
  167. class LLChiclet : public LLUICtrl
  168. {
  169. public:
  170. struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
  171. {
  172. Optional<bool> show_counter,
  173. enable_counter;
  174. Params();
  175. };
  176. /*virtual*/ ~LLChiclet();
  177. /**
  178. * Associates chat session id with chiclet.
  179. */
  180. virtual void setSessionId(const LLUUID& session_id) { mSessionId = session_id; }
  181. /**
  182. * Returns associated chat session.
  183. */
  184. virtual const LLUUID& getSessionId() const { return mSessionId; }
  185. /**
  186. * Sets number of unread notifications.
  187. */
  188. virtual void setCounter(S32 counter) = 0;
  189. /**
  190. * Returns number of unread notifications.
  191. */
  192. virtual S32 getCounter() = 0;
  193. /**
  194. * Sets show counter state.
  195. */
  196. virtual void setShowCounter(bool show) { mShowCounter = show; }
  197. /**
  198. * Returns show counter state.
  199. */
  200. virtual bool getShowCounter() {return mShowCounter;};
  201. /**
  202. * Connects chiclet clicked event with callback.
  203. */
  204. /*virtual*/ boost::signals2::connection setLeftButtonClickCallback(
  205. const commit_callback_t& cb);
  206. typedef boost::function<void (LLChiclet* ctrl, const LLSD& param)>
  207. chiclet_size_changed_callback_t;
  208. /**
  209. * Connects chiclets size changed event with callback.
  210. */
  211. virtual boost::signals2::connection setChicletSizeChangedCallback(
  212. const chiclet_size_changed_callback_t& cb);
  213. /**
  214. * Sets IM Session id using LLSD
  215. */
  216. /*virtual*/ LLSD getValue() const;
  217. /**
  218. * Returns IM Session id using LLSD
  219. */
  220. /*virtual*/ void setValue(const LLSD& value);
  221. protected:
  222. friend class LLUICtrlFactory;
  223. LLChiclet(const Params& p);
  224. /**
  225. * Notifies subscribers about click on chiclet.
  226. */
  227. /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  228. /**
  229. * Notifies subscribers about chiclet size changed event.
  230. */
  231. virtual void onChicletSizeChanged();
  232. private:
  233. LLUUID mSessionId;
  234. bool mShowCounter;
  235. typedef boost::signals2::signal<void (LLChiclet* ctrl, const LLSD& param)>
  236. chiclet_size_changed_signal_t;
  237. chiclet_size_changed_signal_t mChicletSizeChangedSignal;
  238. };
  239. /**
  240. * Base class for Instant Message chiclets.
  241. * IMChiclet displays icon, number of unread messages(optional)
  242. * and voice chat status(optional).
  243. */
  244. class LLIMChiclet : public LLChiclet
  245. {
  246. public:
  247. enum EType {
  248. TYPE_UNKNOWN,
  249. TYPE_IM,
  250. TYPE_GROUP,
  251. TYPE_AD_HOC
  252. };
  253. struct Params : public LLInitParam::Block<Params, LLChiclet::Params>
  254. {};
  255. virtual ~LLIMChiclet() {};
  256. /**
  257. * It is used for default setting up of chicklet:click handler, etc.
  258. */
  259. BOOL postBuild();
  260. /**
  261. * Sets IM session name. This name will be displayed in chiclet tooltip.
  262. */
  263. virtual void setIMSessionName(const std::string& name) { setToolTip(name); }
  264. /**
  265. * Sets id of person/group user is chatting with.
  266. * Session id should be set before calling this
  267. */
  268. virtual void setOtherParticipantId(const LLUUID& other_participant_id) { mOtherParticipantId = other_participant_id; }
  269. /**
  270. * Gets id of person/group user is chatting with.
  271. */
  272. virtual LLUUID getOtherParticipantId() { return mOtherParticipantId; }
  273. /**
  274. * Init Speaker Control with speaker's ID
  275. */
  276. virtual void initSpeakerControl();
  277. /**
  278. * set status (Shows/Hide) for voice control.
  279. */
  280. virtual void setShowSpeaker(bool show);
  281. /**
  282. * Returns voice chat status control visibility.
  283. */
  284. virtual bool getShowSpeaker() {return mShowSpeaker;};
  285. /**
  286. * Shows/Hides for voice control for a chiclet.
  287. */
  288. virtual void toggleSpeakerControl();
  289. /**
  290. * Sets number of unread messages. Will update chiclet's width if number text
  291. * exceeds size of counter and notify it's parent about size change.
  292. */
  293. virtual void setCounter(S32);
  294. /**
  295. * Enables/disables the counter control for a chiclet.
  296. */
  297. virtual void enableCounterControl(bool enable);
  298. /**
  299. * Sets show counter state.
  300. */
  301. virtual void setShowCounter(bool show);
  302. /**
  303. * Shows/Hides for counter control for a chiclet.
  304. */
  305. virtual void toggleCounterControl();
  306. /**
  307. * Sets required width for a chiclet according to visible controls.
  308. */
  309. virtual void setRequiredWidth();
  310. /**
  311. * Shows/hides overlay icon concerning new unread messages.
  312. */
  313. virtual void setShowNewMessagesIcon(bool show);
  314. /**
  315. * Returns visibility of overlay icon concerning new unread messages.
  316. */
  317. virtual bool getShowNewMessagesIcon();
  318. virtual void draw();
  319. /**
  320. * Determine whether given ID refers to a group or an IM chat session.
  321. *
  322. * This is used when we need to chose what IM chiclet (P2P/group)
  323. * class to instantiate.
  324. *
  325. * @param session_id session ID.
  326. * @return TYPE_GROUP in case of group chat session,
  327. * TYPE_IM in case of P2P session,
  328. * TYPE_UNKNOWN otherwise.
  329. */
  330. static EType getIMSessionType(const LLUUID& session_id);
  331. /**
  332. * The action taken on mouse down event.
  333. *
  334. * Made public so that it can be triggered from outside
  335. * (more specifically, from the Active IM window).
  336. */
  337. virtual void onMouseDown();
  338. virtual void setToggleState(bool toggle);
  339. /**
  340. * Displays popup menu.
  341. */
  342. virtual BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
  343. protected:
  344. LLIMChiclet(const LLIMChiclet::Params& p);
  345. protected:
  346. /**
  347. * Creates chiclet popup menu.
  348. */
  349. virtual void createPopupMenu() = 0;
  350. /**
  351. * Enables/disables menus.
  352. */
  353. virtual void updateMenuItems() {};
  354. bool canCreateMenu();
  355. LLMenuGL* mPopupMenu;
  356. bool mShowSpeaker;
  357. bool mCounterEnabled;
  358. /* initial width of chiclet, should not include counter or speaker width */
  359. S32 mDefaultWidth;
  360. LLIconCtrl* mNewMessagesIcon;
  361. LLChicletNotificationCounterCtrl* mCounterCtrl;
  362. LLChicletSpeakerCtrl* mSpeakerCtrl;
  363. LLButton* mChicletButton;
  364. /** the id of another participant, either an avatar id or a group id*/
  365. LLUUID mOtherParticipantId;
  366. template<typename Container>
  367. struct CollectChicletCombiner {
  368. typedef Container result_type;
  369. template<typename InputIterator>
  370. Container operator()(InputIterator first, InputIterator last) const {
  371. Container c = Container();
  372. for (InputIterator iter = first; iter != last; iter++) {
  373. if (*iter != NULL) {
  374. c.push_back(*iter);
  375. }
  376. }
  377. return c;
  378. }
  379. };
  380. public:
  381. static boost::signals2::signal<LLChiclet* (const LLUUID&),
  382. CollectChicletCombiner<std::list<LLChiclet*> > >
  383. sFindChicletsSignal;
  384. };
  385. /**
  386. * Implements P2P chiclet.
  387. */
  388. class LLIMP2PChiclet : public LLIMChiclet
  389. {
  390. public:
  391. struct Params : public LLInitParam::Block<Params, LLIMChiclet::Params>
  392. {
  393. Optional<LLButton::Params> chiclet_button;
  394. Optional<LLChicletAvatarIconCtrl::Params> avatar_icon;
  395. Optional<LLChicletNotificationCounterCtrl::Params> unread_notifications;
  396. Optional<LLChicletSpeakerCtrl::Params> speaker;
  397. Optional<LLIconCtrl::Params> new_message_icon;
  398. Optional<bool> show_speaker;
  399. Params();
  400. };
  401. /* virtual */ void setOtherParticipantId(const LLUUID& other_participant_id);
  402. /**
  403. * Init Speaker Control with speaker's ID
  404. */
  405. /*virtual*/ void initSpeakerControl();
  406. /**
  407. * Returns number of unread messages.
  408. */
  409. /*virtual*/ S32 getCounter() { return mCounterCtrl->getCounter(); }
  410. protected:
  411. LLIMP2PChiclet(const Params& p);
  412. friend class LLUICtrlFactory;
  413. /**
  414. * Creates chiclet popup menu. Will create P2P or Group IM Chat menu
  415. * based on other participant's id.
  416. */
  417. virtual void createPopupMenu();
  418. /**
  419. * Processes clicks on chiclet popup menu.
  420. */
  421. virtual void onMenuItemClicked(const LLSD& user_data);
  422. /**
  423. * Enables/disables menus based on relationship with other participant.
  424. * Enables/disables "show session" menu item depending on visible IM floater existence.
  425. */
  426. virtual void updateMenuItems();
  427. private:
  428. LLChicletAvatarIconCtrl* mChicletIconCtrl;
  429. };
  430. /**
  431. * Implements AD-HOC chiclet.
  432. */
  433. class LLAdHocChiclet : public LLIMChiclet
  434. {
  435. public:
  436. struct Params : public LLInitParam::Block<Params, LLIMChiclet::Params>
  437. {
  438. Optional<LLButton::Params> chiclet_button;
  439. Optional<LLChicletAvatarIconCtrl::Params> avatar_icon;
  440. Optional<LLChicletNotificationCounterCtrl::Params> unread_notifications;
  441. Optional<LLChicletSpeakerCtrl::Params> speaker;
  442. Optional<LLIconCtrl::Params> new_message_icon;
  443. Optional<bool> show_speaker;
  444. Optional<LLColor4> avatar_icon_color;
  445. Params();
  446. };
  447. /**
  448. * Sets session id.
  449. * Session ID for group chat is actually Group ID.
  450. */
  451. /*virtual*/ void setSessionId(const LLUUID& session_id);
  452. /**
  453. * Keep Speaker Control with actual speaker's ID
  454. */
  455. /*virtual*/ void draw();
  456. /**
  457. * Init Speaker Control with speaker's ID
  458. */
  459. /*virtual*/ void initSpeakerControl();
  460. /**
  461. * Returns number of unread messages.
  462. */
  463. /*virtual*/ S32 getCounter() { return mCounterCtrl->getCounter(); }
  464. protected:
  465. LLAdHocChiclet(const Params& p);
  466. friend class LLUICtrlFactory;
  467. /**
  468. * Creates chiclet popup menu. Will create AdHoc Chat menu
  469. * based on other participant's id.
  470. */
  471. virtual void createPopupMenu();
  472. /**
  473. * Processes clicks on chiclet popup menu.
  474. */
  475. virtual void onMenuItemClicked(const LLSD& user_data);
  476. /**
  477. * Finds a current speaker and resets the SpeakerControl with speaker's ID
  478. */
  479. /*virtual*/ void switchToCurrentSpeaker();
  480. private:
  481. LLChicletAvatarIconCtrl* mChicletIconCtrl;
  482. };
  483. /**
  484. * Chiclet for script floaters.
  485. */
  486. class LLScriptChiclet : public LLIMChiclet
  487. {
  488. public:
  489. struct Params : public LLInitParam::Block<Params, LLIMChiclet::Params>
  490. {
  491. Optional<LLButton::Params> chiclet_button;
  492. Optional<LLIconCtrl::Params> icon;
  493. Optional<LLIconCtrl::Params> new_message_icon;
  494. Params();
  495. };
  496. /*virtual*/ void setSessionId(const LLUUID& session_id);
  497. /*virtual*/ void setCounter(S32 counter);
  498. /*virtual*/ S32 getCounter() { return 0; }
  499. /**
  500. * Toggle script floater
  501. */
  502. /*virtual*/ void onMouseDown();
  503. protected:
  504. LLScriptChiclet(const Params&);
  505. friend class LLUICtrlFactory;
  506. /**
  507. * Creates chiclet popup menu.
  508. */
  509. virtual void createPopupMenu();
  510. /**
  511. * Processes clicks on chiclet popup menu.
  512. */
  513. virtual void onMenuItemClicked(const LLSD& user_data);
  514. private:
  515. LLIconCtrl* mChicletIconCtrl;
  516. };
  517. /**
  518. * Chiclet for inventory offer script floaters.
  519. */
  520. class LLInvOfferChiclet: public LLIMChiclet
  521. {
  522. public:
  523. struct Params : public LLInitParam::Block<Params, LLIMChiclet::Params>
  524. {
  525. Optional<LLButton::Params> chiclet_button;
  526. Optional<LLChicletInvOfferIconCtrl::Params> icon;
  527. Optional<LLIconCtrl::Params> new_message_icon;
  528. Params();
  529. };
  530. /*virtual*/ void setSessionId(const LLUUID& session_id);
  531. /*virtual*/ void setCounter(S32 counter);
  532. /*virtual*/ S32 getCounter() { return 0; }
  533. /**
  534. * Toggle script floater
  535. */
  536. /*virtual*/ void onMouseDown();
  537. protected:
  538. LLInvOfferChiclet(const Params&);
  539. friend class LLUICtrlFactory;
  540. /**
  541. * Creates chiclet popup menu.
  542. */
  543. virtual void createPopupMenu();
  544. /**
  545. * Processes clicks on chiclet popup menu.
  546. */
  547. virtual void onMenuItemClicked(const LLSD& user_data);
  548. private:
  549. LLChicletInvOfferIconCtrl* mChicletIconCtrl;
  550. };
  551. /**
  552. * Implements Group chat chiclet.
  553. */
  554. class LLIMGroupChiclet : public LLIMChiclet, public LLGroupMgrObserver
  555. {
  556. public:
  557. struct Params : public LLInitParam::Block<Params, LLIMChiclet::Params>
  558. {
  559. Optional<LLButton::Params> chiclet_button;
  560. Optional<LLChicletGroupIconCtrl::Params> group_icon;
  561. Optional<LLChicletNotificationCounterCtrl::Params> unread_notifications;
  562. Optional<LLChicletSpeakerCtrl::Params> speaker;
  563. Optional<LLIconCtrl::Params> new_message_icon;
  564. Optional<bool> show_speaker;
  565. Params();
  566. };
  567. /**
  568. * Sets session id.
  569. * Session ID for group chat is actually Group ID.
  570. */
  571. /*virtual*/ void setSessionId(const LLUUID& session_id);
  572. /**
  573. * Keep Speaker Control with actual speaker's ID
  574. */
  575. /*virtual*/ void draw();
  576. /**
  577. * Callback for LLGroupMgrObserver, we get this when group data is available or changed.
  578. * Sets group icon.
  579. */
  580. /*virtual*/ void changed(LLGroupChange gc);
  581. /**
  582. * Init Speaker Control with speaker's ID
  583. */
  584. /*virtual*/ void initSpeakerControl();
  585. /**
  586. * Returns number of unread messages.
  587. */
  588. /*virtual*/ S32 getCounter() { return mCounterCtrl->getCounter(); }
  589. ~LLIMGroupChiclet();
  590. protected:
  591. LLIMGroupChiclet(const Params& p);
  592. friend class LLUICtrlFactory;
  593. /**
  594. * Finds a current speaker and resets the SpeakerControl with speaker's ID
  595. */
  596. /*virtual*/ void switchToCurrentSpeaker();
  597. /**
  598. * Creates chiclet popup menu. Will create P2P or Group IM Chat menu
  599. * based on other participant's id.
  600. */
  601. virtual void createPopupMenu();
  602. /**
  603. * Processes clicks on chiclet popup menu.
  604. */
  605. virtual void onMenuItemClicked(const LLSD& user_data);
  606. /**
  607. * Enables/disables "show session" menu item depending on visible IM floater existence.
  608. */
  609. virtual void updateMenuItems();
  610. private:
  611. LLChicletGroupIconCtrl* mChicletIconCtrl;
  612. };
  613. /**
  614. * Implements notification chiclet. Used to display total amount of unread messages
  615. * across all IM sessions, total amount of system notifications. See EXT-3147 for details
  616. */
  617. class LLSysWellChiclet : public LLChiclet
  618. {
  619. public:
  620. struct Params : public LLInitParam::Block<Params, LLChiclet::Params>
  621. {
  622. Optional<LLButton::Params> button;
  623. Optional<LLChicletNotificationCounterCtrl::Params> unread_notifications;
  624. /**
  625. * Contains maximum displayed count of unread messages. Default value is 9.
  626. *
  627. * If count is less than "max_unread_count" will be displayed as is.
  628. * Otherwise 9+ will be shown (for default value).
  629. */
  630. Optional<S32> max_displayed_count;
  631. Params();
  632. };
  633. /*virtual*/ void setCounter(S32 counter);
  634. // *TODO: mantipov: seems getCounter is not necessary for LLNotificationChiclet
  635. // but inherited interface requires it to implement.
  636. // Probably it can be safe removed.
  637. /*virtual*/S32 getCounter() { return mCounter; }
  638. boost::signals2::connection setClickCallback(const commit_callback_t& cb);
  639. /*virtual*/ ~LLSysWellChiclet();
  640. void setToggleState(BOOL toggled);
  641. void setNewMessagesState(bool new_messages);
  642. //this method should change a widget according to state of the SysWellWindow
  643. virtual void updateWidget(bool is_window_empty);
  644. protected:
  645. LLSysWellChiclet(const Params& p);
  646. friend class LLUICtrlFactory;
  647. /**
  648. * Change Well 'Lit' state from 'Lit' to 'Unlit' and vice-versa.
  649. *
  650. * There is an assumption that it will be called 2*N times to do not change its start state.
  651. * @see FlashToLitTimer
  652. */
  653. void changeLitState();
  654. /**
  655. * Displays menu.
  656. */
  657. virtual BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
  658. virtual void createMenu() = 0;
  659. protected:
  660. class FlashToLitTimer;
  661. LLButton* mButton;
  662. S32 mCounter;
  663. S32 mMaxDisplayedCount;
  664. bool mIsNewMessagesState;
  665. FlashToLitTimer* mFlashToLitTimer;
  666. LLContextMenu* mContextMenu;
  667. };
  668. /**
  669. * Class represented a chiclet for IM Well Icon.
  670. *
  671. * It displays a count of unread messages from other participants in all IM sessions.
  672. */
  673. class LLIMWellChiclet : public LLSysWellChiclet, LLIMSessionObserver
  674. {
  675. friend class LLUICtrlFactory;
  676. public:
  677. virtual void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id) {}
  678. virtual void sessionRemoved(const LLUUID& session_id) { messageCountChanged(LLSD()); }
  679. virtual void sessionIDUpdated(const LLUUID& old_session_id, const LLUUID& new_session_id) {}
  680. ~LLIMWellChiclet();
  681. protected:
  682. LLIMWellChiclet(const Params& p);
  683. /**
  684. * Processes clicks on chiclet popup menu.
  685. */
  686. virtual void onMenuItemClicked(const LLSD& user_data);
  687. /**
  688. * Enables chiclet menu items.
  689. */
  690. bool enableMenuItem(const LLSD& user_data);
  691. /**
  692. * Creates menu.
  693. */
  694. /*virtual*/ void createMenu();
  695. /**
  696. * Handles changes in a session (message was added, messages were read, etc.)
  697. *
  698. * It get total count of unread messages from a LLIMMgr in all opened sessions and display it.
  699. *
  700. * @param[in] session_data contains session related data, is not used now
  701. * ["session_id"] - id of an appropriate session
  702. * ["participant_unread"] - count of unread messages from "real" participants.
  703. *
  704. * @see LLIMMgr::getNumberOfUnreadParticipantMessages()
  705. */
  706. void messageCountChanged(const LLSD& session_data);
  707. };
  708. class LLNotificationChiclet : public LLSysWellChiclet
  709. {
  710. friend class LLUICtrlFactory;
  711. public:
  712. struct Params : public LLInitParam::Block<Params, LLSysWellChiclet::Params>{};
  713. protected:
  714. LLNotificationChiclet(const Params& p);
  715. /**
  716. * Processes clicks on chiclet menu.
  717. */
  718. void onMenuItemClicked(const LLSD& user_data);
  719. /**
  720. * Enables chiclet menu items.
  721. */
  722. bool enableMenuItem(const LLSD& user_data);
  723. /**
  724. * Creates menu.
  725. */
  726. /*virtual*/ void createMenu();
  727. // connect counter updaters to the corresponding signals
  728. void connectCounterUpdatersToSignal(const std::string& notification_type);
  729. // methods for updating a number of unread System notifications
  730. void incUreadSystemNotifications() { setCounter(++mUreadSystemNotifications); }
  731. void decUreadSystemNotifications() { setCounter(--mUreadSystemNotifications); }
  732. /*virtual*/ void setCounter(S32 counter);
  733. S32 mUreadSystemNotifications;
  734. };
  735. /**
  736. * Storage class for all IM chiclets. Provides mechanism to display,
  737. * scroll, create, remove chiclets.
  738. */
  739. class LLChicletPanel : public LLPanel
  740. {
  741. public:
  742. struct Params : public LLInitParam::Block<Params, LLPanel::Params>
  743. {
  744. Optional<S32> chiclet_padding,
  745. scrolling_offset,
  746. scroll_button_hpad,
  747. scroll_ratio;
  748. Optional<S32> min_width;
  749. Params();
  750. };
  751. virtual ~LLChicletPanel();
  752. /**
  753. * Creates chiclet and adds it to chiclet list at specified index.
  754. */
  755. template<class T> T* createChiclet(const LLUUID& session_id, S32 index);
  756. /**
  757. * Creates chiclet and adds it to chiclet list at right.
  758. */
  759. template<class T> T* createChiclet(const LLUUID& session_id);
  760. /**
  761. * Returns pointer to chiclet of specified type at specified index.
  762. */
  763. template<class T> T* getChiclet(S32 index);
  764. /**
  765. * Returns pointer to LLChiclet at specified index.
  766. */
  767. LLChiclet* getChiclet(S32 index) { return getChiclet<LLChiclet>(index); }
  768. /**
  769. * Searches a chiclet using IM session id.
  770. */
  771. template<class T> T* findChiclet(const LLUUID& im_session_id);
  772. /**
  773. * Returns number of hosted chiclets.
  774. */
  775. S32 getChicletCount() {return mChicletList.size();};
  776. /**
  777. * Returns index of chiclet in list.
  778. */
  779. S32 getChicletIndex(const LLChiclet* chiclet);
  780. /**
  781. * Removes chiclet by index.
  782. */
  783. void removeChiclet(S32 index);
  784. /**
  785. * Removes chiclet by pointer.
  786. */
  787. void removeChiclet(LLChiclet* chiclet);
  788. /**
  789. * Removes chiclet by IM session id.
  790. */
  791. void removeChiclet(const LLUUID& im_session_id);
  792. /**
  793. * Removes all chiclets.
  794. */
  795. void removeAll();
  796. /**
  797. * Scrolls the panel to the specified chiclet
  798. */
  799. void scrollToChiclet(const LLChiclet* chiclet);
  800. boost::signals2::connection setChicletClickedCallback(
  801. const commit_callback_t& cb);
  802. /*virtual*/ BOOL postBuild();
  803. /**
  804. * Handler for the Voice Client's signal. Finds a corresponding chiclet and toggles its SpeakerControl
  805. */
  806. void onCurrentVoiceChannelChanged(const LLUUID& session_id);
  807. /**
  808. * Reshapes controls and rearranges chiclets if needed.
  809. */
  810. /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE );
  811. /*virtual*/ void draw();
  812. S32 getMinWidth() const { return mMinWidth; }
  813. S32 getTotalUnreadIMCount();
  814. S32 notifyParent(const LLSD& info);
  815. /**
  816. * Toggle chiclet by session id ON and toggle OFF all other chiclets.
  817. */
  818. void setChicletToggleState(const LLUUID& session_id, bool toggle);
  819. protected:
  820. LLChicletPanel(const Params&p);
  821. friend class LLUICtrlFactory;
  822. /**
  823. * Adds chiclet to list and rearranges all chiclets.
  824. * They should be right aligned, most recent right. See EXT-1293
  825. *
  826. * It calculates position of the first chiclet in the list. Other chiclets are placed in arrange().
  827. *
  828. * @see arrange()
  829. */
  830. bool addChiclet(LLChiclet*, S32 index);
  831. /**
  832. * Arranges chiclets to have them in correct positions.
  833. *
  834. * Method bases on assumption that first chiclet has correct rect and starts from the its position.
  835. *
  836. * @see addChiclet()
  837. */
  838. void arrange();
  839. /**
  840. * Returns true if chiclets can be scrolled right.
  841. */
  842. bool canScrollRight();
  843. /**
  844. * Returns true if we need to show scroll buttons
  845. */
  846. bool needShowScroll();
  847. /**
  848. * Returns true if chiclets can be scrolled left.
  849. */
  850. bool canScrollLeft();
  851. /**
  852. * Shows or hides chiclet scroll buttons if chiclets can or can not be scrolled.
  853. */
  854. void showScrollButtonsIfNeeded();
  855. /**
  856. * Shifts chiclets left or right.
  857. */
  858. void shiftChiclets(S32 offset, S32 start_index = 0);
  859. /**
  860. * Removes gaps between first chiclet and scroll area left side,
  861. * last chiclet and scroll area right side.
  862. */
  863. void trimChiclets();
  864. /**
  865. * Scrolls chiclets to right or left.
  866. */
  867. void scroll(S32 offset);
  868. /**
  869. * Verifies that chiclets can be scrolled left, then calls scroll()
  870. */
  871. void scrollLeft();
  872. /**
  873. * Verifies that chiclets can be scrolled right, then calls scroll()
  874. */
  875. void scrollRight();
  876. /**
  877. * Callback for left scroll button clicked
  878. */
  879. void onLeftScrollClick();
  880. /**
  881. * Callback for right scroll button clicked
  882. */
  883. void onRightScrollClick();
  884. /**
  885. * Callback for right scroll button held down event
  886. */
  887. void onLeftScrollHeldDown();
  888. /**
  889. * Callback for left scroll button held down event
  890. */
  891. void onRightScrollHeldDown();
  892. /**
  893. * Callback for mouse wheel scrolled, calls scrollRight() or scrollLeft()
  894. */
  895. BOOL handleScrollWheel(S32 x, S32 y, S32 clicks);
  896. /**
  897. * Notifies subscribers about click on chiclet.
  898. * Do not place any code here, instead subscribe on event (see setChicletClickedCallback).
  899. */
  900. void onChicletClick(LLUICtrl*ctrl,const LLSD&param);
  901. /**
  902. * Callback for chiclet size changed event, rearranges chiclets.
  903. */
  904. void onChicletSizeChanged(LLChiclet* ctrl, const LLSD& param);
  905. typedef std::vector<LLChiclet*> chiclet_list_t;
  906. /**
  907. * Removes chiclet from scroll area and chiclet list.
  908. */
  909. void removeChiclet(chiclet_list_t::iterator it);
  910. S32 getChicletPadding() { return mChicletPadding; }
  911. S32 getScrollingOffset() { return mScrollingOffset; }
  912. bool isAnyIMFloaterDoked();
  913. protected:
  914. chiclet_list_t mChicletList;
  915. LLButton* mLeftScrollButton;
  916. LLButton* mRightScrollButton;
  917. LLPanel* mScrollArea;
  918. S32 mChicletPadding;
  919. S32 mScrollingOffset;
  920. S32 mScrollButtonHPad;
  921. S32 mScrollRatio;
  922. S32 mMinWidth;
  923. bool mShowControls;
  924. static const S32 s_scroll_ratio;
  925. };
  926. template<class T>
  927. T* LLChicletPanel::createChiclet(const LLUUID& session_id, S32 index)
  928. {
  929. typename T::Params params;
  930. T* chiclet = LLUICtrlFactory::create<T>(params);
  931. if(!chiclet)
  932. {
  933. llwarns << "Could not create chiclet" << llendl;
  934. return NULL;
  935. }
  936. if(!addChiclet(chiclet, index))
  937. {
  938. delete chiclet;
  939. llwarns << "Could not add chiclet to chiclet panel" << llendl;
  940. return NULL;
  941. }
  942. if (!isAnyIMFloaterDoked())
  943. {
  944. scrollToChiclet(chiclet);
  945. }
  946. chiclet->setSessionId(session_id);
  947. return chiclet;
  948. }
  949. template<class T>
  950. T* LLChicletPanel::createChiclet(const LLUUID& session_id)
  951. {
  952. return createChiclet<T>(session_id, mChicletList.size());
  953. }
  954. template<class T>
  955. T* LLChicletPanel::findChiclet(const LLUUID& im_session_id)
  956. {
  957. if(im_session_id.isNull())
  958. {
  959. return NULL;
  960. }
  961. chiclet_list_t::const_iterator it = mChicletList.begin();
  962. for( ; mChicletList.end() != it; ++it)
  963. {
  964. LLChiclet* chiclet = *it;
  965. llassert(chiclet);
  966. if (!chiclet) continue;
  967. if(chiclet->getSessionId() == im_session_id)
  968. {
  969. T* result = dynamic_cast<T*>(chiclet);
  970. if(!result)
  971. {
  972. llwarns << "Found chiclet but of wrong type " << llendl;
  973. continue;
  974. }
  975. return result;
  976. }
  977. }
  978. return NULL;
  979. }
  980. template<class T> T* LLChicletPanel::getChiclet(S32 index)
  981. {
  982. if(index < 0 || index >= getChicletCount())
  983. {
  984. return NULL;
  985. }
  986. LLChiclet* chiclet = mChicletList[index];
  987. T*result = dynamic_cast<T*>(chiclet);
  988. if(!result && chiclet)
  989. {
  990. llwarns << "Found chiclet but of wrong type " << llendl;
  991. }
  992. return result;
  993. }
  994. #endif // LL_LLCHICLET_H