summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llcommandmanager.cpp24
-rw-r--r--indra/llui/llcommandmanager.h50
-rw-r--r--indra/llui/lltoolbar.cpp161
-rw-r--r--indra/llui/lltoolbar.h28
-rw-r--r--indra/llui/lltoolbarview.cpp54
-rw-r--r--indra/llui/lltoolbarview.h11
6 files changed, 288 insertions, 40 deletions
diff --git a/indra/llui/llcommandmanager.cpp b/indra/llui/llcommandmanager.cpp
index 071ab24cda..783990780b 100644
--- a/indra/llui/llcommandmanager.cpp
+++ b/indra/llui/llcommandmanager.cpp
@@ -38,11 +38,18 @@
//
+// LLCommandId class
+//
+
+const LLCommandId LLCommandId::null("null command");
+
+//
// LLCommand class
//
LLCommand::Params::Params()
: function("function")
+ , available_in_toybox("available_in_toybox", false)
, icon("icon")
, label_ref("label_ref")
, name("name")
@@ -53,9 +60,10 @@ LLCommand::Params::Params()
LLCommand::LLCommand(const LLCommand::Params& p)
: mFunction(p.function)
+ , mAvailableInToybox(p.available_in_toybox)
, mIcon(p.icon)
+ , mIdentifier(p.name)
, mLabelRef(p.label_ref)
- , mName(p.name)
, mParam(p.param)
, mTooltipRef(p.tooltip_ref)
{
@@ -90,26 +98,26 @@ LLCommand * LLCommandManager::getCommand(U32 commandIndex)
return mCommands[commandIndex];
}
-LLCommand * LLCommandManager::getCommand(const std::string& commandName)
+LLCommand * LLCommandManager::getCommand(const LLCommandId& commandId)
{
- LLCommand * command_name_match = NULL;
+ LLCommand * command_match = NULL;
- CommandIndexMap::const_iterator found = mCommandIndices.find(commandName);
+ CommandIndexMap::const_iterator found = mCommandIndices.find(commandId);
if (found != mCommandIndices.end())
{
- command_name_match = mCommands[found->second];
+ command_match = mCommands[found->second];
}
- return command_name_match;
+ return command_match;
}
void LLCommandManager::addCommand(LLCommand * command)
{
- mCommandIndices[command->name()] = mCommands.size();
+ mCommandIndices[command->id()] = mCommands.size();
mCommands.push_back(command);
- lldebugs << "Successfully added command: " << command->name() << llendl;
+ lldebugs << "Successfully added command: " << command->id().name() << llendl;
}
//static
diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h
index 24378ecd62..5b53b65500 100644
--- a/indra/llui/llcommandmanager.h
+++ b/indra/llui/llcommandmanager.h
@@ -31,11 +31,50 @@
#include "llsingleton.h"
+class LLCommand;
+class LLCommandManager;
+
+
+class LLCommandId
+{
+public:
+ friend LLCommand;
+ friend LLCommandManager;
+
+ LLCommandId(const std::string& name)
+ : mName(name)
+ {
+ }
+
+ const std::string& name() const { return mName; }
+
+ bool operator!=(const LLCommandId& command) const
+ {
+ return (mName != command.mName);
+ }
+
+ bool operator==(const LLCommandId& command) const
+ {
+ return (mName == command.mName);
+ }
+
+ bool operator<(const LLCommandId& command) const
+ {
+ return (mName < command.mName);
+ }
+
+ static const LLCommandId null;
+
+private:
+ std::string mName;
+};
+
class LLCommand
{
public:
struct Params : public LLInitParam::Block<Params>
{
+ Mandatory<bool> available_in_toybox;
Mandatory<std::string> function;
Mandatory<std::string> icon;
Mandatory<std::string> label_ref;
@@ -48,18 +87,21 @@ public:
LLCommand(const LLCommand::Params& p);
+ const bool availableInToybox() const { return mAvailableInToybox; }
const std::string& functionName() const { return mFunction; }
const std::string& icon() const { return mIcon; }
+ const LLCommandId& id() const { return mIdentifier; }
const std::string& labelRef() const { return mLabelRef; }
- const std::string& name() const { return mName; }
const std::string& param() const { return mParam; }
const std::string& tooltipRef() const { return mTooltipRef; }
private:
+ LLCommandId mIdentifier;
+
+ bool mAvailableInToybox;
std::string mFunction;
std::string mIcon;
std::string mLabelRef;
- std::string mName;
std::string mParam;
std::string mTooltipRef;
};
@@ -84,7 +126,7 @@ public:
U32 commandCount() const;
LLCommand * getCommand(U32 commandIndex);
- LLCommand * getCommand(const std::string& commandName);
+ LLCommand * getCommand(const LLCommandId& commandId);
static bool load();
@@ -92,7 +134,7 @@ protected:
void addCommand(LLCommand * command);
private:
- typedef std::map<std::string, U32> CommandIndexMap;
+ typedef std::map<LLCommandId, U32> CommandIndexMap;
typedef std::vector<LLCommand *> CommandVector;
CommandVector mCommands;
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index 90ade136e8..278c04aef8 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -30,7 +30,7 @@
#include <boost/foreach.hpp>
#include "lltoolbar.h"
-#include "llcommandmanager.h"
+#include "llmenugl.h"
#include "lltrans.h"
// uncomment this and remove the one in llui.cpp when there is an external reference to this translation unit
@@ -51,6 +51,7 @@ namespace LLToolBarEnums
return orientation;
}
}
+
using namespace LLToolBarEnums;
@@ -58,8 +59,8 @@ namespace LLInitParam
{
void TypeValues<ButtonType>::declareValues()
{
- declare("icons_only", BTNTYPE_ICONS_ONLY);
declare("icons_with_text", BTNTYPE_ICONS_WITH_TEXT);
+ declare("icons_only", BTNTYPE_ICONS_ONLY);
}
void TypeValues<SideType>::declareValues()
@@ -77,6 +78,7 @@ LLToolBar::Params::Params()
side("side", SIDE_TOP),
button_icon("button_icon"),
button_icon_and_text("button_icon_and_text"),
+ read_only("read_only", false),
wrap("wrap", true),
min_button_width("min_button_width", 0),
max_button_width("max_button_width", S32_MAX),
@@ -91,6 +93,7 @@ LLToolBar::Params::Params()
LLToolBar::LLToolBar(const LLToolBar::Params& p)
: LLUICtrl(p),
+ mReadOnly(p.read_only),
mButtonType(p.button_display_mode),
mSideType(p.side),
mWrap(p.wrap),
@@ -104,10 +107,47 @@ LLToolBar::LLToolBar(const LLToolBar::Params& p)
mPadRight(p.pad_right),
mPadTop(p.pad_top),
mPadBottom(p.pad_bottom),
- mPadBetween(p.pad_between)
+ mPadBetween(p.pad_between),
+ mPopupMenuHandle()
{
- mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_ONLY] = p.button_icon;
mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT] = p.button_icon_and_text;
+ mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_ONLY] = p.button_icon;
+}
+
+LLToolBar::~LLToolBar()
+{
+ LLView::deleteViewByHandle(mPopupMenuHandle);
+}
+
+BOOL LLToolBar::postBuild()
+{
+ if (!mReadOnly)
+ {
+ LLUICtrl::CommitCallbackRegistry::Registrar& commit_reg = LLUICtrl::CommitCallbackRegistry::defaultRegistrar();
+ commit_reg.add("Toolbars.EnableSetting", boost::bind(&LLToolBar::onSettingEnable, this, _2));
+
+ LLUICtrl::EnableCallbackRegistry::Registrar& enable_reg = LLUICtrl::EnableCallbackRegistry::defaultRegistrar();
+ enable_reg.add("Toolbars.CheckSetting", boost::bind(&LLToolBar::isSettingChecked, this, _2));
+
+ //
+ // Setup the context menu
+ //
+
+ LLMenuGL* menu = LLUICtrlFactory::instance().createFromFile<LLMenuGL>("menu_toolbars.xml", LLMenuGL::sMenuContainer, LLMenuHolderGL::child_registry_t::instance());
+
+ if (menu)
+ {
+ menu->setBackgroundColor(LLUIColorTable::instance().getColor("MenuPopupBgColor"));
+
+ mPopupMenuHandle = menu->getHandle();
+ }
+ else
+ {
+ llwarns << "Unable to load toolbars context menu." << llendl;
+ }
+ }
+
+ return TRUE;
}
void LLToolBar::initFromParams(const LLToolBar::Params& p)
@@ -147,7 +187,7 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
LLPanel::Params button_panel_p(p.button_panel);
button_panel_p.rect = center_panel->getLocalRect();
- button_panel_p.follows.flags = FOLLOWS_BOTTOM|FOLLOWS_LEFT;
+ button_panel_p.follows.flags = FOLLOWS_BOTTOM|FOLLOWS_LEFT;
mButtonPanel = LLUICtrlFactory::create<LLPanel>(button_panel_p);
center_panel->addChild(mButtonPanel);
@@ -159,19 +199,26 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
LLToolBarButton* buttonp = LLUICtrlFactory::create<LLToolBarButton>(button_p);
mButtons.push_back(buttonp);
+ mButtonCommands.push_back(LLCommandId::null);
mButtonPanel->addChild(buttonp);
mNeedsLayout = true;
}
}
-bool LLToolBar::addCommand(LLCommand * command)
+bool LLToolBar::addCommand(const LLCommandId& commandId)
{
+ LLCommand * command = LLCommandManager::instance().getCommand(commandId);
+
+ bool add_command = (command != NULL);
+
//
// Init basic toolbar button params
//
+ if (add_command)
+ {
LLToolBarButton::Params button_p(mButtonParams[mButtonType]);
- button_p.name = command->name();
+ button_p.name = commandId.name();
button_p.label = LLTrans::getString(command->labelRef());
button_p.tool_tip = LLTrans::getString(command->tooltipRef());
@@ -180,11 +227,104 @@ bool LLToolBar::addCommand(LLCommand * command)
//
LLToolBarButton * toolbar_button = LLUICtrlFactory::create<LLToolBarButton>(button_p);
mButtons.push_back(toolbar_button);
+ mButtonCommands.push_back(commandId);
mButtonPanel->addChild(toolbar_button);
mNeedsLayout = true;
+ }
+
+ return add_command;
+}
+
+bool LLToolBar::hasCommand(const LLCommandId& commandId) const
+{
+ bool has_command = false;
+
+ if (commandId != LLCommandId::null)
+ {
+ for (std::list<LLCommandId>::const_iterator cmd = mButtonCommands.begin(); cmd != mButtonCommands.end(); ++cmd)
+ {
+ if ((*cmd) == commandId)
+ {
+ has_command = true;
+ break;
+ }
+ }
+ }
+
+ return has_command;
+}
+
+bool LLToolBar::enableCommand(const LLCommandId& commandId, bool enabled)
+{
+ LLButton * command_button = NULL;
+
+ if (commandId != LLCommandId::null)
+ {
+ command_button = mButtonPanel->findChild<LLButton>(commandId.name());
+
+ if (command_button)
+ {
+ command_button->setEnabled(enabled);
+ }
+ }
+
+ return (command_button != NULL);
+}
+
+BOOL LLToolBar::handleRightMouseDown(S32 x, S32 y, MASK mask)
+{
+ BOOL handle_it_here = !mReadOnly;
+
+ if (handle_it_here)
+ {
+ LLMenuGL * menu = (LLMenuGL *) mPopupMenuHandle.get();
+
+ if (menu)
+ {
+ LLMenuGL::showPopup(this, menu, x, y);
+ }
+ }
+
+ return handle_it_here;
+}
+
+BOOL LLToolBar::isSettingChecked(const LLSD& userdata)
+{
+ BOOL retval = FALSE;
+
+ const std::string setting_name = userdata.asString();
+
+ if (setting_name == "icons_and_labels")
+ {
+ retval = (mButtonType == BTNTYPE_ICONS_WITH_TEXT);
+ }
+ else if (setting_name == "icons_only")
+ {
+ retval = (mButtonType == BTNTYPE_ICONS_ONLY);
+ }
+
+ return retval;
+}
+
+void LLToolBar::onSettingEnable(const LLSD& userdata)
+{
+ llassert(!mReadOnly);
+
+ const std::string setting_name = userdata.asString();
+
+ const ButtonType current_button_type = mButtonType;
+
+ if (setting_name == "icons_and_labels")
+ {
+ mButtonType = BTNTYPE_ICONS_WITH_TEXT;
+ }
+ else if (setting_name == "icons_only")
+ {
+ mButtonType = BTNTYPE_ICONS_ONLY;
+ }
- return true;
+ mNeedsLayout |= (current_button_type != mButtonType);
}
void LLToolBar::resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth)
@@ -229,7 +369,6 @@ void LLToolBar::updateLayoutAsNeeded()
max_length = getRect().getWidth() - mPadLeft - mPadRight;
max_total_girth = getRect().getHeight() - mPadTop - mPadBottom;
row_pad_start = mPadLeft;
- row_running_length = row_pad_start;
row_pad_end = mPadRight;
cur_row = mPadTop;
girth_pad_end = mPadBottom;
@@ -239,12 +378,12 @@ void LLToolBar::updateLayoutAsNeeded()
max_length = getRect().getHeight() - mPadTop - mPadBottom;
max_total_girth = getRect().getWidth() - mPadLeft - mPadRight;
row_pad_start = mPadTop;
- row_running_length = row_pad_start;
row_pad_end = mPadBottom;
cur_row = mPadLeft;
girth_pad_end = mPadRight;
}
+ row_running_length = row_pad_start;
cur_start = row_pad_start;
@@ -332,7 +471,7 @@ void LLToolBar::updateLayoutAsNeeded()
reshape(total_girth, getRect().getHeight());
mButtonPanel->reshape(total_girth, max_row_length);
- }
+ }
// re-center toolbar buttons
mCenteringStack->updateLayout();
diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h
index 92c289cd3f..f7562b29d2 100644
--- a/indra/llui/lltoolbar.h
+++ b/indra/llui/lltoolbar.h
@@ -28,9 +28,10 @@
#ifndef LL_LLTOOLBAR_H
#define LL_LLTOOLBAR_H
-#include "lluictrl.h"
-#include "lllayoutstack.h"
#include "llbutton.h"
+#include "llcommandmanager.h"
+#include "lllayoutstack.h"
+#include "lluictrl.h"
class LLCommand;
@@ -51,8 +52,8 @@ namespace LLToolBarEnums
{
enum ButtonType
{
- BTNTYPE_ICONS_ONLY = 0,
- BTNTYPE_ICONS_WITH_TEXT,
+ BTNTYPE_ICONS_WITH_TEXT = 0,
+ BTNTYPE_ICONS_ONLY,
BTNTYPE_COUNT
};
@@ -96,7 +97,9 @@ public:
Optional<LLToolBarButton::Params> button_icon,
button_icon_and_text;
- Optional<bool> wrap;
+ Optional<bool> read_only,
+ wrap;
+
Optional<S32> min_button_width,
max_button_width,
button_height;
@@ -116,21 +119,32 @@ public:
// virtuals
void draw();
+ BOOL postBuild();
void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
- bool addCommand(LLCommand * command);
+ bool addCommand(const LLCommandId& commandId);
+ bool hasCommand(const LLCommandId& commandId) const;
+ bool enableCommand(const LLCommandId& commandId, bool enabled);
protected:
friend class LLUICtrlFactory;
LLToolBar(const Params&);
+ ~LLToolBar();
void initFromParams(const Params&);
+ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
+ BOOL isSettingChecked(const LLSD& userdata);
+ void onSettingEnable(const LLSD& userdata);
+
private:
void updateLayoutAsNeeded();
void resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth);
+ const bool mReadOnly;
+
std::list<LLToolBarButton*> mButtons;
+ std::list<LLCommandId> mButtonCommands;
LLToolBarEnums::ButtonType mButtonType;
LLLayoutStack* mCenteringStack;
LLLayoutStack* mWrapStack;
@@ -149,6 +163,8 @@ private:
mPadBetween;
LLToolBarButton::Params mButtonParams[LLToolBarEnums::BTNTYPE_COUNT];
+
+ LLHandle<LLView> mPopupMenuHandle;
};
diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp
index 27d67184d8..21d3785c82 100644
--- a/indra/llui/lltoolbarview.cpp
+++ b/indra/llui/lltoolbarview.cpp
@@ -37,7 +37,10 @@ LLToolBarView* gToolBarView = NULL;
static LLDefaultChildRegistry::Register<LLToolBarView> r("toolbar_view");
LLToolBarView::LLToolBarView(const LLToolBarView::Params& p)
-: LLUICtrl(p)
+: LLUICtrl(p),
+ mToolbarLeft(NULL),
+ mToolbarRight(NULL),
+ mToolbarBottom(NULL)
{
}
@@ -51,19 +54,46 @@ LLToolBarView::~LLToolBarView()
{
}
+BOOL LLToolBarView::postBuild()
+{
+ mToolbarLeft = getChild<LLToolBar>("toolbar_left");
+ mToolbarRight = getChild<LLToolBar>("toolbar_right");
+ mToolbarBottom = getChild<LLToolBar>("toolbar_bottom");
+ return TRUE;
+}
+
+bool LLToolBarView::hasCommand(const LLCommandId& commandId) const
+{
+ bool has_command = false;
+ if (mToolbarLeft && !has_command)
+ {
+ has_command = mToolbarLeft->hasCommand(commandId);
+ }
+ if (mToolbarRight && !has_command)
+ {
+ has_command = mToolbarRight->hasCommand(commandId);
+ }
+ if (mToolbarBottom && !has_command)
+ {
+ has_command = mToolbarBottom->hasCommand(commandId);
+ }
+ return has_command;
+}
+
void LLToolBarView::draw()
{
static bool debug_print = true;
static S32 old_width = 0;
static S32 old_height = 0;
- LLToolBar* toolbar_bottom = getChild<LLToolBar>("toolbar_bottom");
- LLToolBar* toolbar_left = getChild<LLToolBar>("toolbar_left");
- LLToolBar* toolbar_right = getChild<LLToolBar>("toolbar_right");
+ LLPanel* sizer_left = getChild<LLPanel>("sizer_left");
+
+ LLRect bottom_rect, left_rect, right_rect;
+
+ if (mToolbarBottom) bottom_rect = mToolbarBottom->getRect();
+ if (mToolbarLeft) left_rect = mToolbarLeft->getRect();
+ if (mToolbarRight) right_rect = mToolbarRight->getRect();
- LLRect bottom_rect = toolbar_bottom->getRect();
- LLRect left_rect = toolbar_left->getRect();
- LLRect right_rect = toolbar_right->getRect();
if ((old_width != getRect().getWidth()) || (old_height != getRect().getHeight()))
debug_print = true;
@@ -80,11 +110,15 @@ void LLToolBarView::draw()
}
// Debug draw
LLColor4 back_color = LLColor4::blue;
+ LLColor4 back_color_vert = LLColor4::red;
+ LLColor4 back_color_hori = LLColor4::yellow;
back_color[VALPHA] = 0.5f;
+ back_color_hori[VALPHA] = 0.5f;
+ back_color_vert[VALPHA] = 0.5f;
//gl_rect_2d(getLocalRect(), back_color, TRUE);
- //gl_rect_2d(bottom_rect, LLColor4::red, TRUE);
- //gl_rect_2d(left_rect, LLColor4::green, TRUE);
- //gl_rect_2d(right_rect, LLColor4::yellow, TRUE);
+ gl_rect_2d(bottom_rect, back_color_hori, TRUE);
+ gl_rect_2d(left_rect, back_color_vert, TRUE);
+ gl_rect_2d(right_rect, back_color_vert, TRUE);
LLUICtrl::draw();
}
diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h
index 0e6545015d..2e7885f391 100644
--- a/indra/llui/lltoolbarview.h
+++ b/indra/llui/lltoolbarview.h
@@ -29,6 +29,8 @@
#define LL_LLTOOLBARVIEW_H
#include "lluictrl.h"
+#include "lltoolbar.h"
+#include "llcommandmanager.h"
class LLUICtrlFactory;
@@ -38,9 +40,14 @@ class LLToolBarView : public LLUICtrl
{
public:
struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> {};
+
virtual ~LLToolBarView();
+ /*virtual*/ BOOL postBuild();
+
virtual void draw();
+ bool hasCommand(const LLCommandId& commandId) const;
+
// valid children for LLToolBarView are stored in this registry
typedef LLDefaultChildRegistry child_registry_t;
@@ -51,7 +58,9 @@ protected:
void initFromParams(const Params&);
private:
- LLHandle<LLView> mSnapView;
+ LLToolBar* mToolbarLeft;
+ LLToolBar* mToolbarRight;
+ LLToolBar* mToolbarBottom;
};
extern LLToolBarView* gToolBarView;