summaryrefslogtreecommitdiff
path: root/indra/newview/llfavoritesbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llfavoritesbar.cpp')
-rw-r--r--indra/newview/llfavoritesbar.cpp197
1 files changed, 135 insertions, 62 deletions
diff --git a/indra/newview/llfavoritesbar.cpp b/indra/newview/llfavoritesbar.cpp
index 6dcfa95a0e..98de418878 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"
@@ -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.
@@ -893,84 +895,155 @@ 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);
+ }
+
+ 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();
+}
- if (menu)
+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);
+ item_params.on_click.function(boost::bind(&LLFloaterSidePanelContainer::showPanel, "places", LLSD()));
+ 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(mMoreTextBox->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)