PageRenderTime 385ms CodeModel.GetById 151ms app.highlight 19ms RepoModel.GetById 212ms app.codeStats 0ms

/indra/newview/llfloatertoybox.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 191 lines | 119 code | 40 blank | 32 comment | 13 complexity | 4aad88f7c68dd06a3abfb8e966733b6e MD5 | raw file
  1/** 
  2 * @file llfloatertoybox.cpp
  3 * @brief The toybox for flexibilizing the UI.
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2011, 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#include "llviewerprecompiledheaders.h"
 28
 29#include "llfloatertoybox.h"
 30
 31#include "llbutton.h"
 32#include "llcommandmanager.h"
 33#include "llnotifications.h"
 34#include "llnotificationsutil.h"
 35#include "llpanel.h"
 36#include "lltoolbar.h"
 37#include "lltoolbarview.h"
 38#include "lltrans.h"
 39
 40LLFloaterToybox::LLFloaterToybox(const LLSD& key)
 41	: LLFloater(key)
 42	, mToolBar(NULL)
 43{
 44	mCommitCallbackRegistrar.add("Toybox.RestoreDefaults", boost::bind(&LLFloaterToybox::onBtnRestoreDefaults, this));
 45	mCommitCallbackRegistrar.add("Toybox.ClearAll", boost::bind(&LLFloaterToybox::onBtnClearAll, this));
 46}
 47
 48LLFloaterToybox::~LLFloaterToybox()
 49{
 50}
 51
 52bool compare_localized_command_labels(LLCommand * cmd1, LLCommand * cmd2)
 53{
 54	std::string lab1 = LLTrans::getString(cmd1->labelRef());
 55	std::string lab2 = LLTrans::getString(cmd2->labelRef());
 56
 57	return (lab1 < lab2);
 58}
 59
 60BOOL LLFloaterToybox::postBuild()
 61{	
 62	mToolBar = getChild<LLToolBar>("toybox_toolbar");
 63
 64	mToolBar->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3));
 65	mToolBar->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4));
 66	mToolBar->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4));
 67	mToolBar->setButtonEnterCallback(boost::bind(&LLFloaterToybox::onToolBarButtonEnter,this,_1));
 68	
 69	//
 70	// Sort commands by localized labels so they will appear alphabetized in all languages
 71	//
 72
 73	std::list<LLCommand *> alphabetized_commands;
 74
 75	LLCommandManager& cmdMgr = LLCommandManager::instance();
 76	for (U32 i = 0; i < cmdMgr.commandCount(); i++)
 77	{
 78		LLCommand * command = cmdMgr.getCommand(i);
 79
 80		if (command->availableInToybox())
 81		{
 82			alphabetized_commands.push_back(command);
 83		}
 84	}
 85
 86	alphabetized_commands.sort(compare_localized_command_labels);
 87
 88	//
 89	// Create Buttons
 90	//
 91
 92	for (std::list<LLCommand *>::iterator it = alphabetized_commands.begin(); it != alphabetized_commands.end(); ++it)
 93	{
 94		mToolBar->addCommand((*it)->id());
 95	}
 96
 97	return TRUE;
 98}
 99
100void LLFloaterToybox::draw()
101{
102	llassert(gToolBarView != NULL);
103
104	const command_id_list_t& command_list = mToolBar->getCommandsList();
105
106	for (command_id_list_t::const_iterator it = command_list.begin(); it != command_list.end(); ++it)
107	{
108		const LLCommandId& id = *it;
109
110		const bool command_not_present = (gToolBarView->hasCommand(id) == LLToolBarView::TOOLBAR_NONE);
111		mToolBar->enableCommand(id, command_not_present);
112	}
113
114	LLFloater::draw();
115}
116
117static bool finish_restore_toybox(const LLSD& notification, const LLSD& response)
118{
119	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
120
121	if (option == 0)
122	{
123		LLToolBarView::loadDefaultToolbars();
124	}
125
126	return false;
127}
128
129static bool finish_clear_all_toybox(const LLSD& notification, const LLSD& response)
130{
131	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
132
133	if (option == 0)
134	{
135		LLToolBarView::clearAllToolbars();
136	}
137
138	return false;
139}
140
141static LLNotificationFunctorRegistration finish_restore_toybox_reg("ConfirmRestoreToybox", finish_restore_toybox);
142static LLNotificationFunctorRegistration finish_clear_all_toybox_reg("ConfirmClearAllToybox", finish_clear_all_toybox);
143
144void LLFloaterToybox::onBtnRestoreDefaults()
145{
146	LLNotificationsUtil::add("ConfirmRestoreToybox");
147}
148
149void LLFloaterToybox::onBtnClearAll()
150{
151	LLNotificationsUtil::add("ConfirmClearAllToybox");
152}
153
154BOOL LLFloaterToybox::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
155	EDragAndDropType cargo_type,
156	void* cargo_data,
157	EAcceptance* accept,
158	std::string& tooltip_msg)
159{
160	S32 local_x = x - mToolBar->getRect().mLeft;
161	S32 local_y = y - mToolBar->getRect().mBottom;
162	return mToolBar->handleDragAndDrop(local_x, local_y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
163}
164
165void LLFloaterToybox::onToolBarButtonEnter(LLView* button)
166{
167	std::string suffix = "";
168
169	LLCommandId commandId(button->getName());
170	LLCommand* command = LLCommandManager::instance().getCommand(commandId);
171
172	if (command)
173	{
174		S32 command_loc = gToolBarView->hasCommand(commandId);
175
176		switch(command_loc)
177		{
178		case LLToolBarView::TOOLBAR_BOTTOM:	suffix = LLTrans::getString("Toolbar_Bottom_Tooltip");	break;
179		case LLToolBarView::TOOLBAR_LEFT:	suffix = LLTrans::getString("Toolbar_Left_Tooltip");	break;
180		case LLToolBarView::TOOLBAR_RIGHT:	suffix = LLTrans::getString("Toolbar_Right_Tooltip");	break;
181
182		default:
183			break;
184		}
185	}
186
187	mToolBar->setTooltipButtonSuffix(suffix);
188}
189
190
191// eof