PageRenderTime 69ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llexpandabletextbox.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 214 lines | 73 code | 43 blank | 98 comment | 0 complexity | fb20d666daf9b79796d9b36068d443f6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llexpandabletextbox.h
  3. * @brief LLExpandableTextBox and related class definitions
  4. *
  5. * $LicenseInfo:firstyear=2004&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. #ifndef LL_LLEXPANDABLETEXTBOX_H
  27. #define LL_LLEXPANDABLETEXTBOX_H
  28. #include "lltexteditor.h"
  29. #include "llscrollcontainer.h"
  30. /**
  31. * LLExpandableTextBox is a text box control that will show "More" link at end of text
  32. * if text doesn't fit into text box. After pressing "More" the text box will expand to show
  33. * all text. If text is still too big, a scroll bar will appear inside expanded text box.
  34. */
  35. class LLExpandableTextBox : public LLUICtrl
  36. {
  37. protected:
  38. /**
  39. * Extended text box. "More" link will appear at end of text if
  40. * text is too long to fit into text box size.
  41. */
  42. class LLTextBoxEx : public LLTextEditor
  43. {
  44. public:
  45. struct Params : public LLInitParam::Block<Params, LLTextEditor::Params>
  46. {
  47. Params();
  48. };
  49. // adds or removes "More" link as needed
  50. /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  51. /*virtual*/ void setText(const LLStringExplicit& text, const LLStyle::Params& input_params = LLStyle::Params());
  52. void setTextBase(const std::string& text) { LLTextBase::setText(text); }
  53. /**
  54. * Returns difference between text box height and text height.
  55. * Value is positive if text height is greater than text box height.
  56. */
  57. virtual S32 getVerticalTextDelta();
  58. /**
  59. * Returns the height of text rect.
  60. */
  61. S32 getTextPixelHeight();
  62. /**
  63. * Shows "More" link
  64. */
  65. void showExpandText();
  66. /**
  67. * Hides "More" link
  68. */
  69. void hideExpandText();
  70. /**
  71. * Shows the "More" link if the text is too high to be completely
  72. * visible without expanding the text box. Hides that link otherwise.
  73. */
  74. void hideOrShowExpandTextAsNeeded();
  75. protected:
  76. LLTextBoxEx(const Params& p);
  77. friend class LLUICtrlFactory;
  78. private:
  79. std::string mExpanderLabel;
  80. bool mExpanderVisible;
  81. };
  82. public:
  83. struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
  84. {
  85. Optional<LLTextBoxEx::Params> textbox;
  86. Optional<LLScrollContainer::Params> scroll;
  87. Optional<S32> max_height;
  88. Optional<bool> bg_visible,
  89. expanded_bg_visible;
  90. Optional<LLUIColor> bg_color,
  91. expanded_bg_color;
  92. Params();
  93. };
  94. /**
  95. * Sets text
  96. */
  97. virtual void setText(const std::string& str);
  98. /**
  99. * Returns text
  100. */
  101. virtual std::string getText() const { return mText; }
  102. /**
  103. * Sets text
  104. */
  105. /*virtual*/ void setValue(const LLSD& value);
  106. /**
  107. * Returns text
  108. */
  109. /*virtual*/ LLSD getValue() const { return mText; }
  110. /**
  111. * Collapses text box on focus_lost event
  112. */
  113. /*virtual*/ void onFocusLost();
  114. /**
  115. * Collapses text box on top_lost event
  116. */
  117. /*virtual*/ void onTopLost();
  118. /**
  119. * *HACK: Update the inner textbox shape.
  120. */
  121. void updateTextShape();
  122. /**
  123. * Draws text box, collapses text box if its expanded and its parent's position changed
  124. */
  125. /*virtual*/ void draw();
  126. protected:
  127. LLExpandableTextBox(const Params& p);
  128. friend class LLUICtrlFactory;
  129. /**
  130. * Expands text box.
  131. * A scroll bar will appear if expanded height is greater than max_height
  132. */
  133. virtual void expandTextBox();
  134. /**
  135. * Collapses text box.
  136. */
  137. virtual void collapseTextBox();
  138. /**
  139. * Collapses text box if it is expanded and its parent's position changed
  140. */
  141. virtual void collapseIfPosChanged();
  142. /**
  143. * Updates text box rect to avoid horizontal scroll bar
  144. */
  145. virtual void updateTextBoxRect();
  146. /**
  147. * User clicked on "More" link - expand text box
  148. */
  149. virtual void onExpandClicked();
  150. /**
  151. * Saves collapsed text box's states(rect, parent rect...)
  152. */
  153. virtual void saveCollapsedState();
  154. /**
  155. * Recalculate text delta considering min_height and window rect.
  156. */
  157. virtual S32 recalculateTextDelta(S32 text_delta);
  158. protected:
  159. std::string mText;
  160. LLTextBoxEx* mTextBox;
  161. LLScrollContainer* mScroll;
  162. S32 mMaxHeight;
  163. LLRect mCollapsedRect;
  164. bool mExpanded;
  165. LLRect mParentRect;
  166. bool mBGVisible;
  167. bool mExpandedBGVisible;
  168. LLUIColor mBGColor;
  169. LLUIColor mExpandedBGColor;
  170. };
  171. #endif //LL_LLEXPANDABLETEXTBOX_H