PageRenderTime 42ms CodeModel.GetById 2ms app.highlight 36ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/llsearcheditor.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 169 lines | 107 code | 25 blank | 37 comment | 8 complexity | 6e30a4a55ed7aca282e43486559a8601 MD5 | raw file
  1/** 
  2 * @file llsearcheditor.cpp
  3 * @brief LLSearchEditor implementation
  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// Text editor widget to let users enter a single line.
 28
 29#include "linden_common.h"
 30 
 31#include "llsearcheditor.h"
 32
 33LLSearchEditor::LLSearchEditor(const LLSearchEditor::Params& p)
 34:	LLUICtrl(p),
 35	mSearchButton(NULL),
 36	mClearButton(NULL)
 37{
 38	S32 srch_btn_top = p.search_button.top_pad + p.search_button.rect.height;
 39	S32 srch_btn_right = p.search_button.rect.width + p.search_button.left_pad;
 40	LLRect srch_btn_rect(p.search_button.left_pad, srch_btn_top, srch_btn_right, p.search_button.top_pad);
 41
 42	S32 clr_btn_top = p.clear_button.rect.bottom + p.clear_button.rect.height;
 43	S32 clr_btn_right = getRect().getWidth() - p.clear_button.pad_right;
 44	S32 clr_btn_left = clr_btn_right - p.clear_button.rect.width;
 45	LLRect clear_btn_rect(clr_btn_left, clr_btn_top, clr_btn_right, p.clear_button.rect.bottom);
 46
 47	S32 text_pad_left = p.text_pad_left;
 48	S32 text_pad_right = p.text_pad_right;
 49
 50	if (p.search_button_visible)
 51		text_pad_left += srch_btn_rect.getWidth();
 52
 53	if (p.clear_button_visible)
 54		text_pad_right = getRect().getWidth() - clr_btn_left + p.clear_button.pad_left;
 55
 56	// Set up line editor.
 57	LLLineEditor::Params line_editor_params(p);
 58	line_editor_params.name("filter edit box");
 59	line_editor_params.rect(getLocalRect());
 60	line_editor_params.follows.flags(FOLLOWS_ALL);
 61	line_editor_params.text_pad_left(text_pad_left);
 62	line_editor_params.text_pad_right(text_pad_right);
 63	line_editor_params.revert_on_esc(false);
 64	line_editor_params.commit_callback.function(boost::bind(&LLUICtrl::onCommit, this));
 65	line_editor_params.keystroke_callback(boost::bind(&LLSearchEditor::handleKeystroke, this));
 66
 67	mSearchEditor = LLUICtrlFactory::create<LLLineEditor>(line_editor_params);
 68	mSearchEditor->setPassDelete(TRUE);
 69	addChild(mSearchEditor);
 70
 71	if (p.search_button_visible)
 72	{
 73		// Set up search button.
 74		LLButton::Params srch_btn_params(p.search_button);
 75		srch_btn_params.name(std::string("search button"));
 76		srch_btn_params.rect(srch_btn_rect) ;
 77		srch_btn_params.follows.flags(FOLLOWS_LEFT|FOLLOWS_TOP);
 78		srch_btn_params.tab_stop(false);
 79		srch_btn_params.click_callback.function(boost::bind(&LLUICtrl::onCommit, this));
 80	
 81		mSearchButton = LLUICtrlFactory::create<LLButton>(srch_btn_params);
 82		mSearchEditor->addChild(mSearchButton);
 83	}
 84
 85	if (p.clear_button_visible)
 86	{
 87		// Set up clear button.
 88		LLButton::Params clr_btn_params(p.clear_button);
 89		clr_btn_params.name(std::string("clear button"));
 90		clr_btn_params.rect(clear_btn_rect) ;
 91		clr_btn_params.follows.flags(FOLLOWS_RIGHT|FOLLOWS_TOP);
 92		clr_btn_params.tab_stop(false);
 93		clr_btn_params.click_callback.function(boost::bind(&LLSearchEditor::onClearButtonClick, this, _2));
 94
 95		mClearButton = LLUICtrlFactory::create<LLButton>(clr_btn_params);
 96		mSearchEditor->addChild(mClearButton);
 97	}
 98}
 99
100//virtual
101void LLSearchEditor::draw()
102{
103	if (mClearButton)
104		mClearButton->setVisible(!mSearchEditor->getWText().empty());
105
106	LLUICtrl::draw();
107}
108
109//virtual
110void LLSearchEditor::setValue(const LLSD& value )
111{
112	mSearchEditor->setValue(value);
113}
114
115//virtual
116LLSD LLSearchEditor::getValue() const
117{
118	return mSearchEditor->getValue();
119}
120
121//virtual
122BOOL LLSearchEditor::setTextArg( const std::string& key, const LLStringExplicit& text )
123{
124	return mSearchEditor->setTextArg(key, text);
125}
126
127//virtual
128BOOL LLSearchEditor::setLabelArg( const std::string& key, const LLStringExplicit& text )
129{
130	return mSearchEditor->setLabelArg(key, text);
131}
132
133//virtual
134void LLSearchEditor::setLabel( const LLStringExplicit &new_label )
135{
136	mSearchEditor->setLabel(new_label);
137}
138
139//virtual
140void LLSearchEditor::clear()
141{
142	if (mSearchEditor)
143	{
144		mSearchEditor->clear();
145	}
146}
147
148//virtual
149void LLSearchEditor::setFocus( BOOL b )
150{
151	if (mSearchEditor)
152	{
153		mSearchEditor->setFocus(b);
154	}
155}
156
157void LLSearchEditor::onClearButtonClick(const LLSD& data)
158{
159	setText(LLStringUtil::null);
160	mSearchEditor->onCommit(); // force keystroke callback
161}
162
163void LLSearchEditor::handleKeystroke()
164{
165	if (mKeystrokeCallback)
166	{
167		mKeystrokeCallback(this, getValue());
168	}
169}