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