llstylemap.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * @file llstylemap.cpp
  3. * @brief LLStyleMap class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-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. #include "linden_common.h"
  33. #include <utility>
  34. #include "llstylemap.h"
  35. #include "llstring.h"
  36. extern LLUUID gAgentID; // from ../newview/llagent.cpp
  37. LLStyleMap gStyleMap;
  38. // This is similar to the [] accessor except that if the entry does not already
  39. // exist, then this will create the entry.
  40. const LLStyleSP& LLStyleMap::lookupAgent(const LLUUID& id)
  41. {
  42. // Find this style in the map or add it if not. This map holds links to
  43. // residents' profiles.
  44. iterator it = find(id);
  45. if (it != end())
  46. {
  47. return it->second;
  48. }
  49. LLStyleSP style(new LLStyle);
  50. if (id.notNull() && id != gAgentID)
  51. {
  52. style->setColor(LLUI::sHTMLLinkColor);
  53. std::string link = llformat("secondlife:///app/agent/%s/about",
  54. id.asString().c_str());
  55. style->setLinkHREF(link);
  56. }
  57. else
  58. {
  59. // Make the resident's own name white and do not make the name
  60. // clickable.
  61. style->setColor(LLColor4::white);
  62. }
  63. it = emplace(id, std::move(style)).first;
  64. return it->second;
  65. }
  66. // This is similar to lookupAgent for any generic URL encoded style.
  67. const LLStyleSP& LLStyleMap::lookup(const LLUUID& id, const std::string& link)
  68. {
  69. // Find this style in the map or add it if not.
  70. iterator it = find(id);
  71. if (it != end())
  72. {
  73. LLStyle* style = it->second.get();
  74. if (style->getLinkHREF() != link)
  75. {
  76. style->setLinkHREF(link);
  77. }
  78. return it->second;
  79. }
  80. LLStyleSP style(new LLStyle);
  81. if (id.notNull() && !link.empty())
  82. {
  83. style->setColor(LLUI::sHTMLLinkColor);
  84. style->setLinkHREF(link);
  85. }
  86. else
  87. {
  88. style->setColor(LLColor4::white);
  89. }
  90. it = emplace(id, std::move(style)).first;
  91. return it->second;
  92. }
  93. void LLStyleMap::update()
  94. {
  95. for (style_map_t::iterator it = begin(), eit = end(); it != eit; ++it)
  96. {
  97. LLStyle* style = it->second.get();
  98. // Update the link color in case it has been changed.
  99. style->setColor(LLUI::sHTMLLinkColor);
  100. }
  101. }