diff options
Diffstat (limited to 'indra/newview/llfavoritesbar.cpp')
-rw-r--r-- | indra/newview/llfavoritesbar.cpp | 388 |
1 files changed, 244 insertions, 144 deletions
diff --git a/indra/newview/llfavoritesbar.cpp b/indra/newview/llfavoritesbar.cpp index 0b17d64eb0..575b613ccf 100644 --- a/indra/newview/llfavoritesbar.cpp +++ b/indra/newview/llfavoritesbar.cpp @@ -31,6 +31,7 @@ #include "llfocusmgr.h" #include "llinventory.h" #include "lllandmarkactions.h" +#include "lltoolbarview.h" #include "lltrans.h" #include "lluictrlfactory.h" #include "llmenugl.h" @@ -38,13 +39,13 @@ #include "llagent.h" #include "llclipboard.h" -#include "llinventoryclipboard.h" +#include "llclipboard.h" #include "llinventorybridge.h" #include "llinventoryfunctions.h" +#include "llfloatersidepanelcontainer.h" #include "llfloaterworldmap.h" #include "lllandmarkactions.h" #include "llnotificationsutil.h" -#include "llsidetray.h" #include "lltoggleablemenu.h" #include "llviewerinventory.h" #include "llviewermenu.h" @@ -54,6 +55,7 @@ static LLDefaultChildRegistry::Register<LLFavoritesBarCtrl> r("favorites_bar"); const S32 DROP_DOWN_MENU_WIDTH = 250; +const S32 DROP_DOWN_MENU_TOP_PAD = 13; /** * Helper for LLFavoriteLandmarkButton and LLFavoriteLandmarkMenuItem. @@ -360,7 +362,7 @@ struct LLFavoritesSort LLFavoritesBarCtrl::Params::Params() : image_drag_indication("image_drag_indication"), - chevron_button("chevron_button"), + more_button("more_button"), label("label") { } @@ -389,10 +391,10 @@ LLFavoritesBarCtrl::LLFavoritesBarCtrl(const LLFavoritesBarCtrl::Params& p) gInventory.addObserver(this); //make chevron button - LLButton::Params chevron_button_params(p.chevron_button); - chevron_button_params.click_callback.function(boost::bind(&LLFavoritesBarCtrl::showDropDownMenu, this)); - mChevronButton = LLUICtrlFactory::create<LLButton> (chevron_button_params); - addChild(mChevronButton); + LLTextBox::Params more_button_params(p.more_button); + mMoreTextBox = LLUICtrlFactory::create<LLTextBox> (more_button_params); + mMoreTextBox->setClickedCallback(boost::bind(&LLFavoritesBarCtrl::showDropDownMenu, this)); + addChild(mMoreTextBox); LLTextBox::Params label_param(p.label); mBarLabel = LLUICtrlFactory::create<LLTextBox> (label_param); @@ -403,8 +405,8 @@ LLFavoritesBarCtrl::~LLFavoritesBarCtrl() { gInventory.removeObserver(this); - LLView::deleteViewByHandle(mOverflowMenuHandle); - LLView::deleteViewByHandle(mContextMenuHandle); + if (mOverflowMenuHandle.get()) mOverflowMenuHandle.get()->die(); + if (mContextMenuHandle.get()) mContextMenuHandle.get()->die(); } BOOL LLFavoritesBarCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, @@ -441,17 +443,17 @@ BOOL LLFavoritesBarCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, { setLandingTab(dest); } - /* - * the condition dest == NULL can be satisfied not only in the case - * of dragging to the right from the last tab of the favbar. there is a - * small gap between each tab. if the user drags something exactly there - * then mLandingTab will be set to NULL and the dragged item will be pushed - * to the end of the favorites bar. this is incorrect behavior. that's why - * we need an additional check which excludes the case described previously - * making sure that the mouse pointer is beyond the last tab. - */ - else if (mLastTab && x >= mLastTab->getRect().mRight) + else if (mLastTab && (x >= mLastTab->getRect().mRight)) { + /* + * the condition dest == NULL can be satisfied not only in the case + * of dragging to the right from the last tab of the favbar. there is a + * small gap between each tab. if the user drags something exactly there + * then mLandingTab will be set to NULL and the dragged item will be pushed + * to the end of the favorites bar. this is incorrect behavior. that's why + * we need an additional check which excludes the case described previously + * making sure that the mouse pointer is beyond the last tab. + */ setLandingTab(NULL); } @@ -465,7 +467,6 @@ BOOL LLFavoritesBarCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, if (drop) { handleExistingFavoriteDragAndDrop(x, y); - showDragMarker(FALSE); } } else @@ -488,7 +489,6 @@ BOOL LLFavoritesBarCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, setLandingTab(NULL); } handleNewFavoriteDragAndDrop(item, favorites_id, x, y); - showDragMarker(FALSE); } } } @@ -502,20 +502,29 @@ BOOL LLFavoritesBarCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, void LLFavoritesBarCtrl::handleExistingFavoriteDragAndDrop(S32 x, S32 y) { + // Identify the button hovered and the side to drop LLFavoriteLandmarkButton* dest = dynamic_cast<LLFavoriteLandmarkButton*>(mLandingTab); + bool insert_before = true; + if (!dest) + { + insert_before = false; + dest = dynamic_cast<LLFavoriteLandmarkButton*>(mLastTab); + } - // there is no need to handle if an item was dragged onto itself + // There is no need to handle if an item was dragged onto itself if (dest && dest->getLandmarkId() == mDragItemId) { return; } + // Insert the dragged item in the right place if (dest) { - LLInventoryModel::updateItemsOrder(mItems, mDragItemId, dest->getLandmarkId()); + LLInventoryModel::updateItemsOrder(mItems, mDragItemId, dest->getLandmarkId(), insert_before); } else { + // This can happen when the item list is empty mItems.push_back(gInventory.getItem(mDragItemId)); } @@ -532,22 +541,35 @@ void LLFavoritesBarCtrl::handleExistingFavoriteDragAndDrop(S32 x, S32 y) void LLFavoritesBarCtrl::handleNewFavoriteDragAndDrop(LLInventoryItem *item, const LLUUID& favorites_id, S32 x, S32 y) { - LLFavoriteLandmarkButton* dest = dynamic_cast<LLFavoriteLandmarkButton*>(mLandingTab); - - // there is no need to handle if an item was dragged onto itself + // Identify the button hovered and the side to drop + LLFavoriteLandmarkButton* dest = NULL; + bool insert_before = true; + if (!mItems.empty()) + { + dest = dynamic_cast<LLFavoriteLandmarkButton*>(mLandingTab); + if (!dest) + { + insert_before = false; + dest = dynamic_cast<LLFavoriteLandmarkButton*>(mLastTab); + } + } + + // There is no need to handle if an item was dragged onto itself if (dest && dest->getLandmarkId() == mDragItemId) { return; } - + LLPointer<LLViewerInventoryItem> viewer_item = new LLViewerInventoryItem(item); + // Insert the dragged item in the right place if (dest) { - insertBeforeItem(mItems, dest->getLandmarkId(), viewer_item); + insertItem(mItems, dest->getLandmarkId(), viewer_item, insert_before); } else { + // This can happen when the item list is empty mItems.push_back(viewer_item); } @@ -577,7 +599,11 @@ void LLFavoritesBarCtrl::handleNewFavoriteDragAndDrop(LLInventoryItem *item, con if (tool_dad->getSource() == LLToolDragAndDrop::SOURCE_NOTECARD) { viewer_item->setType(LLAssetType::AT_LANDMARK); - copy_inventory_from_notecard(tool_dad->getObjectID(), tool_dad->getSourceID(), viewer_item.get(), gInventoryCallbacks.registerCB(cb)); + copy_inventory_from_notecard(favorites_id, + tool_dad->getObjectID(), + tool_dad->getSourceID(), + viewer_item.get(), + gInventoryCallbacks.registerCB(cb)); } else { @@ -640,7 +666,7 @@ void LLFavoritesBarCtrl::draw() { // mouse pointer hovers over an existing tab LLRect rect = mLandingTab->getRect(); - mImageDragIndication->draw(rect.mLeft - w/2, rect.getHeight(), w, h); + mImageDragIndication->draw(rect.mLeft, rect.getHeight(), w, h); } else if (mLastTab) { @@ -648,6 +674,8 @@ void LLFavoritesBarCtrl::draw() LLRect rect = mLastTab->getRect(); mImageDragIndication->draw(rect.mRight, rect.getHeight(), w, h); } + // Once drawn, mark this false so we won't draw it again (unless we hit the favorite bar again) + mShowDragMarker = FALSE; } } @@ -692,7 +720,7 @@ void LLFavoritesBarCtrl::updateButtons() const child_list_t* childs = getChildList(); child_list_const_iter_t child_it = childs->begin(); int first_changed_item_index = 0; - int rightest_point = getRect().mRight - mChevronButton->getRect().getWidth(); + int rightest_point = getRect().mRight - mMoreTextBox->getRect().getWidth(); //lets find first changed button while (child_it != childs->end() && first_changed_item_index < mItems.count()) { @@ -719,7 +747,7 @@ void LLFavoritesBarCtrl::updateButtons() if (first_changed_item_index <= mItems.count()) { // Rebuild the buttons only - // child_list_t is a linked list, so safe to erase from the middle if we pre-incrament the iterator + // child_list_t is a linked list, so safe to erase from the middle if we pre-increment the iterator while (child_it != childs->end()) { @@ -735,9 +763,9 @@ void LLFavoritesBarCtrl::updateButtons() } // we have to remove ChevronButton to make sure that the last item will be LandmarkButton to get the right aligning // keep in mind that we are cutting all buttons in space between the last visible child of favbar and ChevronButton - if (mChevronButton->getParent() == this) + if (mMoreTextBox->getParent() == this) { - removeChild(mChevronButton); + removeChild(mMoreTextBox); } int last_right_edge = 0; //calculate new buttons offset @@ -777,13 +805,13 @@ void LLFavoritesBarCtrl::updateButtons() S32 buttonHGap = button_params.rect.left; // default value LLRect rect; // Chevron button should stay right aligned - rect.setOriginAndSize(getRect().mRight - mChevronButton->getRect().getWidth() - buttonHGap, 0, - mChevronButton->getRect().getWidth(), - mChevronButton->getRect().getHeight()); + rect.setOriginAndSize(getRect().mRight - mMoreTextBox->getRect().getWidth() - buttonHGap, 0, + mMoreTextBox->getRect().getWidth(), + mMoreTextBox->getRect().getHeight()); - addChild(mChevronButton); - mChevronButton->setRect(rect); - mChevronButton->setVisible(TRUE); + addChild(mMoreTextBox); + mMoreTextBox->setRect(rect); + mMoreTextBox->setVisible(TRUE); } // Update overflow menu LLToggleableMenu* overflow_menu = static_cast <LLToggleableMenu*> (mOverflowMenuHandle.get()); @@ -808,16 +836,16 @@ LLButton* LLFavoritesBarCtrl::createButton(const LLPointer<LLViewerInventoryItem /** * WORKAROUND: - * there are some problem with displaying of fonts in buttons. - * Empty space (or ...) is displaying instead of last symbols, even though the width of the button is enough. - * Problem will gone, if we stretch out the button. For that reason I have to put additional 20 pixels. + * There are some problem with displaying of fonts in buttons. + * Empty space or ellipsis might be displayed instead of last symbols, even though the width of the button is enough. + * The problem disappears if we pad the button with 20 pixels. */ int required_width = mFont->getWidth(item->getName()) + 20; int width = required_width > def_button_width? def_button_width : required_width; LLFavoriteLandmarkButton* fav_btn = NULL; - // do we have a place for next button + double buttonHGap + mChevronButton ? - if(curr_x + width + 2*button_x_delta + mChevronButton->getRect().getWidth() > getRect().mRight ) + // do we have a place for next button + double buttonHGap + mMoreTextBox ? + if(curr_x + width + 2*button_x_delta + mMoreTextBox->getRect().getWidth() > getRect().mRight ) { return NULL; } @@ -838,7 +866,6 @@ LLButton* LLFavoritesBarCtrl::createButton(const LLPointer<LLViewerInventoryItem fav_btn->setRect(butt_rect); // change only left and save bottom fav_btn->setFont(mFont); - fav_btn->setName(item->getName()); fav_btn->setLabel(item->getName()); fav_btn->setToolTip(item->getName()); fav_btn->setCommitCallback(boost::bind(&LLFavoritesBarCtrl::onButtonClick, this, item->getUUID())); @@ -893,84 +920,157 @@ void LLFavoritesBarCtrl::showDropDownMenu() { if (mOverflowMenuHandle.isDead()) { - LLToggleableMenu::Params menu_p; - menu_p.name("favorites menu"); - menu_p.can_tear_off(false); - menu_p.visible(false); - menu_p.scrollable(true); - menu_p.max_scrollable_items = 10; - menu_p.preferred_width = DROP_DOWN_MENU_WIDTH; - - LLToggleableMenu* menu = LLUICtrlFactory::create<LLFavoriteLandmarkToggleableMenu>(menu_p); - mOverflowMenuHandle = menu->getHandle(); + createOverflowMenu(); } LLToggleableMenu* menu = (LLToggleableMenu*)mOverflowMenuHandle.get(); + if (menu && menu->toggleVisibility()) + { + if (mUpdateDropDownItems) + { + updateMenuItems(menu); + } - if (menu) + menu->buildDrawLabels(); + menu->updateParent(LLMenuGL::sMenuContainer); + menu->setButtonRect(mMoreTextBox->getRect(), this); + positionAndShowMenu(menu); + } +} + +void LLFavoritesBarCtrl::createOverflowMenu() +{ + LLToggleableMenu::Params menu_p; + menu_p.name("favorites menu"); + menu_p.can_tear_off(false); + menu_p.visible(false); + menu_p.scrollable(true); + menu_p.max_scrollable_items = 10; + menu_p.preferred_width = DROP_DOWN_MENU_WIDTH; + + LLToggleableMenu* menu = LLUICtrlFactory::create<LLFavoriteLandmarkToggleableMenu>(menu_p); + mOverflowMenuHandle = menu->getHandle(); +} + +void LLFavoritesBarCtrl::updateMenuItems(LLToggleableMenu* menu) +{ + menu->empty(); + + U32 widest_item = 0; + + for (S32 i = mFirstDropDownItem; i < mItems.count(); i++) { - if (!menu->toggleVisibility()) - return; + LLViewerInventoryItem* item = mItems.get(i); + const std::string& item_name = item->getName(); - U32 max_width = llmin(DROP_DOWN_MENU_WIDTH, getRect().getWidth()); - if (mUpdateDropDownItems) + LLFavoriteLandmarkMenuItem::Params item_params; + item_params.name(item_name); + item_params.label(item_name); + item_params.on_click.function(boost::bind(&LLFavoritesBarCtrl::onButtonClick, this, item->getUUID())); + + LLFavoriteLandmarkMenuItem *menu_item = LLUICtrlFactory::create<LLFavoriteLandmarkMenuItem>(item_params); + menu_item->initFavoritesBarPointer(this); + menu_item->setRightMouseDownCallback(boost::bind(&LLFavoritesBarCtrl::onButtonRightClick, this, item->getUUID(), _1, _2, _3, _4)); + menu_item->LLUICtrl::setMouseDownCallback(boost::bind(&LLFavoritesBarCtrl::onButtonMouseDown, this, item->getUUID(), _1, _2, _3, _4)); + menu_item->LLUICtrl::setMouseUpCallback(boost::bind(&LLFavoritesBarCtrl::onButtonMouseUp, this, item->getUUID(), _1, _2, _3, _4)); + menu_item->setLandmarkID(item->getUUID()); + + fitLabelWidth(menu_item); + + widest_item = llmax(widest_item, menu_item->getNominalWidth()); + + menu->addChild(menu_item); + } + + addOpenLandmarksMenuItem(menu); + mUpdateDropDownItems = false; +} + +void LLFavoritesBarCtrl::fitLabelWidth(LLMenuItemCallGL* menu_item) +{ + U32 max_width = llmin(DROP_DOWN_MENU_WIDTH, getRect().getWidth()); + std::string item_name = menu_item->getName(); + + // Check whether item name wider than menu + if (menu_item->getNominalWidth() > max_width) + { + S32 chars_total = item_name.length(); + S32 chars_fitted = 1; + menu_item->setLabel(LLStringExplicit("")); + S32 label_space = max_width - menu_item->getFont()->getWidth("...") - + menu_item->getNominalWidth();// This returns width of menu item with empty label (pad pixels) + + while (chars_fitted < chars_total + && menu_item->getFont()->getWidth(item_name, 0, chars_fitted) < label_space) { - menu->empty(); + chars_fitted++; + } + chars_fitted--; // Rolling back one char, that doesn't fit - U32 widest_item = 0; + menu_item->setLabel(item_name.substr(0, chars_fitted) + "..."); + } +} - for (S32 i = mFirstDropDownItem; i < mItems.count(); i++) - { - LLViewerInventoryItem* item = mItems.get(i); - const std::string& item_name = item->getName(); - - LLFavoriteLandmarkMenuItem::Params item_params; - item_params.name(item_name); - item_params.label(item_name); - - item_params.on_click.function(boost::bind( - &LLFavoritesBarCtrl::onButtonClick, this, - item->getUUID())); - LLFavoriteLandmarkMenuItem *menu_item = LLUICtrlFactory::create<LLFavoriteLandmarkMenuItem>(item_params); - menu_item->initFavoritesBarPointer(this); - menu_item->setRightMouseDownCallback(boost::bind(&LLFavoritesBarCtrl::onButtonRightClick, this, item->getUUID(), _1, _2, _3, _4)); - menu_item->LLUICtrl::setMouseDownCallback(boost::bind(&LLFavoritesBarCtrl::onButtonMouseDown, this, item->getUUID(), _1, _2, _3, _4)); - menu_item->LLUICtrl::setMouseUpCallback(boost::bind(&LLFavoritesBarCtrl::onButtonMouseUp, this, item->getUUID(), _1, _2, _3, _4)); - menu_item->setLandmarkID(item->getUUID()); - - // Check whether item name wider than menu - if (menu_item->getNominalWidth() > max_width) - { - S32 chars_total = item_name.length(); - S32 chars_fitted = 1; - menu_item->setLabel(LLStringExplicit("")); - S32 label_space = max_width - menu_item->getFont()->getWidth("...") - - menu_item->getNominalWidth();// This returns width of menu item with empty label (pad pixels) - - while (chars_fitted < chars_total - && menu_item->getFont()->getWidth(item_name, 0, chars_fitted) < label_space) - { - chars_fitted++; - } - chars_fitted--; // Rolling back one char, that doesn't fit +void LLFavoritesBarCtrl::addOpenLandmarksMenuItem(LLToggleableMenu* menu) +{ + std::string label_untrans = "Open landmarks"; + std::string label_transl; + bool translated = LLTrans::findString(label_transl, label_untrans); + + LLMenuItemCallGL::Params item_params; + item_params.name("open_my_landmarks"); + item_params.label(translated ? label_transl: label_untrans); + LLSD key; + key["type"] = "open_landmark_tab"; + item_params.on_click.function(boost::bind(&LLFloaterSidePanelContainer::showPanel, "places", key)); + LLMenuItemCallGL* menu_item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params); + + fitLabelWidth(menu_item); + + LLMenuItemSeparatorGL::Params sep_params; + sep_params.enabled_color=LLUIColorTable::instance().getColor("MenuItemEnabledColor"); + sep_params.disabled_color=LLUIColorTable::instance().getColor("MenuItemDisabledColor"); + sep_params.highlight_bg_color=LLUIColorTable::instance().getColor("MenuItemHighlightBgColor"); + sep_params.highlight_fg_color=LLUIColorTable::instance().getColor("MenuItemHighlightFgColor"); + LLMenuItemSeparatorGL* separator = LLUICtrlFactory::create<LLMenuItemSeparatorGL>(sep_params); + + menu->addChild(separator); + menu->addChild(menu_item); +} - menu_item->setLabel(item_name.substr(0, chars_fitted) - + "..."); - } - widest_item = llmax(widest_item, menu_item->getNominalWidth()); +void LLFavoritesBarCtrl::positionAndShowMenu(LLToggleableMenu* menu) +{ + U32 max_width = llmin(DROP_DOWN_MENU_WIDTH, getRect().getWidth()); - menu->addChild(menu_item); - } - mUpdateDropDownItems = false; + S32 menu_x = getRect().getWidth() - max_width; + S32 menu_y = getParent()->getRect().mBottom - DROP_DOWN_MENU_TOP_PAD; + + // the menu should be offset of the right edge of the window + // so it's no covered by buttons in the right-side toolbar. + LLToolBar* right_toolbar = gToolBarView->getChild<LLToolBar>("toolbar_right"); + if (right_toolbar && right_toolbar->hasButtons()) + { + S32 toolbar_top = 0; + + if (LLView* top_border_panel = right_toolbar->getChild<LLView>("button_panel")) + { + toolbar_top = top_border_panel->calcScreenRect().mTop; } - menu->buildDrawLabels(); - menu->updateParent(LLMenuGL::sMenuContainer); + // Calculating the bottom (in screen coord) of the drop down menu + S32 menu_top = getParent()->getRect().mBottom - DROP_DOWN_MENU_TOP_PAD; + S32 menu_bottom = menu_top - menu->getRect().getHeight(); + S32 menu_bottom_screen = 0; - menu->setButtonRect(mChevronButton->getRect(), this); + localPointToScreen(0, menu_bottom, &menu_top, &menu_bottom_screen); - LLMenuGL::showPopup(this, menu, getRect().getWidth() - max_width, 0); + if (menu_bottom_screen < toolbar_top) + { + menu_x -= right_toolbar->getRect().getWidth(); + } } + + LLMenuGL::showPopup(this, menu, menu_x, menu_y); } void LLFavoritesBarCtrl::onButtonClick(LLUUID item_id) @@ -1018,7 +1118,7 @@ BOOL LLFavoritesBarCtrl::handleRightMouseDown(S32 x, S32 y, MASK mask) } void copy_slurl_to_clipboard_cb(std::string& slurl) { - gClipboard.copyFromString(utf8str_to_wstring(slurl)); + LLClipboard::instance().copyToClipboard(utf8str_to_wstring(slurl),0,slurl.size()); LLSD args; args["SLURL"] = slurl; @@ -1057,7 +1157,7 @@ void LLFavoritesBarCtrl::doToSelected(const LLSD& userdata) key["type"] = "landmark"; key["id"] = mSelectedItemID; - LLSideTray::getInstance()->showPanel("panel_places", key); + LLFloaterSidePanelContainer::showPanel("places", key); } else if (action == "copy_slurl") { @@ -1087,7 +1187,7 @@ void LLFavoritesBarCtrl::doToSelected(const LLSD& userdata) } else if (action == "copy") { - LLInventoryClipboard::instance().store(mSelectedItemID); + LLClipboard::instance().copyToClipboard(mSelectedItemID, LLAssetType::AT_LANDMARK); } else if (action == "paste") { @@ -1103,19 +1203,21 @@ void LLFavoritesBarCtrl::doToSelected(const LLSD& userdata) LLToggleableMenu* menu = (LLToggleableMenu*) mOverflowMenuHandle.get(); if (mRestoreOverflowMenu && menu && !menu->getVisible()) { + menu->resetScrollPositionOnShow(false); showDropDownMenu(); + menu->resetScrollPositionOnShow(true); } } BOOL LLFavoritesBarCtrl::isClipboardPasteable() const { - if (!LLInventoryClipboard::instance().hasContents()) + if (!LLClipboard::instance().hasContents()) { return FALSE; } LLDynamicArray<LLUUID> objects; - LLInventoryClipboard::instance().retrieve(objects); + LLClipboard::instance().pasteFromClipboard(objects); S32 count = objects.count(); for(S32 i = 0; i < count; i++) { @@ -1144,7 +1246,7 @@ void LLFavoritesBarCtrl::pastFromClipboard() const { LLInventoryItem* item = NULL; LLDynamicArray<LLUUID> objects; - LLInventoryClipboard::instance().retrieve(objects); + LLClipboard::instance().pasteFromClipboard(objects); S32 count = objects.count(); LLUUID parent_id(mFavoriteFolderId); for(S32 i = 0; i < count; i++) @@ -1225,25 +1327,24 @@ BOOL LLFavoritesBarCtrl::handleHover(S32 x, S32 y, MASK mask) LLUICtrl* LLFavoritesBarCtrl::findChildByLocalCoords(S32 x, S32 y) { - LLUICtrl* ctrl = 0; - S32 screenX, screenY; + LLUICtrl* ctrl = NULL; const child_list_t* list = getChildList(); - localPointToScreen(x, y, &screenX, &screenY); - - // look for a child which contains the point (screenX, screenY) in it's rectangle for (child_list_const_iter_t i = list->begin(); i != list->end(); ++i) { - LLRect rect; - localRectToScreen((*i)->getRect(), &rect); - - if (rect.pointInRect(screenX, screenY)) + // Look only for children that are favorite buttons + if ((*i)->getName() == "favorites_bar_btn") { - ctrl = dynamic_cast<LLUICtrl*>(*i); - break; + LLRect rect = (*i)->getRect(); + // We consider a button hit if the cursor is left of the right side + // This makes the hit a bit less finicky than hitting directly on the button itself + if (x <= rect.mRight) + { + ctrl = dynamic_cast<LLUICtrl*>(*i); + break; + } } } - return ctrl; } @@ -1264,29 +1365,28 @@ BOOL LLFavoritesBarCtrl::needToSaveItemsOrder(const LLInventoryModel::item_array return result; } -LLInventoryModel::item_array_t::iterator LLFavoritesBarCtrl::findItemByUUID(LLInventoryModel::item_array_t& items, const LLUUID& id) +void LLFavoritesBarCtrl::insertItem(LLInventoryModel::item_array_t& items, const LLUUID& dest_item_id, LLViewerInventoryItem* insertedItem, bool insert_before) { - LLInventoryModel::item_array_t::iterator result = items.end(); + // Get the iterator to the destination item + LLInventoryModel::item_array_t::iterator it_dest = LLInventoryModel::findItemIterByUUID(items, dest_item_id); + if (it_dest == items.end()) + return; - for (LLInventoryModel::item_array_t::iterator i = items.begin(); i != items.end(); ++i) + // Go to the next element if one wishes to insert after the dest element + if (!insert_before) { - if ((*i)->getUUID() == id) - { - result = i; - break; - } + ++it_dest; } - - return result; -} - -void LLFavoritesBarCtrl::insertBeforeItem(LLInventoryModel::item_array_t& items, const LLUUID& beforeItemId, LLViewerInventoryItem* insertedItem) -{ - LLViewerInventoryItem* beforeItem = gInventory.getItem(beforeItemId); - llassert(beforeItem); - if (beforeItem) + + // Insert the source item in the right place + if (it_dest != items.end()) + { + items.insert(it_dest, insertedItem); + } + else { - items.insert(findItemByUUID(items, beforeItem->getUUID()), insertedItem); + // Append to the list if it_dest reached the end + items.push_back(insertedItem); } } |