Skip to content
Snippets Groups Projects
lltabcontainer.cpp 51.5 KiB
Newer Older
James Cook's avatar
James Cook committed
/** 
 * @file lltabcontainer.cpp
James Cook's avatar
James Cook committed
 *
 * $LicenseInfo:firstyear=2001&license=viewergpl$
 * 
 * Copyright (c) 2001-2009, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * 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
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("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
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 * 
 * 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
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at
 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
James Cook's avatar
James Cook committed
 */

#include "linden_common.h"
James Cook's avatar
James Cook committed
#include "lltabcontainer.h"
James Cook's avatar
James Cook committed
#include "llfocusmgr.h"
#include "llbutton.h"
James Cook's avatar
James Cook committed
#include "llrect.h"
#include "llresizehandle.h"
#include "lltextbox.h"
#include "llcriticaldamp.h"
#include "lluictrlfactory.h"
#include "llrender.h"

//----------------------------------------------------------------------------

// Implementation Notes:
//  - Each tab points to a LLPanel (see LLTabTuple below)
//  - When a tab is selected, the validation callback
//    (LLUICtrl::mValidateSignal) is called
//  -  If the validation callback returns true (or none is provided),
//     the tab is changed and the commit callback
//     (LLUICtrl::mCommitSignal) is called
//  - Callbacks pass the LLTabContainer as the control,
//    and the NAME of the selected PANEL as the LLSD data

//----------------------------------------------------------------------------
James Cook's avatar
James Cook committed

const F32 SCROLL_STEP_TIME = 0.4f;
const F32 SCROLL_DELAY_TIME = 0.5f;

void LLTabContainer::TabPositions::declareValues()
{
	declare("top", LLTabContainer::TOP);
	declare("bottom", LLTabContainer::BOTTOM);
	declare("left", LLTabContainer::LEFT);
}

//----------------------------------------------------------------------------

// Structure used to map tab buttons to and from tab panels
class LLTabTuple
{
public:
	LLTabTuple( LLTabContainer* c, LLPanel* p, LLButton* b, LLTextBox* placeholder = NULL)
		:
		mTabContainer(c),
		mTabPanel(p),
		mButton(b),
		mOldState(FALSE),
		mPlaceholderText(placeholder),
		mPadding(0)
	{}

	LLTabContainer*  mTabContainer;
	LLPanel*		 mTabPanel;
	LLButton*		 mButton;
	BOOL			 mOldState;
	LLTextBox*		 mPlaceholderText;
	S32				 mPadding;
};

//----------------------------------------------------------------------------

struct LLPlaceHolderPanel : public LLPanel
{
	// create dummy param block to register with "placeholder" nane
	struct Params : public LLPanel::Params{};
	LLPlaceHolderPanel(const Params& p) : LLPanel(p)
	{}
};
static LLDefaultChildRegistry::Register<LLPlaceHolderPanel> r1("placeholder");
static LLDefaultChildRegistry::Register<LLTabContainer> r2("tab_container");
LLTabContainer::TabParams::TabParams()
:	tab_top_image_unselected("tab_top_image_unselected"),
	tab_top_image_selected("tab_top_image_selected"),
	tab_bottom_image_unselected("tab_bottom_image_unselected"),
	tab_bottom_image_selected("tab_bottom_image_selected"),
	tab_left_image_unselected("tab_left_image_unselected"),
	tab_left_image_selected("tab_left_image_selected")
{}

LLTabContainer::Params::Params()
:	tab_width("tab_width"),
	tab_min_width("tab_min_width"),
	tab_max_width("tab_max_width"),
	tab_height("tab_height"),
	tab_position("tab_position"),
	hide_tabs("hide_tabs", false),
	first_tab("first_tab"),
	middle_tab("middle_tab"),
	last_tab("last_tab")
{
	name(std::string("tab_container"));
	mouse_opaque = false;
}

LLTabContainer::LLTabContainer(const LLTabContainer::Params& p)
:	LLPanel(p),
James Cook's avatar
James Cook committed
	mCurrentTabIdx(-1),
	mTabsHidden(p.hide_tabs),
James Cook's avatar
James Cook committed
	mScrolled(FALSE),
	mScrollPos(0),
	mScrollPosPixels(0),
	mMaxScrollPos(0),
	mTitleBox(NULL),
	mTopBorderHeight(LLPANEL_BORDER_WIDTH),
	mMinTabWidth(0),
	mMaxTabWidth(p.tab_max_width),
	mTabHeight(p.tab_height),
	mIsVertical( p.tab_position == LEFT ),
	// Horizontal Specific
	mJumpPrevArrowBtn(NULL),
	mJumpNextArrowBtn(NULL),
	mRightTabBtnOffset(p.tab_padding_right),
	mTotalTabWidth(0),
	mTabPosition(p.tab_position),
	mFontHalign(p.font_halign),
	mFirstTabParams(p.first_tab),
	mMiddleTabParams(p.middle_tab),
	mLastTabParams(p.last_tab)
{
	static LLUICachedControl<S32> tabcntr_vert_tab_min_width ("UITabCntrVertTabMinWidth", 0);

	mDragAndDropDelayTimer.stop();

	if (p.tab_width.isProvided())
	{
		mMinTabWidth = p.tab_width;
	}
	else if (!mIsVertical)
		mMinTabWidth = p.tab_min_width;
	else
	{
		// *HACK: support default min width for legacy vertical
		// tab containers
		mMinTabWidth = tabcntr_vert_tab_min_width;
	}

LLTabContainer::~LLTabContainer()
{
	std::for_each(mTabList.begin(), mTabList.end(), DeletePointer());
}
James Cook's avatar
James Cook committed

//virtual
void LLTabContainer::setValue(const LLSD& value)
James Cook's avatar
James Cook committed
{
	selectTab((S32) value.asInteger());
}

//virtual
void LLTabContainer::reshape(S32 width, S32 height, BOOL called_from_parent)
James Cook's avatar
James Cook committed
{
	LLPanel::reshape( width, height, called_from_parent );
	updateMaxScrollPos();
LLView* LLTabContainer::getChildView(const std::string& name, BOOL recurse) const
James Cook's avatar
James Cook committed
{
	tuple_list_t::const_iterator itor;
	for (itor = mTabList.begin(); itor != mTabList.end(); ++itor)
	{
		LLPanel *panel = (*itor)->mTabPanel;
		if (panel->getName() == name)
		{
			return panel;
		}
	}
James Cook's avatar
James Cook committed
	if (recurse)
	{
		for (itor = mTabList.begin(); itor != mTabList.end(); ++itor)
		{
			LLPanel *panel = (*itor)->mTabPanel;
			LLView *child = panel->getChildView(name, recurse);
James Cook's avatar
James Cook committed
			if (child)
			{
				return child;
			}
		}
	}
	return LLView::getChildView(name, recurse);
}

//virtual
LLView* LLTabContainer::findChildView(const std::string& name, BOOL recurse) const
{
	tuple_list_t::const_iterator itor;
	for (itor = mTabList.begin(); itor != mTabList.end(); ++itor)
	{
		LLPanel *panel = (*itor)->mTabPanel;
		if (panel->getName() == name)
		{
			return panel;
		}
	}

	if (recurse)
	{
		for (itor = mTabList.begin(); itor != mTabList.end(); ++itor)
		{
			LLPanel *panel = (*itor)->mTabPanel;
			LLView *child = panel->findChildView(name, recurse);
			if (child)
			{
				return child;
			}
		}
	}
	return LLView::findChildView(name, recurse);
bool LLTabContainer::addChild(LLView* view, S32 tab_group)
{
	LLPanel* panelp = dynamic_cast<LLPanel*>(view);

	if (panelp)
	{
		panelp->setSaveToXML(TRUE);

		addTabPanel(TabPanelParams().panel(panelp).label(panelp->getLabel()).is_placeholder(dynamic_cast<LLPlaceHolderPanel*>(view) != NULL));
		return true;
	}
	else
	{
		return LLUICtrl::addChild(view, tab_group);
	}
}

BOOL LLTabContainer::postBuild()
{
	selectFirstTab();

	return TRUE;
}

James Cook's avatar
James Cook committed
{
	static LLUICachedControl<S32> tabcntrv_pad ("UITabCntrvPad", 0);
	static LLUICachedControl<S32> tabcntrv_arrow_btn_size ("UITabCntrvArrowBtnSize", 0);
	static LLUICachedControl<S32> tabcntr_tab_h_pad ("UITabCntrTabHPad", 0);
	static LLUICachedControl<S32> tabcntr_arrow_btn_size ("UITabCntrArrowBtnSize", 0);
	static LLUICachedControl<S32> tabcntr_tab_partial_width ("UITabCntrTabPartialWidth", 0);
	S32 cur_scroll_pos = getScrollPos();
James Cook's avatar
James Cook committed
	{
		S32 available_width_with_arrows = getRect().getWidth() - mRightTabBtnOffset - 2 * (LLPANEL_BORDER_WIDTH + tabcntr_arrow_btn_size  + tabcntr_arrow_btn_size + 1);
James Cook's avatar
James Cook committed
		{
			for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
				if (cur_scroll_pos == 0)
				{
					break;
				}
				target_pixel_scroll += (*iter)->mButton->getRect().getWidth();
				cur_scroll_pos--;
			// Show part of the tab to the left of what is fully visible
			target_pixel_scroll -= tabcntr_tab_partial_width;
			// clamp so that rightmost tab never leaves right side of screen
			target_pixel_scroll = llmin(mTotalTabWidth - available_width_with_arrows, target_pixel_scroll);
		}
James Cook's avatar
James Cook committed
	}

	setScrollPosPixels((S32)lerp((F32)getScrollPosPixels(), (F32)target_pixel_scroll, LLCriticalDamp::getInterpolant(0.08f)));
	BOOL has_scroll_arrows = !getTabsHidden() && ((mMaxScrollPos > 0) || (mScrollPosPixels > 0));
James Cook's avatar
James Cook committed
	{
		mJumpPrevArrowBtn->setVisible( has_scroll_arrows );
		mJumpNextArrowBtn->setVisible( has_scroll_arrows );
	}
	mPrevArrowBtn->setVisible( has_scroll_arrows );
	mNextArrowBtn->setVisible( has_scroll_arrows );
James Cook's avatar
James Cook committed

	S32 left = 0, top = 0;
	if (mIsVertical)
	{
		top = getRect().getHeight() - getTopBorderHeight() - LLPANEL_BORDER_WIDTH - 1 - (has_scroll_arrows ? tabcntrv_arrow_btn_size : 0);
		top += getScrollPosPixels();
	}
	else
	{
		// Set the leftmost position of the tab buttons.
		left = LLPANEL_BORDER_WIDTH + (has_scroll_arrows ? (tabcntr_arrow_btn_size * 2) : tabcntr_tab_h_pad);
		left -= getScrollPosPixels();
	}
	
	// Hide all the buttons
	if (getTabsHidden())
		for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
		{
			LLTabTuple* tuple = *iter;
			tuple->mButton->setVisible( FALSE );
		}
	{
		LLRect clip_rect = getLocalRect();
		clip_rect.mLeft+=(LLPANEL_BORDER_WIDTH + 2);
		clip_rect.mRight-=(LLPANEL_BORDER_WIDTH + 2);
		LLLocalClipRect clip(clip_rect);
		LLPanel::draw();
	}

	// if tabs are hidden, don't draw them and leave them in the invisible state
	if (!getTabsHidden())
	{
		// Show all the buttons
		for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
		{
			LLTabTuple* tuple = *iter;
			tuple->mButton->setVisible( TRUE );
James Cook's avatar
James Cook committed

		S32 max_scroll_visible = getTabCount() - getMaxScrollPos() + getScrollPos();
		S32 idx = 0;
		for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
		{
			LLTabTuple* tuple = *iter;
James Cook's avatar
James Cook committed

			tuple->mButton->translate( left ? left - tuple->mButton->getRect().mLeft : 0,
									   top ? top - tuple->mButton->getRect().mTop : 0 );
			if (top) top -= BTN_HEIGHT + tabcntrv_pad;
			if (left) left += tuple->mButton->getRect().getWidth();
James Cook's avatar
James Cook committed

			if (!mIsVertical)
			{
				if( idx < getScrollPos() )
					if( tuple->mButton->getFlashing() )
						mPrevArrowBtn->setFlashing( TRUE );
				else if( max_scroll_visible < idx )
					if( tuple->mButton->getFlashing() )
					{
						mNextArrowBtn->setFlashing( TRUE );
					}
James Cook's avatar
James Cook committed


		if( mIsVertical && has_scroll_arrows )
		{
			// Redraw the arrows so that they appears on top.
			gGL.pushMatrix();
			gGL.translatef((F32)mPrevArrowBtn->getRect().mLeft, (F32)mPrevArrowBtn->getRect().mBottom, 0.f);
			mPrevArrowBtn->draw();
			gGL.popMatrix();

			gGL.pushMatrix();
			gGL.translatef((F32)mNextArrowBtn->getRect().mLeft, (F32)mNextArrowBtn->getRect().mBottom, 0.f);
			mNextArrowBtn->draw();
			gGL.popMatrix();
		}

	mPrevArrowBtn->setFlashing(FALSE);
	mNextArrowBtn->setFlashing(FALSE);
// virtual
BOOL LLTabContainer::handleMouseDown( S32 x, S32 y, MASK mask )
James Cook's avatar
James Cook committed
{
	static LLUICachedControl<S32> tabcntrv_pad ("UITabCntrvPad", 0);
Steven Bennetts's avatar
Steven Bennetts committed
	BOOL has_scroll_arrows = (getMaxScrollPos() > 0) && !getTabsHidden();
James Cook's avatar
James Cook committed

James Cook's avatar
James Cook committed
	{
		if (mJumpPrevArrowBtn&& mJumpPrevArrowBtn->getRect().pointInRect(x, y))
James Cook's avatar
James Cook committed
		{
			S32 local_x = x - mJumpPrevArrowBtn->getRect().mLeft;
			S32 local_y = y - mJumpPrevArrowBtn->getRect().mBottom;
			handled = mJumpPrevArrowBtn->handleMouseDown(local_x, local_y, mask);
		}
		else if (mJumpNextArrowBtn && mJumpNextArrowBtn->getRect().pointInRect(x, y))
		{
			S32 local_x = x - mJumpNextArrowBtn->getRect().mLeft;
			S32 local_y = y - mJumpNextArrowBtn->getRect().mBottom;
			handled = mJumpNextArrowBtn->handleMouseDown(local_x, local_y, mask);
		}
		else if (mPrevArrowBtn && mPrevArrowBtn->getRect().pointInRect(x, y))
		{
			S32 local_x = x - mPrevArrowBtn->getRect().mLeft;
			S32 local_y = y - mPrevArrowBtn->getRect().mBottom;
			handled = mPrevArrowBtn->handleMouseDown(local_x, local_y, mask);
		}
		else if (mNextArrowBtn && mNextArrowBtn->getRect().pointInRect(x, y))
		{
			S32 local_x = x - mNextArrowBtn->getRect().mLeft;
			S32 local_y = y - mNextArrowBtn->getRect().mBottom;
			handled = mNextArrowBtn->handleMouseDown(local_x, local_y, mask);
James Cook's avatar
James Cook committed
		}
	}
	if (!handled)
	{
		handled = LLPanel::handleMouseDown( x, y, mask );
	}
James Cook's avatar
James Cook committed

	S32 tab_count = getTabCount();
	if (tab_count > 0)
James Cook's avatar
James Cook committed
	{
		LLTabTuple* firsttuple = getTab(0);
		LLRect tab_rect;
		if (mIsVertical)
James Cook's avatar
James Cook committed
		{
			tab_rect = LLRect(firsttuple->mButton->getRect().mLeft,
							  has_scroll_arrows ? mPrevArrowBtn->getRect().mBottom - tabcntrv_pad : mPrevArrowBtn->getRect().mTop,
							  has_scroll_arrows ? mNextArrowBtn->getRect().mTop + tabcntrv_pad : mNextArrowBtn->getRect().mBottom );
		}
		else
		{
			tab_rect = LLRect(has_scroll_arrows ? mPrevArrowBtn->getRect().mRight : mJumpPrevArrowBtn->getRect().mLeft,
							  firsttuple->mButton->getRect().mTop,
							  has_scroll_arrows ? mNextArrowBtn->getRect().mLeft : mJumpNextArrowBtn->getRect().mRight,
							  firsttuple->mButton->getRect().mBottom );
		}
		if( tab_rect.pointInRect( x, y ) )
		{
			S32 index = getCurrentPanelIndex();
			index = llclamp(index, 0, tab_count-1);
			LLButton* tab_button = getTab(index)->mButton;
			tab_button->setFocus(TRUE);
James Cook's avatar
James Cook committed
		}
	}
// virtual
BOOL LLTabContainer::handleHover( S32 x, S32 y, MASK mask )
James Cook's avatar
James Cook committed
{
Steven Bennetts's avatar
Steven Bennetts committed
	BOOL has_scroll_arrows = (getMaxScrollPos() > 0) && !getTabsHidden();
James Cook's avatar
James Cook committed
	{
		if (mJumpPrevArrowBtn && mJumpPrevArrowBtn->getRect().pointInRect(x, y))
James Cook's avatar
James Cook committed
		{
			S32 local_x = x - mJumpPrevArrowBtn->getRect().mLeft;
			S32 local_y = y - mJumpPrevArrowBtn->getRect().mBottom;
			handled = mJumpPrevArrowBtn->handleHover(local_x, local_y, mask);
James Cook's avatar
James Cook committed
		}
		else if (mJumpNextArrowBtn && mJumpNextArrowBtn->getRect().pointInRect(x, y))
James Cook's avatar
James Cook committed
		{
			S32 local_x = x - mJumpNextArrowBtn->getRect().mLeft;
			S32 local_y = y - mJumpNextArrowBtn->getRect().mBottom;
			handled = mJumpNextArrowBtn->handleHover(local_x, local_y, mask);
		}
		else if (mPrevArrowBtn && mPrevArrowBtn->getRect().pointInRect(x, y))
		{
			S32 local_x = x - mPrevArrowBtn->getRect().mLeft;
			S32 local_y = y - mPrevArrowBtn->getRect().mBottom;
			handled = mPrevArrowBtn->handleHover(local_x, local_y, mask);
		}
		else if (mNextArrowBtn && mNextArrowBtn->getRect().pointInRect(x, y))
		{
			S32 local_x = x - mNextArrowBtn->getRect().mLeft;
			S32 local_y = y - mNextArrowBtn->getRect().mBottom;
			handled = mNextArrowBtn->handleHover(local_x, local_y, mask);
James Cook's avatar
James Cook committed
		}
	}
James Cook's avatar
James Cook committed
	{
		handled = LLPanel::handleHover(x, y, mask);
// virtual
BOOL LLTabContainer::handleMouseUp( S32 x, S32 y, MASK mask )
James Cook's avatar
James Cook committed
{
Steven Bennetts's avatar
Steven Bennetts committed
	BOOL has_scroll_arrows = (getMaxScrollPos() > 0)  && !getTabsHidden();
James Cook's avatar
James Cook committed

		if (mJumpPrevArrowBtn && mJumpPrevArrowBtn->getRect().pointInRect(x, y))
		{
			S32 local_x = x - mJumpPrevArrowBtn->getRect().mLeft;
			S32 local_y = y - mJumpPrevArrowBtn->getRect().mBottom;
			handled = mJumpPrevArrowBtn->handleMouseUp(local_x, local_y, mask);
		}
		else if (mJumpNextArrowBtn && mJumpNextArrowBtn->getRect().pointInRect(x,	y))
		{
			S32	local_x	= x	- mJumpNextArrowBtn->getRect().mLeft;
			S32	local_y	= y	- mJumpNextArrowBtn->getRect().mBottom;
			handled = mJumpNextArrowBtn->handleMouseUp(local_x,	local_y, mask);
		}
		else if (mPrevArrowBtn && mPrevArrowBtn->getRect().pointInRect(x, y))
		{
			S32 local_x = x - mPrevArrowBtn->getRect().mLeft;
			S32 local_y = y - mPrevArrowBtn->getRect().mBottom;
			handled = mPrevArrowBtn->handleMouseUp(local_x, local_y, mask);
		}
		else if (mNextArrowBtn && mNextArrowBtn->getRect().pointInRect(x, y))
		{
			S32 local_x = x - mNextArrowBtn->getRect().mLeft;
			S32 local_y = y - mNextArrowBtn->getRect().mBottom;
			handled = mNextArrowBtn->handleMouseUp(local_x, local_y, mask);
		}
James Cook's avatar
James Cook committed
	{
		handled = LLPanel::handleMouseUp( x, y, mask );
	commitHoveredButton(x, y);
	LLPanel* cur_panel = getCurrentPanel();
	if (hasMouseCapture())
James Cook's avatar
James Cook committed
	{
		if (cur_panel)
		{
			if (!cur_panel->focusFirstItem(FALSE))
			{
				// if nothing in the panel gets focus, make sure the new tab does
				// otherwise the last tab might keep focus
				getTab(getCurrentPanelIndex())->mButton->setFocus(TRUE);
			}
		}
		gFocusMgr.setMouseCapture(NULL);
James Cook's avatar
James Cook committed
	}
BOOL LLTabContainer::handleToolTip( S32 x, S32 y, MASK mask)
James Cook's avatar
James Cook committed
{
	static LLUICachedControl<S32> tabcntrv_pad ("UITabCntrvPad", 0);
	BOOL handled = LLPanel::handleToolTip( x, y, mask);
James Cook's avatar
James Cook committed
	{
James Cook's avatar
James Cook committed

		BOOL has_scroll_arrows = (getMaxScrollPos() > 0);
		LLRect clip;
		if (mIsVertical)
James Cook's avatar
James Cook committed
		{
			clip = LLRect(firsttuple->mButton->getRect().mLeft,
						  has_scroll_arrows ? mPrevArrowBtn->getRect().mBottom - tabcntrv_pad : mPrevArrowBtn->getRect().mTop,
						  has_scroll_arrows ? mNextArrowBtn->getRect().mTop + tabcntrv_pad : mNextArrowBtn->getRect().mBottom );
James Cook's avatar
James Cook committed
		}
James Cook's avatar
James Cook committed
		{
			clip = LLRect(has_scroll_arrows ? mPrevArrowBtn->getRect().mRight : mJumpPrevArrowBtn->getRect().mLeft,
						  firsttuple->mButton->getRect().mTop,
						  has_scroll_arrows ? mNextArrowBtn->getRect().mLeft : mJumpNextArrowBtn->getRect().mRight,
						  firsttuple->mButton->getRect().mBottom );
James Cook's avatar
James Cook committed
		{
			for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter)
			{
				LLTabTuple* tuple = *iter;
				tuple->mButton->setVisible( TRUE );
				S32 local_x = x - tuple->mButton->getRect().mLeft;
				S32 local_y = y - tuple->mButton->getRect().mBottom;
				handled = tuple->mButton->handleToolTip( local_x, local_y, mask);
James Cook's avatar
James Cook committed
		}
	}
BOOL LLTabContainer::handleKeyHere(KEY key, MASK mask)
{
	BOOL handled = FALSE;
	if (key == KEY_LEFT && mask == MASK_ALT)
James Cook's avatar
James Cook committed
	{
		selectPrevTab();
		handled = TRUE;
	}
	else if (key == KEY_RIGHT && mask == MASK_ALT)
	{
		selectNextTab();
		handled = TRUE;
James Cook's avatar
James Cook committed
	{
James Cook's avatar
James Cook committed
		{
	if (!gFocusMgr.childHasKeyboardFocus(getCurrentPanel()))
James Cook's avatar
James Cook committed
	{
		// if child has focus, but not the current panel, focus is on a button
		if (mIsVertical)
Jon Wolk's avatar
Jon Wolk committed
		{
			switch(key)
			{
			  case KEY_UP:
				selectPrevTab();
				handled = TRUE;
				break;
			  case KEY_DOWN:
				selectNextTab();
				handled = TRUE;
				break;
			  case KEY_LEFT:
				handled = TRUE;
				break;
			  case KEY_RIGHT:
				if (getTabPosition() == LEFT && getCurrentPanel())
				{
					getCurrentPanel()->setFocus(TRUE);
				}
				handled = TRUE;
				break;
			  default:
				break;
			}
Jon Wolk's avatar
Jon Wolk committed
		}
James Cook's avatar
James Cook committed
		{
			switch(key)
			{
			  case KEY_UP:
				if (getTabPosition() == BOTTOM && getCurrentPanel())
				{
					getCurrentPanel()->setFocus(TRUE);
				}
				handled = TRUE;
				break;
			  case KEY_DOWN:
				if (getTabPosition() == TOP && getCurrentPanel())
				{
					getCurrentPanel()->setFocus(TRUE);
				}
				handled = TRUE;
				break;
			  case KEY_LEFT:
				selectPrevTab();
				handled = TRUE;
				break;
			  case KEY_RIGHT:
				selectNextTab();
				handled = TRUE;
				break;
			  default:
				break;
			}
James Cook's avatar
James Cook committed
		}
	}
BOOL LLTabContainer::handleDragAndDrop(S32 x, S32 y, MASK mask,	BOOL drop,	EDragAndDropType type, void* cargo_data, EAcceptance *accept, std::string	&tooltip)
James Cook's avatar
James Cook committed
{
	BOOL has_scroll_arrows = (getMaxScrollPos() > 0);
James Cook's avatar
James Cook committed

	if( mDragAndDropDelayTimer.getStarted() && mDragAndDropDelayTimer.getElapsedTimeF32() > SCROLL_DELAY_TIME )
James Cook's avatar
James Cook committed
	{
			if (mJumpPrevArrowBtn && mJumpPrevArrowBtn->getRect().pointInRect(x, y))
			{
				S32	local_x	= x	- mJumpPrevArrowBtn->getRect().mLeft;
				S32	local_y	= y	- mJumpPrevArrowBtn->getRect().mBottom;
				mJumpPrevArrowBtn->handleHover(local_x,	local_y, mask);
			}
			if (mJumpNextArrowBtn && mJumpNextArrowBtn->getRect().pointInRect(x, y))
			{
				S32	local_x	= x	- mJumpNextArrowBtn->getRect().mLeft;
				S32	local_y	= y	- mJumpNextArrowBtn->getRect().mBottom;
				mJumpNextArrowBtn->handleHover(local_x,	local_y, mask);
			}
			if (mPrevArrowBtn->getRect().pointInRect(x,	y))
			{
				S32	local_x	= x	- mPrevArrowBtn->getRect().mLeft;
				S32	local_y	= y	- mPrevArrowBtn->getRect().mBottom;
				mPrevArrowBtn->handleHover(local_x,	local_y, mask);
			}
			else if	(mNextArrowBtn->getRect().pointInRect(x, y))
			{
				S32	local_x	= x	- mNextArrowBtn->getRect().mLeft;
				S32	local_y	= y	- mNextArrowBtn->getRect().mBottom;
				mNextArrowBtn->handleHover(local_x, local_y, mask);
			}
		}
		for(tuple_list_t::iterator iter	= mTabList.begin();	iter !=	 mTabList.end(); ++iter)
		{
			LLTabTuple*	tuple =	*iter;
			tuple->mButton->setVisible(	TRUE );
			S32	local_x	= x	- tuple->mButton->getRect().mLeft;
			S32	local_y	= y	- tuple->mButton->getRect().mBottom;
			if (tuple->mButton->pointInView(local_x, local_y) &&  tuple->mButton->getEnabled() && !tuple->mTabPanel->getVisible())
			{
				tuple->mButton->onCommit();
				mDragAndDropDelayTimer.stop();
			}
		}
	return LLView::handleDragAndDrop(x,	y, mask, drop, type, cargo_data,  accept, tooltip);
void LLTabContainer::addTabPanel(LLPanel* panelp)
{
	addTabPanel(TabPanelParams().panel(panelp));
}

// function to update images
void LLTabContainer::update_images(LLTabTuple* tuple, TabParams params, LLTabContainer::TabPosition pos)
{
	if (tuple && tuple->mButton)
	{
		if (pos == LLTabContainer::TOP)
		{
			tuple->mButton->setImageUnselected(static_cast<LLUIImage*>(params.tab_top_image_unselected));
			tuple->mButton->setImageSelected(static_cast<LLUIImage*>(params.tab_top_image_selected));
		}
		else if (pos == LLTabContainer::BOTTOM)
		{
			tuple->mButton->setImageUnselected(static_cast<LLUIImage*>(params.tab_bottom_image_unselected));
			tuple->mButton->setImageSelected(static_cast<LLUIImage*>(params.tab_bottom_image_selected));
		}
		else if (pos == LLTabContainer::LEFT)
		{
			tuple->mButton->setImageUnselected(static_cast<LLUIImage*>(params.tab_left_image_unselected));
			tuple->mButton->setImageSelected(static_cast<LLUIImage*>(params.tab_left_image_selected));
		}
	}
}

void LLTabContainer::addTabPanel(const TabPanelParams& panel)
James Cook's avatar
James Cook committed
{
	LLPanel* child = panel.panel();
	const std::string& label = panel.label.isProvided() 
			? panel.label() 
			: panel.panel()->getLabel();
	BOOL select = panel.select_tab(); 
	S32 indent = panel.indent();
	BOOL placeholder = panel.is_placeholder;
	eInsertionPoint insertion_point = panel.insert_at();

	static LLUICachedControl<S32> tabcntrv_pad ("UITabCntrvPad", 0);
	static LLUICachedControl<S32> tabcntr_button_panel_overlap ("UITabCntrButtonPanelOverlap", 0);
	static LLUICachedControl<S32> tab_padding ("UITabPadding", 0);
James Cook's avatar
James Cook committed
	if (child->getParent() == this)
	{
		// already a child of mine
		return;
	}

	// Store the original label for possible xml export.
	child->setLabel(label);
	std::string trimmed_label = label;
	LLStringUtil::trim(trimmed_label);
James Cook's avatar
James Cook committed

	S32 button_width = mMinTabWidth;
	if (!mIsVertical)
	{
		button_width = llclamp(mFont->getWidth(trimmed_label) + tab_padding, mMinTabWidth, mMaxTabWidth);
James Cook's avatar
James Cook committed
	// Tab panel
	S32 tab_panel_top;
	S32 tab_panel_bottom;
Steven Bennetts's avatar
Steven Bennetts committed
	if (!getTabsHidden()) 
James Cook's avatar
James Cook committed
	{
Steven Bennetts's avatar
Steven Bennetts committed
		if( getTabPosition() == LLTabContainer::TOP )
		{
			S32 tab_height = mIsVertical ? BTN_HEIGHT : mTabHeight;
Steven Bennetts's avatar
Steven Bennetts committed
			tab_panel_top = getRect().getHeight() - getTopBorderHeight() - (tab_height - tabcntr_button_panel_overlap);	
			tab_panel_bottom = LLPANEL_BORDER_WIDTH;
		}
		else
		{
			tab_panel_top = getRect().getHeight() - getTopBorderHeight();
			tab_panel_bottom = (mTabHeight - tabcntr_button_panel_overlap);  // Run to the edge, covering up the border
Steven Bennetts's avatar
Steven Bennetts committed
		}
James Cook's avatar
James Cook committed
	}
	else
	{
Steven Bennetts's avatar
Steven Bennetts committed
		//Scip tab button space if they are invisible(EXT - 576)
		tab_panel_top = getRect().getHeight();
		tab_panel_bottom = LLPANEL_BORDER_WIDTH;
James Cook's avatar
James Cook committed
	}
Steven Bennetts's avatar
Steven Bennetts committed

Steven Bennetts's avatar
Steven Bennetts committed
	if (!getTabsHidden() && mIsVertical)
		tab_panel_rect = LLRect(mMinTabWidth + (LLPANEL_BORDER_WIDTH * 2) + tabcntrv_pad, 
								getRect().getHeight() - LLPANEL_BORDER_WIDTH,
								getRect().getWidth() - LLPANEL_BORDER_WIDTH,
								LLPANEL_BORDER_WIDTH);
	}
	else
	{
		tab_panel_rect = LLRect(LLPANEL_BORDER_WIDTH, 
								tab_panel_top,
								getRect().getWidth()-LLPANEL_BORDER_WIDTH,
								tab_panel_bottom );
	}
James Cook's avatar
James Cook committed
	child->setFollowsAll();
	child->translate( tab_panel_rect.mLeft - child->getRect().mLeft, tab_panel_rect.mBottom - child->getRect().mBottom);
	child->reshape( tab_panel_rect.getWidth(), tab_panel_rect.getHeight(), TRUE );
	// add this child later

	child->setVisible( FALSE );  // Will be made visible when selected

	mTotalTabWidth += button_width;

	// Tab button
	LLRect btn_rect;  // Note: btn_rect.mLeft is just a dummy.  Will be updated in draw().
	LLUIImage* tab_img = NULL;
	LLUIImage* tab_selected_img = NULL;
James Cook's avatar
James Cook committed
	S32 tab_fudge = 1;		//  To make new tab art look better, nudge buttons up 1 pel

James Cook's avatar
James Cook committed
	{
		btn_rect.setLeftTopAndSize(tabcntrv_pad + LLPANEL_BORDER_WIDTH + 2,	// JC - Fudge factor
								   (getRect().getHeight() - getTopBorderHeight() - LLPANEL_BORDER_WIDTH - 1) - ((BTN_HEIGHT + tabcntrv_pad) * getTabCount()),
								   mMinTabWidth,
								   BTN_HEIGHT);
	}
	else if( getTabPosition() == LLTabContainer::TOP )
	{
		btn_rect.setLeftTopAndSize( 0, getRect().getHeight() - getTopBorderHeight() + tab_fudge, button_width, mTabHeight);
		tab_img = mMiddleTabParams.tab_top_image_unselected;
		tab_selected_img = mMiddleTabParams.tab_top_image_selected; 
James Cook's avatar
James Cook committed
	}
	else
	{
		btn_rect.setOriginAndSize( 0, 0 + tab_fudge, button_width, mTabHeight);
		tab_img = mMiddleTabParams.tab_bottom_image_unselected;
		tab_selected_img = mMiddleTabParams.tab_bottom_image_selected;
James Cook's avatar
James Cook committed
	if (placeholder)
	{
		btn_rect.translate(0, -LLBUTTON_V_PAD-2);
		LLTextBox::Params params;
		params.name(trimmed_label);
		params.rect(btn_rect);
		params.font(mFont);
		textbox = LLUICtrlFactory::create<LLTextBox> (params);
		btn = LLUICtrlFactory::create<LLButton>(p);
James Cook's avatar
James Cook committed
	}
	else
	{
James Cook's avatar
James Cook committed
		{
			LLButton::Params p;
			p.name(std::string("vert tab button"));
			p.rect(btn_rect);
			p.follows.flags(FOLLOWS_TOP | FOLLOWS_LEFT);
			p.click_callback.function(boost::bind(&LLTabContainer::onTabBtn, this, _2, child));
			p.font(mFont);
			p.image_unselected(mMiddleTabParams.tab_left_image_unselected);
			p.image_selected(mMiddleTabParams.tab_left_image_selected);
			p.font_halign = mFontHalign;
			btn = LLUICtrlFactory::create<LLButton>(p);
James Cook's avatar
James Cook committed
		}
		else
		{
			LLButton::Params p;
			p.name(std::string(child->getName()) + " tab");
			p.rect(btn_rect);
			p.click_callback.function(boost::bind(&LLTabContainer::onTabBtn, this, _2, child));
			p.font(mFont);
			p.label(trimmed_label);
			p.visible(false);
			p.scale_image(true);
			p.image_unselected(tab_img);
			p.image_selected(tab_selected_img);
			p.tab_stop(false);
			p.pad_left(4);
			p.pad_right(2);
			p.font_halign = mFontHalign;
			p.follows.flags = FOLLOWS_LEFT;
			p.follows.flags = FOLLOWS_LEFT;
	
				p.follows.flags = p.follows.flags() | FOLLOWS_TOP;
				p.follows.flags = p.follows.flags() | FOLLOWS_BOTTOM;
++			btn = LLUICtrlFactory::create<LLButton>(p);
James Cook's avatar
James Cook committed
		}
	LLTabTuple* tuple = new LLTabTuple( this, child, btn, textbox );
James Cook's avatar
James Cook committed

	// if new tab was added as a first or last tab, update button image 
	// and update button image of any tab it may have affected
	if (tuple == mTabList.front())
	{  
		update_images(tuple, mFirstTabParams, getTabPosition());

		if (mTabList.size() == 2) 
		{		
			update_images(mTabList[1], mLastTabParams, getTabPosition());
		}
		else if (mTabList.size() > 2) 
		{
			update_images(mTabList[1], mMiddleTabParams, getTabPosition());
		}
	}