summaryrefslogtreecommitdiff
path: root/indra/llui/lltoolbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/lltoolbar.cpp')
-rw-r--r--indra/llui/lltoolbar.cpp89
1 files changed, 72 insertions, 17 deletions
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index 1f5fa5f361..e74aab6e21 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -33,6 +33,7 @@
#include "llcommandmanager.h"
#include "llmenugl.h"
#include "lltrans.h"
+#include "llinventory.h"
// uncomment this and remove the one in llui.cpp when there is an external reference to this translation unit
// thanks, MSVC!
@@ -86,6 +87,7 @@ LLToolBar::Params::Params()
pad_right("pad_right"),
pad_bottom("pad_bottom"),
pad_between("pad_between"),
+ min_girth("min_girth"),
button_panel("button_panel")
{}
@@ -103,6 +105,7 @@ LLToolBar::LLToolBar(const LLToolBar::Params& p)
mPadTop(p.pad_top),
mPadBottom(p.pad_bottom),
mPadBetween(p.pad_between),
+ mMinGirth(p.min_girth),
mPopupMenuHandle(),
mStartDragItemCallback(NULL),
mHandleDragItemCallback(NULL),
@@ -201,14 +204,16 @@ bool LLToolBar::addCommand(const LLCommandId& commandId, int rank)
{
LLCommand * command = LLCommandManager::instance().getCommand(commandId);
if (!command) return false;
-
+ llinfos << "Merov debug : addCommand, " << commandId.name() << ", " << commandId.uuid() << llendl;
+
// Create the button and do the things that don't need ordering
LLToolBarButton* button = createButton(commandId);
mButtonPanel->addChild(button);
- mButtonMap.insert(std::make_pair(commandId, button));
+ mButtonMap.insert(std::make_pair(commandId.uuid(), button));
+
// Insert the command and button in the right place in their respective lists
- if ((rank >= mButtonCommands.size()) || (rank < 0))
+ if ((rank >= mButtonCommands.size()) || (rank == RANK_NONE))
{
// In that case, back load
mButtonCommands.push_back(commandId);
@@ -235,21 +240,28 @@ bool LLToolBar::addCommand(const LLCommandId& commandId, int rank)
return true;
}
-bool LLToolBar::removeCommand(const LLCommandId& commandId)
+// Remove a command from the list
+// Returns the rank of the command in the original list so that doing addCommand(id,rank) right after
+// a removeCommand(id) would leave the list unchanged.
+// Returns RANK_NONE if the command is not found in the list
+int LLToolBar::removeCommand(const LLCommandId& commandId)
{
- if (!hasCommand(commandId)) return false;
+ if (!hasCommand(commandId)) return RANK_NONE;
+ llinfos << "Merov debug : removeCommand, " << commandId.name() << ", " << commandId.uuid() << llendl;
// First erase the map record
- command_id_map::iterator it = mButtonMap.find(commandId);
+ command_id_map::iterator it = mButtonMap.find(commandId.uuid());
mButtonMap.erase(it);
// Now iterate on the commands and buttons to identify the relevant records
+ int rank = 0;
std::list<LLToolBarButton*>::iterator it_button = mButtons.begin();
command_id_list_t::iterator it_command = mButtonCommands.begin();
while (*it_command != commandId)
{
++it_button;
++it_command;
+ ++rank;
}
// Delete the button and erase the command and button records
@@ -259,7 +271,7 @@ bool LLToolBar::removeCommand(const LLCommandId& commandId)
mNeedsLayout = true;
- return true;
+ return rank;
}
void LLToolBar::clearCommandsList()
@@ -274,7 +286,7 @@ bool LLToolBar::hasCommand(const LLCommandId& commandId) const
{
if (commandId != LLCommandId::null)
{
- command_id_map::const_iterator it = mButtonMap.find(commandId);
+ command_id_map::const_iterator it = mButtonMap.find(commandId.uuid());
return (it != mButtonMap.end());
}
@@ -287,7 +299,7 @@ bool LLToolBar::enableCommand(const LLCommandId& commandId, bool enabled)
if (commandId != LLCommandId::null)
{
- command_id_map::iterator it = mButtonMap.find(commandId);
+ command_id_map::iterator it = mButtonMap.find(commandId.uuid());
if (it != mButtonMap.end())
{
it->second->setEnabled(enabled);
@@ -382,6 +394,10 @@ void LLToolBar::resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row
}
}
+// Returns the position of the coordinates as a rank in the button list.
+// The rank is the position a tool dropped in (x,y) would assume in the button list.
+// The value returned is between 0 and mButtons.size(), 0 being the first element to the left
+// (or top) and mButtons.size() the last one to the right (or bottom).
int LLToolBar::getRankFromPosition(S32 x, S32 y)
{
int rank = 0;
@@ -505,7 +521,7 @@ void LLToolBar::updateLayoutAsNeeded()
button_rect.setLeftTopAndSize(cur_row, panel_rect.mTop - cur_start, button_clamped_width, button->getRect().getHeight());
}
button->setShape(button_rect);
-
+
buttons_in_row.push_back(button);
row_running_length += button_length + mPadBetween;
@@ -517,6 +533,8 @@ void LLToolBar::updateLayoutAsNeeded()
S32 total_girth = cur_row // current row position...
+ max_row_girth // ...incremented by size of final row...
+ girth_pad_end; // ...plus padding reserved on end
+ total_girth = llmax(total_girth,mMinGirth);
+
max_row_length = llmax(max_row_length, row_running_length - mPadBetween + row_pad_end);
resizeButtonsInRow(buttons_in_row, max_row_girth);
@@ -618,7 +636,7 @@ void LLToolBar::createButtons()
LLToolBarButton* button = createButton(command_id);
mButtons.push_back(button);
mButtonPanel->addChild(button);
- mButtonMap.insert(std::make_pair(command_id, button));
+ mButtonMap.insert(std::make_pair(command_id.uuid(), button));
}
mNeedsLayout = true;
}
@@ -641,11 +659,25 @@ LLToolBarButton* LLToolBar::createButton(const LLCommandId& id)
if (!mReadOnly)
{
- LLUICtrl::CommitCallbackParam cbParam;
- cbParam.function_name = commandp->executeFunctionName();
- cbParam.parameter = commandp->executeParameters();
+ LLUICtrl::CommitCallbackParam executeParam;
+ executeParam.function_name = commandp->executeFunctionName();
+ executeParam.parameter = commandp->executeParameters();
- button->setCommitCallback(cbParam);
+ // If we have a "stop" function then we map the command to mouse down / mouse up otherwise commit
+ const std::string& executeStopFunction = commandp->executeStopFunctionName();
+ if (executeStopFunction.length() > 0)
+ {
+ LLUICtrl::CommitCallbackParam executeStopParam;
+ executeStopParam.function_name = executeStopFunction;
+ executeStopParam.parameter = commandp->executeStopParameters();
+
+ button->setMouseDownCallback(executeParam);
+ button->setMouseUpCallback(executeStopParam);
+ }
+ else
+ {
+ button->setCommitCallback(executeParam);
+ }
const std::string& isEnabledFunction = commandp->isEnabledFunctionName();
if (isEnabledFunction.length() > 0)
@@ -695,7 +727,7 @@ BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
EAcceptance* accept,
std::string& tooltip_msg)
{
- //llinfos << "Merov debug : handleDragAndDrop. drop = " << drop << ", x = " << x << ", y = " << y << llendl;
+ llinfos << "Merov debug : handleDragAndDrop. drop = " << drop << ", x = " << x << ", y = " << y << llendl;
// If we have a drop callback, that means that we can handle the drop
BOOL handled = (mHandleDropCallback ? TRUE : FALSE);
@@ -709,7 +741,25 @@ BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
*accept = (handled ? ACCEPT_YES_SINGLE : ACCEPT_NO);
// We'll use that flag to change the visual aspect of the toolbar target on draw()
- mDragAndDropTarget = handled;
+ mDragAndDropTarget = false;
+
+ // HACK!!!
+ if (!isReadOnly() && handled)
+ {
+ if (!drop)
+ {
+ LLInventoryItem* inv_item = (LLInventoryItem*)cargo_data;
+ LLAssetType::EType type = inv_item->getType();
+ if (type == LLAssetType::AT_WIDGET)
+ {
+ LLCommandId dragged_command(inv_item->getUUID());
+ int rank = getRankFromPosition(x, y);
+ removeCommand(dragged_command);
+ addCommand(dragged_command,rank);
+ mDragAndDropTarget = true;
+ }
+ }
+ }
return handled;
}
@@ -787,3 +837,8 @@ void LLToolBarButton::onMouseCaptureLost()
{
mIsDragged = false;
}
+
+void LLToolBarButton::reshape(S32 width, S32 height, BOOL called_from_parent)
+{
+ LLButton::reshape(mWidthRange.clamp(width), height, called_from_parent);
+}