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