PageRenderTime 32ms CodeModel.GetById 13ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lltabcontainer.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 313 lines | 208 code | 57 blank | 48 comment | 0 complexity | 42b60824d4823957640746969ad9fb86 MD5 | raw file
  1/** 
  2 * @file lltabcontainer.h
  3 * @brief LLTabContainer class
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_TABCONTAINER_H
 28#define LL_TABCONTAINER_H
 29
 30#include "llpanel.h"
 31#include "lltextbox.h"
 32#include "llframetimer.h"
 33#include "lliconctrl.h"
 34#include "llbutton.h"
 35
 36class LLTabTuple;
 37
 38class LLTabContainer : public LLPanel
 39{
 40public:
 41	enum TabPosition
 42	{
 43		TOP,
 44		BOTTOM,
 45		LEFT
 46	};
 47	typedef enum e_insertion_point
 48	{
 49		START,
 50		END,
 51		LEFT_OF_CURRENT,
 52		RIGHT_OF_CURRENT
 53	} eInsertionPoint;
 54
 55	struct TabPositions : public LLInitParam::TypeValuesHelper<LLTabContainer::TabPosition, TabPositions>
 56	{
 57		static void declareValues();
 58	};
 59
 60	struct TabParams : public LLInitParam::Block<TabParams>
 61	{
 62		Optional<LLUIImage*>				tab_top_image_unselected,
 63											tab_top_image_selected,
 64											tab_top_image_flash,
 65											tab_bottom_image_unselected,
 66											tab_bottom_image_selected,
 67											tab_bottom_image_flash,
 68											tab_left_image_unselected,
 69											tab_left_image_selected,
 70											tab_left_image_flash;		
 71		TabParams();
 72	};
 73
 74	struct Params
 75	:	public LLInitParam::Block<Params, LLPanel::Params>
 76	{
 77		Optional<TabPosition, TabPositions>	tab_position;
 78		Optional<S32>						tab_width,
 79											tab_min_width,
 80											tab_max_width,
 81											tab_height,
 82											label_pad_bottom,
 83											label_pad_left;
 84
 85		Optional<bool>						hide_tabs;
 86		Optional<S32>						tab_padding_right;
 87
 88		Optional<TabParams>					first_tab,
 89											middle_tab,
 90											last_tab;
 91
 92		/**
 93		 * Tab label horizontal alignment
 94		 */
 95		Optional<LLFontGL::HAlign>			font_halign;
 96
 97		/**
 98		 * Tab label ellipses
 99		 */
100		Optional<bool>						use_ellipses;
101
102		/**
103		 * Use LLCustomButtonIconCtrl or LLButton in LLTabTuple
104		 */
105		Optional<bool>						use_custom_icon_ctrl;
106
107		/**
108		 * Open tabs on hover in drag and drop situations
109		 */
110		Optional<bool>						open_tabs_on_drag_and_drop;
111		
112		/**
113		 *  Paddings for LLIconCtrl in case of LLCustomButtonIconCtrl usage(use_custom_icon_ctrl = true)
114		 */
115		Optional<S32>						tab_icon_ctrl_pad;
116
117		Params();
118	};
119
120protected:
121	LLTabContainer(const Params&);
122	friend class LLUICtrlFactory;
123
124public:
125	//LLTabContainer( const std::string& name, const LLRect& rect, TabPosition pos,
126	//				BOOL bordered, BOOL is_vertical);
127
128	/*virtual*/ ~LLTabContainer();
129
130	// from LLView
131	/*virtual*/ void setValue(const LLSD& value);
132
133	/*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
134	/*virtual*/ void draw();
135	/*virtual*/ BOOL handleMouseDown( S32 x, S32 y, MASK mask );
136	/*virtual*/ BOOL handleHover( S32 x, S32 y, MASK mask );
137	/*virtual*/ BOOL handleMouseUp( S32 x, S32 y, MASK mask );
138	/*virtual*/ BOOL handleToolTip(S32 x, S32 y, MASK mask);
139	/*virtual*/ BOOL handleKeyHere(KEY key, MASK mask);
140	/*virtual*/ BOOL handleDragAndDrop(S32 x, S32 y, MASK mask,	BOOL drop,
141									   EDragAndDropType type, void* cargo_data,
142									   EAcceptance* accept, std::string& tooltip);
143	/*virtual*/ LLView* getChildView(const std::string& name, BOOL recurse = TRUE) const;
144	/*virtual*/ LLView* findChildView(const std::string& name, BOOL recurse = TRUE) const;
145	/*virtual*/ void initFromParams(const LLPanel::Params& p);
146	/*virtual*/ bool addChild(LLView* view, S32 tab_group = 0);
147	/*virtual*/ BOOL postBuild();
148
149	struct TabPanelParams : public LLInitParam::Block<TabPanelParams>
150	{
151		Mandatory<LLPanel*>			panel;
152		
153		Optional<std::string>		label;
154		Optional<bool>				select_tab,
155									is_placeholder;
156		Optional<S32>				indent;
157		Optional<eInsertionPoint>	insert_at;
158		Optional<void*>				user_data;
159
160		TabPanelParams()
161		:	panel("panel", NULL),
162			label("label"),
163			select_tab("select_tab"),
164			is_placeholder("is_placeholder"),
165			indent("indent"),
166			insert_at("insert_at", END)
167		{}
168	};
169
170	void		addTabPanel(LLPanel* panel);
171	void		addTabPanel(const TabPanelParams& panel);
172	void 		addPlaceholder(LLPanel* child, const std::string& label);
173	void 		removeTabPanel( LLPanel* child );
174	void 		lockTabs(S32 num_tabs = 0);
175	void 		unlockTabs();
176	S32 		getNumLockedTabs() { return mLockedTabCount; }
177	void 		enableTabButton(S32 which, BOOL enable);
178	void 		deleteAllTabs();
179	LLPanel*	getCurrentPanel();
180	S32			getCurrentPanelIndex();
181	S32			getTabCount();
182	LLPanel*	getPanelByIndex(S32 index);
183	S32			getIndexForPanel(LLPanel* panel);
184	S32			getPanelIndexByTitle(const std::string& title);
185	LLPanel*	getPanelByName(const std::string& name);
186	void		setCurrentTabName(const std::string& name);
187
188	void		selectFirstTab();
189	void		selectLastTab();
190	void		selectNextTab();
191	 void		selectPrevTab();
192	BOOL 		selectTabPanel( LLPanel* child );
193	BOOL 		selectTab(S32 which);
194	BOOL 		selectTabByName(const std::string& title);
195
196	BOOL        getTabPanelFlashing(LLPanel* child);
197	void		setTabPanelFlashing(LLPanel* child, BOOL state);
198	void 		setTabImage(LLPanel* child, std::string img_name, const LLColor4& color = LLColor4::white);
199	void 		setTabImage(LLPanel* child, const LLUUID& img_id, const LLColor4& color = LLColor4::white);
200	void		setTabImage(LLPanel* child, LLIconCtrl* icon);
201	void		setTitle( const std::string& title );
202	const std::string getPanelTitle(S32 index);
203
204	void		setTopBorderHeight(S32 height);
205	S32			getTopBorderHeight() const;
206	
207	void 		setRightTabBtnOffset( S32 offset );
208	void 		setPanelTitle(S32 index, const std::string& title);
209
210	TabPosition getTabPosition() const { return mTabPosition; }
211	void		setMinTabWidth(S32 width) { mMinTabWidth = width; }
212	void		setMaxTabWidth(S32 width) { mMaxTabWidth = width; }
213	S32			getMinTabWidth() const { return mMinTabWidth; }
214	S32			getMaxTabWidth() const { return mMaxTabWidth; }
215
216	void		startDragAndDropDelayTimer() { mDragAndDropDelayTimer.start(); }
217	
218	void onTabBtn( const LLSD& data, LLPanel* panel );
219	void onNextBtn(const LLSD& data);
220	void onNextBtnHeld(const LLSD& data);
221	void onPrevBtn(const LLSD& data);
222	void onPrevBtnHeld(const LLSD& data);
223	void onJumpFirstBtn( const LLSD& data );
224	void onJumpLastBtn( const LLSD& data );
225
226private:
227
228	void initButtons();
229	
230	BOOL		setTab(S32 which);
231
232	LLTabTuple* getTab(S32 index) 		{ return mTabList[index]; }
233	LLTabTuple* getTabByPanel(LLPanel* child);
234	void insertTuple(LLTabTuple * tuple, eInsertionPoint insertion_point);
235
236	S32 getScrollPos() const			{ return mScrollPos; }
237	void setScrollPos(S32 pos)			{ mScrollPos = pos; }
238	S32 getMaxScrollPos() const			{ return mMaxScrollPos; }
239	void setMaxScrollPos(S32 pos)		{ mMaxScrollPos = pos; }
240	S32 getScrollPosPixels() const		{ return mScrollPosPixels; }
241	void setScrollPosPixels(S32 pixels)	{ mScrollPosPixels = pixels; }
242
243	void setTabsHidden(BOOL hidden)		{ mTabsHidden = hidden; }
244	BOOL getTabsHidden() const			{ return mTabsHidden; }
245	
246	void setCurrentPanelIndex(S32 index) { mCurrentTabIdx = index; }
247
248	void scrollPrev() { mScrollPos = llmax(0, mScrollPos-1); } // No wrap
249	void scrollNext() { mScrollPos = llmin(mScrollPos+1, mMaxScrollPos); } // No wrap
250
251	void updateMaxScrollPos();
252	void commitHoveredButton(S32 x, S32 y);
253
254	// updates tab button images given the tuple, tab position and the corresponding params
255	void update_images(LLTabTuple* tuple, TabParams params, LLTabContainer::TabPosition pos);
256	void reshapeTuple(LLTabTuple* tuple);
257
258	// Variables
259	
260	typedef std::vector<LLTabTuple*> tuple_list_t;
261	tuple_list_t					mTabList;
262	
263	S32								mCurrentTabIdx;
264	BOOL							mTabsHidden;
265
266	BOOL							mScrolled;
267	LLFrameTimer					mScrollTimer;
268	S32								mScrollPos;
269	S32								mScrollPosPixels;
270	S32								mMaxScrollPos;
271
272	LLTextBox*						mTitleBox;
273
274	S32								mTopBorderHeight;
275	TabPosition 					mTabPosition;
276	S32								mLockedTabCount;
277	S32								mMinTabWidth;
278	LLButton*						mPrevArrowBtn;
279	LLButton*						mNextArrowBtn;
280
281	BOOL							mIsVertical;
282
283	// Horizontal specific
284	LLButton*						mJumpPrevArrowBtn;
285	LLButton*						mJumpNextArrowBtn;
286
287	S32								mRightTabBtnOffset; // Extra room to the right of the tab buttons.
288
289	S32								mMaxTabWidth;
290	S32								mTotalTabWidth;
291	S32								mTabHeight;
292
293	// Padding under the text labels of tab buttons
294	S32								mLabelPadBottom;
295	// Padding to the left of text labels of tab buttons
296	S32								mLabelPadLeft;
297
298	LLFrameTimer					mDragAndDropDelayTimer;
299	
300	LLFontGL::HAlign                mFontHalign;
301	const LLFontGL*					mFont;
302
303	TabParams						mFirstTabParams;
304	TabParams						mMiddleTabParams;
305	TabParams						mLastTabParams;
306
307	bool							mCustomIconCtrlUsed;
308	bool							mOpenTabsOnDragAndDrop;
309	S32								mTabIconCtrlPad;
310	bool							mUseTabEllipses;
311};
312
313#endif  // LL_TABCONTAINER_H