Updated LLFocusMgr to use boost::signals2 instead of vanilla function pointers. Also removed top-focus handling from lluictrl because it doesn't belong there.

This commit is contained in:
Shyotl
2012-02-18 01:58:02 -06:00
parent ae7b12f230
commit 1810a7c7f9
38 changed files with 298 additions and 316 deletions

View File

@@ -2,31 +2,25 @@
* @file llfocusmgr.cpp
* @brief LLFocusMgr base class
*
* $LicenseInfo:firstyear=2002&license=viewergpl$
*
* Copyright (c) 2002-2009, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
* Copyright (C) 2010, Linden Research, Inc.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -38,13 +32,11 @@
const F32 FOCUS_FADE_TIME = 0.3f;
// NOTE: the LLFocusableElement implementation has been here from lluictrl.cpp.
LLFocusableElement::LLFocusableElement()
: mFocusLostCallback(NULL),
mFocusReceivedCallback(NULL),
mFocusChangedCallback(NULL),
mFocusCallbackUserData(NULL)
mTopLostCallback(NULL)
{
}
@@ -63,31 +55,27 @@ BOOL LLFocusableElement::handleUnicodeChar(llwchar uni_char, BOOL called_from_pa
// virtual
LLFocusableElement::~LLFocusableElement()
{
delete mFocusLostCallback;
delete mFocusReceivedCallback;
delete mFocusChangedCallback;
delete mTopLostCallback;
}
void LLFocusableElement::onFocusReceived()
{
if( mFocusReceivedCallback )
{
mFocusReceivedCallback( this, mFocusCallbackUserData );
}
if( mFocusChangedCallback )
{
mFocusChangedCallback( this, mFocusCallbackUserData );
}
if (mFocusReceivedCallback) (*mFocusReceivedCallback)(this);
if (mFocusChangedCallback) (*mFocusChangedCallback)(this);
}
void LLFocusableElement::onFocusLost()
{
if( mFocusLostCallback )
{
mFocusLostCallback( this, mFocusCallbackUserData );
}
if (mFocusLostCallback) (*mFocusLostCallback)(this);
if (mFocusChangedCallback) (*mFocusChangedCallback)(this);
}
if( mFocusChangedCallback )
{
mFocusChangedCallback( this, mFocusCallbackUserData );
}
void LLFocusableElement::onTopLost()
{
if (mTopLostCallback) (*mTopLostCallback)(this);
}
BOOL LLFocusableElement::hasFocus() const
@@ -99,28 +87,63 @@ void LLFocusableElement::setFocus(BOOL b)
{
}
boost::signals2::connection LLFocusableElement::setFocusLostCallback( const focus_signal_t::slot_type& cb)
{
if (!mFocusLostCallback) mFocusLostCallback = new focus_signal_t();
return mFocusLostCallback->connect(cb);
}
boost::signals2::connection LLFocusableElement::setFocusReceivedCallback(const focus_signal_t::slot_type& cb)
{
if (!mFocusReceivedCallback) mFocusReceivedCallback = new focus_signal_t();
return mFocusReceivedCallback->connect(cb);
}
boost::signals2::connection LLFocusableElement::setFocusChangedCallback(const focus_signal_t::slot_type& cb)
{
if (!mFocusChangedCallback) mFocusChangedCallback = new focus_signal_t();
return mFocusChangedCallback->connect(cb);
}
boost::signals2::connection LLFocusableElement::setTopLostCallback(const focus_signal_t::slot_type& cb)
{
if (!mTopLostCallback) mTopLostCallback = new focus_signal_t();
return mTopLostCallback->connect(cb);
}
typedef std::list<LLHandle<LLView> > view_handle_list_t;
typedef std::map<LLHandle<LLView>, LLHandle<LLView> > focus_history_map_t;
struct LLFocusMgr::Impl
{
// caching list of keyboard focus ancestors for calling onFocusReceived and onFocusLost
view_handle_list_t mCachedKeyboardFocusList;
focus_history_map_t mFocusHistory;
};
LLFocusMgr gFocusMgr;
LLFocusMgr::LLFocusMgr()
:
mLockedView( NULL ),
: mLockedView( NULL ),
mMouseCaptor( NULL ),
mKeyboardFocus( NULL ),
mLastKeyboardFocus( NULL ),
mDefaultKeyboardFocus( NULL ),
mKeystrokesOnly(FALSE),
mTopCtrl( NULL ),
mFocusWeight(0.f),
mAppHasFocus(TRUE) // Macs don't seem to notify us that we've gotten focus, so default to true
#ifdef _DEBUG
, mMouseCaptorName("none")
, mKeyboardFocusName("none")
, mTopCtrlName("none")
#endif
mAppHasFocus(TRUE), // Macs don't seem to notify us that we've gotten focus, so default to true
mImpl(new LLFocusMgr::Impl)
{
}
LLFocusMgr::~LLFocusMgr()
{
mImpl->mFocusHistory.clear();
delete mImpl;
mImpl = NULL;
}
void LLFocusMgr::releaseFocusIfNeeded( const LLView* view )
{
@@ -151,6 +174,12 @@ void LLFocusMgr::releaseFocusIfNeeded( const LLView* view )
void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL keystrokes_only)
{
// notes if keyboard focus is changed again (by onFocusLost/onFocusReceived)
// making the rest of our processing unnecessary since it will already be
// handled by the recursive call
static bool focus_dirty;
focus_dirty = false;
if (mLockedView &&
(new_focus == NULL ||
(new_focus != mLockedView
@@ -162,8 +191,6 @@ void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL
return;
}
//llinfos << "Keyboard focus handled by " << (new_focus ? new_focus->getName() : "nothing") << llendl;
mKeystrokesOnly = keystrokes_only;
if( new_focus != mKeyboardFocus )
@@ -171,23 +198,58 @@ void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL
mLastKeyboardFocus = mKeyboardFocus;
mKeyboardFocus = new_focus;
if( mLastKeyboardFocus )
// list of the focus and it's ancestors
view_handle_list_t old_focus_list = mImpl->mCachedKeyboardFocusList;
view_handle_list_t new_focus_list;
// walk up the tree to root and add all views to the new_focus_list
for (LLView* ctrl = dynamic_cast<LLView*>(mKeyboardFocus); ctrl; ctrl = ctrl->getParent())
{
mLastKeyboardFocus->onFocusLost();
new_focus_list.push_back(ctrl->getHandle());
}
// clear out any existing flash
if (new_focus)
// remove all common ancestors since their focus is unchanged
while (!new_focus_list.empty() &&
!old_focus_list.empty() &&
new_focus_list.back() == old_focus_list.back())
{
mFocusWeight = 0.f;
new_focus->onFocusReceived();
new_focus_list.pop_back();
old_focus_list.pop_back();
}
mFocusTimer.reset();
#ifdef _DEBUG
LLUICtrl* focus_ctrl = dynamic_cast<LLUICtrl*>(new_focus);
mKeyboardFocusName = focus_ctrl ? focus_ctrl->getName() : std::string("none");
#endif
// walk up the old focus branch calling onFocusLost
// we bubble up the tree to release focus, and back down to add
for (view_handle_list_t::iterator old_focus_iter = old_focus_list.begin();
old_focus_iter != old_focus_list.end() && !focus_dirty;
old_focus_iter++)
{
LLView* old_focus_view = old_focus_iter->get();
if (old_focus_view)
{
mImpl->mCachedKeyboardFocusList.pop_front();
old_focus_view->onFocusLost();
}
}
// walk down the new focus branch calling onFocusReceived
for (view_handle_list_t::reverse_iterator new_focus_riter = new_focus_list.rbegin();
new_focus_riter != new_focus_list.rend() && !focus_dirty;
new_focus_riter++)
{
LLView* new_focus_view = new_focus_riter->get();
if (new_focus_view)
{
mImpl->mCachedKeyboardFocusList.push_front(new_focus_view->getHandle());
new_focus_view->onFocusReceived();
}
}
// if focus was changed as part of an onFocusLost or onFocusReceived call
// stop iterating on current list since it is now invalid
if (focus_dirty)
{
return;
}
// If we've got a default keyboard focus, and the caller is
// releasing keyboard focus, move to the default.
@@ -212,7 +274,7 @@ void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL
if (focus_subtree)
{
LLView* focused_view = dynamic_cast<LLView*>(mKeyboardFocus);
mFocusHistory[focus_subtree->getHandle()] = focused_view ? focused_view->getHandle() : LLHandle<LLView>();
mImpl->mFocusHistory[focus_subtree->getHandle()] = focused_view ? focused_view->getHandle() : LLHandle<LLView>();
}
}
@@ -220,6 +282,8 @@ void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL
{
lockFocus();
}
focus_dirty = true;
}
@@ -241,7 +305,7 @@ BOOL LLFocusMgr::childHasKeyboardFocus(const LLView* parent ) const
// Returns TRUE is parent or any descedent of parent is the mouse captor.
BOOL LLFocusMgr::childHasMouseCapture( const LLView* parent ) const
{
if( mMouseCaptor && mMouseCaptor->isView() )
if( mMouseCaptor && dynamic_cast<LLView*>(mMouseCaptor) != NULL )
{
LLView* captor_view = (LLView*)mMouseCaptor;
while( captor_view )
@@ -268,65 +332,42 @@ void LLFocusMgr::removeKeyboardFocusWithoutCallback( const LLFocusableElement* f
if( mKeyboardFocus == focus )
{
mKeyboardFocus = NULL;
#ifdef _DEBUG
mKeyboardFocusName = std::string("none");
#endif
}
}
void LLFocusMgr::setMouseCapture( LLMouseHandler* new_captor )
{
//if (mFocusLocked)
//{
// return;
//}
if( new_captor != mMouseCaptor )
{
LLMouseHandler* old_captor = mMouseCaptor;
mMouseCaptor = new_captor;
/*
if (new_captor)
if (LLView::sDebugMouseHandling)
{
if ( new_captor->getName() == "Stickto")
if (new_captor)
{
llinfos << "New mouse captor: " << new_captor->getName() << llendl;
}
else
{
llinfos << "New mouse captor: " << new_captor->getName() << llendl;
llinfos << "New mouse captor: NULL" << llendl;
}
}
else
{
llinfos << "New mouse captor: NULL" << llendl;
}
*/
if( old_captor )
{
old_captor->onMouseCaptureLost();
}
#ifdef _DEBUG
mMouseCaptorName = new_captor ? new_captor->getName() : std::string("none");
#endif
}
}
void LLFocusMgr::removeMouseCaptureWithoutCallback( const LLMouseHandler* captor )
{
//if (mFocusLocked)
//{
// return;
//}
if( mMouseCaptor == captor )
{
mMouseCaptor = NULL;
#ifdef _DEBUG
mMouseCaptorName = std::string("none");
#endif
}
}
@@ -355,13 +396,9 @@ void LLFocusMgr::setTopCtrl( LLUICtrl* new_top )
{
mTopCtrl = new_top;
#ifdef _DEBUG
mTopCtrlName = new_top ? new_top->getName() : std::string("none");
#endif
if (old_top)
{
old_top->onLostTop();
old_top->onTopLost();
}
}
}
@@ -371,9 +408,6 @@ void LLFocusMgr::removeTopCtrlWithoutCallback( const LLUICtrl* top_view )
if( mTopCtrl == top_view )
{
mTopCtrl = NULL;
#ifdef _DEBUG
mTopCtrlName = std::string("none");
#endif
}
}
@@ -389,12 +423,13 @@ void LLFocusMgr::unlockFocus()
F32 LLFocusMgr::getFocusFlashAmt() const
{
return clamp_rescale(getFocusTime(), 0.f, FOCUS_FADE_TIME, mFocusWeight, 0.f);
return clamp_rescale(mFocusFlashTimer.getElapsedTimeF32(), 0.f, FOCUS_FADE_TIME, 1.f, 0.f);
}
LLColor4 LLFocusMgr::getFocusColor() const
{
LLColor4 focus_color = lerp(LLUI::sColorsGroup->getColor( "FocusColor" ), LLColor4::white, getFocusFlashAmt());
static LLCachedControl<LLColor4> focus_color_cached(*LLUI::sColorsGroup,"FocusColor", LLColor4::white);
LLColor4 focus_color = lerp(focus_color_cached, LLColor4::white, getFocusFlashAmt());
// de-emphasize keyboard focus when app has lost focus (to avoid typing into wrong window problem)
if (!mAppHasFocus)
{
@@ -405,8 +440,7 @@ LLColor4 LLFocusMgr::getFocusColor() const
void LLFocusMgr::triggerFocusFlash()
{
mFocusTimer.reset();
mFocusWeight = 1.f;
mFocusFlashTimer.reset();
}
void LLFocusMgr::setAppHasFocus(BOOL focus)
@@ -428,8 +462,8 @@ LLUICtrl* LLFocusMgr::getLastFocusForGroup(LLView* subtree_root) const
{
if (subtree_root)
{
focus_history_map_t::const_iterator found_it = mFocusHistory.find(subtree_root->getHandle());
if (found_it != mFocusHistory.end())
focus_history_map_t::const_iterator found_it = mImpl->mFocusHistory.find(subtree_root->getHandle());
if (found_it != mImpl->mFocusHistory.end())
{
// found last focus for this subtree
return static_cast<LLUICtrl*>(found_it->second.get());
@@ -442,6 +476,6 @@ void LLFocusMgr::clearLastFocusForGroup(LLView* subtree_root)
{
if (subtree_root)
{
mFocusHistory.erase(subtree_root->getHandle());
mImpl->mFocusHistory.erase(subtree_root->getHandle());
}
}