PageRenderTime 91ms CodeModel.GetById 0ms RepoModel.GetById 1ms 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
Possible License(s): LGPL-2.1
  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. // Text editor widget to let users enter a single line.
  27. #include "linden_common.h"
  28. #include "llsearcheditor.h"
  29. LLSearchEditor::LLSearchEditor(const LLSearchEditor::Params& p)
  30. : LLUICtrl(p),
  31. mSearchButton(NULL),
  32. mClearButton(NULL)
  33. {
  34. S32 srch_btn_top = p.search_button.top_pad + p.search_button.rect.height;
  35. S32 srch_btn_right = p.search_button.rect.width + p.search_button.left_pad;
  36. LLRect srch_btn_rect(p.search_button.left_pad, srch_btn_top, srch_btn_right, p.search_button.top_pad);
  37. S32 clr_btn_top = p.clear_button.rect.bottom + p.clear_button.rect.height;
  38. S32 clr_btn_right = getRect().getWidth() - p.clear_button.pad_right;
  39. S32 clr_btn_left = clr_btn_right - p.clear_button.rect.width;
  40. LLRect clear_btn_rect(clr_btn_left, clr_btn_top, clr_btn_right, p.clear_button.rect.bottom);
  41. S32 text_pad_left = p.text_pad_left;
  42. S32 text_pad_right = p.text_pad_right;
  43. if (p.search_button_visible)
  44. text_pad_left += srch_btn_rect.getWidth();
  45. if (p.clear_button_visible)
  46. text_pad_right = getRect().getWidth() - clr_btn_left + p.clear_button.pad_left;
  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.text_pad_right(text_pad_right);
  54. line_editor_params.revert_on_esc(false);
  55. line_editor_params.commit_callback.function(boost::bind(&LLUICtrl::onCommit, this));
  56. line_editor_params.keystroke_callback(boost::bind(&LLSearchEditor::handleKeystroke, this));
  57. mSearchEditor = LLUICtrlFactory::create<LLLineEditor>(line_editor_params);
  58. mSearchEditor->setPassDelete(TRUE);
  59. addChild(mSearchEditor);
  60. if (p.search_button_visible)
  61. {
  62. // Set up search button.
  63. LLButton::Params srch_btn_params(p.search_button);
  64. srch_btn_params.name(std::string("search button"));
  65. srch_btn_params.rect(srch_btn_rect) ;
  66. srch_btn_params.follows.flags(FOLLOWS_LEFT|FOLLOWS_TOP);
  67. srch_btn_params.tab_stop(false);
  68. srch_btn_params.click_callback.function(boost::bind(&LLUICtrl::onCommit, this));
  69. mSearchButton = LLUICtrlFactory::create<LLButton>(srch_btn_params);
  70. mSearchEditor->addChild(mSearchButton);
  71. }
  72. if (p.clear_button_visible)
  73. {
  74. // Set up clear button.
  75. LLButton::Params clr_btn_params(p.clear_button);
  76. clr_btn_params.name(std::string("clear button"));
  77. clr_btn_params.rect(clear_btn_rect) ;
  78. clr_btn_params.follows.flags(FOLLOWS_RIGHT|FOLLOWS_TOP);
  79. clr_btn_params.tab_stop(false);
  80. clr_btn_params.click_callback.function(boost::bind(&LLSearchEditor::onClearButtonClick, this, _2));
  81. mClearButton = LLUICtrlFactory::create<LLButton>(clr_btn_params);
  82. mSearchEditor->addChild(mClearButton);
  83. }
  84. }
  85. //virtual
  86. void LLSearchEditor::draw()
  87. {
  88. if (mClearButton)
  89. mClearButton->setVisible(!mSearchEditor->getWText().empty());
  90. LLUICtrl::draw();
  91. }
  92. //virtual
  93. void LLSearchEditor::setValue(const LLSD& value )
  94. {
  95. mSearchEditor->setValue(value);
  96. }
  97. //virtual
  98. LLSD LLSearchEditor::getValue() const
  99. {
  100. return mSearchEditor->getValue();
  101. }
  102. //virtual
  103. BOOL LLSearchEditor::setTextArg( const std::string& key, const LLStringExplicit& text )
  104. {
  105. return mSearchEditor->setTextArg(key, text);
  106. }
  107. //virtual
  108. BOOL LLSearchEditor::setLabelArg( const std::string& key, const LLStringExplicit& text )
  109. {
  110. return mSearchEditor->setLabelArg(key, text);
  111. }
  112. //virtual
  113. void LLSearchEditor::setLabel( const LLStringExplicit &new_label )
  114. {
  115. mSearchEditor->setLabel(new_label);
  116. }
  117. //virtual
  118. void LLSearchEditor::clear()
  119. {
  120. if (mSearchEditor)
  121. {
  122. mSearchEditor->clear();
  123. }
  124. }
  125. //virtual
  126. void LLSearchEditor::setFocus( BOOL b )
  127. {
  128. if (mSearchEditor)
  129. {
  130. mSearchEditor->setFocus(b);
  131. }
  132. }
  133. void LLSearchEditor::onClearButtonClick(const LLSD& data)
  134. {
  135. setText(LLStringUtil::null);
  136. mSearchEditor->onCommit(); // force keystroke callback
  137. }
  138. void LLSearchEditor::handleKeystroke()
  139. {
  140. if (mKeystrokeCallback)
  141. {
  142. mKeystrokeCallback(this, getValue());
  143. }
  144. }