lltextbox.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * @file lltextbox.h
  3. * @brief A single text item display
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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. #ifndef LL_LLTEXTBOX_H
  33. #define LL_LLTEXTBOX_H
  34. #include "llcolor4.h"
  35. #include "lluictrl.h"
  36. class LLTextBox : public LLUICtrl
  37. {
  38. public:
  39. // By default, follows top and left and is mouse-opaque. If no text,
  40. // text = name. If no font, uses default system font.
  41. LLTextBox(const std::string& name,
  42. const LLRect& rect,
  43. const std::string& text,
  44. const LLFontGL* fontp = NULL,
  45. bool mouse_opaque = true);
  46. // Construct a textbox which handles word wrapping for us.
  47. LLTextBox(const std::string& name,
  48. const std::string& text,
  49. F32 max_width = 200,
  50. const LLFontGL* fontp = NULL,
  51. bool mouse_opaque = true);
  52. // "Simple" constructors for text boxes that have the same name and label
  53. // *TO BE DEPRECATED*
  54. LLTextBox(const std::string& name_and_label,
  55. const LLRect& rect);
  56. // Consolidate common member initialization
  57. void initDefaults();
  58. const std::string& getTag() const override;
  59. LLXMLNodePtr getXML(bool save_children = true) const override;
  60. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  61. class LLUICtrlFactory* factory);
  62. void draw() override;
  63. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  64. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  65. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  66. bool handleHover(S32 x, S32 y, MASK mask) override;
  67. LL_INLINE void setColor(const LLColor4& c) override { mTextColor = c; }
  68. LL_INLINE void setDisabledColor(const LLColor4& c) { mDisabledColor = c; }
  69. LL_INLINE void setBackgroundColor(const LLColor4& c) { mBackgroundColor = c; }
  70. LL_INLINE void setBorderColor(const LLColor4& c) { mBorderColor = c; }
  71. LL_INLINE void setHoverColor(const LLColor4& c) { mHoverColor = c; }
  72. LL_INLINE void setHoverActive(bool active) { mHoverActive = active; }
  73. void setText(const std::string& text);
  74. // max_width = -1 means use existing control width
  75. void setWrappedText(const std::string& text, F32 max_width = -1.f);
  76. LL_INLINE void setUseEllipses(bool b) { mUseEllipses = b; }
  77. LL_INLINE void setBackgroundVisible(bool b) { mBackgroundVisible = b; }
  78. LL_INLINE void setBorderVisible(bool b) { mBorderVisible = b; }
  79. LL_INLINE void setFontStyle(U8 style) { mFontStyle = style; }
  80. LL_INLINE void setBorderDropshadowVisible(bool b) { mBorderDropShadowVisible = b; }
  81. LL_INLINE void setHPad(S32 pixels) { mHPad = pixels; }
  82. LL_INLINE void setVPad(S32 pixels) { mVPad = pixels; }
  83. LL_INLINE void setRightAlign() { mHAlign = LLFontGL::RIGHT; }
  84. LL_INLINE void setHAlign(LLFontGL::HAlign align) { mHAlign = align; }
  85. // Mouse down and up within text area
  86. LL_INLINE void setClickedCallback(void (*cb)(void*), void* data = NULL)
  87. {
  88. mClickedCallback = cb;
  89. mCallbackUserData = data;
  90. }
  91. // Allow to change the font on the fly. HB
  92. void setFont(LLFontGL* fontp);
  93. LL_INLINE LLFontGL* getFont() const { return mFontGL; }
  94. void reshapeToFitText();
  95. LL_INLINE const std::string& getText() const { return mText.getString(); }
  96. S32 getTextPixelWidth();
  97. S32 getTextPixelHeight();
  98. LL_INLINE void setValue(const LLSD& value) override { setText(value.asString()); }
  99. LL_INLINE LLSD getValue() const override { return LLSD(getText()); }
  100. bool setTextArg(const std::string& key, const std::string& text) override;
  101. private:
  102. void setLineLengths();
  103. void drawText(S32 x, S32 y, const LLColor4& color);
  104. private:
  105. LLUIString mText;
  106. LLFontGL* mFontGL;
  107. LLColor4 mTextColor;
  108. LLColor4 mDisabledColor;
  109. LLColor4 mBackgroundColor;
  110. LLColor4 mBorderColor;
  111. LLColor4 mHoverColor;
  112. S32 mLineSpacing;
  113. S32 mHPad;
  114. S32 mVPad;
  115. LLFontGL::HAlign mHAlign;
  116. LLFontGL::VAlign mVAlign;
  117. void (*mClickedCallback)(void* data);
  118. void* mCallbackUserData;
  119. bool mHoverActive;
  120. bool mHasHover;
  121. bool mBackgroundVisible;
  122. bool mBorderVisible;
  123. bool mBorderDropShadowVisible;
  124. bool mUseEllipses;
  125. U8 mFontStyle; // Style bit flags for font
  126. std::vector<S32> mLineLengthList;
  127. };
  128. #endif