PageRenderTime 54ms CodeModel.GetById 32ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llaccordionctrl.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 193 lines | 103 code | 44 blank | 46 comment | 0 complexity | 3592218618c30809ac17282c0e7294e0 MD5 | raw file
  1/** 
  2 * @file LLAccordionCtrl.h
  3 * @brief Accordion Panel implementation
  4 *
  5 * $LicenseInfo:firstyear=2004&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_ACCORDIONCTRL_H
 28#define LL_ACCORDIONCTRL_H
 29
 30#include "llpanel.h"
 31#include "lltextbox.h"
 32#include "llscrollbar.h"
 33
 34#include <vector>
 35#include <algorithm>
 36#include <string>
 37
 38class LLAccordionCtrlTab;
 39
 40class LLAccordionCtrl: public LLPanel
 41{
 42private:
 43
 44	std::vector<LLAccordionCtrlTab*> mAccordionTabs;
 45
 46	void ctrlSetLeftTopAndSize(LLView* panel, S32 left, S32 top, S32 width, S32 height);
 47	void ctrlShiftVertical(LLView* panel,S32 delta);
 48	
 49	void onCollapseCtrlCloseOpen(S16 panel_num); 
 50	void shiftAccordionTabs(S16 panel_num, S32 delta);
 51
 52
 53public:
 54	/**
 55	 * Abstract comparator for accordion tabs.
 56	 */
 57	class LLTabComparator
 58	{
 59	public:
 60		LLTabComparator() {};
 61		virtual ~LLTabComparator() {};
 62
 63		/** Returns true if tab1 < tab2, false otherwise */
 64		virtual bool compare(const LLAccordionCtrlTab* tab1, const LLAccordionCtrlTab* tab2) const = 0;
 65	};
 66
 67	struct Params 
 68		: public LLInitParam::Block<Params, LLPanel::Params>
 69	{
 70		Optional<bool>			single_expansion,
 71								fit_parent; /* Accordion will fit its parent size, controls that are placed into 
 72								accordion tabs are responsible for scrolling their content.
 73								*NOTE fit_parent works best when combined with single_expansion.
 74								Accordion view should implement getRequiredRect() and provide valid height*/
 75		Optional<LLTextBox::Params>	no_matched_tabs_text;
 76		Optional<LLTextBox::Params>	no_visible_tabs_text;
 77
 78		Params()
 79			: single_expansion("single_expansion",false)
 80			, fit_parent("fit_parent", false)
 81			, no_matched_tabs_text("no_matched_tabs_text")
 82			, no_visible_tabs_text("no_visible_tabs_text")
 83		{};
 84	};
 85
 86	LLAccordionCtrl(const Params& params);
 87
 88    LLAccordionCtrl();
 89    virtual ~LLAccordionCtrl();
 90
 91	virtual BOOL postBuild();
 92	
 93	virtual BOOL handleRightMouseDown	( S32 x, S32 y, MASK mask); 
 94	virtual BOOL handleScrollWheel		( S32 x, S32 y, S32 clicks );
 95	virtual BOOL handleKeyHere			(KEY key, MASK mask);
 96	virtual BOOL handleDragAndDrop		(S32 x, S32 y, MASK mask, BOOL drop,
 97										 EDragAndDropType cargo_type,
 98										 void* cargo_data,
 99										 EAcceptance* accept,
100										 std::string& tooltip_msg);
101	//
102
103	// Call reshape after changing splitter's size
104	virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
105
106	void addCollapsibleCtrl(LLView* view);
107	void removeCollapsibleCtrl(LLView* view);
108	void arrange();
109
110
111	void	draw();
112	
113	void	onScrollPosChangeCallback(S32, LLScrollbar*);
114
115	void	onOpen		(const LLSD& key);
116	S32		notifyParent(const LLSD& info);
117
118	void	reset		();
119	void	expandDefaultTab();
120
121	void	setComparator(const LLTabComparator* comp) { mTabComparator = comp; }
122	void	sort();
123
124	/**
125	 * Sets filter substring as a search_term for help text when there are no any visible tabs.
126	 */
127	void	setFilterSubString(const std::string& filter_string);
128
129	/**
130	 * This method returns the first expanded accordion tab.
131	 * It is expected to be called for accordion which doesn't allow multiple
132	 * tabs to be expanded. Use with care.
133	 */
134	const LLAccordionCtrlTab* getExpandedTab() const;
135
136	LLAccordionCtrlTab* getSelectedTab() const { return mSelectedTab; }
137
138	bool getFitParent() const {return mFitParent;}
139
140private:
141	void	initNoTabsWidget(const LLTextBox::Params& tb_params);
142	void	updateNoTabsHelpTextVisibility();
143
144	void	arrangeSinge();
145	void	arrangeMultiple();
146
147	// Calc Splitter's height that is necessary to display all child content
148	S32		calcRecuiredHeight();
149	S32		getRecuiredHeight() const { return mInnerRect.getHeight(); }
150	S32		calcExpandedTabHeight(S32 tab_index = 0, S32 available_height = 0);
151
152	void	updateLayout			(S32 width, S32 height);
153
154	void	show_hide_scrollbar		(S32 width, S32 height);
155
156	void	showScrollbar			(S32 width, S32 height);
157	void	hideScrollbar			(S32 width, S32 height);
158
159	BOOL	autoScroll				(S32 x, S32 y);
160
161	/**
162	 * An adaptor for LLTabComparator
163	 */
164	struct LLComparatorAdaptor
165	{
166		LLComparatorAdaptor(const LLTabComparator& comparator) : mComparator(comparator) {};
167
168		bool operator()(const LLAccordionCtrlTab* tab1, const LLAccordionCtrlTab* tab2)
169		{
170			return mComparator.compare(tab1, tab2);
171		}
172
173		const LLTabComparator& mComparator;
174	};
175
176private:
177	LLRect			mInnerRect;
178	LLScrollbar*	mScrollbar;
179	bool			mSingleExpansion;
180	bool			mFitParent;
181	bool			mAutoScrolling;
182	F32				mAutoScrollRate;
183	LLTextBox*		mNoVisibleTabsHelpText;
184
185	std::string		mNoMatchedTabsOrigString;
186	std::string		mNoVisibleTabsOrigString;
187
188	LLAccordionCtrlTab*		mSelectedTab;
189	const LLTabComparator*	mTabComparator;
190};
191
192
193#endif // LL_LLSPLITTER_H