diff options
Diffstat (limited to 'indra/newview/lltoolbarview.cpp')
| -rw-r--r-- | indra/newview/lltoolbarview.cpp | 362 | 
1 files changed, 260 insertions, 102 deletions
diff --git a/indra/newview/lltoolbarview.cpp b/indra/newview/lltoolbarview.cpp index 5d2cebe031..ed1dfbb8cd 100644 --- a/indra/newview/lltoolbarview.cpp +++ b/indra/newview/lltoolbarview.cpp @@ -30,12 +30,16 @@  #include "lltoolbarview.h"  #include "llappviewer.h" +#include "llbutton.h" +#include "llclipboard.h"  #include "lldir.h" -#include "llxmlnode.h" +#include "lldockablefloater.h" +#include "lldockcontrol.h" +#include "llimview.h" +#include "lltransientfloatermgr.h"  #include "lltoolbar.h" -#include "llbutton.h"  #include "lltooldraganddrop.h" -#include "llclipboard.h" +#include "llxmlnode.h"  #include "llagent.h"  // HACK for destinations guide on startup  #include "llfloaterreg.h"  // HACK for destinations guide on startup @@ -68,13 +72,14 @@ LLToolBarView::ToolbarSet::ToolbarSet()  LLToolBarView::LLToolBarView(const LLToolBarView::Params& p)  :	LLUICtrl(p), -	mToolbarLeft(NULL), -	mToolbarRight(NULL), -	mToolbarBottom(NULL),  	mDragStarted(false),  	mDragToolbarButton(NULL),  	mToolbarsLoaded(false)  { +	for (S32 i = 0; i < TOOLBAR_COUNT; i++) +	{ +		mToolbars[i] = NULL; +	}  }  void LLToolBarView::initFromParams(const LLToolBarView::Params& p) @@ -90,46 +95,100 @@ LLToolBarView::~LLToolBarView()  BOOL LLToolBarView::postBuild()  { -	mToolbarLeft   = getChild<LLToolBar>("toolbar_left"); -	mToolbarRight  = getChild<LLToolBar>("toolbar_right"); -	mToolbarBottom = getChild<LLToolBar>("toolbar_bottom"); +	mToolbars[TOOLBAR_LEFT]   = getChild<LLToolBar>("toolbar_left"); +	mToolbars[TOOLBAR_RIGHT]  = getChild<LLToolBar>("toolbar_right"); +	mToolbars[TOOLBAR_BOTTOM] = getChild<LLToolBar>("toolbar_bottom"); -	mToolbarLeft->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3)); -	mToolbarLeft->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4)); -	mToolbarLeft->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4)); -	 -	mToolbarRight->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3)); -	mToolbarRight->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4)); -	mToolbarRight->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4)); -	 -	mToolbarBottom->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3)); -	mToolbarBottom->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4)); -	mToolbarBottom->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4)); +	for (int i = TOOLBAR_FIRST; i <= TOOLBAR_LAST; i++) +	{ +		mToolbars[i]->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3)); +		mToolbars[i]->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4)); +		mToolbars[i]->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4)); +		mToolbars[i]->setButtonAddCallback(boost::bind(LLToolBarView::onToolBarButtonAdded,_1)); +		mToolbars[i]->setButtonRemoveCallback(boost::bind(LLToolBarView::onToolBarButtonRemoved,_1)); +	}  	LLAppViewer::instance()->setOnLoginCompletedCallback(boost::bind(&handleLoginToolbarSetup));  	return TRUE;  } -bool LLToolBarView::hasCommand(const LLCommandId& commandId) const +S32 LLToolBarView::hasCommand(const LLCommandId& commandId) const +{ +	S32 command_location = TOOLBAR_NONE; + +	for (S32 loc = TOOLBAR_FIRST; loc <= TOOLBAR_LAST; loc++) +	{ +		if (mToolbars[loc]->hasCommand(commandId)) +		{ +			command_location = loc; +			break; +		} +	} + +	return command_location; +} + +S32 LLToolBarView::addCommand(const LLCommandId& commandId, EToolBarLocation toolbar, int rank) +{ +	int old_rank; +	removeCommand(commandId, old_rank); + +	S32 command_location = mToolbars[toolbar]->addCommand(commandId, rank); + +	return command_location; +} + +S32 LLToolBarView::removeCommand(const LLCommandId& commandId, int& rank)  { -	bool has_command = false; -	if (mToolbarLeft && !has_command) +	S32 command_location = hasCommand(commandId); +	rank = LLToolBar::RANK_NONE; + +	if (command_location != TOOLBAR_NONE)  	{ -		has_command = mToolbarLeft->hasCommand(commandId); +		rank = mToolbars[command_location]->removeCommand(commandId);  	} -	if (mToolbarRight && !has_command) + +	return command_location; +} + +S32 LLToolBarView::enableCommand(const LLCommandId& commandId, bool enabled) +{ +	S32 command_location = hasCommand(commandId); + +	if (command_location != TOOLBAR_NONE) +	{ +		mToolbars[command_location]->enableCommand(commandId, enabled); +	} + +	return command_location; +} + +S32 LLToolBarView::stopCommandInProgress(const LLCommandId& commandId) +{ +	S32 command_location = hasCommand(commandId); + +	if (command_location != TOOLBAR_NONE)  	{ -		has_command = mToolbarRight->hasCommand(commandId); +		mToolbars[command_location]->stopCommandInProgress(commandId);  	} -	if (mToolbarBottom && !has_command) + +	return command_location; +} + +S32 LLToolBarView::flashCommand(const LLCommandId& commandId, bool flash) +{ +	S32 command_location = hasCommand(commandId); + +	if (command_location != TOOLBAR_NONE)  	{ -		has_command = mToolbarBottom->hasCommand(commandId); +		mToolbars[command_location]->flashCommand(commandId, flash);  	} -	return has_command; + +	return command_location;  } -bool LLToolBarView::addCommand(const LLCommandId& command, LLToolBar* toolbar) +bool LLToolBarView::addCommandInternal(const LLCommandId& command, LLToolBar* toolbar)  {  	LLCommandManager& mgr = LLCommandManager::instance();  	if (mgr.getCommand(command)) @@ -147,6 +206,7 @@ bool LLToolBarView::addCommand(const LLCommandId& command, LLToolBar* toolbar)  bool LLToolBarView::loadToolbars(bool force_default)  {  	LLToolBarView::ToolbarSet toolbar_set; +	bool err = false;  	// Load the toolbars.xml file  	std::string toolbar_file = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "toolbars.xml"); @@ -164,80 +224,90 @@ bool LLToolBarView::loadToolbars(bool force_default)  	if(!LLXMLNode::parseFile(toolbar_file, root, NULL))  	{  		llwarns << "Unable to load toolbars from file: " << toolbar_file << llendl; -		return false; +		err = true;  	} -	if(!root->hasName("toolbars")) +	 +	if (!err && !root->hasName("toolbars"))  	{  		llwarns << toolbar_file << " is not a valid toolbars definition file" << llendl; -		return false; +		err = true;  	}  	// Parse the toolbar settings  	LLXUIParser parser; +	if (!err) +	{  	parser.readXUI(root, toolbar_set, toolbar_file); -	if (!toolbar_set.validateBlock()) +	} +	if (!err && !toolbar_set.validateBlock())  	{ -		llerrs << "Unable to validate toolbars from file: " << toolbar_file << llendl; -		return false; +		llwarns << "Unable to validate toolbars from file: " << toolbar_file << llendl; +		err = true;  	} -	// Clear the toolbars now before adding the loaded commands and settings -	if (mToolbarLeft) +	if (err)  	{ -		mToolbarLeft->clearCommandsList(); +		if (force_default) +		{ +			llerrs << "Unable to load toolbars from default file : " << toolbar_file << llendl; +		return false;  	} -	if (mToolbarRight) -	{ -		mToolbarRight->clearCommandsList(); +		// Try to load the default toolbars +		return loadToolbars(true);  	} -	if (mToolbarBottom) +	 +	// Clear the toolbars now before adding the loaded commands and settings +	for (S32 i = TOOLBAR_FIRST; i <= TOOLBAR_LAST; i++)  	{ -		mToolbarBottom->clearCommandsList(); +		if (mToolbars[i]) +		{ +			mToolbars[i]->clearCommandsList(); +		}  	}  	// Add commands to each toolbar -	if (toolbar_set.left_toolbar.isProvided() && mToolbarLeft) +	if (toolbar_set.left_toolbar.isProvided() && mToolbars[TOOLBAR_LEFT])  	{  		if (toolbar_set.left_toolbar.button_display_mode.isProvided())  		{  			LLToolBarEnums::ButtonType button_type = toolbar_set.left_toolbar.button_display_mode; -			mToolbarLeft->setButtonType(button_type); +			mToolbars[TOOLBAR_LEFT]->setButtonType(button_type);  		} -		BOOST_FOREACH(const LLCommandId::Params& command_name_param, toolbar_set.left_toolbar.commands) +		BOOST_FOREACH(const LLCommandId::Params& command_params, toolbar_set.left_toolbar.commands)  		{ -			if (addCommand(LLCommandId(command_name_param), mToolbarLeft) == false) +			if (addCommandInternal(LLCommandId(command_params), mToolbars[TOOLBAR_LEFT]))  			{ -				llwarns << "Error adding command '" << command_name_param.name() << "' to left toolbar." << llendl; +				llwarns << "Error adding command '" << command_params.name() << "' to left toolbar." << llendl;  			}  		}  	} -	if (toolbar_set.right_toolbar.isProvided() && mToolbarRight) +	if (toolbar_set.right_toolbar.isProvided() && mToolbars[TOOLBAR_RIGHT])  	{  		if (toolbar_set.right_toolbar.button_display_mode.isProvided())  		{  			LLToolBarEnums::ButtonType button_type = toolbar_set.right_toolbar.button_display_mode; -			mToolbarRight->setButtonType(button_type); +			mToolbars[TOOLBAR_RIGHT]->setButtonType(button_type);  		} -		BOOST_FOREACH(const LLCommandId::Params& command_name_param, toolbar_set.right_toolbar.commands) +		BOOST_FOREACH(const LLCommandId::Params& command_params, toolbar_set.right_toolbar.commands)  		{ -			if (addCommand(LLCommandId(command_name_param), mToolbarRight) == false) +			if (addCommandInternal(LLCommandId(command_params), mToolbars[TOOLBAR_RIGHT]))  			{ -				llwarns << "Error adding command '" << command_name_param.name() << "' to right toolbar." << llendl; +				llwarns << "Error adding command '" << command_params.name() << "' to right toolbar." << llendl;  			}  		}  	} -	if (toolbar_set.bottom_toolbar.isProvided() && mToolbarBottom) +	if (toolbar_set.bottom_toolbar.isProvided() && mToolbars[TOOLBAR_BOTTOM])  	{  		if (toolbar_set.bottom_toolbar.button_display_mode.isProvided())  		{  			LLToolBarEnums::ButtonType button_type = toolbar_set.bottom_toolbar.button_display_mode; -			mToolbarBottom->setButtonType(button_type); +			mToolbars[TOOLBAR_BOTTOM]->setButtonType(button_type);  		} -		BOOST_FOREACH(const LLCommandId::Params& command_name_param, toolbar_set.bottom_toolbar.commands) +		BOOST_FOREACH(const LLCommandId::Params& command_params, toolbar_set.bottom_toolbar.commands)  		{ -			if (addCommand(LLCommandId(command_name_param), mToolbarBottom) == false) +			if (addCommandInternal(LLCommandId(command_params), mToolbars[TOOLBAR_BOTTOM]))  			{ -				llwarns << "Error adding command '" << command_name_param.name() << "' to bottom toolbar." << llendl; +				llwarns << "Error adding command '" << command_params.name() << "' to bottom toolbar." << llendl;  			}  		}  	} @@ -269,20 +339,20 @@ void LLToolBarView::saveToolbars() const  	// Build the parameter tree from the toolbar data  	LLToolBarView::ToolbarSet toolbar_set; -	if (mToolbarLeft) +	if (mToolbars[TOOLBAR_LEFT])  	{ -		toolbar_set.left_toolbar.button_display_mode = mToolbarLeft->getButtonType(); -		addToToolset(mToolbarLeft->getCommandsList(),toolbar_set.left_toolbar); +		toolbar_set.left_toolbar.button_display_mode = mToolbars[TOOLBAR_LEFT]->getButtonType(); +		addToToolset(mToolbars[TOOLBAR_LEFT]->getCommandsList(), toolbar_set.left_toolbar);  	} -	if (mToolbarRight) +	if (mToolbars[TOOLBAR_RIGHT])  	{ -		toolbar_set.right_toolbar.button_display_mode = mToolbarRight->getButtonType(); -		addToToolset(mToolbarRight->getCommandsList(),toolbar_set.right_toolbar); +		toolbar_set.right_toolbar.button_display_mode = mToolbars[TOOLBAR_RIGHT]->getButtonType(); +		addToToolset(mToolbars[TOOLBAR_RIGHT]->getCommandsList(), toolbar_set.right_toolbar);  	} -	if (mToolbarBottom) +	if (mToolbars[TOOLBAR_BOTTOM])  	{ -		toolbar_set.bottom_toolbar.button_display_mode = mToolbarBottom->getButtonType(); -		addToToolset(mToolbarBottom->getCommandsList(),toolbar_set.bottom_toolbar); +		toolbar_set.bottom_toolbar.button_display_mode = mToolbars[TOOLBAR_BOTTOM]->getButtonType(); +		addToToolset(mToolbars[TOOLBAR_BOTTOM]->getCommandsList(), toolbar_set.bottom_toolbar);  	}  	// Serialize the parameter tree @@ -323,35 +393,122 @@ void LLToolBarView::addToToolset(command_id_list_t& command_list, Toolbar& toolb  	}  } -void LLToolBarView::draw() +void LLToolBarView::onToolBarButtonAdded(LLView* button)  { -	//LLPanel* sizer_left = getChild<LLPanel>("sizer_left"); +	llassert(button); -	LLRect bottom_rect, left_rect, right_rect; +	if (button->getName() == "speak") +	{ +		// Add the "Speak" button as a control view in LLTransientFloaterMgr +		// to prevent hiding the transient IM floater upon pressing "Speak". +		LLTransientFloaterMgr::getInstance()->addControlView(button); +		 +		// Redock incoming and/or outgoing call windows, if applicable +		 +		LLFloater* incoming_floater = LLFloaterReg::getLastFloaterInGroup("incoming_call"); +		LLFloater* outgoing_floater = LLFloaterReg::getLastFloaterInGroup("outgoing_call"); +		 +		if (incoming_floater && incoming_floater->isShown()) +		{ +			LLCallDialog* incoming = dynamic_cast<LLCallDialog *>(incoming_floater); +			llassert(incoming); +			 +			LLDockControl* dock_control = incoming->getDockControl(); +			if (dock_control->getDock() == NULL) +			{ +				incoming->dockToToolbarButton("speak"); +			} +		} +		 +		if (outgoing_floater && outgoing_floater->isShown()) +		{ +			LLCallDialog* outgoing = dynamic_cast<LLCallDialog *>(outgoing_floater); +			llassert(outgoing); +			 +			LLDockControl* dock_control = outgoing->getDockControl(); +			if (dock_control->getDock() == NULL) +			{ +				outgoing->dockToToolbarButton("speak"); +			} +		} +	} +	else if (button->getName() == "voice") +	{ +		// Add the "Voice controls" button as a control view in LLTransientFloaterMgr +		// to prevent hiding the transient IM floater upon pressing "Voice controls". +		LLTransientFloaterMgr::getInstance()->addControlView(button); +	} +} -	if (mToolbarBottom)  +void LLToolBarView::onToolBarButtonRemoved(LLView* button) +{ +	llassert(button); + +	if (button->getName() == "speak")  	{ -		mToolbarBottom->getParent()->reshape(mToolbarBottom->getParent()->getRect().getWidth(), mToolbarBottom->getRect().getHeight()); -		mToolbarBottom->localRectToOtherView(mToolbarBottom->getLocalRect(), &bottom_rect, this); +		LLTransientFloaterMgr::getInstance()->removeControlView(button); +		 +		// Undock incoming and/or outgoing call windows +		 +		LLFloater* incoming_floater = LLFloaterReg::getLastFloaterInGroup("incoming_call"); +		LLFloater* outgoing_floater = LLFloaterReg::getLastFloaterInGroup("outgoing_call"); +		 +		if (incoming_floater && incoming_floater->isShown()) +		{ +			LLDockableFloater* incoming = dynamic_cast<LLDockableFloater *>(incoming_floater); +			llassert(incoming); + +			LLDockControl* dock_control = incoming->getDockControl(); +			dock_control->setDock(NULL); +		} +		 +		if (outgoing_floater && outgoing_floater->isShown()) +		{ +			LLDockableFloater* outgoing = dynamic_cast<LLDockableFloater *>(outgoing_floater); +			llassert(outgoing); + +			LLDockControl* dock_control = outgoing->getDockControl(); +			dock_control->setDock(NULL); +		}  	} -	if (mToolbarLeft)    +	else if (button->getName() == "voice")  	{ -		mToolbarLeft->getParent()->reshape(mToolbarLeft->getRect().getWidth(), mToolbarLeft->getParent()->getRect().getHeight()); -		mToolbarLeft->localRectToOtherView(mToolbarLeft->getLocalRect(), &left_rect, this); +		LLTransientFloaterMgr::getInstance()->removeControlView(button);  	} -	if (mToolbarRight)   +} + +void LLToolBarView::draw() +{ +	LLRect toolbar_rects[TOOLBAR_COUNT]; +	 +	for (S32 i = TOOLBAR_FIRST; i <= TOOLBAR_LAST; i++)  	{ -		mToolbarRight->getParent()->reshape(mToolbarRight->getRect().getWidth(), mToolbarRight->getParent()->getRect().getHeight()); -		mToolbarRight->localRectToOtherView(mToolbarRight->getLocalRect(), &right_rect, this); +		if (mToolbars[i]) +		{ +			LLLayoutStack::ELayoutOrientation orientation = LLToolBarEnums::getOrientation(mToolbars[i]->getSideType()); + +			if (orientation == LLLayoutStack::HORIZONTAL) +			{ +				mToolbars[i]->getParent()->reshape(mToolbars[i]->getParent()->getRect().getWidth(), mToolbars[i]->getRect().getHeight()); +			} +			else +			{ +				mToolbars[i]->getParent()->reshape(mToolbars[i]->getRect().getWidth(), mToolbars[i]->getParent()->getRect().getHeight()); +			} + +			mToolbars[i]->localRectToOtherView(mToolbars[i]->getLocalRect(), &toolbar_rects[i], this); +		}  	}  	// Draw drop zones if drop of a tool is active  	if (isToolDragged())  	{  		LLColor4 drop_color = LLUIColorTable::instance().getColor( "ToolbarDropZoneColor" ); -		gl_rect_2d(bottom_rect, drop_color, TRUE); -		gl_rect_2d(left_rect, drop_color, TRUE); -		gl_rect_2d(right_rect, drop_color, TRUE); + +		for (S32 i = TOOLBAR_FIRST; i <= TOOLBAR_LAST; i++) +		{ +			gl_rect_2d(toolbar_rects[i], drop_color, TRUE); +		}  	}  	LLUICtrl::draw(); @@ -363,9 +520,9 @@ void LLToolBarView::draw()  // ---------------------------------------- -void LLToolBarView::startDragTool(S32 x, S32 y, LLToolBarButton* button) +void LLToolBarView::startDragTool(S32 x, S32 y, LLToolBarButton* toolbarButton)  { -	resetDragTool(button); +	resetDragTool(toolbarButton);  	// Flag the tool dragging but don't start it yet  	LLToolDragAndDrop::getInstance()->setDragStart( x, y ); @@ -391,9 +548,7 @@ BOOL LLToolBarView::handleDragTool( S32 x, S32 y, const LLUUID& uuid, LLAssetTyp  			// Second, stop the command if it is in progress and requires stopping!  			LLCommandId command_id = LLCommandId(uuid); -			gToolBarView->mToolbarLeft->stopCommandInProgress(command_id); -			gToolBarView->mToolbarRight->stopCommandInProgress(command_id); -			gToolBarView->mToolbarBottom->stopCommandInProgress(command_id); +			gToolBarView->stopCommandInProgress(command_id);  			gToolBarView->mDragStarted = true;  			return TRUE; @@ -424,10 +579,10 @@ BOOL LLToolBarView::handleDropTool( void* cargo_data, S32 x, S32 y, LLToolBar* t  		{  			// Suppress the command from the toolbars (including the one it's dropped in,   			// this will handle move position). -			bool command_present = gToolBarView->hasCommand(command_id); +			S32 old_toolbar_loc = gToolBarView->hasCommand(command_id);  			LLToolBar* old_toolbar = NULL; -			if (command_present) +			if (old_toolbar_loc != TOOLBAR_NONE)  			{  				llassert(gToolBarView->mDragToolbarButton);  				old_toolbar = gToolBarView->mDragToolbarButton->getParentByType<LLToolBar>(); @@ -437,9 +592,8 @@ BOOL LLToolBarView::handleDropTool( void* cargo_data, S32 x, S32 y, LLToolBar* t  				}  				else  				{ -					gToolBarView->mToolbarBottom->removeCommand(command_id); -					gToolBarView->mToolbarLeft->removeCommand(command_id); -					gToolBarView->mToolbarRight->removeCommand(command_id); +					int old_rank = LLToolBar::RANK_NONE; +					gToolBarView->removeCommand(command_id, old_rank);  				}  			} @@ -463,27 +617,29 @@ BOOL LLToolBarView::handleDropTool( void* cargo_data, S32 x, S32 y, LLToolBar* t  	return handled;  } -void LLToolBarView::resetDragTool(LLToolBarButton* button) +void LLToolBarView::resetDragTool(LLToolBarButton* toolbarButton)  {  	// Clear the saved command, toolbar and rank  	gToolBarView->mDragStarted = false; -	gToolBarView->mDragToolbarButton = button; +	gToolBarView->mDragToolbarButton = toolbarButton;  }  void LLToolBarView::setToolBarsVisible(bool visible)  { -	mToolbarBottom->getParent()->setVisible(visible); -	mToolbarLeft->getParent()->setVisible(visible); -	mToolbarRight->getParent()->setVisible(visible); +	for (S32 i = TOOLBAR_FIRST; i <= TOOLBAR_LAST; i++) +	{ +		mToolbars[i]->getParent()->setVisible(visible); +	}  }  bool LLToolBarView::isModified() const  {  	bool modified = false; -	modified |= mToolbarBottom->isModified(); -	modified |= mToolbarLeft->isModified(); -	modified |= mToolbarRight->isModified(); +	for (S32 i = TOOLBAR_FIRST; i <= TOOLBAR_LAST; i++) +	{ +		modified |= mToolbars[i]->isModified(); +	}  	return modified;  } @@ -496,9 +652,11 @@ bool LLToolBarView::isModified() const  void handleLoginToolbarSetup()  {  	// Open the destinations guide by default on first login, per Rhett -	if (gSavedSettings.getBOOL("FirstLoginThisInstall") || gAgent.isFirstLogin()) +	if (gSavedPerAccountSettings.getBOOL("DisplayDestinationsOnInitialRun") || gAgent.isFirstLogin())  	{  		LLFloaterReg::showInstance("destinations"); + +		gSavedPerAccountSettings.setBOOL("DisplayDestinationsOnInitialRun", FALSE);  	}  }  | 
