diff options
author | Leyla Farazha <leyla@lindenlab.com> | 2011-10-05 15:12:07 -0700 |
---|---|---|
committer | Leyla Farazha <leyla@lindenlab.com> | 2011-10-05 15:12:07 -0700 |
commit | 11a0d0cd59c86cee18b6b2fd92fcbac62502ede0 (patch) | |
tree | 74dba5131b40874232a8dd50a2a79f9d81d3f143 /indra/llui/lltoolbar.cpp | |
parent | 6f9ed8b303e9e840fcd624b03ec0958dceba3dc7 (diff) | |
parent | eda12bd009d8f71eb82b6e6238335a172d6e5fb0 (diff) |
merge
Diffstat (limited to 'indra/llui/lltoolbar.cpp')
-rw-r--r-- | indra/llui/lltoolbar.cpp | 111 |
1 files changed, 93 insertions, 18 deletions
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index efa077ffa1..07beb147d7 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::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) @@ -525,8 +601,8 @@ LLToolBarButton* LLToolBar::createButton(const LLCommandId& id) if (!mReadOnly) { LLUICtrl::CommitCallbackParam cbParam; - cbParam.function_name = commandp->functionName(); - cbParam.parameter = commandp->parameter(); + cbParam.function_name = commandp->executeFunctionName(); + cbParam.parameter = commandp->executeParameters(); button->setCommitCallback(cbParam); button->setStartDragCallback(mStartDragItemCallback); button->setHandleDragCallback(mHandleDragItemCallback); @@ -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; @@ -570,7 +646,6 @@ LLToolBarButton::LLToolBarButton(const Params& p) mDesiredHeight(p.desired_height), mId("") { - mUUID = LLUUID::generateNewID(p.name); } BOOL LLToolBarButton::handleMouseDown(S32 x, S32 y, MASK mask) @@ -589,15 +664,15 @@ 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 { handled = LLButton::handleHover(x, y, mask); |