lltabcontainer.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**
  2. * @file lltabcontainer.h
  3. * @brief LLTabContainer class
  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_TABCONTAINER_H
  33. #define LL_TABCONTAINER_H
  34. #include "llframetimer.h"
  35. #include "llpanel.h"
  36. #include "lltextbox.h"
  37. constexpr S32 TABCNTR_CLOSE_BTN_SIZE = 16;
  38. constexpr S32 TABCNTR_HEADER_HEIGHT = LLPANEL_BORDER_WIDTH +
  39. TABCNTR_CLOSE_BTN_SIZE;
  40. class LLTabContainer : public LLPanel
  41. {
  42. protected:
  43. LOG_CLASS(LLTabContainer);
  44. public:
  45. enum TabPosition
  46. {
  47. TOP,
  48. BOTTOM,
  49. LEFT
  50. };
  51. typedef enum e_insertion_point
  52. {
  53. START,
  54. END,
  55. LEFT_OF_CURRENT,
  56. RIGHT_OF_CURRENT
  57. } eInsertionPoint;
  58. LLTabContainer(const std::string& name, const LLRect& rect,
  59. TabPosition pos, bool bordered, bool is_vertical);
  60. ~LLTabContainer() override;
  61. // From LLView
  62. void setValue(const LLSD& value) override;
  63. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  64. void draw() override;
  65. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  66. bool handleHover(S32 x, S32 y, MASK mask) override;
  67. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  68. bool handleToolTip(S32 x, S32 y, std::string& msg, LLRect* rect) override;
  69. bool handleKeyHere(KEY key, MASK mask) override;
  70. bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  71. EDragAndDropType type, void* cargo_data,
  72. EAcceptance* accept, std::string& tooltip) override;
  73. const std::string& getTag() const override;
  74. LLXMLNodePtr getXML(bool save_children = true) const override;
  75. LLView* getChildView(const char* name, bool recurse = true,
  76. bool create_if_missing = true) const override;
  77. void addTabPanel(LLPanel* child, const std::string& label,
  78. bool select = false,
  79. void (*on_tab_clicked)(void*, bool) = NULL,
  80. void* userdata = NULL,
  81. S32 indent = 0, bool placeholder = false,
  82. eInsertionPoint insertion_point = END);
  83. void addPlaceholder(LLPanel* child, const std::string& label);
  84. void removeTabPanel(LLPanel* child);
  85. void lockTabs(S32 num_tabs = 0);
  86. void unlockTabs();
  87. LL_INLINE S32 getNumLockedTabs() { return mLockedTabCount; }
  88. void enableTabButton(S32 which, bool enable);
  89. void deleteAllTabs();
  90. LLPanel* getCurrentPanel();
  91. S32 getCurrentPanelIndex();
  92. S32 getTabCount();
  93. LLPanel* getPanelByIndex(S32 index);
  94. S32 getIndexForPanel(LLPanel* panel);
  95. S32 getPanelIndexByTitle(const std::string& title);
  96. LLPanel* getPanelByName(const std::string& name);
  97. void setCurrentTabName(const std::string& name);
  98. LL_INLINE S32 getTotalTabWidth() const { return mTotalTabWidth; }
  99. void selectFirstTab();
  100. void selectLastTab();
  101. void selectNextTab();
  102. void selectPrevTab();
  103. bool selectTabPanel(LLPanel* child);
  104. bool selectTab(S32 which);
  105. bool selectTabByName(const std::string& title);
  106. bool setTab(S32 which);
  107. // Sets a tooltip on the tab button: when 'tooltip' is an empty string,
  108. // the tooltip is reverted to the default one.
  109. void setTabButtonTooltip(LLPanel* child, const std::string& tooltip);
  110. bool getTabPanelFlashing(LLPanel* child);
  111. void setTabPanelFlashing(LLPanel* child, bool state);
  112. void setTabImage(LLPanel* child, std::string img_name,
  113. const LLColor4& color = LLColor4::white);
  114. void setTitle(const std::string& title);
  115. const std::string getPanelTitle(S32 index);
  116. void setTopBorderHeight(S32 height);
  117. S32 getTopBorderHeight() const;
  118. void setTabChangeCallback(LLPanel* tab,
  119. void (*on_tab_clicked)(void*, bool));
  120. void setTabPrecommitChangeCallback(LLPanel* tab,
  121. void (*on_precommit)(void*, bool));
  122. void setTabUserData(LLPanel* tab, void* userdata);
  123. void setRightTabBtnOffset(S32 offset);
  124. void setPanelTitle(S32 index, const std::string& title);
  125. LL_INLINE TabPosition getTabPosition() const { return mTabPosition; }
  126. LL_INLINE void setMinTabWidth(S32 width) { mMinTabWidth = width; }
  127. LL_INLINE void setMaxTabWidth(S32 width) { mMaxTabWidth = width; }
  128. LL_INLINE S32 getMinTabWidth() const { return mMinTabWidth; }
  129. LL_INLINE S32 getMaxTabWidth() const { return mMaxTabWidth; }
  130. LL_INLINE void startDragAndDropDelayTimer() { mDragAndDropDelayTimer.start(); }
  131. static void onCloseBtn(void* userdata);
  132. static void onTabBtn(void* userdata);
  133. static void onNextBtn(void* userdata);
  134. static void onNextBtnHeld(void* userdata);
  135. static void onPrevBtn(void* userdata);
  136. static void onPrevBtnHeld(void* userdata);
  137. static void onJumpFirstBtn(void* userdata);
  138. static void onJumpLastBtn(void* userdata);
  139. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  140. LLUICtrlFactory* factory);
  141. private:
  142. // Structure used to map tab buttons to and from tab panels
  143. struct LLTabTuple
  144. {
  145. LLTabTuple(LLTabContainer* c, LLPanel* p, LLButton* b,
  146. void (*cb)(void*, bool), void* userdata,
  147. LLTextBox* placeholder = NULL,
  148. void (*pcb)(void*, bool) = NULL)
  149. : mTabContainer(c),
  150. mTabPanel(p),
  151. mButton(b),
  152. mOnChangeCallback(cb),
  153. mPrecommitChangeCallback(pcb),
  154. mUserData(userdata),
  155. mPlaceholderText(placeholder),
  156. mPadding(0)
  157. {
  158. }
  159. LLTabContainer* mTabContainer;
  160. LLPanel* mTabPanel;
  161. LLButton* mButton;
  162. void (*mOnChangeCallback)(void*, bool);
  163. // Precommit callback gets called before tab is changed and can prevent
  164. // it from being changed. onChangeCallback is called immediately after
  165. // tab is actually changed - Nyx
  166. void (*mPrecommitChangeCallback)(void*, bool);
  167. void* mUserData;
  168. LLTextBox* mPlaceholderText;
  169. S32 mPadding;
  170. };
  171. void initButtons();
  172. LL_INLINE LLTabTuple* getTab(S32 index) { return mTabList[index]; }
  173. LLTabTuple* getTabByPanel(LLPanel* child);
  174. void insertTuple(LLTabTuple * tuple, eInsertionPoint insertion_point);
  175. LL_INLINE S32 getScrollPos() const { return mScrollPos; }
  176. LL_INLINE void setScrollPos(S32 pos) { mScrollPos = pos; }
  177. LL_INLINE S32 getMaxScrollPos() const { return mMaxScrollPos; }
  178. LL_INLINE void setMaxScrollPos(S32 pos) { mMaxScrollPos = pos; }
  179. LL_INLINE S32 getScrollPosPixels() const { return mScrollPosPixels; }
  180. LL_INLINE void setScrollPosPixels(S32 pixels) { mScrollPosPixels = pixels; }
  181. LL_INLINE void setTabsHidden(bool hidden) { mTabsHidden = hidden; }
  182. LL_INLINE bool getTabsHidden() const { return mTabsHidden; }
  183. LL_INLINE void setCurrentPanelIndex(S32 index) { mCurrentTabIdx = index; }
  184. // No wrap
  185. LL_INLINE void scrollPrev() { mScrollPos = llmax(0, mScrollPos - 1); }
  186. LL_INLINE void scrollNext() { mScrollPos = llmin(mScrollPos + 1, mMaxScrollPos); }
  187. void updateMaxScrollPos();
  188. void commitHoveredButton(S32 x, S32 y);
  189. private:
  190. LLTextBox* mTitleBox;
  191. LLButton* mPrevArrowBtn;
  192. LLButton* mNextArrowBtn;
  193. // Horizontal specific
  194. LLButton* mJumpPrevArrowBtn;
  195. LLButton* mJumpNextArrowBtn;
  196. S32 mCurrentTabIdx;
  197. S32 mNextTabIdx;
  198. S32 mScrollPos;
  199. S32 mScrollPosPixels;
  200. S32 mMaxScrollPos;
  201. void (*mCloseCallback)(void*);
  202. void* mCallbackUserdata;
  203. TabPosition mTabPosition;
  204. S32 mTopBorderHeight;
  205. S32 mLockedTabCount;
  206. S32 mMinTabWidth;
  207. // Extra room to the right of the tab buttons.
  208. S32 mRightTabBtnOffset;
  209. S32 mMaxTabWidth;
  210. S32 mTotalTabWidth;
  211. LLFrameTimer mScrollTimer;
  212. LLFrameTimer mDragAndDropDelayTimer;
  213. bool mTabsHidden;
  214. bool mIsVertical;
  215. bool mScrolled;
  216. typedef std::vector<LLTabTuple*> tuple_list_t;
  217. tuple_list_t mTabList;
  218. };
  219. #endif // LL_TABCONTAINER_H