/indra/newview/llnamelistctrl.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 147 lines · 86 code · 24 blank · 37 comment · 0 complexity · 073cd386aed3a8f19fb0fffdfa5be699 MD5 · raw file

  1. /**
  2. * @file llnamelistctrl.h
  3. * @brief A list of names, automatically refreshing from the name cache.
  4. *
  5. * $LicenseInfo:firstyear=2003&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_LLNAMELISTCTRL_H
  27. #define LL_LLNAMELISTCTRL_H
  28. #include <set>
  29. #include "llscrolllistctrl.h"
  30. class LLAvatarName;
  31. class LLNameListCtrl
  32. : public LLScrollListCtrl, public LLInstanceTracker<LLNameListCtrl>
  33. {
  34. public:
  35. typedef enum e_name_type
  36. {
  37. INDIVIDUAL,
  38. GROUP,
  39. SPECIAL
  40. } ENameType;
  41. // provide names for enums
  42. struct NameTypeNames : public LLInitParam::TypeValuesHelper<LLNameListCtrl::ENameType, NameTypeNames>
  43. {
  44. static void declareValues();
  45. };
  46. struct NameItem : public LLInitParam::Block<NameItem, LLScrollListItem::Params>
  47. {
  48. Optional<std::string> name;
  49. Optional<ENameType, NameTypeNames> target;
  50. NameItem()
  51. : name("name"),
  52. target("target", INDIVIDUAL)
  53. {}
  54. };
  55. struct NameColumn : public LLInitParam::ChoiceBlock<NameColumn>
  56. {
  57. Alternative<S32> column_index;
  58. Alternative<std::string> column_name;
  59. NameColumn()
  60. : column_name("name_column"),
  61. column_index("name_column_index", 0)
  62. {}
  63. };
  64. struct Params : public LLInitParam::Block<Params, LLScrollListCtrl::Params>
  65. {
  66. Optional<NameColumn> name_column;
  67. Optional<bool> allow_calling_card_drop;
  68. Optional<bool> short_names;
  69. Params();
  70. };
  71. protected:
  72. LLNameListCtrl(const Params&);
  73. friend class LLUICtrlFactory;
  74. public:
  75. // Add a user to the list by name. It will be added, the name
  76. // requested from the cache, and updated as necessary.
  77. void addNameItem(const LLUUID& agent_id, EAddPosition pos = ADD_BOTTOM,
  78. BOOL enabled = TRUE, const std::string& suffix = LLStringUtil::null);
  79. void addNameItem(NameItem& item, EAddPosition pos = ADD_BOTTOM);
  80. /*virtual*/ LLScrollListItem* addElement(const LLSD& element, EAddPosition pos = ADD_BOTTOM, void* userdata = NULL);
  81. LLScrollListItem* addNameItemRow(const NameItem& value, EAddPosition pos = ADD_BOTTOM, const std::string& suffix = LLStringUtil::null);
  82. // Add a user to the list by name. It will be added, the name
  83. // requested from the cache, and updated as necessary.
  84. void addGroupNameItem(const LLUUID& group_id, EAddPosition pos = ADD_BOTTOM,
  85. BOOL enabled = TRUE);
  86. void addGroupNameItem(NameItem& item, EAddPosition pos = ADD_BOTTOM);
  87. void removeNameItem(const LLUUID& agent_id);
  88. // LLView interface
  89. /*virtual*/ BOOL handleDragAndDrop(S32 x, S32 y, MASK mask,
  90. BOOL drop, EDragAndDropType cargo_type, void *cargo_data,
  91. EAcceptance *accept,
  92. std::string& tooltip_msg);
  93. /*virtual*/ BOOL handleToolTip(S32 x, S32 y, MASK mask);
  94. void setAllowCallingCardDrop(BOOL b) { mAllowCallingCardDrop = b; }
  95. /*virtual*/ void updateColumns();
  96. /*virtual*/ void mouseOverHighlightNthItem( S32 index );
  97. private:
  98. void showInspector(const LLUUID& avatar_id, bool is_group);
  99. void onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name);
  100. private:
  101. S32 mNameColumnIndex;
  102. std::string mNameColumn;
  103. BOOL mAllowCallingCardDrop;
  104. bool mShortNames; // display name only, no SLID
  105. };
  106. /**
  107. * LLNameListCtrl item
  108. *
  109. * We don't use LLScrollListItem to be able to override getUUID(), which is needed
  110. * because the name list item value is not simply an UUID but a map (uuid, is_group).
  111. */
  112. class LLNameListItem : public LLScrollListItem
  113. {
  114. public:
  115. LLUUID getUUID() const { return getValue()["uuid"].asUUID(); }
  116. protected:
  117. friend class LLNameListCtrl;
  118. LLNameListItem( const LLScrollListItem::Params& p )
  119. : LLScrollListItem(p)
  120. {
  121. }
  122. };
  123. #endif