PageRenderTime 40ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llaccordionctrl.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 193 lines | 103 code | 44 blank | 46 comment | 0 complexity | 3592218618c30809ac17282c0e7294e0 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file LLAccordionCtrl.h
  3. * @brief Accordion Panel 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_ACCORDIONCTRL_H
  27. #define LL_ACCORDIONCTRL_H
  28. #include "llpanel.h"
  29. #include "lltextbox.h"
  30. #include "llscrollbar.h"
  31. #include <vector>
  32. #include <algorithm>
  33. #include <string>
  34. class LLAccordionCtrlTab;
  35. class LLAccordionCtrl: public LLPanel
  36. {
  37. private:
  38. std::vector<LLAccordionCtrlTab*> mAccordionTabs;
  39. void ctrlSetLeftTopAndSize(LLView* panel, S32 left, S32 top, S32 width, S32 height);
  40. void ctrlShiftVertical(LLView* panel,S32 delta);
  41. void onCollapseCtrlCloseOpen(S16 panel_num);
  42. void shiftAccordionTabs(S16 panel_num, S32 delta);
  43. public:
  44. /**
  45. * Abstract comparator for accordion tabs.
  46. */
  47. class LLTabComparator
  48. {
  49. public:
  50. LLTabComparator() {};
  51. virtual ~LLTabComparator() {};
  52. /** Returns true if tab1 < tab2, false otherwise */
  53. virtual bool compare(const LLAccordionCtrlTab* tab1, const LLAccordionCtrlTab* tab2) const = 0;
  54. };
  55. struct Params
  56. : public LLInitParam::Block<Params, LLPanel::Params>
  57. {
  58. Optional<bool> single_expansion,
  59. fit_parent; /* Accordion will fit its parent size, controls that are placed into
  60. accordion tabs are responsible for scrolling their content.
  61. *NOTE fit_parent works best when combined with single_expansion.
  62. Accordion view should implement getRequiredRect() and provide valid height*/
  63. Optional<LLTextBox::Params> no_matched_tabs_text;
  64. Optional<LLTextBox::Params> no_visible_tabs_text;
  65. Params()
  66. : single_expansion("single_expansion",false)
  67. , fit_parent("fit_parent", false)
  68. , no_matched_tabs_text("no_matched_tabs_text")
  69. , no_visible_tabs_text("no_visible_tabs_text")
  70. {};
  71. };
  72. LLAccordionCtrl(const Params& params);
  73. LLAccordionCtrl();
  74. virtual ~LLAccordionCtrl();
  75. virtual BOOL postBuild();
  76. virtual BOOL handleRightMouseDown ( S32 x, S32 y, MASK mask);
  77. virtual BOOL handleScrollWheel ( S32 x, S32 y, S32 clicks );
  78. virtual BOOL handleKeyHere (KEY key, MASK mask);
  79. virtual BOOL handleDragAndDrop (S32 x, S32 y, MASK mask, BOOL drop,
  80. EDragAndDropType cargo_type,
  81. void* cargo_data,
  82. EAcceptance* accept,
  83. std::string& tooltip_msg);
  84. //
  85. // Call reshape after changing splitter's size
  86. virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  87. void addCollapsibleCtrl(LLView* view);
  88. void removeCollapsibleCtrl(LLView* view);
  89. void arrange();
  90. void draw();
  91. void onScrollPosChangeCallback(S32, LLScrollbar*);
  92. void onOpen (const LLSD& key);
  93. S32 notifyParent(const LLSD& info);
  94. void reset ();
  95. void expandDefaultTab();
  96. void setComparator(const LLTabComparator* comp) { mTabComparator = comp; }
  97. void sort();
  98. /**
  99. * Sets filter substring as a search_term for help text when there are no any visible tabs.
  100. */
  101. void setFilterSubString(const std::string& filter_string);
  102. /**
  103. * This method returns the first expanded accordion tab.
  104. * It is expected to be called for accordion which doesn't allow multiple
  105. * tabs to be expanded. Use with care.
  106. */
  107. const LLAccordionCtrlTab* getExpandedTab() const;
  108. LLAccordionCtrlTab* getSelectedTab() const { return mSelectedTab; }
  109. bool getFitParent() const {return mFitParent;}
  110. private:
  111. void initNoTabsWidget(const LLTextBox::Params& tb_params);
  112. void updateNoTabsHelpTextVisibility();
  113. void arrangeSinge();
  114. void arrangeMultiple();
  115. // Calc Splitter's height that is necessary to display all child content
  116. S32 calcRecuiredHeight();
  117. S32 getRecuiredHeight() const { return mInnerRect.getHeight(); }
  118. S32 calcExpandedTabHeight(S32 tab_index = 0, S32 available_height = 0);
  119. void updateLayout (S32 width, S32 height);
  120. void show_hide_scrollbar (S32 width, S32 height);
  121. void showScrollbar (S32 width, S32 height);
  122. void hideScrollbar (S32 width, S32 height);
  123. BOOL autoScroll (S32 x, S32 y);
  124. /**
  125. * An adaptor for LLTabComparator
  126. */
  127. struct LLComparatorAdaptor
  128. {
  129. LLComparatorAdaptor(const LLTabComparator& comparator) : mComparator(comparator) {};
  130. bool operator()(const LLAccordionCtrlTab* tab1, const LLAccordionCtrlTab* tab2)
  131. {
  132. return mComparator.compare(tab1, tab2);
  133. }
  134. const LLTabComparator& mComparator;
  135. };
  136. private:
  137. LLRect mInnerRect;
  138. LLScrollbar* mScrollbar;
  139. bool mSingleExpansion;
  140. bool mFitParent;
  141. bool mAutoScrolling;
  142. F32 mAutoScrollRate;
  143. LLTextBox* mNoVisibleTabsHelpText;
  144. std::string mNoMatchedTabsOrigString;
  145. std::string mNoVisibleTabsOrigString;
  146. LLAccordionCtrlTab* mSelectedTab;
  147. const LLTabComparator* mTabComparator;
  148. };
  149. #endif // LL_LLSPLITTER_H