PageRenderTime 1032ms CodeModel.GetById 1017ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llaccordionctrltab.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 247 lines | 128 code | 72 blank | 47 comment | 0 complexity | d924248925c39248a9f64207bc037815 MD5 | raw file
  1/** 
  2 * @file LLAccordionCtrlTab.h
  3 * @brief Collapsible box control 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_ACCORDIONCTRLTAB_H_
 28#define LL_ACCORDIONCTRLTAB_H_
 29
 30#include <string>
 31#include "llrect.h"
 32#include "lluictrl.h"
 33#include "lluicolor.h"
 34#include "llstyle.h"
 35
 36class LLUICtrlFactory;
 37class LLUIImage;
 38class LLButton;
 39class LLTextBox;
 40class LLScrollbar;
 41
 42
 43
 44// LLAccordionCtrlTab is a container for other controls. 
 45// It has a Header, by clicking on which hosted controls are shown or hidden.
 46// When hosted controls are show - LLAccordionCtrlTab is expanded.
 47// When hosted controls are hidden - LLAccordionCtrlTab is collapsed.
 48
 49class LLAccordionCtrlTab : public LLUICtrl
 50{
 51// Interface
 52public:
 53
 54	struct Params 
 55	 : public LLInitParam::Block<Params, LLUICtrl::Params>
 56	{
 57		Optional<bool>			display_children, //expanded or collapsed after initialization
 58								collapsible;
 59
 60		Optional<std::string>	title;
 61
 62		Optional<S32>			header_height,
 63								min_width,
 64								min_height;
 65
 66		// Overlay images (arrows on the left)
 67		Mandatory<LLUIImage*>	header_expand_img,
 68								header_expand_img_pressed,
 69								header_collapse_img,
 70								header_collapse_img_pressed;
 71
 72		// Background images for the accordion tabs
 73		Mandatory<LLUIImage*>	header_image,
 74								header_image_over,
 75								header_image_pressed,
 76								header_image_focused;
 77
 78		Optional<LLUIColor>		header_bg_color,
 79								header_text_color,
 80								dropdown_bg_color;
 81
 82		Optional<bool>			header_visible;
 83
 84		Optional<bool>			fit_panel;
 85
 86		Optional<bool>			selection_enabled;
 87
 88		Optional<S32>			padding_left,
 89								padding_right,
 90								padding_top,
 91								padding_bottom;
 92
 93		Params();
 94	};
 95
 96	typedef LLDefaultChildRegistry child_registry_t;
 97
 98	virtual ~LLAccordionCtrlTab();
 99	
100	// Registers callback for expand/collapse events.
101	boost::signals2::connection setDropDownStateChangedCallback(commit_callback_t cb);
102
103	// Changes expand/collapse state
104	virtual void setDisplayChildren(bool display);
105
106	// Returns expand/collapse state
107	virtual bool getDisplayChildren() const {return mDisplayChildren;};
108
109	//set LLAccordionCtrlTab panel
110	void		setAccordionView(LLView* panel);
111	LLView*		getAccordionView() { return mContainerPanel; };
112
113	std::string getTitle() const;
114
115	// Set text and highlight substring in LLAccordionCtrlTabHeader
116	void setTitle(const std::string& title, const std::string& hl = LLStringUtil::null);
117
118	// Set text font style in LLAccordionCtrlTabHeader
119	void setTitleFontStyle(std::string style);
120
121	// Set text color in LLAccordionCtrlTabHeader
122	void setTitleColor(LLUIColor color);
123
124	boost::signals2::connection setFocusReceivedCallback(const focus_signal_t::slot_type& cb);
125	boost::signals2::connection setFocusLostCallback(const focus_signal_t::slot_type& cb);
126
127	void setSelected(bool is_selected);
128
129	bool getCollapsible() {return mCollapsible;};
130
131	void setCollapsible(bool collapsible) {mCollapsible = collapsible;};
132	void changeOpenClose(bool is_open);
133
134	void canOpenClose(bool can_open_close) { mCanOpenClose = can_open_close;};
135	bool canOpenClose() const { return mCanOpenClose; };
136
137	virtual BOOL postBuild();
138
139	S32	notifyParent(const LLSD& info);
140	S32 notify(const LLSD& info);
141	bool notifyChildren(const LLSD& info);
142
143	void draw();
144
145	void    storeOpenCloseState		();
146	void    restoreOpenCloseState	();
147
148protected:
149	LLAccordionCtrlTab(const LLAccordionCtrlTab::Params&);
150	friend class LLUICtrlFactory;
151
152// Overrides
153public:
154
155	// Call reshape after changing size
156	virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
157
158	/**
159	 * Raises notifyParent event with "child_visibility_change" = new_visibility
160	 */
161	void handleVisibilityChange(BOOL new_visibility);
162
163	// Changes expand/collapse state and triggers expand/collapse callbacks
164	virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
165
166	virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask);
167	virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
168
169	virtual BOOL handleToolTip(S32 x, S32 y, MASK mask);
170	virtual BOOL handleScrollWheel( S32 x, S32 y, S32 clicks );
171
172
173	virtual bool addChild(LLView* child, S32 tab_group = 0 );
174
175	bool isExpanded() const { return mDisplayChildren; }
176
177	S32 getHeaderHeight();
178
179	// Min size functions
180
181	void setHeaderVisible(bool value);
182
183	bool getHeaderVisible() { return mHeaderVisible;}
184
185	S32 mExpandedHeight; // Height of expanded ctrl.
186						 // Used to restore height after expand.
187
188	S32	getPaddingLeft() const { return mPaddingLeft;}
189	S32	getPaddingRight() const { return mPaddingRight;}
190	S32	getPaddingTop() const { return mPaddingTop;}
191	S32	getPaddingBottom() const { return mPaddingBottom;}
192
193	void showAndFocusHeader();
194
195	void setFitPanel( bool fit ) { mFitPanel = true; }
196	bool getFitParent() const { return mFitPanel; }
197
198protected:
199	void adjustContainerPanel	(const LLRect& child_rect);
200	void adjustContainerPanel	();
201	S32	 getChildViewHeight		();
202
203	void onScrollPosChangeCallback(S32, LLScrollbar*);
204
205	void show_hide_scrollbar	(const LLRect& child_rect);
206	void showScrollbar			(const LLRect& child_rect);
207	void hideScrollbar			(const LLRect& child_rect);
208
209	void updateLayout			( const LLRect& child_rect );
210	void ctrlSetLeftTopAndSize	(LLView* panel, S32 left, S32 top, S32 width, S32 height);
211
212	void drawChild(const LLRect& root_rect,LLView* child);
213
214	LLView* findContainerView	();
215
216	void selectOnFocusReceived();
217	void deselectOnFocusLost();
218
219private:
220
221	class LLAccordionCtrlTabHeader;
222	LLAccordionCtrlTabHeader* mHeader; //Header
223
224	bool mDisplayChildren; //Expanded/collapsed
225	bool mCollapsible;
226	bool mHeaderVisible;
227
228	bool mCanOpenClose;
229	bool mFitPanel;
230
231	S32	mPaddingLeft;
232	S32	mPaddingRight;
233	S32	mPaddingTop;
234	S32	mPaddingBottom;
235
236	bool mStoredOpenCloseState;
237	bool mWasStateStored;
238
239	bool mSelectionEnabled;
240
241	LLScrollbar*	mScrollbar;
242	LLView*			mContainerPanel;
243
244	LLUIColor mDropdownBGColor;
245};
246
247#endif