llnamelistctrl.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @file llnamelistctrl.h
  3. * @brief A list of names, automatically refreshing from the name cache.
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-2009, 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. #ifndef LL_LLNAMELISTCTRL_H
  33. #define LL_LLNAMELISTCTRL_H
  34. #include "llcachename.h"
  35. #include "hbfastmap.h"
  36. #include "llscrolllistctrl.h"
  37. #include "lluuid.h"
  38. class LLNameListCtrl : public LLScrollListCtrl
  39. {
  40. public:
  41. LLNameListCtrl(const std::string& name, const LLRect& rect,
  42. LLUICtrlCallback callback, void* userdata,
  43. bool allow_multiple_selection, bool draw_border = true,
  44. S32 name_column_index = 0,
  45. const std::string& tooltip = LLStringUtil::null);
  46. ~LLNameListCtrl() override;
  47. void draw() override;
  48. const std::string& getTag() const override;
  49. LLXMLNodePtr getXML(bool save_children = true) const override;
  50. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  51. LLUICtrlFactory* factory);
  52. // Add a user to the list by name. It will be added, the name requested
  53. // from the cache, and updated as necessary.
  54. bool addNameItem(const LLUUID& agent_id, EAddPosition pos = ADD_BOTTOM,
  55. bool enabled = true,
  56. const std::string& suffix = LLStringUtil::null);
  57. bool addNameItem(LLScrollListItem* item, EAddPosition pos = ADD_BOTTOM);
  58. LLScrollListItem* addElement(const LLSD& value,
  59. EAddPosition pos = ADD_BOTTOM,
  60. void* userdata = NULL) override;
  61. // Add a user to the list by name. It will be added, the name requested
  62. // from the cache, and updated as necessary.
  63. void addGroupNameItem(const LLUUID& group_id,
  64. EAddPosition pos = ADD_BOTTOM, bool enabled = true);
  65. void addGroupNameItem(LLScrollListItem* item,
  66. EAddPosition pos = ADD_BOTTOM);
  67. void removeNameItem(const LLUUID& agent_id);
  68. void refresh(const LLUUID& id, const std::string& fullname, bool is_group);
  69. static void refreshAll(const LLUUID& id, const std::string& fullname,
  70. bool is_group);
  71. void sortByName(bool ascending);
  72. LLScrollListItem* getItemById(const LLUUID& id);
  73. bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  74. EDragAndDropType cargo_type,
  75. void* cargo_data, EAcceptance* accept,
  76. std::string& tooltip_msg) override;
  77. LL_INLINE void setAllowCallingCardDrop(bool b) { mAllowCallingCardDrop = b; }
  78. LL_INLINE void setUseDisplayNames(bool b) { mUseDisplayNames = b; }
  79. LL_INLINE void setLazyUpdateInterval(F32 delay) { mLazyUpdateInterval = delay; }
  80. private:
  81. bool getResidentName(const LLUUID& agent_id, std::string& fullname);
  82. bool getGroupName(const LLUUID& group_id, std::string& name);
  83. static void onAvatarNameCache(const LLUUID& agent_id,
  84. const LLAvatarName& av_name,
  85. LLNameListCtrl* self);
  86. static void onGroupNameCache(const LLUUID& group_id,
  87. const std::string& name,
  88. LLNameListCtrl* self);
  89. private:
  90. S32 mNameColumnIndex;
  91. F32 mLazyUpdateInterval;
  92. F64 mLastUpdate;
  93. bool mAllowCallingCardDrop;
  94. bool mUseDisplayNames;
  95. typedef fast_hmap<LLUUID, std::string> pending_map_t;
  96. pending_map_t mPendingUpdates;
  97. typedef fast_hset<LLNameListCtrl*> instances_list_t;
  98. static instances_list_t sInstances;
  99. };
  100. #endif