PageRenderTime 204ms CodeModel.GetById 101ms app.highlight 9ms RepoModel.GetById 91ms app.codeStats 0ms

/indra/newview/llexpandabletextbox.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 214 lines | 73 code | 43 blank | 98 comment | 0 complexity | fb20d666daf9b79796d9b36068d443f6 MD5 | raw file
  1/** 
  2 * @file llexpandabletextbox.h
  3 * @brief LLExpandableTextBox and related class definitions
  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_LLEXPANDABLETEXTBOX_H
 28#define LL_LLEXPANDABLETEXTBOX_H
 29
 30#include "lltexteditor.h"
 31#include "llscrollcontainer.h"
 32
 33/**
 34 * LLExpandableTextBox is a text box control that will show "More" link at end of text
 35 * if text doesn't fit into text box. After pressing "More" the text box will expand to show
 36 * all text. If text is still too big, a scroll bar will appear inside expanded text box.
 37 */
 38class LLExpandableTextBox : public LLUICtrl
 39{
 40protected:
 41
 42	/**
 43	 * Extended text box. "More" link will appear at end of text if 
 44	 * text is too long to fit into text box size.
 45	 */
 46	class LLTextBoxEx : public LLTextEditor
 47	{
 48	public:
 49		struct Params :	public LLInitParam::Block<Params, LLTextEditor::Params>
 50		{
 51			Params();
 52		};
 53
 54		// adds or removes "More" link as needed
 55		/*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
 56		/*virtual*/ void setText(const LLStringExplicit& text, const LLStyle::Params& input_params = LLStyle::Params());
 57		void setTextBase(const std::string& text) { LLTextBase::setText(text); }
 58
 59		/**
 60		 * Returns difference between text box height and text height.
 61		 * Value is positive if text height is greater than text box height.
 62		 */
 63		virtual S32 getVerticalTextDelta();
 64
 65		/**
 66		 * Returns the height of text rect.
 67		 */
 68		S32 getTextPixelHeight();
 69
 70		/**
 71		 * Shows "More" link
 72		 */
 73		void showExpandText();
 74
 75		/**
 76		 * Hides "More" link
 77		 */
 78		void hideExpandText();
 79
 80		/**
 81		 * Shows the "More" link if the text is too high to be completely
 82		 * visible without expanding the text box. Hides that link otherwise.
 83		 */
 84		void hideOrShowExpandTextAsNeeded();
 85
 86	protected:
 87
 88		LLTextBoxEx(const Params& p);
 89		friend class LLUICtrlFactory;
 90
 91	private:
 92		std::string mExpanderLabel;
 93
 94		bool mExpanderVisible;
 95	};
 96
 97public:
 98
 99	struct Params :	public LLInitParam::Block<Params, LLUICtrl::Params>
100	{
101		Optional<LLTextBoxEx::Params> textbox;
102
103		Optional<LLScrollContainer::Params> scroll;
104
105		Optional<S32> max_height;
106
107		Optional<bool> bg_visible,
108					   expanded_bg_visible;
109
110		Optional<LLUIColor> bg_color,
111						   expanded_bg_color;
112
113		Params();
114	};
115
116	/**
117	 * Sets text
118	 */
119	virtual void setText(const std::string& str);
120
121	/**
122	 * Returns text
123	 */
124	virtual std::string getText() const { return mText; }
125
126	/**
127	 * Sets text
128	 */
129	/*virtual*/ void setValue(const LLSD& value);
130
131	/**
132	 * Returns text
133	 */
134	/*virtual*/ LLSD getValue() const { return mText; }
135
136	/**
137	 * Collapses text box on focus_lost event
138	 */
139	/*virtual*/ void onFocusLost();
140
141	/**
142	 * Collapses text box on top_lost event
143	 */
144	/*virtual*/ void onTopLost();
145
146	/**
147	 * *HACK: Update the inner textbox shape.
148	 */
149	void updateTextShape();
150
151	/**
152	 * Draws text box, collapses text box if its expanded and its parent's position changed
153	 */
154	/*virtual*/ void draw();
155
156protected:
157
158	LLExpandableTextBox(const Params& p);
159	friend class LLUICtrlFactory;
160
161	/**
162	 * Expands text box.
163	 * A scroll bar will appear if expanded height is greater than max_height
164	 */
165	virtual void expandTextBox();
166
167	/**
168	 * Collapses text box.
169	 */
170	virtual void collapseTextBox();
171
172	/**
173	 * Collapses text box if it is expanded and its parent's position changed
174	 */
175	virtual void collapseIfPosChanged();
176
177	/**
178	 * Updates text box rect to avoid horizontal scroll bar
179	 */
180	virtual void updateTextBoxRect();
181
182	/**
183	 * User clicked on "More" link - expand text box
184	 */
185	virtual void onExpandClicked();
186
187	/**
188	 * Saves collapsed text box's states(rect, parent rect...)
189	 */
190	virtual void saveCollapsedState();
191
192	/**
193	 * Recalculate text delta considering min_height and window rect.
194	 */
195	virtual S32 recalculateTextDelta(S32 text_delta);
196
197protected:
198
199	std::string mText;
200	LLTextBoxEx* mTextBox;
201	LLScrollContainer* mScroll;
202
203	S32 mMaxHeight;
204	LLRect mCollapsedRect;
205	bool mExpanded;
206	LLRect mParentRect;
207
208	bool mBGVisible;
209	bool mExpandedBGVisible;
210	LLUIColor mBGColor;
211	LLUIColor mExpandedBGColor;
212};
213
214#endif //LL_LLEXPANDABLETEXTBOX_H