PageRenderTime 39ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llaccordionctrltab.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 247 lines | 128 code | 72 blank | 47 comment | 0 complexity | d924248925c39248a9f64207bc037815 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file LLAccordionCtrlTab.h
  3. * @brief Collapsible box control implementation
  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_ACCORDIONCTRLTAB_H_
  27. #define LL_ACCORDIONCTRLTAB_H_
  28. #include <string>
  29. #include "llrect.h"
  30. #include "lluictrl.h"
  31. #include "lluicolor.h"
  32. #include "llstyle.h"
  33. class LLUICtrlFactory;
  34. class LLUIImage;
  35. class LLButton;
  36. class LLTextBox;
  37. class LLScrollbar;
  38. // LLAccordionCtrlTab is a container for other controls.
  39. // It has a Header, by clicking on which hosted controls are shown or hidden.
  40. // When hosted controls are show - LLAccordionCtrlTab is expanded.
  41. // When hosted controls are hidden - LLAccordionCtrlTab is collapsed.
  42. class LLAccordionCtrlTab : public LLUICtrl
  43. {
  44. // Interface
  45. public:
  46. struct Params
  47. : public LLInitParam::Block<Params, LLUICtrl::Params>
  48. {
  49. Optional<bool> display_children, //expanded or collapsed after initialization
  50. collapsible;
  51. Optional<std::string> title;
  52. Optional<S32> header_height,
  53. min_width,
  54. min_height;
  55. // Overlay images (arrows on the left)
  56. Mandatory<LLUIImage*> header_expand_img,
  57. header_expand_img_pressed,
  58. header_collapse_img,
  59. header_collapse_img_pressed;
  60. // Background images for the accordion tabs
  61. Mandatory<LLUIImage*> header_image,
  62. header_image_over,
  63. header_image_pressed,
  64. header_image_focused;
  65. Optional<LLUIColor> header_bg_color,
  66. header_text_color,
  67. dropdown_bg_color;
  68. Optional<bool> header_visible;
  69. Optional<bool> fit_panel;
  70. Optional<bool> selection_enabled;
  71. Optional<S32> padding_left,
  72. padding_right,
  73. padding_top,
  74. padding_bottom;
  75. Params();
  76. };
  77. typedef LLDefaultChildRegistry child_registry_t;
  78. virtual ~LLAccordionCtrlTab();
  79. // Registers callback for expand/collapse events.
  80. boost::signals2::connection setDropDownStateChangedCallback(commit_callback_t cb);
  81. // Changes expand/collapse state
  82. virtual void setDisplayChildren(bool display);
  83. // Returns expand/collapse state
  84. virtual bool getDisplayChildren() const {return mDisplayChildren;};
  85. //set LLAccordionCtrlTab panel
  86. void setAccordionView(LLView* panel);
  87. LLView* getAccordionView() { return mContainerPanel; };
  88. std::string getTitle() const;
  89. // Set text and highlight substring in LLAccordionCtrlTabHeader
  90. void setTitle(const std::string& title, const std::string& hl = LLStringUtil::null);
  91. // Set text font style in LLAccordionCtrlTabHeader
  92. void setTitleFontStyle(std::string style);
  93. // Set text color in LLAccordionCtrlTabHeader
  94. void setTitleColor(LLUIColor color);
  95. boost::signals2::connection setFocusReceivedCallback(const focus_signal_t::slot_type& cb);
  96. boost::signals2::connection setFocusLostCallback(const focus_signal_t::slot_type& cb);
  97. void setSelected(bool is_selected);
  98. bool getCollapsible() {return mCollapsible;};
  99. void setCollapsible(bool collapsible) {mCollapsible = collapsible;};
  100. void changeOpenClose(bool is_open);
  101. void canOpenClose(bool can_open_close) { mCanOpenClose = can_open_close;};
  102. bool canOpenClose() const { return mCanOpenClose; };
  103. virtual BOOL postBuild();
  104. S32 notifyParent(const LLSD& info);
  105. S32 notify(const LLSD& info);
  106. bool notifyChildren(const LLSD& info);
  107. void draw();
  108. void storeOpenCloseState ();
  109. void restoreOpenCloseState ();
  110. protected:
  111. LLAccordionCtrlTab(const LLAccordionCtrlTab::Params&);
  112. friend class LLUICtrlFactory;
  113. // Overrides
  114. public:
  115. // Call reshape after changing size
  116. virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  117. /**
  118. * Raises notifyParent event with "child_visibility_change" = new_visibility
  119. */
  120. void handleVisibilityChange(BOOL new_visibility);
  121. // Changes expand/collapse state and triggers expand/collapse callbacks
  122. virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  123. virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask);
  124. virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
  125. virtual BOOL handleToolTip(S32 x, S32 y, MASK mask);
  126. virtual BOOL handleScrollWheel( S32 x, S32 y, S32 clicks );
  127. virtual bool addChild(LLView* child, S32 tab_group = 0 );
  128. bool isExpanded() const { return mDisplayChildren; }
  129. S32 getHeaderHeight();
  130. // Min size functions
  131. void setHeaderVisible(bool value);
  132. bool getHeaderVisible() { return mHeaderVisible;}
  133. S32 mExpandedHeight; // Height of expanded ctrl.
  134. // Used to restore height after expand.
  135. S32 getPaddingLeft() const { return mPaddingLeft;}
  136. S32 getPaddingRight() const { return mPaddingRight;}
  137. S32 getPaddingTop() const { return mPaddingTop;}
  138. S32 getPaddingBottom() const { return mPaddingBottom;}
  139. void showAndFocusHeader();
  140. void setFitPanel( bool fit ) { mFitPanel = true; }
  141. bool getFitParent() const { return mFitPanel; }
  142. protected:
  143. void adjustContainerPanel (const LLRect& child_rect);
  144. void adjustContainerPanel ();
  145. S32 getChildViewHeight ();
  146. void onScrollPosChangeCallback(S32, LLScrollbar*);
  147. void show_hide_scrollbar (const LLRect& child_rect);
  148. void showScrollbar (const LLRect& child_rect);
  149. void hideScrollbar (const LLRect& child_rect);
  150. void updateLayout ( const LLRect& child_rect );
  151. void ctrlSetLeftTopAndSize (LLView* panel, S32 left, S32 top, S32 width, S32 height);
  152. void drawChild(const LLRect& root_rect,LLView* child);
  153. LLView* findContainerView ();
  154. void selectOnFocusReceived();
  155. void deselectOnFocusLost();
  156. private:
  157. class LLAccordionCtrlTabHeader;
  158. LLAccordionCtrlTabHeader* mHeader; //Header
  159. bool mDisplayChildren; //Expanded/collapsed
  160. bool mCollapsible;
  161. bool mHeaderVisible;
  162. bool mCanOpenClose;
  163. bool mFitPanel;
  164. S32 mPaddingLeft;
  165. S32 mPaddingRight;
  166. S32 mPaddingTop;
  167. S32 mPaddingBottom;
  168. bool mStoredOpenCloseState;
  169. bool mWasStateStored;
  170. bool mSelectionEnabled;
  171. LLScrollbar* mScrollbar;
  172. LLView* mContainerPanel;
  173. LLUIColor mDropdownBGColor;
  174. };
  175. #endif