PageRenderTime 23ms CodeModel.GetById 10ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llui/llfocusmgr.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 151 lines | 82 code | 32 blank | 37 comment | 1 complexity | 1c39eaa647300a6f13628b51d138a700 MD5 | raw file
  1/** 
  2 * @file llfocusmgr.h
  3 * @brief LLFocusMgr 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// Singleton that manages keyboard and mouse focus
 28
 29#ifndef LL_LLFOCUSMGR_H
 30#define LL_LLFOCUSMGR_H
 31
 32#include "llstring.h"
 33#include "llframetimer.h"
 34#include "llui.h"
 35
 36class LLUICtrl;
 37class LLMouseHandler;
 38class LLView;
 39
 40// NOTE: the LLFocusableElement class declaration has been moved here from lluictrl.h.
 41class LLFocusableElement
 42{
 43	friend class LLFocusMgr; // allow access to focus change handlers
 44public:
 45	LLFocusableElement();
 46	virtual ~LLFocusableElement();
 47
 48	virtual void	setFocus( BOOL b );
 49	virtual BOOL	hasFocus() const;
 50
 51	typedef boost::signals2::signal<void(LLFocusableElement*)> focus_signal_t;
 52	
 53	boost::signals2::connection setFocusLostCallback( const focus_signal_t::slot_type& cb);
 54	boost::signals2::connection	setFocusReceivedCallback(const focus_signal_t::slot_type& cb);
 55	boost::signals2::connection	setFocusChangedCallback(const focus_signal_t::slot_type& cb);
 56	boost::signals2::connection	setTopLostCallback(const focus_signal_t::slot_type& cb);
 57
 58	// These were brought up the hierarchy from LLView so that we don't have to use dynamic_cast when dealing with keyboard focus.
 59	virtual BOOL	handleKey(KEY key, MASK mask, BOOL called_from_parent);
 60	virtual BOOL	handleUnicodeChar(llwchar uni_char, BOOL called_from_parent);
 61
 62	virtual void	onTopLost();	// called when registered as top ctrl and user clicks elsewhere
 63protected:	
 64	virtual void	onFocusReceived();
 65	virtual void	onFocusLost();
 66	focus_signal_t*  mFocusLostCallback;
 67	focus_signal_t*  mFocusReceivedCallback;
 68	focus_signal_t*  mFocusChangedCallback;
 69	focus_signal_t*  mTopLostCallback;
 70};
 71
 72
 73class LLFocusMgr
 74{
 75public:
 76	LLFocusMgr();
 77	~LLFocusMgr();
 78
 79	// Mouse Captor
 80	void			setMouseCapture(LLMouseHandler* new_captor);	// new_captor = NULL to release the mouse.
 81	LLMouseHandler* getMouseCapture() const { return mMouseCaptor; } 
 82	void			removeMouseCaptureWithoutCallback( const LLMouseHandler* captor );
 83	BOOL			childHasMouseCapture( const LLView* parent ) const;
 84
 85	// Keyboard Focus
 86	void			setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock = FALSE, BOOL keystrokes_only = FALSE);		// new_focus = NULL to release the focus.
 87	LLFocusableElement*		getKeyboardFocus() const { return mKeyboardFocus; }  
 88	LLFocusableElement*		getLastKeyboardFocus() const { return mLastKeyboardFocus; }  
 89	BOOL			childHasKeyboardFocus( const LLView* parent ) const;
 90	void			removeKeyboardFocusWithoutCallback( const LLFocusableElement* focus );
 91	BOOL			getKeystrokesOnly() { return mKeystrokesOnly; }
 92	void			setKeystrokesOnly(BOOL keystrokes_only) { mKeystrokesOnly = keystrokes_only; }
 93
 94	F32				getFocusFlashAmt() const;
 95	S32				getFocusFlashWidth() const { return llround(lerp(1.f, 3.f, getFocusFlashAmt())); }
 96	LLColor4		getFocusColor() const;
 97	void			triggerFocusFlash();
 98	BOOL			getAppHasFocus() const { return mAppHasFocus; }
 99	void			setAppHasFocus(BOOL focus);
100	LLUICtrl*		getLastFocusForGroup(LLView* subtree_root) const;
101	void			clearLastFocusForGroup(LLView* subtree_root);
102
103	// If setKeyboardFocus(NULL) is called, and there is a non-NULL default
104	// keyboard focus view, focus goes there. JC
105	void			setDefaultKeyboardFocus(LLFocusableElement* default_focus) { mDefaultKeyboardFocus = default_focus; }
106	LLFocusableElement*		getDefaultKeyboardFocus() const { return mDefaultKeyboardFocus; }
107
108	
109	// Top View
110	void			setTopCtrl(LLUICtrl* new_top);
111	LLUICtrl*		getTopCtrl() const					{ return mTopCtrl; }
112	void			removeTopCtrlWithoutCallback( const LLUICtrl* top_view );
113	BOOL			childIsTopCtrl( const LLView* parent ) const;
114
115	// All Three
116	void			releaseFocusIfNeeded( LLView* top_view );
117	void			lockFocus();
118	void			unlockFocus();
119	BOOL			focusLocked() const { return mLockedView != NULL; }
120
121	bool			keyboardFocusHasAccelerators() const;
122
123	struct Impl;
124
125private:
126	LLUICtrl*			mLockedView;
127
128	// Mouse Captor
129	LLMouseHandler*		mMouseCaptor;				// Mouse events are premptively routed to this object
130
131	// Keyboard Focus
132	LLFocusableElement*	mKeyboardFocus;				// Keyboard events are preemptively routed to this object
133	LLFocusableElement*	mLastKeyboardFocus;			// who last had focus
134	LLFocusableElement*	mDefaultKeyboardFocus;
135	BOOL				mKeystrokesOnly;
136	
137	// Top View
138	LLUICtrl*			mTopCtrl;
139
140	LLFrameTimer		mFocusFlashTimer;
141
142	BOOL				mAppHasFocus;
143
144	Impl * mImpl;
145};
146
147extern LLFocusMgr gFocusMgr;
148
149#endif  // LL_LLFOCUSMGR_H
150
151