From 305b65f6f600b81de9a78e1246d2a5353cc3189b Mon Sep 17 00:00:00 2001
From: Leslie Linden <leslie@lindenlab.com>
Date: Wed, 21 Sep 2011 12:11:23 -0700
Subject: [PATCH] EXP-1205 PROGRESS -- As a User, I want a toybox which will
 contain all buttons that I can d&d into the toolbars EXP-1210 FIX --
 Implement new toybox floater window EXP-1231 FIX -- Add menu option to toggle
 the toybox floater on and off

* Basic toybox floater implemented as its own class
* Toybox is available through "Me -> Toolbars..." menu option or ctrl-T shortcut
* Toolbars now have "side" type rather than simple orientation, as well as button
  state for "icons only" or "icons with text".

Reviewed by Richard
---
 indra/llui/lltoolbar.cpp                      |  58 ++++++++--
 indra/llui/lltoolbar.h                        |  55 ++++++++--
 indra/newview/CMakeLists.txt                  |   2 +
 indra/newview/llfloatertoybox.cpp             | 103 ++++++++++++++++++
 indra/newview/llfloatertoybox.h               |  58 ++++++++++
 indra/newview/llviewerfloaterreg.cpp          |   2 +
 .../skins/default/xui/en/floater_toybox.xml   |  63 +++++++++++
 .../skins/default/xui/en/menu_login.xml       |   2 +-
 .../skins/default/xui/en/menu_viewer.xml      |  14 ++-
 9 files changed, 336 insertions(+), 21 deletions(-)
 create mode 100644 indra/newview/llfloatertoybox.cpp
 create mode 100644 indra/newview/llfloatertoybox.h
 create mode 100644 indra/newview/skins/default/xui/en/floater_toybox.xml

diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index cdd3a502053..2c1e141ca79 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -32,23 +32,45 @@
 
 //static LLDefaultChildRegistry::Register<LLToolBar> r1("toolbar");
 
+
+namespace LLToolBarEnums
+{
+	LLLayoutStack::ELayoutOrientation getOrientation(SideType sideType)
+	{
+		LLLayoutStack::ELayoutOrientation orientation = LLLayoutStack::HORIZONTAL;
+
+		if ((sideType == SIDE_LEFT) || (sideType == SIDE_RIGHT))
+		{
+			orientation = LLLayoutStack::VERTICAL;
+		}
+
+		return orientation;
+	}
+}
+
+
 LLToolBar::Params::Params()
-:	orientation("orientation"),
-	buttons("button")
+:	button_display_mode("button_display_mode"),
+	buttons("button"),
+	side("side")
 {}
 
 LLToolBar::LLToolBar(const Params& p)
 :	LLUICtrl(p),
-	mOrientation(p.orientation),
+	mButtonType(p.button_display_mode),
+	mSideType(p.side),
 	mStack(NULL)
-{}
+{
+}
 
 void LLToolBar::initFromParams(const LLToolBar::Params& p)
 {
+	LLLayoutStack::ELayoutOrientation orientation = LLToolBarEnums::getOrientation(p.side);
+
 	LLLayoutStack::Params centering_stack_p;
 	centering_stack_p.rect = getLocalRect();
 	centering_stack_p.follows.flags = FOLLOWS_ALL;
-	centering_stack_p.orientation = p.orientation;
+	centering_stack_p.orientation = orientation;
 	centering_stack_p.name = "centering_stack";
 
 	LLLayoutPanel::Params border_panel_p;
@@ -75,8 +97,8 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
 	LLLayoutStack::Params stack_p;
 	stack_p.rect = getLocalRect();
 	stack_p.name = "button_stack";
-	stack_p.orientation = p.orientation;
-	stack_p.follows.flags = (mOrientation == LLLayoutStack::HORIZONTAL)
+	stack_p.orientation = orientation;
+	stack_p.follows.flags = (orientation == LLLayoutStack::HORIZONTAL)
 							? (FOLLOWS_TOP|FOLLOWS_BOTTOM)  // horizontal
 							: (FOLLOWS_LEFT|FOLLOWS_RIGHT); // vertical
 
@@ -88,7 +110,7 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
 		// remove any offset from button
 		LLRect button_rect(button_p.rect);
 
-		if (mOrientation == LLLayoutStack::HORIZONTAL)
+		if (orientation == LLLayoutStack::HORIZONTAL)
 		{
 			button_rect.setOriginAndSize(0, 0, 0, getRect().getHeight());
 		}
@@ -139,7 +161,7 @@ void LLToolBar::updateLayout()
 		max_height = llmax(button->getRect().getHeight(), max_height);
 	}
 
-	if (mOrientation == LLLayoutStack::HORIZONTAL)
+	if (LLToolBarEnums::getOrientation(mSideType) == LLLayoutStack::HORIZONTAL)
 	{
 		mStack->reshape(total_width, mStack->getParent()->getRect().getHeight());
 	}
@@ -153,6 +175,24 @@ void LLToolBar::updateLayout()
 
 void LLToolBar::draw()
 {
+	//gl_rect_2d(getLocalRect(), LLColor4::blue, TRUE);
 	LLUICtrl::draw();
 }
 
+namespace LLInitParam
+{
+	void TypeValues<LLToolBarEnums::ButtonType>::declareValues()
+	{
+		declare("icons_only",		LLToolBarEnums::BTNTYPE_ICONS_ONLY);
+		declare("icons_with_text",	LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT);
+	}
+
+	void TypeValues<LLToolBarEnums::SideType>::declareValues()
+	{
+		declare("none",		LLToolBarEnums::SIDE_NONE);
+		declare("bottom",	LLToolBarEnums::SIDE_BOTTOM);
+		declare("left",		LLToolBarEnums::SIDE_LEFT);
+		declare("right",	LLToolBarEnums::SIDE_RIGHT);
+		declare("top",		LLToolBarEnums::SIDE_TOP);
+	}
+}
diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h
index fb03095c566..60a848a6e39 100644
--- a/indra/llui/lltoolbar.h
+++ b/indra/llui/lltoolbar.h
@@ -32,6 +32,7 @@
 #include "lllayoutstack.h"
 #include "llbutton.h"
 
+
 class LLToolBarButton : public LLButton
 {
 public:
@@ -40,9 +41,44 @@ class LLToolBarButton : public LLButton
 	};
 
 	LLToolBarButton(const Params& p) : LLButton(p) {}
-
 };
 
+
+namespace LLToolBarEnums
+{
+	enum ButtonType
+	{
+		BTNTYPE_ICONS_ONLY = 0,
+		BTNTYPE_ICONS_WITH_TEXT,
+	};
+
+	enum SideType
+	{
+		SIDE_NONE = 0,
+		SIDE_BOTTOM,
+		SIDE_LEFT,
+		SIDE_RIGHT,
+		SIDE_TOP,
+	};
+}
+
+// NOTE: This needs to occur before Param block declaration for proper compilation.
+namespace LLInitParam
+{
+	template<>
+	struct TypeValues<LLToolBarEnums::ButtonType> : public TypeValuesHelper<LLToolBarEnums::ButtonType>
+	{
+		static void declareValues();
+	};
+
+	template<>
+	struct TypeValues<LLToolBarEnums::SideType> : public TypeValuesHelper<LLToolBarEnums::SideType>
+	{
+		static void declareValues();
+	};
+}
+
+
 class LLToolBar
 :	public LLUICtrl
 {
@@ -50,26 +86,29 @@ class LLToolBar
 
 	struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
 	{
-		Mandatory<LLLayoutStack::ELayoutOrientation, 
-				LLLayoutStack::OrientationNames>		orientation;
-		Multiple<LLToolBarButton::Params>				buttons;
+		Mandatory<LLToolBarEnums::ButtonType>	button_display_mode;
+		Multiple<LLToolBarButton::Params>		buttons;
+		Mandatory<LLToolBarEnums::SideType>		side;
 
 		Params();
 	};
 
-	/*virtual*/ void draw();
+	// virtuals
+	void draw();
 
 protected:
 	friend class LLUICtrlFactory;
 	LLToolBar(const Params&);
+
 	void initFromParams(const Params&);
 	void addButton(LLToolBarButton* buttonp);
 	void updateLayout();
 
 private:
-	LLLayoutStack::ELayoutOrientation	mOrientation;
-	LLLayoutStack*						mStack;
-	std::list<LLToolBarButton*>			mButtons;
+	std::list<LLToolBarButton*>		mButtons;
+	LLToolBarEnums::ButtonType		mButtonType;
+	LLToolBarEnums::SideType		mSideType;
+	LLLayoutStack*					mStack;
 };
 
 
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 73511447658..18e092eb4a3 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -237,6 +237,7 @@ set(viewer_SOURCE_FILES
     llfloatertools.cpp
     llfloatertopobjects.cpp
     llfloatertos.cpp
+    llfloatertoybox.cpp
     llfloateruipreview.cpp
     llfloaterurlentry.cpp
     llfloatervoiceeffect.cpp
@@ -800,6 +801,7 @@ set(viewer_HEADER_FILES
     llfloatertools.h
     llfloatertopobjects.h
     llfloatertos.h
+    llfloatertoybox.h
     llfloateruipreview.h
     llfloaterurlentry.h
     llfloatervoiceeffect.h
diff --git a/indra/newview/llfloatertoybox.cpp b/indra/newview/llfloatertoybox.cpp
new file mode 100644
index 00000000000..b4fb2e45ab9
--- /dev/null
+++ b/indra/newview/llfloatertoybox.cpp
@@ -0,0 +1,103 @@
+/** 
+ * @file llfloatertoybox.cpp
+ * @brief The toybox for flexibilizing the UI.
+ *
+ * $LicenseInfo:firstyear=2002&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2011, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llfloatertoybox.h"
+
+#include "llbutton.h"
+#include "llpanel.h"
+
+
+LLFloaterToybox::LLFloaterToybox(const LLSD& key)
+	: LLFloater(key)
+	, mBtnRestoreDefaults(NULL)
+{
+	mCommitCallbackRegistrar.add("Toybox.RestoreDefaults", boost::bind(&LLFloaterToybox::onBtnRestoreDefaults, this));
+}
+
+LLFloaterToybox::~LLFloaterToybox()
+{
+}
+
+BOOL LLFloaterToybox::postBuild()
+{	
+	center();
+
+	mBtnRestoreDefaults = getChild<LLButton>("btn_restore_defaults");
+
+	//
+	// Create Buttons
+	//
+/*
+	LLToyboxButtons::load();
+
+	for (size_t i = 0; i < LLToyboxButtons::buttonCount(); i++)
+	{
+		LLToyboxButton * button = LLToyboxButtons::get(i);
+
+		// Panel opacity depends on whether or not button position is established
+		LLPanel * buttonPanel = createPanelForButton(button);
+
+		mToolBar->add(buttonPanel);
+	}
+*/
+
+	return TRUE;
+}
+
+void LLFloaterToybox::onOpen(const LLSD& key)
+{
+
+}
+
+BOOL LLFloaterToybox::canClose()
+{
+	return TRUE;
+}
+
+void LLFloaterToybox::onClose(bool app_quitting)
+{
+
+}
+
+void LLFloaterToybox::draw()
+{
+	LLFloater::draw();
+}
+
+void LLFloaterToybox::onFocusReceived()
+{
+
+}
+
+void LLFloaterToybox::onBtnRestoreDefaults()
+{
+
+}
+
+
+// eof
diff --git a/indra/newview/llfloatertoybox.h b/indra/newview/llfloatertoybox.h
new file mode 100644
index 00000000000..bb9392a0e3b
--- /dev/null
+++ b/indra/newview/llfloatertoybox.h
@@ -0,0 +1,58 @@
+/** 
+ * @file llfloatertoybox.h
+ * @brief The toybox for flexibilizing the UI.
+ *
+ * $LicenseInfo:firstyear=2002&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2011, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLFLOATERTOYBOX_H
+#define LL_LLFLOATERTOYBOX_H
+
+#include "llfloater.h"
+
+
+class LLButton;
+
+
+class LLFloaterToybox
+: public LLFloater
+{
+public:
+	LLFloaterToybox(const LLSD& key);
+	virtual ~LLFloaterToybox();
+
+	// virtuals
+	BOOL postBuild();
+	void onOpen(const LLSD& key);
+	BOOL canClose();
+	void onClose(bool app_quitting);
+	void draw();
+	void onFocusReceived();
+
+protected:
+	void onBtnRestoreDefaults();
+
+public:
+	LLButton *	mBtnRestoreDefaults;
+};
+
+#endif // LL_LLFLOATERTOYBOX_H
diff --git a/indra/newview/llviewerfloaterreg.cpp b/indra/newview/llviewerfloaterreg.cpp
index 4af5fdd9f36..375ee3ad33b 100644
--- a/indra/newview/llviewerfloaterreg.cpp
+++ b/indra/newview/llviewerfloaterreg.cpp
@@ -103,6 +103,7 @@
 #include "llfloatertools.h"
 #include "llfloatertos.h"
 #include "llfloatertopobjects.h"
+#include "llfloatertoybox.h"
 #include "llfloateruipreview.h"
 #include "llfloatervoiceeffect.h"
 #include "llfloaterwhitelistentry.h"
@@ -255,6 +256,7 @@ void LLViewerFloaterReg::registerFloaters()
 	LLFloaterReg::add("test_text_editor", "floater_test_text_editor.xml", &LLFloaterReg::build<LLFloater>);
 	LLFloaterReg::add("test_widgets", "floater_test_widgets.xml", &LLFloaterReg::build<LLFloater>);
 	LLFloaterReg::add("top_objects", "floater_top_objects.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterTopObjects>);
+	LLFloaterReg::add("toybox", "floater_toybox.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterToybox>);
 	
 	LLFloaterReg::add("reporter", "floater_report_abuse.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterReporter>);
 	LLFloaterReg::add("reset_queue", "floater_script_queue.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterResetQueue>);
diff --git a/indra/newview/skins/default/xui/en/floater_toybox.xml b/indra/newview/skins/default/xui/en/floater_toybox.xml
new file mode 100644
index 00000000000..19514973091
--- /dev/null
+++ b/indra/newview/skins/default/xui/en/floater_toybox.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<floater
+  can_close="true"
+  can_dock="false"
+  can_minimize="false"
+  can_resize="false"
+  default_tab_group="1"
+  height="460"
+  help_topic="toybox"
+  layout="topleft"
+  legacy_header_height="18"
+  name="Toybox"
+  open_centered="true"
+  single_instance="true"
+  title="Customize toolbars"
+  width="658">
+  <text
+    follows="left|top"
+    font="SansSerifMedium"
+    halign="left"
+    height="20"
+    layout="topleft"
+    left="40"
+    length="1"
+    name="toybox label 1"
+    right="-40"
+    top="35"
+    type="string">
+      Add or remove buttons by dragging them to or from the toolbars.
+  </text>
+  <text
+    follows="left|top"
+    font="SansSerifMedium"
+    halign="left"
+    height="20"
+    layout="topleft"
+    left="40"
+    length="1"
+    name="toybox label 2"
+    right="-40"
+    top="55"
+    type="string">
+      Buttons will appear as shown or as icon-only depending on each toolbar's settings.
+  </text>
+  <toolbar
+    bottom="395"
+    left="40"
+    right="-40"
+    top="85">
+  </toolbar>
+  <button
+    follows="left|bottom"
+    height="23"
+    label="Restore defaults"
+    label_selected="Restore defaults"
+    layout="topleft"
+    left="40"
+    name="btn_restore_defaults"
+    top="415"
+    width="130">
+    <button.commit_callback function="Toybox.RestoreDefaults" />
+  </button>
+</floater>
diff --git a/indra/newview/skins/default/xui/en/menu_login.xml b/indra/newview/skins/default/xui/en/menu_login.xml
index 4c4ff3e5c45..bb58dd500f0 100644
--- a/indra/newview/skins/default/xui/en/menu_login.xml
+++ b/indra/newview/skins/default/xui/en/menu_login.xml
@@ -13,7 +13,7 @@
      tear_off="true"
      name="File">
         <menu_item_call
-         label="Preferences"
+         label="Preferences..."
          name="Preferences..."
          shortcut="control|P">
             <menu_item_call.on_click
diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml
index 36ebe737532..2e93243b0f0 100644
--- a/indra/newview/skins/default/xui/en/menu_viewer.xml
+++ b/indra/newview/skins/default/xui/en/menu_viewer.xml
@@ -9,14 +9,22 @@
      name="Me"
      tear_off="true">
         <menu_item_call
-         label="Preferences"
+         label="Preferences..."
          name="Preferences"
          shortcut="control|P">
             <menu_item_call.on_click
              function="Floater.Show"
              parameter="preferences" />
         </menu_item_call>
-         <menu_item_call
+        <menu_item_call
+         label="Toolbars..."
+         name="Toolbars"
+         shortcut="control|T">
+            <menu_item_call.on_click
+             function="Floater.Toggle"
+             parameter="toybox" />
+        </menu_item_call>
+        <menu_item_call
              label="My Dashboard"
              name="Manage My Account">
                 <menu_item_call.on_click
@@ -2855,7 +2863,7 @@
                  function="ToggleControl"
                  parameter="BottomPanelNew" />
             </menu_item_check>-->
-            <menu_item_call
+          <menu_item_call
              label="Media Browser Test"
              name="Web Browser Test">
                 <menu_item_call.on_click
-- 
GitLab