PageRenderTime 34ms CodeModel.GetById 10ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "llfloatertoybox.h"
  28. #include "llbutton.h"
  29. #include "llcommandmanager.h"
  30. #include "llnotifications.h"
  31. #include "llnotificationsutil.h"
  32. #include "llpanel.h"
  33. #include "lltoolbar.h"
  34. #include "lltoolbarview.h"
  35. #include "lltrans.h"
  36. LLFloaterToybox::LLFloaterToybox(const LLSD& key)
  37. : LLFloater(key)
  38. , mToolBar(NULL)
  39. {
  40. mCommitCallbackRegistrar.add("Toybox.RestoreDefaults", boost::bind(&LLFloaterToybox::onBtnRestoreDefaults, this));
  41. mCommitCallbackRegistrar.add("Toybox.ClearAll", boost::bind(&LLFloaterToybox::onBtnClearAll, this));
  42. }
  43. LLFloaterToybox::~LLFloaterToybox()
  44. {
  45. }
  46. bool compare_localized_command_labels(LLCommand * cmd1, LLCommand * cmd2)
  47. {
  48. std::string lab1 = LLTrans::getString(cmd1->labelRef());
  49. std::string lab2 = LLTrans::getString(cmd2->labelRef());
  50. return (lab1 < lab2);
  51. }
  52. BOOL LLFloaterToybox::postBuild()
  53. {
  54. mToolBar = getChild<LLToolBar>("toybox_toolbar");
  55. mToolBar->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3));
  56. mToolBar->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4));
  57. mToolBar->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4));
  58. mToolBar->setButtonEnterCallback(boost::bind(&LLFloaterToybox::onToolBarButtonEnter,this,_1));
  59. //
  60. // Sort commands by localized labels so they will appear alphabetized in all languages
  61. //
  62. std::list<LLCommand *> alphabetized_commands;
  63. LLCommandManager& cmdMgr = LLCommandManager::instance();
  64. for (U32 i = 0; i < cmdMgr.commandCount(); i++)
  65. {
  66. LLCommand * command = cmdMgr.getCommand(i);
  67. if (command->availableInToybox())
  68. {
  69. alphabetized_commands.push_back(command);
  70. }
  71. }
  72. alphabetized_commands.sort(compare_localized_command_labels);
  73. //
  74. // Create Buttons
  75. //
  76. for (std::list<LLCommand *>::iterator it = alphabetized_commands.begin(); it != alphabetized_commands.end(); ++it)
  77. {
  78. mToolBar->addCommand((*it)->id());
  79. }
  80. return TRUE;
  81. }
  82. void LLFloaterToybox::draw()
  83. {
  84. llassert(gToolBarView != NULL);
  85. const command_id_list_t& command_list = mToolBar->getCommandsList();
  86. for (command_id_list_t::const_iterator it = command_list.begin(); it != command_list.end(); ++it)
  87. {
  88. const LLCommandId& id = *it;
  89. const bool command_not_present = (gToolBarView->hasCommand(id) == LLToolBarView::TOOLBAR_NONE);
  90. mToolBar->enableCommand(id, command_not_present);
  91. }
  92. LLFloater::draw();
  93. }
  94. static bool finish_restore_toybox(const LLSD& notification, const LLSD& response)
  95. {
  96. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  97. if (option == 0)
  98. {
  99. LLToolBarView::loadDefaultToolbars();
  100. }
  101. return false;
  102. }
  103. static bool finish_clear_all_toybox(const LLSD& notification, const LLSD& response)
  104. {
  105. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  106. if (option == 0)
  107. {
  108. LLToolBarView::clearAllToolbars();
  109. }
  110. return false;
  111. }
  112. static LLNotificationFunctorRegistration finish_restore_toybox_reg("ConfirmRestoreToybox", finish_restore_toybox);
  113. static LLNotificationFunctorRegistration finish_clear_all_toybox_reg("ConfirmClearAllToybox", finish_clear_all_toybox);
  114. void LLFloaterToybox::onBtnRestoreDefaults()
  115. {
  116. LLNotificationsUtil::add("ConfirmRestoreToybox");
  117. }
  118. void LLFloaterToybox::onBtnClearAll()
  119. {
  120. LLNotificationsUtil::add("ConfirmClearAllToybox");
  121. }
  122. BOOL LLFloaterToybox::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
  123. EDragAndDropType cargo_type,
  124. void* cargo_data,
  125. EAcceptance* accept,
  126. std::string& tooltip_msg)
  127. {
  128. S32 local_x = x - mToolBar->getRect().mLeft;
  129. S32 local_y = y - mToolBar->getRect().mBottom;
  130. return mToolBar->handleDragAndDrop(local_x, local_y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
  131. }
  132. void LLFloaterToybox::onToolBarButtonEnter(LLView* button)
  133. {
  134. std::string suffix = "";
  135. LLCommandId commandId(button->getName());
  136. LLCommand* command = LLCommandManager::instance().getCommand(commandId);
  137. if (command)
  138. {
  139. S32 command_loc = gToolBarView->hasCommand(commandId);
  140. switch(command_loc)
  141. {
  142. case LLToolBarView::TOOLBAR_BOTTOM: suffix = LLTrans::getString("Toolbar_Bottom_Tooltip"); break;
  143. case LLToolBarView::TOOLBAR_LEFT: suffix = LLTrans::getString("Toolbar_Left_Tooltip"); break;
  144. case LLToolBarView::TOOLBAR_RIGHT: suffix = LLTrans::getString("Toolbar_Right_Tooltip"); break;
  145. default:
  146. break;
  147. }
  148. }
  149. mToolBar->setTooltipButtonSuffix(suffix);
  150. }
  151. // eof