Set tooltip for vertical tabs

This commit is contained in:
miKaぴょん
2015-10-05 17:50:35 +02:00
parent 1c40bcf63d
commit fa07fcf5a7

View File

@@ -1,11 +1,11 @@
/** /**
* @file lltabcontainer.cpp * @file lltabcontainer.cpp
* @brief LLTabContainer class * @brief LLTabContainer class
* *
* $LicenseInfo:firstyear=2001&license=viewergpl$ * $LicenseInfo:firstyear=2001&license=viewergpl$
* *
* Copyright (c) 2001-2009, Linden Research, Inc. * Copyright (c) 2001-2009, Linden Research, Inc.
* *
* Second Life Viewer Source Code * Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab * The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0 * to you under the terms of the GNU General Public License, version 2.0
@@ -13,17 +13,17 @@
* ("Other License"), formally executed by you and Linden Lab. Terms of * ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or * the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
* *
* There are special exceptions to the terms and conditions of the GPL as * There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception * it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or * in the file doc/FLOSS-exception.txt in this software distribution, or
* online at * online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception * http://secondlifegrid.net/programs/open_source/licensing/flossexception
* *
* By copying, modifying or distributing this software, you acknowledge * By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above, * that you have read and understood your obligations described above,
* and agree to abide by those obligations. * and agree to abide by those obligations.
* *
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE. * COMPLETENESS OR PERFORMANCE.
@@ -92,7 +92,7 @@ public:
LLTabContainer::LLTabContainer(const std::string& name, const LLRect& rect, TabPosition pos, LLTabContainer::LLTabContainer(const std::string& name, const LLRect& rect, TabPosition pos,
BOOL bordered, BOOL is_vertical ) BOOL bordered, BOOL is_vertical )
: :
LLPanel(name, rect, bordered), LLPanel(name, rect, bordered),
mCurrentTabIdx(-1), mCurrentTabIdx(-1),
mTabsHidden(FALSE), mTabsHidden(FALSE),
@@ -114,7 +114,7 @@ LLTabContainer::LLTabContainer(const std::string& name, const LLRect& rect, TabP
mJumpNextArrowBtn(NULL), mJumpNextArrowBtn(NULL),
mRightTabBtnOffset(0), mRightTabBtnOffset(0),
mTotalTabWidth(0) mTotalTabWidth(0)
{ {
//RN: HACK to support default min width for legacy vertical tab containers //RN: HACK to support default min width for legacy vertical tab containers
if (mIsVertical) if (mIsVertical)
{ {
@@ -237,7 +237,7 @@ void LLTabContainer::draw()
left = LLPANEL_BORDER_WIDTH + (has_scroll_arrows ? (TABCNTR_ARROW_BTN_SIZE * 2) : TABCNTR_TAB_H_PAD); left = LLPANEL_BORDER_WIDTH + (has_scroll_arrows ? (TABCNTR_ARROW_BTN_SIZE * 2) : TABCNTR_TAB_H_PAD);
left -= getScrollPosPixels(); left -= getScrollPosPixels();
} }
// Hide all the buttons // Hide all the buttons
if (getTabsHidden() || mIsVertical) if (getTabsHidden() || mIsVertical)
{ {
@@ -507,7 +507,7 @@ BOOL LLTabContainer::handleMouseUp( S32 x, S32 y, MASK mask )
BOOL LLTabContainer::handleToolTip( S32 x, S32 y, std::string& msg, LLRect* sticky_rect ) BOOL LLTabContainer::handleToolTip( S32 x, S32 y, std::string& msg, LLRect* sticky_rect )
{ {
BOOL handled = LLPanel::handleToolTip( x, y, msg, sticky_rect ); BOOL handled = LLPanel::handleToolTip( x, y, msg, sticky_rect );
if (!handled && getTabCount() > 0 && !getTabsHidden()) if (!handled && getTabCount() > 0 && !getTabsHidden())
{ {
LLTabTuple* firsttuple = getTab(0); LLTabTuple* firsttuple = getTab(0);
@@ -700,7 +700,7 @@ BOOL LLTabContainer::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDrag
mDragAndDropDelayTimer.stop(); mDragAndDropDelayTimer.stop();
} }
} }
else else
{ {
// Start a timer so we don't open tabs as soon as we hover on them // Start a timer so we don't open tabs as soon as we hover on them
mDragAndDropDelayTimer.start(); mDragAndDropDelayTimer.start();
@@ -710,9 +710,9 @@ BOOL LLTabContainer::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDrag
return LLView::handleDragAndDrop(x, y, mask, drop, type, cargo_data, accept, tooltip); return LLView::handleDragAndDrop(x, y, mask, drop, type, cargo_data, accept, tooltip);
} }
void LLTabContainer::addTabPanel(LLPanel* child, void LLTabContainer::addTabPanel(LLPanel* child,
const std::string& label, const std::string& label,
BOOL select, BOOL select,
S32 indent, S32 indent,
BOOL placeholder, BOOL placeholder,
eInsertionPoint insertion_point) eInsertionPoint insertion_point)
@@ -735,16 +735,16 @@ void LLTabContainer::addTabPanel(LLPanel* child,
{ {
button_width = llclamp(font->getWidth(trimmed_label) + TAB_PADDING, mMinTabWidth, mMaxTabWidth); button_width = llclamp(font->getWidth(trimmed_label) + TAB_PADDING, mMinTabWidth, mMaxTabWidth);
} }
// Tab panel // Tab panel
S32 tab_panel_top; S32 tab_panel_top;
S32 tab_panel_bottom; S32 tab_panel_bottom;
if (!getTabsHidden()) if (!getTabsHidden())
{ {
if( getTabPosition() == LLTabContainer::TOP ) if( getTabPosition() == LLTabContainer::TOP )
{ {
S32 tab_height = mIsVertical ? BTN_HEIGHT : TABCNTR_TAB_HEIGHT; S32 tab_height = mIsVertical ? BTN_HEIGHT : TABCNTR_TAB_HEIGHT;
tab_panel_top = getRect().getHeight() - getTopBorderHeight() - (tab_height - TABCNTR_BUTTON_PANEL_OVERLAP); tab_panel_top = getRect().getHeight() - getTopBorderHeight() - (tab_height - TABCNTR_BUTTON_PANEL_OVERLAP);
tab_panel_bottom = LLPANEL_BORDER_WIDTH; tab_panel_bottom = LLPANEL_BORDER_WIDTH;
} }
else else
@@ -769,7 +769,7 @@ void LLTabContainer::addTabPanel(LLPanel* child,
} }
else else
{ {
tab_panel_rect = LLRect(LLPANEL_BORDER_WIDTH, tab_panel_rect = LLRect(LLPANEL_BORDER_WIDTH,
tab_panel_top, tab_panel_top,
getRect().getWidth()-LLPANEL_BORDER_WIDTH, getRect().getWidth()-LLPANEL_BORDER_WIDTH,
tab_panel_bottom ); tab_panel_bottom );
@@ -811,12 +811,12 @@ void LLTabContainer::addTabPanel(LLPanel* child,
LLTextBox* textbox = NULL; LLTextBox* textbox = NULL;
LLButton* btn = NULL; LLButton* btn = NULL;
if (placeholder) if (placeholder)
{ {
btn_rect.translate(0, -LLBUTTON_V_PAD-2); btn_rect.translate(0, -LLBUTTON_V_PAD-2);
textbox = new LLTextBox(trimmed_label, btn_rect, trimmed_label, font); textbox = new LLTextBox(trimmed_label, btn_rect, trimmed_label, font);
btn = new LLButton(LLStringUtil::null); btn = new LLButton(LLStringUtil::null);
} }
else else
@@ -826,8 +826,8 @@ void LLTabContainer::addTabPanel(LLPanel* child,
btn = new LLButton(std::string("vert tab button"), btn = new LLButton(std::string("vert tab button"),
btn_rect, btn_rect,
LLStringUtil::null, LLStringUtil::null,
LLStringUtil::null, LLStringUtil::null,
LLStringUtil::null, LLStringUtil::null,
NULL, NULL,
font, font,
trimmed_label, trimmed_label); trimmed_label, trimmed_label);
@@ -843,18 +843,13 @@ void LLTabContainer::addTabPanel(LLPanel* child,
} }
else else
{ {
std::string tooltip = trimmed_label;
tooltip += "\nAlt-Left arrow for previous tab";
tooltip += "\nAlt-Right arrow for next tab";
btn = new LLButton(std::string(child->getName()) + " tab", btn = new LLButton(std::string(child->getName()) + " tab",
btn_rect, btn_rect,
LLStringUtil::null, LLStringUtil::null, LLStringUtil::null, LLStringUtil::null, LLStringUtil::null, LLStringUtil::null,
NULL, // set userdata below NULL, // set userdata below
font, font,
trimmed_label, trimmed_label ); trimmed_label, trimmed_label );
btn->setVisible( FALSE ); btn->setVisible( FALSE );
btn->setToolTip( tooltip );
btn->setScaleImage(TRUE); btn->setScaleImage(TRUE);
btn->setImages(tab_img, tab_selected_img); btn->setImages(tab_img, tab_selected_img);
@@ -877,8 +872,13 @@ void LLTabContainer::addTabPanel(LLPanel* child,
btn->setFollowsBottom(); btn->setFollowsBottom();
} }
} }
std::string tooltip = trimmed_label;
// FIXME: Tooltip can not be translated when hardcoded.
tooltip += "\nAlt-Left arrow for previous tab";
tooltip += "\nAlt-Right arrow for next tab";
btn->setToolTip( tooltip );
} }
LLTabTuple* tuple = new LLTabTuple( this, child, btn, textbox ); LLTabTuple* tuple = new LLTabTuple( this, child, btn, textbox );
insertTuple( tuple, insertion_point ); insertTuple( tuple, insertion_point );
@@ -906,7 +906,7 @@ void LLTabContainer::addTabPanel(LLPanel* child,
sendChildToFront(mNextArrowBtn); sendChildToFront(mNextArrowBtn);
sendChildToFront(mJumpPrevArrowBtn); sendChildToFront(mJumpPrevArrowBtn);
sendChildToFront(mJumpNextArrowBtn); sendChildToFront(mJumpNextArrowBtn);
if( select ) if( select )
{ {
selectLastTab(); selectLastTab();
@@ -958,7 +958,7 @@ void LLTabContainer::removeTabPanel(LLPanel* child)
} }
} }
} }
BOOL has_focus = gFocusMgr.childHasKeyboardFocus(this); BOOL has_focus = gFocusMgr.childHasKeyboardFocus(this);
// If the tab being deleted is the selected one, select a different tab. // If the tab being deleted is the selected one, select a different tab.
@@ -972,7 +972,7 @@ void LLTabContainer::removeTabPanel(LLPanel* child)
removeChild( tuple->mTabPanel ); removeChild( tuple->mTabPanel );
// delete tuple->mTabPanel; // delete tuple->mTabPanel;
mTabList.erase( iter ); mTabList.erase( iter );
delete tuple; delete tuple;
@@ -1041,7 +1041,7 @@ void LLTabContainer::deleteAllTabs()
// Actually delete the tuples themselves // Actually delete the tuples themselves
std::for_each(mTabList.begin(), mTabList.end(), DeletePointer()); std::for_each(mTabList.begin(), mTabList.end(), DeletePointer());
mTabList.clear(); mTabList.clear();
// And there isn't a current tab any more // And there isn't a current tab any more
mCurrentTabIdx = -1; mCurrentTabIdx = -1;
} }
@@ -1173,7 +1173,7 @@ void LLTabContainer::selectPrevTab()
{ {
mTabList[idx]->mButton->setFocus(TRUE); mTabList[idx]->mButton->setFocus(TRUE);
} }
} }
BOOL LLTabContainer::selectTabPanel(LLPanel* child) BOOL LLTabContainer::selectTabPanel(LLPanel* child)
{ {
@@ -1205,7 +1205,7 @@ BOOL LLTabContainer::selectTab(S32 which)
{ {
return FALSE; return FALSE;
} }
LLSD cbdata; LLSD cbdata;
if (selected_tuple->mTabPanel) if (selected_tuple->mTabPanel)
cbdata = selected_tuple->mTabPanel->getName(); cbdata = selected_tuple->mTabPanel->getName();
@@ -1219,7 +1219,7 @@ BOOL LLTabContainer::selectTab(S32 which)
(*mCommitSignal)(this, cbdata); (*mCommitSignal)(this, cbdata);
} }
} }
return res; return res;
} }
@@ -1247,7 +1247,7 @@ BOOL LLTabContainer::setTab(S32 which)
tuple->mButton->setToggleState( is_selected ); tuple->mButton->setToggleState( is_selected );
// RN: this limits tab-stops to active button only, which would require arrow keys to switch tabs // RN: this limits tab-stops to active button only, which would require arrow keys to switch tabs
tuple->mButton->setTabStop( is_selected ); tuple->mButton->setTabStop( is_selected );
if (is_selected) if (is_selected)
{ {
// Make sure selected tab is within scroll region // Make sure selected tab is within scroll region
@@ -1391,7 +1391,7 @@ void LLTabContainer::reshapeTuple(LLTabTuple* tuple)
{ {
const LLFontGL* fontp = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); const LLFontGL* fontp = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL );
S32 image_overlay_width = 0; S32 image_overlay_width = 0;
image_overlay_width = tuple->mButton->getImageOverlay().notNull() ? image_overlay_width = tuple->mButton->getImageOverlay().notNull() ?
tuple->mButton->getImageOverlay()->getImage()->getWidth(0) : 0; tuple->mButton->getImageOverlay()->getImage()->getWidth(0) : 0;
// remove current width from total tab strip width // remove current width from total tab strip width
mTotalTabWidth -= tuple->mButton->getRect().getWidth(); mTotalTabWidth -= tuple->mButton->getRect().getWidth();
@@ -1401,7 +1401,7 @@ void LLTabContainer::reshapeTuple(LLTabTuple* tuple)
tuple->mPadding = image_overlay_width; tuple->mPadding = image_overlay_width;
tuple->mButton->setRightHPad(6); tuple->mButton->setRightHPad(6);
tuple->mButton->reshape(llclamp(fontp->getWidth(tuple->mButton->getLabelSelected()) + TAB_PADDING + tuple->mPadding, mMinTabWidth, mMaxTabWidth), tuple->mButton->reshape(llclamp(fontp->getWidth(tuple->mButton->getLabelSelected()) + TAB_PADDING + tuple->mPadding, mMinTabWidth, mMaxTabWidth),
tuple->mButton->getRect().getHeight()); tuple->mButton->getRect().getHeight());
// add back in button width to total tab strip width // add back in button width to total tab strip width
mTotalTabWidth += tuple->mButton->getRect().getWidth(); mTotalTabWidth += tuple->mButton->getRect().getWidth();
@@ -1412,7 +1412,7 @@ void LLTabContainer::reshapeTuple(LLTabTuple* tuple)
} }
void LLTabContainer::setTitle(const std::string& title) void LLTabContainer::setTitle(const std::string& title)
{ {
if (mTitleBox) if (mTitleBox)
{ {
mTitleBox->setText( title ); mTitleBox->setText( title );
@@ -1556,7 +1556,7 @@ LLView* LLTabContainer::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFacto
node->getAttributeBOOL("border", border); node->getAttributeBOOL("border", border);
LLTabContainer* tab_container = new LLTabContainer(name, LLRect::null, tab_position, border, is_vertical); LLTabContainer* tab_container = new LLTabContainer(name, LLRect::null, tab_position, border, is_vertical);
S32 tab_min_width = tab_container->mMinTabWidth; S32 tab_min_width = tab_container->mMinTabWidth;
if (node->hasAttribute("tab_width")) if (node->hasAttribute("tab_width"))
{ {
@@ -1573,9 +1573,9 @@ LLView* LLTabContainer::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFacto
node->getAttributeS32("tab_max_width", tab_max_width); node->getAttributeS32("tab_max_width", tab_max_width);
} }
tab_container->setMinTabWidth(tab_min_width); tab_container->setMinTabWidth(tab_min_width);
tab_container->setMaxTabWidth(tab_max_width); tab_container->setMaxTabWidth(tab_max_width);
BOOL hidden(tab_container->getTabsHidden()); BOOL hidden(tab_container->getTabsHidden());
node->getAttributeBOOL("hide_tabs", hidden); node->getAttributeBOOL("hide_tabs", hidden);
tab_container->setTabsHidden(hidden); tab_container->setTabsHidden(hidden);
@@ -1614,7 +1614,7 @@ LLView* LLTabContainer::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFacto
tab_container->postBuild(); tab_container->postBuild();
tab_container->initButtons(); // now that we have the correct rect tab_container->initButtons(); // now that we have the correct rect
return tab_container; return tab_container;
} }
@@ -1627,7 +1627,7 @@ void LLTabContainer::initButtons()
{ {
return; // Don't have a rect yet or already got called return; // Don't have a rect yet or already got called
} }
std::string out_id; std::string out_id;
std::string in_id; std::string in_id;
@@ -1650,7 +1650,7 @@ void LLTabContainer::initButtons()
mPrevArrowBtn->setFollowsTop(); mPrevArrowBtn->setFollowsTop();
mPrevArrowBtn->setFollowsLeft(); mPrevArrowBtn->setFollowsLeft();
mPrevArrowBtn->setHeldDownCallback(boost::bind(&LLTabContainer::onPrevBtnHeld, this, _2)); mPrevArrowBtn->setHeldDownCallback(boost::bind(&LLTabContainer::onPrevBtnHeld, this, _2));
out_id = "UIImgBtnScrollDownOutUUID"; out_id = "UIImgBtnScrollDownOutUUID";
in_id = "UIImgBtnScrollDownInUUID"; in_id = "UIImgBtnScrollDownInUUID";
mNextArrowBtn = new LLButton(std::string("Down Arrow"), down_arrow_btn_rect, mNextArrowBtn = new LLButton(std::string("Down Arrow"), down_arrow_btn_rect,
@@ -1661,7 +1661,7 @@ void LLTabContainer::initButtons()
} }
else // Horizontal else // Horizontal
{ {
S32 arrow_fudge = 1; // match new art better S32 arrow_fudge = 1; // match new art better
// tabs on bottom reserve room for resize handle (just in case) // tabs on bottom reserve room for resize handle (just in case)
if (getTabPosition() == BOTTOM) if (getTabPosition() == BOTTOM)
@@ -1705,7 +1705,7 @@ void LLTabContainer::initButtons()
boost::bind(&LLTabContainer::onPrevBtn, this, _2), LLFontGL::getFontSansSerif() ); boost::bind(&LLTabContainer::onPrevBtn, this, _2), LLFontGL::getFontSansSerif() );
mPrevArrowBtn->setHeldDownCallback(boost::bind(&LLTabContainer::onPrevBtnHeld, this, _2)); mPrevArrowBtn->setHeldDownCallback(boost::bind(&LLTabContainer::onPrevBtnHeld, this, _2));
mPrevArrowBtn->setFollowsLeft(); mPrevArrowBtn->setFollowsLeft();
out_id = "UIImgBtnJumpRightOutUUID"; out_id = "UIImgBtnJumpRightOutUUID";
in_id = "UIImgBtnJumpRightInUUID"; in_id = "UIImgBtnJumpRightInUUID";
mJumpNextArrowBtn = new LLButton(std::string("Jump Right Arrow"), jump_right_arrow_btn_rect, mJumpNextArrowBtn = new LLButton(std::string("Jump Right Arrow"), jump_right_arrow_btn_rect,
@@ -1740,7 +1740,7 @@ void LLTabContainer::initButtons()
mPrevArrowBtn->setSaveToXML(false); mPrevArrowBtn->setSaveToXML(false);
mPrevArrowBtn->setTabStop(FALSE); mPrevArrowBtn->setTabStop(FALSE);
addChild(mPrevArrowBtn); addChild(mPrevArrowBtn);
mNextArrowBtn->setSaveToXML(false); mNextArrowBtn->setSaveToXML(false);
mNextArrowBtn->setTabStop(FALSE); mNextArrowBtn->setTabStop(FALSE);
addChild(mNextArrowBtn); addChild(mNextArrowBtn);
@@ -1758,7 +1758,7 @@ void LLTabContainer::initButtons()
mJumpNextArrowBtn->setTabStop(FALSE); mJumpNextArrowBtn->setTabStop(FALSE);
addChild(mJumpNextArrowBtn); addChild(mJumpNextArrowBtn);
} }
// set default tab group to be panel contents // set default tab group to be panel contents
setDefaultTabGroup(1); setDefaultTabGroup(1);
} }