PageRenderTime 29ms CodeModel.GetById 15ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lltextbox.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 179 lines | 110 code | 34 blank | 35 comment | 11 complexity | e047fa0350f493b09e737bcad456fabb MD5 | raw file
  1/** 
  2 * @file lltextbox.cpp
  3 * @brief A text display widget
  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#include "linden_common.h"
 28
 29#define LLTEXTBOX_CPP
 30#include "lltextbox.h"
 31
 32#include "lluictrlfactory.h"
 33#include "llfocusmgr.h"
 34#include "llwindow.h"
 35#include "llurlregistry.h"
 36#include "llstyle.h"
 37
 38static LLDefaultChildRegistry::Register<LLTextBox> r("text");
 39
 40// Compiler optimization, generate extern template
 41template class LLTextBox* LLView::getChild<class LLTextBox>(
 42	const std::string& name, BOOL recurse) const;
 43
 44LLTextBox::LLTextBox(const LLTextBox::Params& p)
 45:	LLTextBase(p),
 46	mClickedCallback(NULL)
 47{}
 48
 49LLTextBox::~LLTextBox()
 50{}
 51
 52BOOL LLTextBox::handleMouseDown(S32 x, S32 y, MASK mask)
 53{
 54	BOOL	handled = LLTextBase::handleMouseDown(x, y, mask);
 55
 56	if (getSoundFlags() & MOUSE_DOWN)
 57	{
 58		make_ui_sound("UISndClick");
 59	}
 60
 61	if (!handled && mClickedCallback)
 62	{
 63		// Route future Mouse messages here preemptively.  (Release on mouse up.)
 64		gFocusMgr.setMouseCapture( this );
 65
 66		handled = TRUE;
 67	}
 68
 69	return handled;
 70}
 71
 72BOOL LLTextBox::handleMouseUp(S32 x, S32 y, MASK mask)
 73{
 74	BOOL	handled = FALSE;
 75
 76	if (getSoundFlags() & MOUSE_UP)
 77	{
 78		make_ui_sound("UISndClickRelease");
 79	}
 80
 81	// We only handle the click if the click both started and ended within us
 82	if (hasMouseCapture())
 83	{
 84		// Release the mouse
 85		gFocusMgr.setMouseCapture( NULL );
 86
 87		// DO THIS AT THE VERY END to allow the button  to be destroyed
 88		// as a result of being clicked.  If mouseup in the widget,
 89		// it's been clicked
 90		if (mClickedCallback && !handled)
 91		{
 92			mClickedCallback();
 93			handled = TRUE;
 94		}
 95	}
 96	else
 97	{
 98		handled = LLTextBase::handleMouseUp(x, y, mask);
 99	}
100
101	return handled;
102}
103
104BOOL LLTextBox::handleHover(S32 x, S32 y, MASK mask)
105{
106	BOOL handled = LLTextBase::handleHover(x, y, mask);
107	if (!handled && mClickedCallback)
108	{
109		// Clickable text boxes change the cursor to a hand
110		LLUI::getWindow()->setCursor(UI_CURSOR_HAND);
111		return TRUE;
112	}
113	return handled;
114}
115
116void LLTextBox::setEnabled(BOOL enabled)
117{
118	// just treat enabled as read-only flag
119	bool read_only = !enabled;
120	if (read_only != mReadOnly)
121	{
122		LLTextBase::setReadOnly(read_only);
123		updateSegments();
124	}
125}
126
127void LLTextBox::setText(const LLStringExplicit& text , const LLStyle::Params& input_params )
128{
129	// does string argument insertion
130	mText.assign(text);
131	
132	LLTextBase::setText(mText.getString(), input_params );
133}
134
135void LLTextBox::setClickedCallback( boost::function<void (void*)> cb, void* userdata /*= NULL */ )
136{
137	mClickedCallback = boost::bind(cb, userdata);
138}
139
140S32 LLTextBox::getTextPixelWidth()
141{
142	return getTextBoundingRect().getWidth();
143}
144
145S32 LLTextBox::getTextPixelHeight()
146{
147	return getTextBoundingRect().getHeight();
148}
149
150
151LLSD LLTextBox::getValue() const
152{
153	return LLSD(getText());
154}
155
156BOOL LLTextBox::setTextArg( const std::string& key, const LLStringExplicit& text )
157{
158	mText.setArg(key, text);
159	LLTextBase::setText(mText.getString());
160
161	return TRUE;
162}
163
164
165void LLTextBox::reshapeToFitText()
166{
167	reflow();
168
169	S32 width = getTextPixelWidth();
170	S32 height = getTextPixelHeight();
171	reshape( width + 2 * mHPad, height + 2 * mVPad, FALSE );
172}
173
174
175void LLTextBox::onUrlLabelUpdated(const std::string &url, const std::string &label)
176{
177	needsReflow();
178}
179