PageRenderTime 82ms CodeModel.GetById 18ms app.highlight 59ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llfloater.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 555 lines | 352 code | 125 blank | 78 comment | 2 complexity | e9c51a5055b92c6ca9f16a7011b99091 MD5 | raw file
  1/** 
  2 * @file llfloater.h
  3 * @brief LLFloater base class
  4 *
  5 * $LicenseInfo:firstyear=2002&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
 27// Floating "windows" within the GL display, like the inventory floater,
 28// mini-map floater, etc.
 29
 30
 31#ifndef LL_FLOATER_H
 32#define LL_FLOATER_H
 33
 34#include "llpanel.h"
 35#include "lluuid.h"
 36//#include "llnotificationsutil.h"
 37#include <set>
 38#include <boost/signals2.hpp>
 39
 40class LLDragHandle;
 41class LLResizeHandle;
 42class LLResizeBar;
 43class LLButton;
 44class LLMultiFloater;
 45class LLFloater;
 46
 47
 48const BOOL RESIZE_YES = TRUE;
 49const BOOL RESIZE_NO = FALSE;
 50
 51const BOOL DRAG_ON_TOP = FALSE;
 52const BOOL DRAG_ON_LEFT = TRUE;
 53
 54const BOOL MINIMIZE_YES = TRUE;
 55const BOOL MINIMIZE_NO = FALSE;
 56
 57const BOOL CLOSE_YES = TRUE;
 58const BOOL CLOSE_NO = FALSE;
 59
 60const BOOL ADJUST_VERTICAL_YES = TRUE;
 61const BOOL ADJUST_VERTICAL_NO = FALSE;
 62
 63namespace LLFloaterEnums
 64{
 65	enum EOpenPositioning
 66	{
 67		OPEN_POSITIONING_NONE,
 68		OPEN_POSITIONING_CASCADING,
 69		OPEN_POSITIONING_CASCADE_GROUP,
 70		OPEN_POSITIONING_CENTERED,
 71		OPEN_POSITIONING_SPECIFIED,
 72		OPEN_POSITIONING_COUNT
 73	};
 74}
 75
 76namespace LLInitParam
 77{
 78	template<>
 79	struct TypeValues<LLFloaterEnums::EOpenPositioning> : public TypeValuesHelper<LLFloaterEnums::EOpenPositioning>
 80	{
 81		static void declareValues();
 82	};
 83}
 84
 85
 86class LLFloater : public LLPanel, public LLInstanceTracker<LLFloater>
 87{
 88	friend class LLFloaterView;
 89	friend class LLFloaterReg;
 90	friend class LLMultiFloater;
 91
 92public:
 93	struct KeyCompare
 94	{
 95//		static bool compare(const LLSD& a, const LLSD& b);
 96		static bool equate(const LLSD& a, const LLSD& b);
 97/*==========================================================================*|
 98		bool operator()(const LLSD& a, const LLSD& b) const
 99		{
100			return compare(a, b);
101		}
102|*==========================================================================*/
103	};
104	
105	enum EFloaterButton
106	{
107		BUTTON_CLOSE = 0,
108		BUTTON_RESTORE,
109		BUTTON_MINIMIZE,
110		BUTTON_TEAR_OFF,
111		BUTTON_DOCK,
112		BUTTON_HELP,
113		BUTTON_COUNT
114	};
115	
116	struct Params 
117	:	public LLInitParam::Block<Params, LLPanel::Params>
118	{
119		Optional<std::string>	title,
120								short_title;
121		
122		Optional<bool>			single_instance,
123								reuse_instance,
124								can_resize,
125								can_minimize,
126								can_close,
127								can_drag_on_left,
128								can_tear_off,
129								save_rect,
130								save_visibility,
131								save_dock_state,
132								can_dock,
133								show_title;
134		
135		Optional<LLFloaterEnums::EOpenPositioning>	open_positioning;
136		Optional<S32>								specified_left;
137		Optional<S32>								specified_bottom;
138
139		
140		Optional<S32>			header_height,
141								legacy_header_height; // HACK see initFromXML()
142
143		// Images for top-right controls
144		Optional<LLUIImage*>	close_image,
145								restore_image,
146								minimize_image,
147								tear_off_image,
148								dock_image,
149								help_image;
150		Optional<LLUIImage*>	close_pressed_image,
151								restore_pressed_image,
152								minimize_pressed_image,
153								tear_off_pressed_image,
154								dock_pressed_image,
155								help_pressed_image;
156		
157		Optional<CommitCallbackParam> open_callback,
158									  close_callback;
159
160		Ignored					follows;
161		
162		Params();
163	};
164	
165	// use this to avoid creating your own default LLFloater::Param instance
166	static const Params& getDefaultParams();
167
168	// Load translations for tooltips for standard buttons
169	static void initClass();
170
171	LLFloater(const LLSD& key, const Params& params = getDefaultParams());
172
173	virtual ~LLFloater();
174
175	// Don't export top/left for rect, only height/width
176	static void setupParamsForExport(Params& p, LLView* parent);
177	bool buildFromFile(const std::string &filename, LLXMLNodePtr output_node = NULL);
178
179	boost::signals2::connection setMinimizeCallback( const commit_signal_t::slot_type& cb );
180	boost::signals2::connection setOpenCallback( const commit_signal_t::slot_type& cb );
181	boost::signals2::connection setCloseCallback( const commit_signal_t::slot_type& cb );
182
183	void initFromParams(const LLFloater::Params& p);
184	bool initFloaterXML(LLXMLNodePtr node, LLView *parent, const std::string& filename, LLXMLNodePtr output_node = NULL);
185
186	/*virtual*/ void handleReshape(const LLRect& new_rect, bool by_user = false);
187	/*virtual*/ BOOL canSnapTo(const LLView* other_view);
188	/*virtual*/ void setSnappedTo(const LLView* snap_view);
189	/*virtual*/ void setFocus( BOOL b );
190	/*virtual*/ void setIsChrome(BOOL is_chrome);
191	/*virtual*/ void setRect(const LLRect &rect);
192
193	void 			initFloater(const Params& p);
194
195	void			openFloater(const LLSD& key = LLSD());
196
197	// If allowed, close the floater cleanly, releasing focus.
198	void			closeFloater(bool app_quitting = false);
199
200	/*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
201	
202	// Release keyboard and mouse focus
203	void			releaseFocus();
204
205	// moves to center of gFloaterView
206	void			center();
207
208	LLMultiFloater* getHost();
209
210	void			applyTitle();
211	std::string		getCurrentTitle() const;
212	void			setTitle( const std::string& title);
213	std::string		getTitle() const;
214	void			setShortTitle( const std::string& short_title );
215	std::string		getShortTitle() const;
216	virtual void	setMinimized(BOOL b);
217	void			moveResizeHandlesToFront();
218	void			addDependentFloater(LLFloater* dependent, BOOL reposition = TRUE);
219	void			addDependentFloater(LLHandle<LLFloater> dependent_handle, BOOL reposition = TRUE);
220	LLFloater*		getDependee() { return (LLFloater*)mDependeeHandle.get(); }
221	void		removeDependentFloater(LLFloater* dependent);
222	BOOL			isMinimized() const				{ return mMinimized; }
223	/// isShown() differs from getVisible() in that isShown() also considers
224	/// isMinimized(). isShown() is true only if visible and not minimized.
225	bool			isShown() const;
226	/// The static isShown() can accept a NULL pointer (which of course
227	/// returns false). When non-NULL, it calls the non-static isShown().
228	static bool		isShown(const LLFloater* floater);
229	static bool     isVisible(const LLFloater* floater);
230	static bool     isMinimized(const LLFloater* floater);
231	BOOL			isFirstLook() { return mFirstLook; } // EXT-2653: This function is necessary to prevent overlapping for secondary showed toasts
232	BOOL			isFrontmost();
233	BOOL			isDependent()					{ return !mDependeeHandle.isDead(); }
234	void			setCanMinimize(BOOL can_minimize);
235	void			setCanClose(BOOL can_close);
236	void			setCanTearOff(BOOL can_tear_off);
237	virtual void	setCanResize(BOOL can_resize);
238	void			setCanDrag(BOOL can_drag);
239	bool			getCanDrag();
240	void			setHost(LLMultiFloater* host);
241	BOOL			isResizable() const				{ return mResizable; }
242	void			setResizeLimits( S32 min_width, S32 min_height );
243	void			getResizeLimits( S32* min_width, S32* min_height ) { *min_width = mMinWidth; *min_height = mMinHeight; }
244	LLRect			getSavedRect() const;
245	bool			hasSavedRect() const;
246
247	static std::string		getControlName(const std::string& name, const LLSD& key);
248	static LLControlGroup*	getControlGroup();
249
250	bool			isMinimizeable() const{ return mCanMinimize; }
251	bool			isCloseable() const{ return mCanClose; }
252	bool			isDragOnLeft() const{ return mDragOnLeft; }
253	S32				getMinWidth() const{ return mMinWidth; }
254	S32				getMinHeight() const{ return mMinHeight; }
255	S32				getHeaderHeight() const { return mHeaderHeight; }
256
257	virtual BOOL	handleMouseDown(S32 x, S32 y, MASK mask);
258	virtual BOOL	handleRightMouseDown(S32 x, S32 y, MASK mask);
259	virtual BOOL	handleDoubleClick(S32 x, S32 y, MASK mask);
260	virtual BOOL	handleMiddleMouseDown(S32 x, S32 y, MASK mask);
261	
262	virtual BOOL	handleScrollWheel(S32 x, S32 y, S32 mask);
263	
264	virtual void	draw();
265	virtual void	drawShadow(LLPanel* panel);
266	
267	virtual void	onOpen(const LLSD& key) {}
268	virtual void	onClose(bool app_quitting) {}
269
270	// This cannot be "const" until all derived floater canClose()
271	// methods are const as well.  JC
272	virtual BOOL	canClose() { return TRUE; }
273
274	/*virtual*/ void setVisible(BOOL visible); // do not override
275	/*virtual*/ void handleVisibilityChange ( BOOL new_visibility ); // do not override
276	
277	void			setFrontmost(BOOL take_focus = TRUE);
278	
279	// Defaults to false.
280	virtual BOOL	canSaveAs() const { return FALSE; }
281
282	virtual void	saveAs() {}
283
284	void			setSnapTarget(LLHandle<LLFloater> handle) { mSnappedTo = handle; }
285	void			clearSnapTarget() { mSnappedTo.markDead(); }
286	LLHandle<LLFloater>	getSnapTarget() const { return mSnappedTo; }
287
288	LLHandle<LLFloater> getHandle() const { return getDerivedHandle<LLFloater>(); }
289	const LLSD& 	getKey() { return mKey; }
290	virtual bool	matchesKey(const LLSD& key) { return mSingleInstance || KeyCompare::equate(key, mKey); }
291	
292	const std::string& getInstanceName() { return mInstanceName; }
293	
294	bool            isDockable() const { return mCanDock; }
295	void            setCanDock(bool b);
296
297	bool            isDocked() const { return mDocked; }
298	virtual void    setDocked(bool docked, bool pop_on_undock = true);
299
300	virtual void    setTornOff(bool torn_off) { mTornOff = torn_off; }
301
302	// Return a closeable floater, if any, given the current focus.
303	static LLFloater* getClosableFloaterFromFocus(); 
304
305	// Close the floater returned by getClosableFloaterFromFocus() and 
306	// handle refocusing.
307	static void		closeFocusedFloater();
308
309//	LLNotification::Params contextualNotification(const std::string& name) 
310//	{ 
311//	    return LLNotification::Params(name).context(mNotificationContext); 
312//	}
313
314	static void		onClickClose(LLFloater* floater);
315	static void		onClickMinimize(LLFloater* floater);
316	static void		onClickTearOff(LLFloater* floater);
317	static void     onClickDock(LLFloater* floater);
318	static void		onClickHelp(LLFloater* floater);
319
320	static void		setFloaterHost(LLMultiFloater* hostp) {sHostp = hostp; }
321	static LLMultiFloater* getFloaterHost() {return sHostp; }
322
323	void			updateTransparency(ETypeTransparency transparency_type);
324		
325	void			enableResizeCtrls(bool enable, bool width = true, bool height = true);
326
327	bool			isPositioning(LLFloaterEnums::EOpenPositioning p) const { return (p == mOpenPositioning); }
328protected:
329	void			applyControlsAndPosition(LLFloater* other);
330
331	void			stackWith(LLFloater& other);
332
333	virtual bool	applyRectControl();
334	bool			applyDockState();
335	void			applyPositioning(LLFloater* other);
336	void			storeRectControl();
337	void			storeVisibilityControl();
338	void			storeDockStateControl();
339
340	void		 	setKey(const LLSD& key);
341	void		 	setInstanceName(const std::string& name);
342	
343	virtual void	bringToFront(S32 x, S32 y);
344	virtual void	setVisibleAndFrontmost(BOOL take_focus=TRUE);    
345	
346	void			setExpandedRect(const LLRect& rect) { mExpandedRect = rect; } // size when not minimized
347	const LLRect&	getExpandedRect() const { return mExpandedRect; }
348
349	void			setAutoFocus(BOOL focus) { mAutoFocus = focus; } // whether to automatically take focus when opened
350	BOOL			getAutoFocus() const { return mAutoFocus; }
351	LLDragHandle*	getDragHandle() const { return mDragHandle; }
352
353	void			destroy(); // Don't call this directly.  You probably want to call closeFloater()
354
355	virtual	void	onClickCloseBtn();
356
357	virtual void	updateTitleButtons();
358
359private:
360	void			setForeground(BOOL b);	// called only by floaterview
361	void			cleanupHandles(); // remove handles to dead floaters
362	void			createMinimizeButton();
363	void			buildButtons(const Params& p);
364	
365	// Images and tooltips are named in the XML, but we want to look them
366	// up by index.
367	static LLUIImage*	getButtonImage(const Params& p, EFloaterButton e);
368	static LLUIImage*	getButtonPressedImage(const Params& p, EFloaterButton e);
369	
370	/**
371	 * @params is_chrome - if floater is Chrome it means that floater will never get focus.
372	 * Therefore it can't be closed with 'Ctrl+W'. So the tooltip text of close button( X )
373	 * should be 'Close' not 'Close(Ctrl+W)' as for usual floaters.
374	 */
375	static std::string	getButtonTooltip(const Params& p, EFloaterButton e, bool is_chrome);
376
377	BOOL			offerClickToButton(S32 x, S32 y, MASK mask, EFloaterButton index);
378	void			addResizeCtrls();
379	void			layoutResizeCtrls();
380	void 			addDragHandle();
381	void			layoutDragHandle();		// repair layout
382
383	static void		updateActiveFloaterTransparency();
384	static void		updateInactiveFloaterTransparency();
385	void			updateTransparency(LLView* view, ETypeTransparency transparency_type);
386
387public:
388	// Called when floater is opened, passes mKey
389	// Public so external views or floaters can watch for this floater opening
390	commit_signal_t mOpenSignal;
391
392	// Called when floater is closed, passes app_qitting as LLSD()
393	// Public so external views or floaters can watch for this floater closing
394	commit_signal_t mCloseSignal;		
395
396	commit_signal_t* mMinimizeSignal;
397
398protected:
399	std::string		mRectControl;
400	std::string		mVisibilityControl;
401	std::string		mDocStateControl;
402	LLSD			mKey;				// Key used for retrieving instances; set (for now) by LLFLoaterReg
403
404	LLDragHandle*	mDragHandle;
405	LLResizeBar*	mResizeBar[4];
406	LLResizeHandle*	mResizeHandle[4];
407
408	LLButton*		mButtons[BUTTON_COUNT];
409private:
410	LLRect			mExpandedRect;
411	
412	LLUIString		mTitle;
413	LLUIString		mShortTitle;
414	
415	BOOL			mSingleInstance;	// TRUE if there is only ever one instance of the floater
416	bool			mReuseInstance;		// true if we want to hide the floater when we close it instead of destroying it
417	std::string		mInstanceName;		// Store the instance name so we can remove ourselves from the list
418	
419	BOOL			mCanTearOff;
420	BOOL			mCanMinimize;
421	BOOL			mCanClose;
422	BOOL			mDragOnLeft;
423	BOOL			mResizable;
424
425	LLFloaterEnums::EOpenPositioning	mOpenPositioning;
426	S32									mSpecifiedLeft;
427	S32									mSpecifiedBottom;
428	
429	S32				mMinWidth;
430	S32				mMinHeight;
431	S32				mHeaderHeight;		// height in pixels of header for title, drag bar
432	S32				mLegacyHeaderHeight;// HACK see initFloaterXML()
433	
434	BOOL			mMinimized;
435	BOOL			mForeground;
436	LLHandle<LLFloater>	mDependeeHandle;
437	
438
439	BOOL			mFirstLook;			// TRUE if the _next_ time this floater is visible will be the first time in the session that it is visible.
440	
441	typedef std::set<LLHandle<LLFloater> > handle_set_t;
442	typedef std::set<LLHandle<LLFloater> >::iterator handle_set_iter_t;
443	handle_set_t	mDependents;
444
445	bool			mButtonsEnabled[BUTTON_COUNT];
446	F32				mButtonScale;
447	BOOL			mAutoFocus;
448	LLHandle<LLFloater> mSnappedTo;
449	
450	LLHandle<LLFloater> mHostHandle;
451	LLHandle<LLFloater> mLastHostHandle;
452
453	bool            mCanDock;
454	bool            mDocked;
455	bool            mTornOff;
456
457	static LLMultiFloater* sHostp;
458	static BOOL		sQuitting;
459	static std::string	sButtonNames[BUTTON_COUNT];
460	static std::string	sButtonToolTips[BUTTON_COUNT];
461	static std::string  sButtonToolTipsIndex[BUTTON_COUNT];
462	
463	typedef void(*click_callback)(LLFloater*);
464	static click_callback sButtonCallbacks[BUTTON_COUNT];
465
466	BOOL			mHasBeenDraggedWhileMinimized;
467	S32				mPreviousMinimizedBottom;
468	S32				mPreviousMinimizedLeft;
469};
470
471
472/////////////////////////////////////////////////////////////
473// LLFloaterView
474// Parent of all floating panels
475
476class LLFloaterView : public LLUICtrl
477{
478public:
479	struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>{};
480
481protected:
482	LLFloaterView (const Params& p);
483	friend class LLUICtrlFactory;
484
485public:
486
487	/*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
488	/*virtual*/ void draw();
489	/*virtual*/ LLRect getSnapRect() const;
490	/*virtual*/ void refresh();
491
492	LLRect			findNeighboringPosition( LLFloater* reference_floater, LLFloater* neighbor );
493
494	// Given a child of gFloaterView, make sure this view can fit entirely onscreen.
495	void			adjustToFitScreen(LLFloater* floater, BOOL allow_partial_outside);
496
497	void			setMinimizePositionVerticalOffset(S32 offset) { mMinimizePositionVOffset = offset; }
498	void			getMinimizePosition( S32 *left, S32 *bottom);
499	void			restoreAll();		// un-minimize all floaters
500	typedef std::set<LLView*> skip_list_t;
501	void pushVisibleAll(BOOL visible, const skip_list_t& skip_list = skip_list_t());
502	void popVisibleAll(const skip_list_t& skip_list = skip_list_t());
503
504	void			setCycleMode(BOOL mode) { mFocusCycleMode = mode; }
505	BOOL			getCycleMode() const { return mFocusCycleMode; }
506	void			bringToFront( LLFloater* child, BOOL give_focus = TRUE );
507	void			highlightFocusedFloater();
508	void			unhighlightFocusedFloater();
509	void			focusFrontFloater();
510	void			destroyAllChildren();
511	// attempt to close all floaters
512	void			closeAllChildren(bool app_quitting);
513	BOOL			allChildrenClosed();
514	void			shiftFloaters(S32 x_offset, S32 y_offset);
515
516	void			hideAllFloaters();
517	void			showHiddenFloaters();
518
519
520	LLFloater* getFrontmost() const;
521	LLFloater* getBackmost() const;
522	LLFloater* getParentFloater(LLView* viewp) const;
523	LLFloater* getFocusedFloater() const;
524	void		syncFloaterTabOrder();
525
526	// Returns z order of child provided. 0 is closest, larger numbers
527	// are deeper in the screen. If there is no such child, the return
528	// value is not defined.
529	S32 getZOrder(LLFloater* child);
530
531	void setFloaterSnapView(LLHandle<LLView> snap_view) {mSnapView = snap_view; }
532
533private:
534	void hiddenFloaterClosed(LLFloater* floater);
535
536	LLRect				mLastSnapRect;
537	LLHandle<LLView>	mSnapView;
538	BOOL			mFocusCycleMode;
539	S32				mSnapOffsetBottom;
540	S32				mSnapOffsetRight;
541	S32				mMinimizePositionVOffset;
542	typedef std::vector<std::pair<LLHandle<LLFloater>, boost::signals2::connection> > hidden_floaters_t;
543	hidden_floaters_t mHiddenFloaters;
544};
545
546//
547// Globals
548//
549
550extern LLFloaterView* gFloaterView;
551
552#endif  // LL_FLOATER_H
553
554
555