/indra/newview/llnameeditor.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 107 lines · 63 code · 18 blank · 26 comment · 6 complexity · 0b5efcada6e0433631f38065b817cfdf MD5 · raw file

  1. /**
  2. * @file llnameeditor.cpp
  3. * @brief Name Editor to refresh a name.
  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. #include "llviewerprecompiledheaders.h"
  27. #include "llnameeditor.h"
  28. #include "llcachename.h"
  29. #include "llfontgl.h"
  30. #include "lluuid.h"
  31. #include "llrect.h"
  32. #include "llstring.h"
  33. #include "llui.h"
  34. static LLDefaultChildRegistry::Register<LLNameEditor> r("name_editor");
  35. // statics
  36. std::set<LLNameEditor*> LLNameEditor::sInstances;
  37. LLNameEditor::LLNameEditor(const LLNameEditor::Params& p)
  38. : LLLineEditor(p)
  39. {
  40. LLNameEditor::sInstances.insert(this);
  41. if(!p.name_id().isNull())
  42. {
  43. setNameID(p.name_id, p.is_group);
  44. }
  45. }
  46. LLNameEditor::~LLNameEditor()
  47. {
  48. LLNameEditor::sInstances.erase(this);
  49. }
  50. void LLNameEditor::setNameID(const LLUUID& name_id, BOOL is_group)
  51. {
  52. mNameID = name_id;
  53. std::string name;
  54. if (!is_group)
  55. {
  56. gCacheName->getFullName(name_id, name);
  57. }
  58. else
  59. {
  60. gCacheName->getGroupName(name_id, name);
  61. }
  62. setText(name);
  63. }
  64. void LLNameEditor::refresh(const LLUUID& id, const std::string& full_name, bool is_group)
  65. {
  66. if (id == mNameID)
  67. {
  68. setText(full_name);
  69. }
  70. }
  71. void LLNameEditor::refreshAll(const LLUUID& id, const std::string& full_name, bool is_group)
  72. {
  73. std::set<LLNameEditor*>::iterator it;
  74. for (it = LLNameEditor::sInstances.begin();
  75. it != LLNameEditor::sInstances.end();
  76. ++it)
  77. {
  78. LLNameEditor* box = *it;
  79. box->refresh(id, full_name, is_group);
  80. }
  81. }
  82. void LLNameEditor::setValue( const LLSD& value )
  83. {
  84. setNameID(value.asUUID(), FALSE);
  85. }
  86. LLSD LLNameEditor::getValue() const
  87. {
  88. return LLSD(mNameID);
  89. }