void LLMenuButton::hideMenu()
{
	if(mMenuHandle.isDead()) return;

	LLToggleableMenu* menu = dynamic_cast<LLToggleableMenu*>(mMenuHandle.get());
	if (menu)
	{
		menu->setVisible(FALSE);
	}
}
Exemplo n.º 2
0
void LLPanelPlaces::onOverflowButtonClicked()
{
	LLToggleableMenu* menu;

	bool is_agent_place_info_visible = mPlaceInfoType == AGENT_INFO_TYPE;

	if ((is_agent_place_info_visible ||
		 mPlaceInfoType == REMOTE_PLACE_INFO_TYPE ||
		 mPlaceInfoType == TELEPORT_HISTORY_INFO_TYPE) && mPlaceMenu != NULL)
	{
		menu = mPlaceMenu;

		// Enable adding a landmark only for agent current parcel and if
		// there is no landmark already pointing to that parcel in agent's inventory.
		menu->getChild<LLMenuItemCallGL>("landmark")->setEnabled(is_agent_place_info_visible &&
																 !LLLandmarkActions::landmarkAlreadyExists());
	}
	else if (mPlaceInfoType == LANDMARK_INFO_TYPE && mLandmarkMenu != NULL)
	{
		menu = mLandmarkMenu;

		BOOL is_landmark_removable = FALSE;
		if (mItem.notNull())
		{
			const LLUUID& item_id = mItem->getUUID();
			const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
			is_landmark_removable = gInventory.isObjectDescendentOf(item_id, gInventory.getRootFolderID()) &&
									!gInventory.isObjectDescendentOf(item_id, trash_id);
		}

		menu->getChild<LLMenuItemCallGL>("delete")->setEnabled(is_landmark_removable);
	}
	else
	{
		return;
	}

	if (!menu->toggleVisibility())
		return;

	if (menu->getButtonRect().isEmpty())
	{
		menu->setButtonRect(mOverflowBtn);
	}
	menu->updateParent(LLMenuGL::sMenuContainer);
	LLRect rect = mOverflowBtn->getRect();
	LLMenuGL::showPopup(this, menu, rect.mRight, rect.mTop);
}
void LLMenuButton::toggleMenu()
{
	if(mMenuHandle.isDead()) return;

	LLToggleableMenu* menu = dynamic_cast<LLToggleableMenu*>(mMenuHandle.get());
	if (!menu) return;

	// Store the button rectangle to toggle menu visibility if a mouse event
	// occurred inside or outside the button rect.
	menu->setButtonRect(this);

	if (!menu->toggleVisibility() && mIsMenuShown)
	{
		setForcePressedState(false);
		mIsMenuShown = false;
	}
	else
	{
		menu->buildDrawLabels();
		menu->arrangeAndClear();
		menu->updateParent(LLMenuGL::sMenuContainer);

		updateMenuOrigin();

		LLMenuGL::showPopup(getParent(), menu, mX, mY);

		setForcePressedState(true);
		mIsMenuShown = true;
	}
}
BOOL LLMenuButton::handleKeyHere(KEY key, MASK mask )
{
	if (mMenuHandle.isDead()) return FALSE;

	if( KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key))
	{
		// *HACK: We emit the mouse down signal to fire the callback bound to the
		// menu emerging event before actually displaying the menu. See STORM-263.
		LLUICtrl::handleMouseDown(-1, -1, MASK_NONE);

		toggleMenu();
		return TRUE;
	}

	LLToggleableMenu* menu = dynamic_cast<LLToggleableMenu*>(mMenuHandle.get());
	if (menu && menu->getVisible() && key == KEY_ESCAPE && mask == MASK_NONE)
	{
		menu->setVisible(FALSE);
		return TRUE;
	}
	
	return FALSE;
}
LLMenuButton::LLMenuButton(const LLMenuButton::Params& p)
:	LLButton(p),
	mIsMenuShown(false),
	mMenuPosition(MP_BOTTOM_LEFT)
{
	std::string menu_filename = p.menu_filename;

	if (!menu_filename.empty())
	{
		LLToggleableMenu* menu = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>(menu_filename, LLMenuGL::sMenuContainer, LLMenuHolderGL::child_registry_t::instance());
		if (!menu)
		{
			llwarns << "Error loading menu_button menu" << llendl;
			return;
		}

		menu->setVisibilityChangeCallback(boost::bind(&LLMenuButton::onMenuVisibilityChange, this, _2));

		mMenuHandle = menu->getHandle();

		updateMenuOrigin();
	}
}