PageRenderTime 18ms CodeModel.GetById 1ms app.highlight 14ms 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
  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
 28#ifndef LL_LLTOOLBAR_H
 29#define LL_LLTOOLBAR_H
 30
 31#include "llbutton.h"
 32#include "llcommandmanager.h"
 33#include "lllayoutstack.h"
 34#include "lluictrl.h"
 35#include "llcommandmanager.h"
 36#include "llassettype.h"
 37
 38class LLToolBar;
 39class LLToolBarButton;
 40
 41typedef boost::function<void (S32 x, S32 y, LLToolBarButton* button)> tool_startdrag_callback_t;
 42typedef boost::function<BOOL (S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)> tool_handledrag_callback_t;
 43typedef boost::function<BOOL (void* data, S32 x, S32 y, LLToolBar* toolbar)> tool_handledrop_callback_t;
 44
 45class LLToolBarButton : public LLButton
 46{
 47	friend class LLToolBar;
 48public:
 49	struct Params : public LLInitParam::Block<Params, LLButton::Params>
 50	{
 51		Optional<LLUI::RangeS32::Params>	button_width;
 52		Optional<S32>						desired_height;
 53
 54		Params()
 55		:	button_width("button_width"),
 56			desired_height("desired_height", 20)
 57		{}
 58
 59	};
 60
 61	LLToolBarButton(const Params& p);
 62	~LLToolBarButton();
 63
 64	BOOL handleMouseDown(S32 x, S32 y, MASK mask);
 65	BOOL handleHover(S32 x, S32 y, MASK mask);
 66
 67	void reshape(S32 width, S32 height, BOOL called_from_parent = true);
 68	void setEnabled(BOOL enabled);
 69	void setCommandId(const LLCommandId& id) { mId = id; }
 70	LLCommandId getCommandId() { return mId; }
 71
 72	void setStartDragCallback(tool_startdrag_callback_t cb)   { mStartDragItemCallback  = cb; }
 73	void setHandleDragCallback(tool_handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
 74
 75	void onMouseEnter(S32 x, S32 y, MASK mask);
 76	void onMouseLeave(S32 x, S32 y, MASK mask);
 77	void onMouseCaptureLost();
 78
 79	void onCommit();
 80
 81	virtual const std::string getToolTip() const;		
 82
 83private:
 84	void callIfEnabled(LLUICtrl::commit_callback_t commit, LLUICtrl* ctrl, const LLSD& param );
 85
 86	LLCommandId		mId;
 87	S32				mMouseDownX;
 88	S32				mMouseDownY;
 89	LLUI::RangeS32	mWidthRange;
 90	S32				mDesiredHeight;
 91	bool							mIsDragged;
 92	tool_startdrag_callback_t		mStartDragItemCallback;
 93	tool_handledrag_callback_t		mHandleDragItemCallback;
 94
 95	enable_signal_t*	mIsEnabledSignal;
 96	enable_signal_t*	mIsRunningSignal;
 97	enable_signal_t*	mIsStartingSignal;
 98	LLPointer<LLUIImage>	mOriginalImageSelected,
 99							mOriginalImageUnselected,
100							mOriginalImagePressed,
101							mOriginalImagePressedSelected;
102	LLUIColor				mOriginalLabelColor,
103							mOriginalLabelColorSelected,
104							mOriginalImageOverlayColor,
105							mOriginalImageOverlaySelectedColor;
106};
107
108
109namespace LLToolBarEnums
110{
111	enum ButtonType
112	{
113		BTNTYPE_ICONS_WITH_TEXT = 0,
114		BTNTYPE_ICONS_ONLY,
115
116		BTNTYPE_COUNT
117	};
118
119	enum SideType
120	{
121		SIDE_BOTTOM,
122		SIDE_LEFT,
123		SIDE_RIGHT,
124		SIDE_TOP,
125	};
126
127	LLLayoutStack::ELayoutOrientation getOrientation(SideType sideType);
128}
129
130// NOTE: This needs to occur before Param block declaration for proper compilation.
131namespace LLInitParam
132{
133	template<>
134	struct TypeValues<LLToolBarEnums::ButtonType> : public TypeValuesHelper<LLToolBarEnums::ButtonType>
135	{
136		static void declareValues();
137	};
138
139	template<>
140	struct TypeValues<LLToolBarEnums::SideType> : public TypeValuesHelper<LLToolBarEnums::SideType>
141	{
142		static void declareValues();
143	};
144}
145
146
147class LLToolBar
148:	public LLUICtrl
149{
150	friend class LLToolBarButton;
151public:
152	struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
153	{
154		Mandatory<LLToolBarEnums::ButtonType>	button_display_mode;
155		Mandatory<LLToolBarEnums::SideType>		side;
156
157		Optional<LLToolBarButton::Params>		button_icon,
158												button_icon_and_text;
159
160		Optional<bool>							read_only,
161												wrap;
162
163		Optional<S32>							pad_left,
164												pad_top,
165												pad_right,
166												pad_bottom,
167												pad_between,
168												min_girth;
169
170		// default command set
171		Multiple<LLCommandId::Params>			commands;
172
173		Optional<LLPanel::Params>				button_panel;
174
175		Params();
176	};
177
178	// virtuals
179	void draw();
180	void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
181	BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
182	virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
183								   EDragAndDropType cargo_type,
184								   void* cargo_data,
185								   EAcceptance* accept,
186								   std::string& tooltip_msg);
187	
188	static const int RANK_NONE = -1;
189	bool addCommand(const LLCommandId& commandId, int rank = RANK_NONE);
190	int  removeCommand(const LLCommandId& commandId);		// Returns the rank the removed command was at, RANK_NONE if not found
191	bool hasCommand(const LLCommandId& commandId) const;	// is this command bound to a button in this toolbar
192	bool enableCommand(const LLCommandId& commandId, bool enabled);	// enable/disable button bound to the specified command, if it exists in this toolbar
193	bool stopCommandInProgress(const LLCommandId& commandId);	// stop command if it is currently active
194	bool flashCommand(const LLCommandId& commandId, bool flash); // flash button associated with given command, if in this toolbar
195
196	void setStartDragCallback(tool_startdrag_callback_t cb)   { mStartDragItemCallback  = cb; } // connects drag and drop behavior to external logic
197	void setHandleDragCallback(tool_handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
198	void setHandleDropCallback(tool_handledrop_callback_t cb) { mHandleDropCallback     = cb; }
199	bool isReadOnly() const { return mReadOnly; }
200
201	LLToolBarButton* createButton(const LLCommandId& id);
202
203	typedef boost::signals2::signal<void (LLView* button)> button_signal_t;
204	boost::signals2::connection setButtonAddCallback(const button_signal_t::slot_type& cb);
205	boost::signals2::connection setButtonEnterCallback(const button_signal_t::slot_type& cb);
206	boost::signals2::connection setButtonLeaveCallback(const button_signal_t::slot_type& cb);
207	boost::signals2::connection setButtonRemoveCallback(const button_signal_t::slot_type& cb);
208
209	// append the specified string to end of tooltip
210	void setTooltipButtonSuffix(const std::string& suffix) { mButtonTooltipSuffix = suffix; } 
211
212	LLToolBarEnums::SideType getSideType() const { return mSideType; }
213	bool hasButtons() const { return !mButtons.empty(); }
214	bool isModified() const { return mModified; }
215
216	int  getRankFromPosition(S32 x, S32 y);	
217	int  getRankFromPosition(const LLCommandId& id);	
218
219	// Methods used in loading and saving toolbar settings
220	void setButtonType(LLToolBarEnums::ButtonType button_type);
221	LLToolBarEnums::ButtonType getButtonType() { return mButtonType; }
222	command_id_list_t& getCommandsList() { return mButtonCommands; }
223	void clearCommandsList();
224
225private:
226	friend class LLUICtrlFactory;
227	LLToolBar(const Params&);
228	~LLToolBar();
229
230	void initFromParams(const Params&);
231	void createContextMenu();
232	void updateLayoutAsNeeded();
233	void createButtons();
234	void resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth);
235	BOOL isSettingChecked(const LLSD& userdata);
236	void onSettingEnable(const LLSD& userdata);
237	void onRemoveSelectedCommand();
238
239private:
240	// static layout state
241	const bool						mReadOnly;
242	const LLToolBarEnums::SideType	mSideType;
243	const bool						mWrap;
244	const S32						mPadLeft,
245									mPadRight,
246									mPadTop,
247									mPadBottom,
248									mPadBetween,
249									mMinGirth;
250
251	// drag and drop state
252	tool_startdrag_callback_t		mStartDragItemCallback;
253	tool_handledrag_callback_t		mHandleDragItemCallback;
254	tool_handledrop_callback_t		mHandleDropCallback;
255	bool							mDragAndDropTarget;
256	int								mDragRank;
257	S32								mDragx,
258									mDragy,
259									mDragGirth;
260
261	typedef std::list<LLToolBarButton*> toolbar_button_list;
262	typedef std::map<LLUUID, LLToolBarButton*> command_id_map;
263	toolbar_button_list				mButtons;
264	command_id_list_t				mButtonCommands;
265	command_id_map					mButtonMap;
266
267	LLToolBarEnums::ButtonType		mButtonType;
268	LLToolBarButton::Params			mButtonParams[LLToolBarEnums::BTNTYPE_COUNT];
269
270	// related widgets
271	LLLayoutStack*					mCenteringStack;
272	LLPanel*						mButtonPanel;
273	LLHandle<class LLContextMenu>	mPopupMenuHandle;
274	LLHandle<class LLView>			mRemoveButtonHandle;
275
276	LLToolBarButton*				mRightMouseTargetButton;
277
278	bool							mNeedsLayout;
279	bool							mModified;
280
281	button_signal_t*				mButtonAddSignal;
282	button_signal_t*				mButtonEnterSignal;
283	button_signal_t*				mButtonLeaveSignal;
284	button_signal_t*				mButtonRemoveSignal;
285
286	std::string						mButtonTooltipSuffix;
287};
288
289
290#endif  // LL_LLTOOLBAR_H