llscrollcontainer.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @file llscrollcontainer.h
  3. * @brief LLScrollableContainer class header file.
  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_LLSCROLLCONTAINER_H
  33. #define LL_LLSCROLLCONTAINER_H
  34. #include "llcoord.h"
  35. #include "llscrollbar.h"
  36. #include "lluictrl.h"
  37. #include "llcolor4.h"
  38. class LLViewBorder;
  39. class LLUICtrlFactory;
  40. // A decorator view class meant to encapsulate a clipped region which is
  41. // scrollable. It automatically takes care of pixel perfect scrolling and
  42. // clipping, as well as turning the scrollbars on or off based on the width
  43. // and height of the view you're scrolling.
  44. class LLScrollableContainer : public LLUICtrl
  45. {
  46. protected:
  47. LOG_CLASS(LLScrollableContainer);
  48. public:
  49. // Note: vertical comes before horizontal because vertical
  50. // scrollbars have priority for mouse and keyboard events.
  51. enum SCROLL_ORIENTATION { VERTICAL, HORIZONTAL, SCROLLBAR_COUNT };
  52. LLScrollableContainer(const std::string& name, const LLRect& rect,
  53. LLView* scrolled_view, bool is_opaque = false,
  54. const LLColor4& bg_color = LLColor4(0, 0, 0, 0));
  55. LLScrollableContainer(const std::string& name, const LLRect& rect,
  56. LLUICtrl* scrolled_ctrl, bool is_opaque = false,
  57. const LLColor4& bg_color = LLColor4(0, 0, 0, 0));
  58. ~LLScrollableContainer() override;
  59. LL_INLINE void setScrolledView(LLView* view) { mScrolledView = view; }
  60. LL_INLINE void setValue(const LLSD& v) override { mInnerRect.setValue(v); }
  61. void calcVisibleSize(S32* visible_width, S32* visible_height,
  62. bool* show_h_scrollbar, bool* show_v_scrollbar) const;
  63. void calcVisibleSize(const LLRect& doc_rect, S32* visible_width,
  64. S32* visible_height, bool* show_h_scrollbar,
  65. bool* show_v_scrollbar) const;
  66. void setBorderVisible(bool b);
  67. void scrollToShowRect(const LLRect& rect, const LLCoordGL& desired_offset);
  68. LL_INLINE void setReserveScrollCorner(bool b) { mReserveScrollCorner = b; }
  69. LL_INLINE const LLRect& getScrolledViewRect() const { return mScrolledView->getRect(); }
  70. LLRect getContentWindowRect();
  71. void pageUp(S32 overlap = 0);
  72. void pageDown(S32 overlap = 0);
  73. void goToTop();
  74. void goToBottom();
  75. S32 getBorderWidth() const;
  76. bool needsToScroll(S32 x, S32 y, SCROLL_ORIENTATION axis) const;
  77. // LLView functionality
  78. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  79. bool handleKeyHere(KEY key, MASK mask) override;
  80. bool handleScrollWheel(S32 x, S32 y, S32 clicks) override;
  81. bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  82. EDragAndDropType cargo_type,
  83. void* cargo_data, EAcceptance* accept,
  84. std::string& tooltip_msg) override;
  85. bool handleToolTip(S32 x, S32 y, std::string& msg, LLRect* rect) override;
  86. void draw() override;
  87. const std::string& getTag() const override;
  88. LLXMLNodePtr getXML(bool save_children = true) const override;
  89. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  90. LLUICtrlFactory* factory);
  91. private:
  92. void init();
  93. // Internal scrollbar handlers
  94. virtual void scrollHorizontal(S32 new_pos);
  95. virtual void scrollVertical(S32 new_pos);
  96. void updateScroll();
  97. private:
  98. LLScrollbar* mScrollbar[SCROLLBAR_COUNT];
  99. LLView* mScrolledView;
  100. LLColor4 mBackgroundColor;
  101. LLRect mInnerRect;
  102. LLViewBorder* mBorder;
  103. F32 mAutoScrollRate;
  104. bool mAutoScrolling;
  105. bool mReserveScrollCorner;
  106. bool mIsOpaque;
  107. };
  108. #endif // LL_LLSCROLLCONTAINER_H