summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
Diffstat (limited to 'indra')
-rw-r--r--indra/llui/llcommandmanager.cpp18
-rw-r--r--indra/llui/llcommandmanager.h13
-rw-r--r--indra/llui/lltoolbar.cpp103
-rw-r--r--indra/llui/lltoolbar.h38
-rw-r--r--indra/newview/lltoolbarview.cpp54
-rw-r--r--indra/newview/lltoolbarview.h2
6 files changed, 165 insertions, 63 deletions
diff --git a/indra/llui/llcommandmanager.cpp b/indra/llui/llcommandmanager.cpp
index b1147134c2..a8127ab3e3 100644
--- a/indra/llui/llcommandmanager.cpp
+++ b/indra/llui/llcommandmanager.cpp
@@ -112,9 +112,25 @@ LLCommand * LLCommandManager::getCommand(const LLCommandId& commandId)
return command_match;
}
+LLCommand * LLCommandManager::getCommand(const LLUUID& commandUUID)
+{
+ LLCommand * command_match = NULL;
+
+ CommandUUIDMap::const_iterator found = mCommandUUIDs.find(commandUUID);
+
+ if (found != mCommandUUIDs.end())
+ {
+ command_match = mCommands[found->second];
+ }
+
+ return command_match;
+}
+
void LLCommandManager::addCommand(LLCommand * command)
{
- mCommandIndices[command->id()] = mCommands.size();
+ LLCommandId command_id = command->id();
+ mCommandIndices[command_id] = mCommands.size();
+ mCommandUUIDs[command_id.uuid()] = mCommands.size();
mCommands.push_back(command);
lldebugs << "Successfully added command: " << command->id().name() << llendl;
diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h
index 6481a05689..c3d2cccd73 100644
--- a/indra/llui/llcommandmanager.h
+++ b/indra/llui/llcommandmanager.h
@@ -52,13 +52,18 @@ public:
LLCommandId(const std::string& name)
: mName(name)
- {}
+ {
+ mUUID = LLUUID::LLUUID::generateNewID(name);
+ }
LLCommandId(const Params& p)
: mName(p.name)
- {}
+ {
+ mUUID = LLUUID::LLUUID::generateNewID(p.name);
+ }
const std::string& name() const { return mName; }
+ const LLUUID& uuid() const { return mUUID; }
bool operator!=(const LLCommandId& command) const
{
@@ -79,6 +84,7 @@ public:
private:
std::string mName;
+ LLUUID mUUID;
};
typedef std::list<LLCommandId> command_id_list_t;
@@ -141,6 +147,7 @@ public:
U32 commandCount() const;
LLCommand * getCommand(U32 commandIndex);
LLCommand * getCommand(const LLCommandId& commandId);
+ LLCommand * getCommand(const LLUUID& commandUUID);
static bool load();
@@ -148,11 +155,13 @@ protected:
void addCommand(LLCommand * command);
private:
+ typedef std::map<LLUUID, U32> CommandUUIDMap;
typedef std::map<LLCommandId, U32> CommandIndexMap;
typedef std::vector<LLCommand *> CommandVector;
CommandVector mCommands;
CommandIndexMap mCommandIndices;
+ CommandUUIDMap mCommandUUIDs;
};
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index 199574629f..c349bbcf2e 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -107,7 +107,6 @@ LLToolBar::LLToolBar(const LLToolBar::Params& p)
{
mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT] = p.button_icon_and_text;
mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_ONLY] = p.button_icon;
- mUUID = LLUUID::LLUUID::generateNewID(p.name);
}
LLToolBar::~LLToolBar()
@@ -193,21 +192,71 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
mNeedsLayout = true;
}
-bool LLToolBar::addCommand(const LLCommandId& commandId)
+bool LLToolBar::addCommand(const LLCommandId& commandId, int rank)
{
LLCommand * command = LLCommandManager::instance().getCommand(commandId);
if (!command) return false;
- mButtonCommands.push_back(commandId);
+ // Create the button and do the things that don't need ordering
LLToolBarButton* button = createButton(commandId);
- mButtons.push_back(button);
mButtonPanel->addChild(button);
mButtonMap.insert(std::make_pair(commandId, button));
+
+ // Insert the command and button in the right place in their respective lists
+ if ((rank >= mButtonCommands.size()) || (rank < 0))
+ {
+ // In that case, back load
+ mButtonCommands.push_back(commandId);
+ mButtons.push_back(button);
+ }
+ else
+ {
+ // Insert in place: iterate to the right spot...
+ std::list<LLToolBarButton*>::iterator it_button = mButtons.begin();
+ command_id_list_t::iterator it_command = mButtonCommands.begin();
+ while (rank > 0)
+ {
+ ++it_button;
+ ++it_command;
+ rank--;
+ }
+ // ...then insert
+ mButtonCommands.insert(it_command,commandId);
+ mButtons.insert(it_button,button);
+ }
+
mNeedsLayout = true;
return true;
}
+bool LLToolBar::removeCommand(const LLCommandId& commandId)
+{
+ if (!hasCommand(commandId)) return false;
+
+ // First erase the map record
+ command_id_map::iterator it = mButtonMap.find(commandId);
+ mButtonMap.erase(it);
+
+ // Now iterate on the commands and buttons to identify the relevant records
+ 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;
+ }
+
+ // Delete the button and erase the command and button records
+ delete (*it_button);
+ mButtonCommands.erase(it_command);
+ mButtons.erase(it_button);
+
+ mNeedsLayout = true;
+
+ return true;
+}
+
void LLToolBar::clearCommandsList()
{
// Clears the commands list
@@ -328,6 +377,33 @@ void LLToolBar::resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row
}
}
+int LLToolBar::getRankFromPosition(S32 x, S32 y)
+{
+ int rank = 0;
+
+ LLLayoutStack::ELayoutOrientation orientation = getOrientation(mSideType);
+
+ // Simply compare the passed coord with the buttons outbound box
+ std::list<LLToolBarButton*>::iterator it_button = mButtons.begin();
+ std::list<LLToolBarButton*>::iterator end_button = mButtons.end();
+ while (it_button != end_button)
+ {
+ LLRect button_rect = (*it_button)->getRect();
+ if (((orientation == LLLayoutStack::HORIZONTAL) && (button_rect.mRight > x)) ||
+ ((orientation == LLLayoutStack::VERTICAL) && (button_rect.mTop > y)) )
+ {
+ llinfos << "Merov debug : rank compute: orientation = " << orientation << ", x = " << x << ", y = " << y << llendl;
+ llinfos << "Merov debug : rank compute: rect = " << button_rect.mLeft << ", " << button_rect.mTop << ", " << button_rect.mRight << ", " << button_rect.mBottom << llendl;
+ break;
+ }
+ rank++;
+ ++it_button;
+ }
+ llinfos << "Merov debug : rank = " << rank << llendl;
+
+ return rank;
+}
+
void LLToolBar::updateLayoutAsNeeded()
{
if (!mNeedsLayout) return;
@@ -494,6 +570,7 @@ void LLToolBar::createButtons()
delete button;
}
mButtons.clear();
+ mButtonMap.clear();
BOOST_FOREACH(LLCommandId& command_id, mButtonCommands)
{
@@ -503,7 +580,6 @@ void LLToolBar::createButtons()
mButtonMap.insert(std::make_pair(command_id, button));
}
mNeedsLayout = true;
-
}
LLToolBarButton* LLToolBar::createButton(const LLCommandId& id)
@@ -543,20 +619,20 @@ BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
EAcceptance* accept,
std::string& tooltip_msg)
{
- llinfos << "Merov debug : handleDragAndDrop. drop = " << drop << ", tooltip = " << tooltip_msg << 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);
- // if drop, time to call the drop callback to get the operation done
+ // if drop is set, it's time to call the callback to get the operation done
if (handled && drop)
{
- handled = mHandleDropCallback(cargo_type,cargo_data,mUUID);
+ handled = mHandleDropCallback(cargo_data, x, y ,this);
}
- // We accept multi drop by default
- *accept = (handled ? ACCEPT_YES_MULTI : ACCEPT_NO);
+ // We accept only single tool drop on toolbars
+ *accept = (handled ? ACCEPT_YES_SINGLE : ACCEPT_NO);
- // We'll use that flag to change the visual aspect of the target on draw()
+ // We'll use that flag to change the visual aspect of the toolbar target on draw()
mDragAndDropTarget = handled;
return handled;
@@ -571,7 +647,6 @@ LLToolBarButton::LLToolBarButton(const Params& p)
mDesiredHeight(p.desired_height),
mId("")
{
- mUUID = LLUUID::LLUUID::generateNewID(p.name);
}
BOOL LLToolBarButton::handleMouseDown(S32 x, S32 y, MASK mask)
@@ -590,13 +665,13 @@ BOOL LLToolBarButton::handleHover( S32 x, S32 y, MASK mask )
{
if (!mIsDragged)
{
- mStartDragItemCallback(x,y,mUUID);
+ mStartDragItemCallback(x,y,mId.uuid());
mIsDragged = true;
handled = TRUE;
}
else
{
- handled = mHandleDragItemCallback(x,y,mUUID,LLAssetType::AT_WIDGET);
+ handled = mHandleDragItemCallback(x,y,mId.uuid(),LLAssetType::AT_WIDGET);
}
}
else
diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h
index 10e5f49c0f..ddf2e048b6 100644
--- a/indra/llui/lltoolbar.h
+++ b/indra/llui/lltoolbar.h
@@ -35,9 +35,11 @@
#include "llcommandmanager.h"
#include "llassettype.h"
-typedef boost::function<void (S32 x, S32 y, const LLUUID& uuid)> startdrag_callback_t;
-typedef boost::function<BOOL (S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)> handledrag_callback_t;
-typedef boost::function<BOOL (EDragAndDropType type, void* data, const LLUUID& uuid)> handledrop_callback_t;
+class LLToolBar;
+
+typedef boost::function<void (S32 x, S32 y, const LLUUID& uuid)> tool_startdrag_callback_t;
+typedef boost::function<BOOL (S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)> tool_handledrag_callback_t;
+typedef boost::function<BOOL (void* data, S32 x, S32 y, LLToolBar* toolbar)> tool_handledrop_callback_t;
class LLToolBarButton : public LLButton
{
@@ -63,8 +65,8 @@ public:
BOOL handleHover(S32 x, S32 y, MASK mask);
void setCommandId(const LLCommandId& id) { mId = id; }
- void setStartDragCallback(startdrag_callback_t cb) { mStartDragItemCallback = cb; }
- void setHandleDragCallback(handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
+ void setStartDragCallback(tool_startdrag_callback_t cb) { mStartDragItemCallback = cb; }
+ void setHandleDragCallback(tool_handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
private:
LLCommandId mId;
S32 mMouseDownX;
@@ -72,10 +74,9 @@ private:
S32 mMinWidth;
S32 mMaxWidth;
S32 mDesiredHeight;
- bool mIsDragged;
- startdrag_callback_t mStartDragItemCallback;
- handledrag_callback_t mHandleDragItemCallback;
- LLUUID mUUID;
+ bool mIsDragged;
+ tool_startdrag_callback_t mStartDragItemCallback;
+ tool_handledrag_callback_t mHandleDragItemCallback;
};
@@ -146,6 +147,7 @@ public:
// virtuals
void draw();
void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
+ int getRankFromPosition(S32 x, S32 y);
BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
EDragAndDropType cargo_type,
@@ -153,12 +155,13 @@ public:
EAcceptance* accept,
std::string& tooltip_msg);
- bool addCommand(const LLCommandId& commandId);
+ bool addCommand(const LLCommandId& commandId, int rank = -1);
+ bool removeCommand(const LLCommandId& commandId);
bool hasCommand(const LLCommandId& commandId) const;
bool enableCommand(const LLCommandId& commandId, bool enabled);
- void setStartDragCallback(startdrag_callback_t cb) { mStartDragItemCallback = cb; }
- void setHandleDragCallback(handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
- void setHandleDropCallback(handledrop_callback_t cb) { mHandleDropCallback = cb; }
+ void setStartDragCallback(tool_startdrag_callback_t cb) { mStartDragItemCallback = cb; }
+ void setHandleDragCallback(tool_handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
+ void setHandleDropCallback(tool_handledrop_callback_t cb) { mHandleDropCallback = cb; }
LLToolBarButton* createButton(const LLCommandId& id);
@@ -168,10 +171,10 @@ protected:
~LLToolBar();
void initFromParams(const Params&);
- startdrag_callback_t mStartDragItemCallback;
- handledrag_callback_t mHandleDragItemCallback;
- handledrop_callback_t mHandleDropCallback;
- bool mDragAndDropTarget;
+ tool_startdrag_callback_t mStartDragItemCallback;
+ tool_handledrag_callback_t mHandleDragItemCallback;
+ tool_handledrop_callback_t mHandleDropCallback;
+ bool mDragAndDropTarget;
public:
// Methods used in loading and saving toolbar settings
@@ -188,7 +191,6 @@ private:
BOOL isSettingChecked(const LLSD& userdata);
void onSettingEnable(const LLSD& userdata);
- LLUUID mUUID;
const bool mReadOnly;
std::list<LLToolBarButton*> mButtons;
diff --git a/indra/newview/lltoolbarview.cpp b/indra/newview/lltoolbarview.cpp
index 5822f682df..a0ea1f43e3 100644
--- a/indra/newview/lltoolbarview.cpp
+++ b/indra/newview/lltoolbarview.cpp
@@ -82,15 +82,15 @@ BOOL LLToolBarView::postBuild()
mToolbarLeft->setStartDragCallback(boost::bind(LLToolBarView::startDragItem,_1,_2,_3));
mToolbarLeft->setHandleDragCallback(boost::bind(LLToolBarView::handleDragItem,_1,_2,_3,_4));
- mToolbarLeft->setHandleDropCallback(boost::bind(LLToolBarView::handleDrop,_1,_2,_3));
+ mToolbarLeft->setHandleDropCallback(boost::bind(LLToolBarView::handleDrop,_1,_2,_3,_4));
mToolbarRight->setStartDragCallback(boost::bind(LLToolBarView::startDragItem,_1,_2,_3));
mToolbarRight->setHandleDragCallback(boost::bind(LLToolBarView::handleDragItem,_1,_2,_3,_4));
- mToolbarRight->setHandleDropCallback(boost::bind(LLToolBarView::handleDrop,_1,_2,_3));
+ mToolbarRight->setHandleDropCallback(boost::bind(LLToolBarView::handleDrop,_1,_2,_3,_4));
mToolbarBottom->setStartDragCallback(boost::bind(LLToolBarView::startDragItem,_1,_2,_3));
mToolbarBottom->setHandleDragCallback(boost::bind(LLToolBarView::handleDragItem,_1,_2,_3,_4));
- mToolbarBottom->setHandleDropCallback(boost::bind(LLToolBarView::handleDrop,_1,_2,_3));
+ mToolbarBottom->setHandleDropCallback(boost::bind(LLToolBarView::handleDrop,_1,_2,_3,_4));
return TRUE;
}
@@ -286,10 +286,6 @@ void LLToolBarView::addToToolset(command_id_list_t& command_list, Toolbar& toolb
void LLToolBarView::draw()
{
- static bool debug_print = true;
- static S32 old_width = 0;
- static S32 old_height = 0;
-
//LLPanel* sizer_left = getChild<LLPanel>("sizer_left");
LLRect bottom_rect, left_rect, right_rect;
@@ -310,19 +306,6 @@ void LLToolBarView::draw()
mToolbarRight->localRectToOtherView(mToolbarRight->getLocalRect(), &right_rect, this);
}
- if ((old_width != getRect().getWidth()) || (old_height != getRect().getHeight()))
- debug_print = true;
- if (debug_print)
- {
- LLRect ctrl_rect = getRect();
- llinfos << "Merov debug : draw control rect = " << ctrl_rect.mLeft << ", " << ctrl_rect.mTop << ", " << ctrl_rect.mRight << ", " << ctrl_rect.mBottom << llendl;
- llinfos << "Merov debug : draw bottom rect = " << bottom_rect.mLeft << ", " << bottom_rect.mTop << ", " << bottom_rect.mRight << ", " << bottom_rect.mBottom << llendl;
- llinfos << "Merov debug : draw left rect = " << left_rect.mLeft << ", " << left_rect.mTop << ", " << left_rect.mRight << ", " << left_rect.mBottom << llendl;
- llinfos << "Merov debug : draw right rect = " << right_rect.mLeft << ", " << right_rect.mTop << ", " << right_rect.mRight << ", " << right_rect.mBottom << llendl;
- old_width = ctrl_rect.getWidth();
- old_height = ctrl_rect.getHeight();
- debug_print = false;
- }
// Debug draw
LLColor4 back_color = LLColor4::blue;
LLColor4 back_color_vert = LLColor4::red;
@@ -365,7 +348,7 @@ BOOL LLToolBarView::handleDragItem( S32 x, S32 y, const LLUUID& uuid, LLAssetTyp
gClipboard.setSourceObject(uuid,LLAssetType::AT_WIDGET);
LLToolDragAndDrop::ESource src = LLToolDragAndDrop::SOURCE_VIEWER;
LLUUID srcID;
- llinfos << "Merov debug: handleDragItem() : beginMultiDrag()" << llendl;
+ llinfos << "Merov debug: handleDragItem() : beginMultiDrag()" << llendl;
LLToolDragAndDrop::getInstance()->beginMultiDrag(types, cargo_ids, src, srcID);
sDragStarted = true;
return TRUE;
@@ -379,18 +362,35 @@ BOOL LLToolBarView::handleDragItem( S32 x, S32 y, const LLUUID& uuid, LLAssetTyp
return FALSE;
}
-BOOL LLToolBarView::handleDrop( EDragAndDropType cargo_type, void* cargo_data, const LLUUID& toolbar_id)
+BOOL LLToolBarView::handleDrop( void* cargo_data, S32 x, S32 y, LLToolBar* toolbar)
{
LLInventoryItem* inv_item = (LLInventoryItem*)cargo_data;
- llinfos << "Merov debug : handleDrop. Drop " << inv_item->getUUID() << " named " << inv_item->getName() << " of type " << inv_item->getType() << " to toolbar " << toolbar_id << " under cargo type " << cargo_type << llendl;
+ llinfos << "Merov debug : handleDrop. Drop " << inv_item->getUUID() << " named " << inv_item->getName() << " of type " << inv_item->getType() << llendl;
LLAssetType::EType type = inv_item->getType();
if (type == LLAssetType::AT_WIDGET)
{
- llinfos << "Merov debug : handleDrop. Drop source is a widget -> that's where we'll get code in..." << llendl;
- // Find out if he command is in one of the toolbar
- // If it is, pull it out of the toolbar
- // Now insert it in the toolbar in the correct spot...
+ llinfos << "Merov debug : handleDrop. Drop source is a widget -> drop it in place..." << llendl;
+ // Get the command from its uuid
+ LLCommandManager& mgr = LLCommandManager::instance();
+ LLCommand* command = mgr.getCommand(inv_item->getUUID());
+ if (command)
+ {
+ // Convert the (x,y) position in rank in toolbar
+ int rank = toolbar->getRankFromPosition(x,y);
+ // Suppress the command from the toolbars (including the one it's dropped in,
+ // this will handle move position).
+ gToolBarView->mToolbarLeft->removeCommand(command->id());
+ gToolBarView->mToolbarRight->removeCommand(command->id());
+ gToolBarView->mToolbarBottom->removeCommand(command->id());
+ // Now insert it in the toolbar at the detected rank
+ toolbar->addCommand(command->id(),rank);
+ }
+ else
+ {
+ llwarns << "Merov debug : handleDrop failing: command couldn't be found in manager" << llendl;
+ }
+
}
else
{
diff --git a/indra/newview/lltoolbarview.h b/indra/newview/lltoolbarview.h
index b7d3a4033a..3d488f837f 100644
--- a/indra/newview/lltoolbarview.h
+++ b/indra/newview/lltoolbarview.h
@@ -76,7 +76,7 @@ public:
static void startDragItem( S32 x, S32 y, const LLUUID& uuid);
static BOOL handleDragItem( S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type);
- static BOOL handleDrop( EDragAndDropType cargo_type, void* cargo_data, const LLUUID& folder_id);
+ static BOOL handleDrop( void* cargo_data, S32 x, S32 y, LLToolBar* toolbar);
protected:
friend class LLUICtrlFactory;