PageRenderTime 52ms CodeModel.GetById 20ms app.highlight 15ms RepoModel.GetById 15ms app.codeStats 0ms

/indra/newview/lltransientfloatermgr.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 169 lines | 112 code | 27 blank | 30 comment | 18 complexity | 29257b0b7dbe73443aac2c9f2df1a4c7 MD5 | raw file
  1/** 
  2 * @file lltransientfloatermgr.cpp
  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#include "llviewerprecompiledheaders.h"
 28
 29#include "lltransientfloatermgr.h"
 30#include "llfocusmgr.h"
 31#include "llrootview.h"
 32#include "llviewerwindow.h"
 33#include "lldockablefloater.h"
 34#include "llmenugl.h"
 35
 36
 37LLTransientFloaterMgr::LLTransientFloaterMgr()
 38{
 39	if(gViewerWindow)
 40	{
 41		gViewerWindow->getRootView()->getChild<LLUICtrl>("popup_holder")->setMouseDownCallback(boost::bind(
 42			&LLTransientFloaterMgr::leftMouseClickCallback, this, _2, _3, _4));
 43	}
 44
 45	mGroupControls.insert(std::pair<ETransientGroup, controls_set_t >(GLOBAL, controls_set_t()));
 46	mGroupControls.insert(std::pair<ETransientGroup, controls_set_t >(DOCKED, controls_set_t()));
 47	mGroupControls.insert(std::pair<ETransientGroup, controls_set_t >(IM, controls_set_t()));
 48}
 49
 50void LLTransientFloaterMgr::registerTransientFloater(LLTransientFloater* floater)
 51{
 52	mTransSet.insert(floater);
 53}
 54
 55void LLTransientFloaterMgr::unregisterTransientFloater(LLTransientFloater* floater)
 56{
 57	mTransSet.erase(floater);
 58}
 59
 60void LLTransientFloaterMgr::addControlView(ETransientGroup group, LLView* view)
 61{
 62	if (!view) return;
 63
 64	mGroupControls.find(group)->second.insert(view->getHandle());
 65}
 66
 67void LLTransientFloaterMgr::removeControlView(ETransientGroup group, LLView* view)
 68{
 69	if (!view) return;
 70
 71	mGroupControls.find(group)->second.erase(view->getHandle());
 72}
 73
 74void LLTransientFloaterMgr::addControlView(LLView* view)
 75{
 76	addControlView(GLOBAL, view);
 77}
 78
 79void LLTransientFloaterMgr::removeControlView(LLView* view)
 80{
 81	// we will still get focus lost callbacks on this view, but that's ok
 82	// since we run sanity checking logic every time
 83	removeControlView(GLOBAL, view);
 84}
 85
 86void LLTransientFloaterMgr::hideTransientFloaters(S32 x, S32 y)
 87{
 88	for (std::set<LLTransientFloater*>::iterator it = mTransSet.begin(); it
 89			!= mTransSet.end(); it++)
 90	{
 91		LLTransientFloater* floater = *it;
 92		if (floater->isTransientDocked())
 93		{
 94			ETransientGroup group = floater->getGroup();
 95
 96			bool hide = isControlClicked(group, mGroupControls.find(group)->second, x, y);
 97			if (hide)
 98			{
 99				floater->setTransientVisible(FALSE);
100			}
101		}
102	}
103}
104
105bool LLTransientFloaterMgr::isControlClicked(ETransientGroup group, controls_set_t& set, S32 x, S32 y)
106{
107	std::list< LLHandle<LLView> > dead_handles;
108	
109	bool res = true;
110	for (controls_set_t::iterator it = set.begin(); it
111			!= set.end(); it++)
112	{
113		LLView* control_view = NULL;
114
115		LLHandle<LLView> handle = *it;
116		if (handle.isDead())
117		{
118			dead_handles.push_back(handle);
119			continue;
120		}
121
122		control_view = handle.get();
123
124		if (!control_view->getVisible())
125		{
126			continue;
127		}
128
129		LLRect rect = control_view->calcScreenRect();
130		// if click inside view rect
131		if (rect.pointInRect(x, y))
132		{
133			res = false;
134			break;
135		}
136	}
137
138	for (std::list< LLHandle<LLView> >::iterator it = dead_handles.begin(); it != dead_handles.end(); ++it)
139	{
140		LLHandle<LLView> handle = *it;
141		mGroupControls.find(group)->second.erase(handle);
142	}
143	
144	return res;
145}
146
147void LLTransientFloaterMgr::leftMouseClickCallback(S32 x, S32 y,
148		MASK mask)
149{
150	// don't hide transient floater if any context menu opened
151	if (LLMenuGL::sMenuContainer->getVisibleMenu() != NULL)
152	{
153		return;
154	}
155
156	bool hide = isControlClicked(DOCKED, mGroupControls.find(DOCKED)->second, x, y)
157			&& isControlClicked(GLOBAL, mGroupControls.find(GLOBAL)->second, x, y);
158	if (hide)
159	{
160		hideTransientFloaters(x, y);
161	}
162}
163
164void LLTransientFloater::init(LLFloater* thiz)
165{
166	// used since LLTransientFloater(this) can't be used in descendant constructor parameter initialization.
167	mFloater = thiz;
168}
169