PageRenderTime 33ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lltoolbar.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 290 lines | 202 code | 54 blank | 34 comment | 0 complexity | 344fbc1aa44aa2019c4b53ff1a5160ba MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltoolbar.h
  3. * @author Richard Nelson
  4. * @brief User customizable toolbar class
  5. *
  6. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2011, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #ifndef LL_LLTOOLBAR_H
  28. #define LL_LLTOOLBAR_H
  29. #include "llbutton.h"
  30. #include "llcommandmanager.h"
  31. #include "lllayoutstack.h"
  32. #include "lluictrl.h"
  33. #include "llcommandmanager.h"
  34. #include "llassettype.h"
  35. class LLToolBar;
  36. class LLToolBarButton;
  37. typedef boost::function<void (S32 x, S32 y, LLToolBarButton* button)> tool_startdrag_callback_t;
  38. typedef boost::function<BOOL (S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)> tool_handledrag_callback_t;
  39. typedef boost::function<BOOL (void* data, S32 x, S32 y, LLToolBar* toolbar)> tool_handledrop_callback_t;
  40. class LLToolBarButton : public LLButton
  41. {
  42. friend class LLToolBar;
  43. public:
  44. struct Params : public LLInitParam::Block<Params, LLButton::Params>
  45. {
  46. Optional<LLUI::RangeS32::Params> button_width;
  47. Optional<S32> desired_height;
  48. Params()
  49. : button_width("button_width"),
  50. desired_height("desired_height", 20)
  51. {}
  52. };
  53. LLToolBarButton(const Params& p);
  54. ~LLToolBarButton();
  55. BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  56. BOOL handleHover(S32 x, S32 y, MASK mask);
  57. void reshape(S32 width, S32 height, BOOL called_from_parent = true);
  58. void setEnabled(BOOL enabled);
  59. void setCommandId(const LLCommandId& id) { mId = id; }
  60. LLCommandId getCommandId() { return mId; }
  61. void setStartDragCallback(tool_startdrag_callback_t cb) { mStartDragItemCallback = cb; }
  62. void setHandleDragCallback(tool_handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
  63. void onMouseEnter(S32 x, S32 y, MASK mask);
  64. void onMouseLeave(S32 x, S32 y, MASK mask);
  65. void onMouseCaptureLost();
  66. void onCommit();
  67. virtual const std::string getToolTip() const;
  68. private:
  69. void callIfEnabled(LLUICtrl::commit_callback_t commit, LLUICtrl* ctrl, const LLSD& param );
  70. LLCommandId mId;
  71. S32 mMouseDownX;
  72. S32 mMouseDownY;
  73. LLUI::RangeS32 mWidthRange;
  74. S32 mDesiredHeight;
  75. bool mIsDragged;
  76. tool_startdrag_callback_t mStartDragItemCallback;
  77. tool_handledrag_callback_t mHandleDragItemCallback;
  78. enable_signal_t* mIsEnabledSignal;
  79. enable_signal_t* mIsRunningSignal;
  80. enable_signal_t* mIsStartingSignal;
  81. LLPointer<LLUIImage> mOriginalImageSelected,
  82. mOriginalImageUnselected,
  83. mOriginalImagePressed,
  84. mOriginalImagePressedSelected;
  85. LLUIColor mOriginalLabelColor,
  86. mOriginalLabelColorSelected,
  87. mOriginalImageOverlayColor,
  88. mOriginalImageOverlaySelectedColor;
  89. };
  90. namespace LLToolBarEnums
  91. {
  92. enum ButtonType
  93. {
  94. BTNTYPE_ICONS_WITH_TEXT = 0,
  95. BTNTYPE_ICONS_ONLY,
  96. BTNTYPE_COUNT
  97. };
  98. enum SideType
  99. {
  100. SIDE_BOTTOM,
  101. SIDE_LEFT,
  102. SIDE_RIGHT,
  103. SIDE_TOP,
  104. };
  105. LLLayoutStack::ELayoutOrientation getOrientation(SideType sideType);
  106. }
  107. // NOTE: This needs to occur before Param block declaration for proper compilation.
  108. namespace LLInitParam
  109. {
  110. template<>
  111. struct TypeValues<LLToolBarEnums::ButtonType> : public TypeValuesHelper<LLToolBarEnums::ButtonType>
  112. {
  113. static void declareValues();
  114. };
  115. template<>
  116. struct TypeValues<LLToolBarEnums::SideType> : public TypeValuesHelper<LLToolBarEnums::SideType>
  117. {
  118. static void declareValues();
  119. };
  120. }
  121. class LLToolBar
  122. : public LLUICtrl
  123. {
  124. friend class LLToolBarButton;
  125. public:
  126. struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
  127. {
  128. Mandatory<LLToolBarEnums::ButtonType> button_display_mode;
  129. Mandatory<LLToolBarEnums::SideType> side;
  130. Optional<LLToolBarButton::Params> button_icon,
  131. button_icon_and_text;
  132. Optional<bool> read_only,
  133. wrap;
  134. Optional<S32> pad_left,
  135. pad_top,
  136. pad_right,
  137. pad_bottom,
  138. pad_between,
  139. min_girth;
  140. // default command set
  141. Multiple<LLCommandId::Params> commands;
  142. Optional<LLPanel::Params> button_panel;
  143. Params();
  144. };
  145. // virtuals
  146. void draw();
  147. void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  148. BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
  149. virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
  150. EDragAndDropType cargo_type,
  151. void* cargo_data,
  152. EAcceptance* accept,
  153. std::string& tooltip_msg);
  154. static const int RANK_NONE = -1;
  155. bool addCommand(const LLCommandId& commandId, int rank = RANK_NONE);
  156. int removeCommand(const LLCommandId& commandId); // Returns the rank the removed command was at, RANK_NONE if not found
  157. bool hasCommand(const LLCommandId& commandId) const; // is this command bound to a button in this toolbar
  158. bool enableCommand(const LLCommandId& commandId, bool enabled); // enable/disable button bound to the specified command, if it exists in this toolbar
  159. bool stopCommandInProgress(const LLCommandId& commandId); // stop command if it is currently active
  160. bool flashCommand(const LLCommandId& commandId, bool flash); // flash button associated with given command, if in this toolbar
  161. void setStartDragCallback(tool_startdrag_callback_t cb) { mStartDragItemCallback = cb; } // connects drag and drop behavior to external logic
  162. void setHandleDragCallback(tool_handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
  163. void setHandleDropCallback(tool_handledrop_callback_t cb) { mHandleDropCallback = cb; }
  164. bool isReadOnly() const { return mReadOnly; }
  165. LLToolBarButton* createButton(const LLCommandId& id);
  166. typedef boost::signals2::signal<void (LLView* button)> button_signal_t;
  167. boost::signals2::connection setButtonAddCallback(const button_signal_t::slot_type& cb);
  168. boost::signals2::connection setButtonEnterCallback(const button_signal_t::slot_type& cb);
  169. boost::signals2::connection setButtonLeaveCallback(const button_signal_t::slot_type& cb);
  170. boost::signals2::connection setButtonRemoveCallback(const button_signal_t::slot_type& cb);
  171. // append the specified string to end of tooltip
  172. void setTooltipButtonSuffix(const std::string& suffix) { mButtonTooltipSuffix = suffix; }
  173. LLToolBarEnums::SideType getSideType() const { return mSideType; }
  174. bool hasButtons() const { return !mButtons.empty(); }
  175. bool isModified() const { return mModified; }
  176. int getRankFromPosition(S32 x, S32 y);
  177. int getRankFromPosition(const LLCommandId& id);
  178. // Methods used in loading and saving toolbar settings
  179. void setButtonType(LLToolBarEnums::ButtonType button_type);
  180. LLToolBarEnums::ButtonType getButtonType() { return mButtonType; }
  181. command_id_list_t& getCommandsList() { return mButtonCommands; }
  182. void clearCommandsList();
  183. private:
  184. friend class LLUICtrlFactory;
  185. LLToolBar(const Params&);
  186. ~LLToolBar();
  187. void initFromParams(const Params&);
  188. void createContextMenu();
  189. void updateLayoutAsNeeded();
  190. void createButtons();
  191. void resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth);
  192. BOOL isSettingChecked(const LLSD& userdata);
  193. void onSettingEnable(const LLSD& userdata);
  194. void onRemoveSelectedCommand();
  195. private:
  196. // static layout state
  197. const bool mReadOnly;
  198. const LLToolBarEnums::SideType mSideType;
  199. const bool mWrap;
  200. const S32 mPadLeft,
  201. mPadRight,
  202. mPadTop,
  203. mPadBottom,
  204. mPadBetween,
  205. mMinGirth;
  206. // drag and drop state
  207. tool_startdrag_callback_t mStartDragItemCallback;
  208. tool_handledrag_callback_t mHandleDragItemCallback;
  209. tool_handledrop_callback_t mHandleDropCallback;
  210. bool mDragAndDropTarget;
  211. int mDragRank;
  212. S32 mDragx,
  213. mDragy,
  214. mDragGirth;
  215. typedef std::list<LLToolBarButton*> toolbar_button_list;
  216. typedef std::map<LLUUID, LLToolBarButton*> command_id_map;
  217. toolbar_button_list mButtons;
  218. command_id_list_t mButtonCommands;
  219. command_id_map mButtonMap;
  220. LLToolBarEnums::ButtonType mButtonType;
  221. LLToolBarButton::Params mButtonParams[LLToolBarEnums::BTNTYPE_COUNT];
  222. // related widgets
  223. LLLayoutStack* mCenteringStack;
  224. LLPanel* mButtonPanel;
  225. LLHandle<class LLContextMenu> mPopupMenuHandle;
  226. LLHandle<class LLView> mRemoveButtonHandle;
  227. LLToolBarButton* mRightMouseTargetButton;
  228. bool mNeedsLayout;
  229. bool mModified;
  230. button_signal_t* mButtonAddSignal;
  231. button_signal_t* mButtonEnterSignal;
  232. button_signal_t* mButtonLeaveSignal;
  233. button_signal_t* mButtonRemoveSignal;
  234. std::string mButtonTooltipSuffix;
  235. };
  236. #endif // LL_LLTOOLBAR_H