PageRenderTime 73ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/lltabcontainer.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 313 lines | 208 code | 57 blank | 48 comment | 0 complexity | 42b60824d4823957640746969ad9fb86 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltabcontainer.h
  3. * @brief LLTabContainer class
  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. #ifndef LL_TABCONTAINER_H
  27. #define LL_TABCONTAINER_H
  28. #include "llpanel.h"
  29. #include "lltextbox.h"
  30. #include "llframetimer.h"
  31. #include "lliconctrl.h"
  32. #include "llbutton.h"
  33. class LLTabTuple;
  34. class LLTabContainer : public LLPanel
  35. {
  36. public:
  37. enum TabPosition
  38. {
  39. TOP,
  40. BOTTOM,
  41. LEFT
  42. };
  43. typedef enum e_insertion_point
  44. {
  45. START,
  46. END,
  47. LEFT_OF_CURRENT,
  48. RIGHT_OF_CURRENT
  49. } eInsertionPoint;
  50. struct TabPositions : public LLInitParam::TypeValuesHelper<LLTabContainer::TabPosition, TabPositions>
  51. {
  52. static void declareValues();
  53. };
  54. struct TabParams : public LLInitParam::Block<TabParams>
  55. {
  56. Optional<LLUIImage*> tab_top_image_unselected,
  57. tab_top_image_selected,
  58. tab_top_image_flash,
  59. tab_bottom_image_unselected,
  60. tab_bottom_image_selected,
  61. tab_bottom_image_flash,
  62. tab_left_image_unselected,
  63. tab_left_image_selected,
  64. tab_left_image_flash;
  65. TabParams();
  66. };
  67. struct Params
  68. : public LLInitParam::Block<Params, LLPanel::Params>
  69. {
  70. Optional<TabPosition, TabPositions> tab_position;
  71. Optional<S32> tab_width,
  72. tab_min_width,
  73. tab_max_width,
  74. tab_height,
  75. label_pad_bottom,
  76. label_pad_left;
  77. Optional<bool> hide_tabs;
  78. Optional<S32> tab_padding_right;
  79. Optional<TabParams> first_tab,
  80. middle_tab,
  81. last_tab;
  82. /**
  83. * Tab label horizontal alignment
  84. */
  85. Optional<LLFontGL::HAlign> font_halign;
  86. /**
  87. * Tab label ellipses
  88. */
  89. Optional<bool> use_ellipses;
  90. /**
  91. * Use LLCustomButtonIconCtrl or LLButton in LLTabTuple
  92. */
  93. Optional<bool> use_custom_icon_ctrl;
  94. /**
  95. * Open tabs on hover in drag and drop situations
  96. */
  97. Optional<bool> open_tabs_on_drag_and_drop;
  98. /**
  99. * Paddings for LLIconCtrl in case of LLCustomButtonIconCtrl usage(use_custom_icon_ctrl = true)
  100. */
  101. Optional<S32> tab_icon_ctrl_pad;
  102. Params();
  103. };
  104. protected:
  105. LLTabContainer(const Params&);
  106. friend class LLUICtrlFactory;
  107. public:
  108. //LLTabContainer( const std::string& name, const LLRect& rect, TabPosition pos,
  109. // BOOL bordered, BOOL is_vertical);
  110. /*virtual*/ ~LLTabContainer();
  111. // from LLView
  112. /*virtual*/ void setValue(const LLSD& value);
  113. /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  114. /*virtual*/ void draw();
  115. /*virtual*/ BOOL handleMouseDown( S32 x, S32 y, MASK mask );
  116. /*virtual*/ BOOL handleHover( S32 x, S32 y, MASK mask );
  117. /*virtual*/ BOOL handleMouseUp( S32 x, S32 y, MASK mask );
  118. /*virtual*/ BOOL handleToolTip(S32 x, S32 y, MASK mask);
  119. /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask);
  120. /*virtual*/ BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
  121. EDragAndDropType type, void* cargo_data,
  122. EAcceptance* accept, std::string& tooltip);
  123. /*virtual*/ LLView* getChildView(const std::string& name, BOOL recurse = TRUE) const;
  124. /*virtual*/ LLView* findChildView(const std::string& name, BOOL recurse = TRUE) const;
  125. /*virtual*/ void initFromParams(const LLPanel::Params& p);
  126. /*virtual*/ bool addChild(LLView* view, S32 tab_group = 0);
  127. /*virtual*/ BOOL postBuild();
  128. struct TabPanelParams : public LLInitParam::Block<TabPanelParams>
  129. {
  130. Mandatory<LLPanel*> panel;
  131. Optional<std::string> label;
  132. Optional<bool> select_tab,
  133. is_placeholder;
  134. Optional<S32> indent;
  135. Optional<eInsertionPoint> insert_at;
  136. Optional<void*> user_data;
  137. TabPanelParams()
  138. : panel("panel", NULL),
  139. label("label"),
  140. select_tab("select_tab"),
  141. is_placeholder("is_placeholder"),
  142. indent("indent"),
  143. insert_at("insert_at", END)
  144. {}
  145. };
  146. void addTabPanel(LLPanel* panel);
  147. void addTabPanel(const TabPanelParams& panel);
  148. void addPlaceholder(LLPanel* child, const std::string& label);
  149. void removeTabPanel( LLPanel* child );
  150. void lockTabs(S32 num_tabs = 0);
  151. void unlockTabs();
  152. S32 getNumLockedTabs() { return mLockedTabCount; }
  153. void enableTabButton(S32 which, BOOL enable);
  154. void deleteAllTabs();
  155. LLPanel* getCurrentPanel();
  156. S32 getCurrentPanelIndex();
  157. S32 getTabCount();
  158. LLPanel* getPanelByIndex(S32 index);
  159. S32 getIndexForPanel(LLPanel* panel);
  160. S32 getPanelIndexByTitle(const std::string& title);
  161. LLPanel* getPanelByName(const std::string& name);
  162. void setCurrentTabName(const std::string& name);
  163. void selectFirstTab();
  164. void selectLastTab();
  165. void selectNextTab();
  166. void selectPrevTab();
  167. BOOL selectTabPanel( LLPanel* child );
  168. BOOL selectTab(S32 which);
  169. BOOL selectTabByName(const std::string& title);
  170. BOOL getTabPanelFlashing(LLPanel* child);
  171. void setTabPanelFlashing(LLPanel* child, BOOL state);
  172. void setTabImage(LLPanel* child, std::string img_name, const LLColor4& color = LLColor4::white);
  173. void setTabImage(LLPanel* child, const LLUUID& img_id, const LLColor4& color = LLColor4::white);
  174. void setTabImage(LLPanel* child, LLIconCtrl* icon);
  175. void setTitle( const std::string& title );
  176. const std::string getPanelTitle(S32 index);
  177. void setTopBorderHeight(S32 height);
  178. S32 getTopBorderHeight() const;
  179. void setRightTabBtnOffset( S32 offset );
  180. void setPanelTitle(S32 index, const std::string& title);
  181. TabPosition getTabPosition() const { return mTabPosition; }
  182. void setMinTabWidth(S32 width) { mMinTabWidth = width; }
  183. void setMaxTabWidth(S32 width) { mMaxTabWidth = width; }
  184. S32 getMinTabWidth() const { return mMinTabWidth; }
  185. S32 getMaxTabWidth() const { return mMaxTabWidth; }
  186. void startDragAndDropDelayTimer() { mDragAndDropDelayTimer.start(); }
  187. void onTabBtn( const LLSD& data, LLPanel* panel );
  188. void onNextBtn(const LLSD& data);
  189. void onNextBtnHeld(const LLSD& data);
  190. void onPrevBtn(const LLSD& data);
  191. void onPrevBtnHeld(const LLSD& data);
  192. void onJumpFirstBtn( const LLSD& data );
  193. void onJumpLastBtn( const LLSD& data );
  194. private:
  195. void initButtons();
  196. BOOL setTab(S32 which);
  197. LLTabTuple* getTab(S32 index) { return mTabList[index]; }
  198. LLTabTuple* getTabByPanel(LLPanel* child);
  199. void insertTuple(LLTabTuple * tuple, eInsertionPoint insertion_point);
  200. S32 getScrollPos() const { return mScrollPos; }
  201. void setScrollPos(S32 pos) { mScrollPos = pos; }
  202. S32 getMaxScrollPos() const { return mMaxScrollPos; }
  203. void setMaxScrollPos(S32 pos) { mMaxScrollPos = pos; }
  204. S32 getScrollPosPixels() const { return mScrollPosPixels; }
  205. void setScrollPosPixels(S32 pixels) { mScrollPosPixels = pixels; }
  206. void setTabsHidden(BOOL hidden) { mTabsHidden = hidden; }
  207. BOOL getTabsHidden() const { return mTabsHidden; }
  208. void setCurrentPanelIndex(S32 index) { mCurrentTabIdx = index; }
  209. void scrollPrev() { mScrollPos = llmax(0, mScrollPos-1); } // No wrap
  210. void scrollNext() { mScrollPos = llmin(mScrollPos+1, mMaxScrollPos); } // No wrap
  211. void updateMaxScrollPos();
  212. void commitHoveredButton(S32 x, S32 y);
  213. // updates tab button images given the tuple, tab position and the corresponding params
  214. void update_images(LLTabTuple* tuple, TabParams params, LLTabContainer::TabPosition pos);
  215. void reshapeTuple(LLTabTuple* tuple);
  216. // Variables
  217. typedef std::vector<LLTabTuple*> tuple_list_t;
  218. tuple_list_t mTabList;
  219. S32 mCurrentTabIdx;
  220. BOOL mTabsHidden;
  221. BOOL mScrolled;
  222. LLFrameTimer mScrollTimer;
  223. S32 mScrollPos;
  224. S32 mScrollPosPixels;
  225. S32 mMaxScrollPos;
  226. LLTextBox* mTitleBox;
  227. S32 mTopBorderHeight;
  228. TabPosition mTabPosition;
  229. S32 mLockedTabCount;
  230. S32 mMinTabWidth;
  231. LLButton* mPrevArrowBtn;
  232. LLButton* mNextArrowBtn;
  233. BOOL mIsVertical;
  234. // Horizontal specific
  235. LLButton* mJumpPrevArrowBtn;
  236. LLButton* mJumpNextArrowBtn;
  237. S32 mRightTabBtnOffset; // Extra room to the right of the tab buttons.
  238. S32 mMaxTabWidth;
  239. S32 mTotalTabWidth;
  240. S32 mTabHeight;
  241. // Padding under the text labels of tab buttons
  242. S32 mLabelPadBottom;
  243. // Padding to the left of text labels of tab buttons
  244. S32 mLabelPadLeft;
  245. LLFrameTimer mDragAndDropDelayTimer;
  246. LLFontGL::HAlign mFontHalign;
  247. const LLFontGL* mFont;
  248. TabParams mFirstTabParams;
  249. TabParams mMiddleTabParams;
  250. TabParams mLastTabParams;
  251. bool mCustomIconCtrlUsed;
  252. bool mOpenTabsOnDragAndDrop;
  253. S32 mTabIconCtrlPad;
  254. bool mUseTabEllipses;
  255. };
  256. #endif // LL_TABCONTAINER_H