/indra/newview/lllistcontextmenu.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 117 lines · 63 code · 17 blank · 37 comment · 8 complexity · c042d5235a790918c945a00cfe74f2fd MD5 · raw file

  1. /**
  2. * @file lllistcontextmenu.cpp
  3. * @brief Base class of misc lists' context menus
  4. *
  5. * $LicenseInfo:firstyear=2010&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 "lllistcontextmenu.h"
  28. // libs
  29. #include "llmenugl.h" // for LLContextMenu
  30. // newview
  31. #include "llviewermenu.h" // for LLViewerMenuHolderGL
  32. LLListContextMenu::LLListContextMenu()
  33. {
  34. }
  35. LLListContextMenu::~LLListContextMenu()
  36. {
  37. // do not forget delete LLContextMenu* mMenu.
  38. // It can have registered Enable callbacks which are called from the LLMenuHolderGL::draw()
  39. // via selected item (menu_item_call) by calling LLMenuItemCallGL::buildDrawLabel.
  40. // we can have a crash via using callbacks of deleted instance of ContextMenu. EXT-4725
  41. // menu holder deletes its menus on viewer exit, so we have no way to determine if instance
  42. // of mMenu has already been deleted except of using LLHandle. EXT-4762.
  43. if (!mMenuHandle.isDead())
  44. {
  45. mMenuHandle.get()->die();
  46. }
  47. }
  48. void LLListContextMenu::show(LLView* spawning_view, const uuid_vec_t& uuids, S32 x, S32 y)
  49. {
  50. LLContextMenu* menup = mMenuHandle.get();
  51. if (menup)
  52. {
  53. //preventing parent (menu holder) from deleting already "dead" context menus on exit
  54. LLView* parent = menup->getParent();
  55. if (parent)
  56. {
  57. parent->removeChild(menup);
  58. }
  59. delete menup;
  60. mUUIDs.clear();
  61. }
  62. if ( uuids.empty() )
  63. {
  64. return;
  65. }
  66. mUUIDs.resize(uuids.size());
  67. std::copy(uuids.begin(), uuids.end(), mUUIDs.begin());
  68. menup = createMenu();
  69. if (!menup)
  70. {
  71. llwarns << "Context menu creation failed" << llendl;
  72. return;
  73. }
  74. mMenuHandle = menup->getHandle();
  75. menup->show(x, y);
  76. LLMenuGL::showPopup(spawning_view, menup, x, y);
  77. }
  78. void LLListContextMenu::hide()
  79. {
  80. if(mMenuHandle.get())
  81. {
  82. mMenuHandle.get()->hide();
  83. }
  84. }
  85. // static
  86. void LLListContextMenu::handleMultiple(functor_t functor, const uuid_vec_t& ids)
  87. {
  88. uuid_vec_t::const_iterator it;
  89. for (it = ids.begin(); it != ids.end(); ++it)
  90. {
  91. functor(*it);
  92. }
  93. }
  94. // static
  95. LLContextMenu* LLListContextMenu::createFromFile(const std::string& filename)
  96. {
  97. return LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu>(
  98. filename, LLContextMenu::sMenuContainer, LLViewerMenuHolderGL::child_registry_t::instance());
  99. }
  100. // EOF