llsearcheditor.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:5k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llsearcheditor.cpp
  3.  * @brief LLSearchEditor implementation
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. // Text editor widget to let users enter a single line.
  33. #include "linden_common.h"
  34.  
  35. #include "llsearcheditor.h"
  36. LLSearchEditor::LLSearchEditor(const LLSearchEditor::Params& p)
  37. : LLUICtrl(p),
  38. mSearchButton(NULL),
  39. mClearButton(NULL)
  40. {
  41. S32 srch_btn_top = p.search_button.top_pad + p.search_button.rect.height;
  42. S32 srch_btn_right = p.search_button.rect.width + p.search_button.left_pad;
  43. LLRect srch_btn_rect(p.search_button.left_pad, srch_btn_top, srch_btn_right, p.search_button.top_pad);
  44. S32 text_pad_left = p.text_pad_left;
  45. if (p.search_button_visible)
  46. text_pad_left += srch_btn_rect.getWidth();
  47. // Set up line editor.
  48. LLLineEditor::Params line_editor_params(p);
  49. line_editor_params.name("filter edit box");
  50. line_editor_params.rect(getLocalRect());
  51. line_editor_params.follows.flags(FOLLOWS_ALL);
  52. line_editor_params.text_pad_left(text_pad_left);
  53. line_editor_params.revert_on_esc(false);
  54. line_editor_params.commit_callback.function(boost::bind(&LLUICtrl::onCommit, this));
  55. line_editor_params.keystroke_callback(boost::bind(&LLSearchEditor::handleKeystroke, this));
  56. mSearchEditor = LLUICtrlFactory::create<LLLineEditor>(line_editor_params);
  57. mSearchEditor->setPassDelete(TRUE);
  58. addChild(mSearchEditor);
  59. if (p.search_button_visible)
  60. {
  61. // Set up search button.
  62. LLButton::Params srch_btn_params(p.search_button);
  63. srch_btn_params.name(std::string("search button"));
  64. srch_btn_params.rect(srch_btn_rect) ;
  65. srch_btn_params.follows.flags(FOLLOWS_LEFT|FOLLOWS_TOP);
  66. srch_btn_params.tab_stop(false);
  67. srch_btn_params.click_callback.function(boost::bind(&LLUICtrl::onCommit, this));
  68. mSearchButton = LLUICtrlFactory::create<LLButton>(srch_btn_params);
  69. mSearchEditor->addChild(mSearchButton);
  70. }
  71. if (p.clear_button_visible)
  72. {
  73. // Set up clear button.
  74. LLButton::Params clr_btn_params(p.clear_button);
  75. clr_btn_params.name(std::string("clear button"));
  76. S32 clr_btn_top = clr_btn_params.rect.bottom + clr_btn_params.rect.height;
  77. S32 clr_btn_right = getRect().getWidth() - clr_btn_params.pad_right;
  78. S32 clr_btn_left = clr_btn_right - clr_btn_params.rect.width;
  79. LLRect clear_btn_rect(clr_btn_left, clr_btn_top, clr_btn_right, p.clear_button.rect.bottom);
  80. clr_btn_params.rect(clear_btn_rect) ;
  81. clr_btn_params.follows.flags(FOLLOWS_RIGHT|FOLLOWS_TOP);
  82. clr_btn_params.tab_stop(false);
  83. clr_btn_params.click_callback.function(boost::bind(&LLSearchEditor::onClearButtonClick, this, _2));
  84. mClearButton = LLUICtrlFactory::create<LLButton>(clr_btn_params);
  85. mSearchEditor->addChild(mClearButton);
  86. }
  87. }
  88. //virtual
  89. void LLSearchEditor::draw()
  90. {
  91. if (mClearButton)
  92. mClearButton->setVisible(!mSearchEditor->getWText().empty());
  93. LLUICtrl::draw();
  94. }
  95. //virtual
  96. void LLSearchEditor::setValue(const LLSD& value )
  97. {
  98. mSearchEditor->setValue(value);
  99. }
  100. //virtual
  101. LLSD LLSearchEditor::getValue() const
  102. {
  103. return mSearchEditor->getValue();
  104. }
  105. //virtual
  106. BOOL LLSearchEditor::setTextArg( const std::string& key, const LLStringExplicit& text )
  107. {
  108. return mSearchEditor->setTextArg(key, text);
  109. }
  110. //virtual
  111. BOOL LLSearchEditor::setLabelArg( const std::string& key, const LLStringExplicit& text )
  112. {
  113. return mSearchEditor->setLabelArg(key, text);
  114. }
  115. //virtual
  116. void LLSearchEditor::setLabel( const LLStringExplicit &new_label )
  117. {
  118. mSearchEditor->setLabel(new_label);
  119. }
  120. //virtual
  121. void LLSearchEditor::clear()
  122. {
  123. if (mSearchEditor)
  124. {
  125. mSearchEditor->clear();
  126. }
  127. }
  128. //virtual
  129. void LLSearchEditor::setFocus( BOOL b )
  130. {
  131. if (mSearchEditor)
  132. {
  133. mSearchEditor->setFocus(b);
  134. }
  135. }
  136. void LLSearchEditor::onClearButtonClick(const LLSD& data)
  137. {
  138. mSearchEditor->selectAll();
  139. mSearchEditor->doDelete(); // force keystroke callback
  140. }
  141. void LLSearchEditor::handleKeystroke()
  142. {
  143. if (mKeystrokeCallback)
  144. {
  145. mKeystrokeCallback(this, getValue());
  146. }
  147. }