PageRenderTime 84ms CodeModel.GetById 8ms app.highlight 55ms RepoModel.GetById 12ms app.codeStats 1ms

/indra/newview/llpopupview.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 271 lines | 206 code | 35 blank | 30 comment | 29 complexity | f30b59a060c7015d51ee9e81ae34d200 MD5 | raw file
  1/** 
  2 * @file llpopupview.cpp
  3 * @brief Holds transient popups
  4 *
  5 * $LicenseInfo:firstyear=2001&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#include "llviewerprecompiledheaders.h"
 27
 28#include "llpopupview.h"
 29
 30static LLRegisterPanelClassWrapper<LLPopupView> r("popup_holder");
 31
 32bool view_visible_and_enabled(LLView* viewp)
 33{
 34	return viewp->getVisible() && viewp->getEnabled();
 35}
 36
 37bool view_visible(LLView* viewp)
 38{
 39	return viewp->getVisible();
 40}
 41
 42
 43LLPopupView::LLPopupView(const LLPopupView::Params& p)
 44: LLPanel(p)
 45{
 46	// register ourself as handler of UI popups
 47	LLUI::setPopupFuncs(boost::bind(&LLPopupView::addPopup, this, _1), boost::bind(&LLPopupView::removePopup, this, _1), boost::bind(&LLPopupView::clearPopups, this));
 48}
 49
 50LLPopupView::~LLPopupView()
 51{
 52	// set empty callback function so we can't handle popups anymore
 53	LLUI::setPopupFuncs(LLUI::add_popup_t(), LLUI::remove_popup_t(), LLUI::clear_popups_t());
 54}
 55
 56void LLPopupView::draw()
 57{
 58	S32 screen_x, screen_y;
 59
 60	// remove dead popups
 61	for (popup_list_t::iterator popup_it = mPopups.begin();
 62		popup_it != mPopups.end();)
 63	{
 64		if (!popup_it->get())
 65		{
 66			mPopups.erase(popup_it++);
 67		}
 68		else
 69		{
 70			popup_it++;
 71		}
 72	}
 73
 74	// draw in reverse order (most recent is on top)
 75	for (popup_list_t::reverse_iterator popup_it = mPopups.rbegin();
 76		popup_it != mPopups.rend();)
 77	{
 78		LLView* popup = popup_it->get();
 79
 80		if (popup->getVisible())
 81		{
 82			popup->localPointToScreen(0, 0, &screen_x, &screen_y);
 83
 84			LLUI::pushMatrix();
 85			{
 86				LLUI::translate( (F32) screen_x, (F32) screen_y, 0.f);
 87				popup->draw();
 88			}
 89			LLUI::popMatrix();
 90		}
 91		++popup_it;
 92	}
 93
 94	LLPanel::draw();
 95}
 96
 97BOOL LLPopupView::handleMouseEvent(boost::function<BOOL(LLView*, S32, S32)> func, 
 98								   boost::function<bool(LLView*)> predicate, 
 99								   S32 x, S32 y,
100								   bool close_popups)
101{
102	BOOL handled = FALSE;
103
104	// make a copy of list of popups, in case list is modified during mouse event handling
105	popup_list_t popups(mPopups);
106	for (popup_list_t::iterator popup_it = popups.begin(), popup_end = popups.end();
107		popup_it != popup_end;
108		++popup_it)
109	{
110		LLView* popup = popup_it->get();
111		if (!popup 
112			|| !predicate(popup))
113		{
114			continue;
115		}
116
117		S32 popup_x, popup_y;
118		if (localPointToOtherView(x, y, &popup_x, &popup_y, popup) 
119			&& popup->pointInView(popup_x, popup_y))
120		{
121			if (func(popup, popup_x, popup_y))
122			{
123				handled = TRUE;
124				break;
125			}
126		}
127
128		if (close_popups)
129		{
130			mPopups.remove(*popup_it);
131			popup->onTopLost();
132		}
133	}
134
135	return handled;
136}
137
138
139BOOL LLPopupView::handleMouseDown(S32 x, S32 y, MASK mask)
140{
141	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y, true);
142	if (!handled)
143	{
144		handled = LLPanel::handleMouseDown(x, y, mask);
145	}
146	return handled;
147}
148
149BOOL LLPopupView::handleMouseUp(S32 x, S32 y, MASK mask)
150{
151	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y, false);
152	if (!handled)
153	{
154		handled = LLPanel::handleMouseUp(x, y, mask);
155	}
156	return handled;
157}
158
159BOOL LLPopupView::handleMiddleMouseDown(S32 x, S32 y, MASK mask)
160{
161	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleMiddleMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y, true);
162	if (!handled)
163	{
164		handled = LLPanel::handleMiddleMouseDown(x, y, mask);
165	}
166	return handled;	
167}
168
169BOOL LLPopupView::handleMiddleMouseUp(S32 x, S32 y, MASK mask)
170{
171	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleMiddleMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y, false);
172	if (!handled)
173	{
174		handled = LLPanel::handleMiddleMouseUp(x, y, mask);
175	}
176	return handled;	
177}
178
179BOOL LLPopupView::handleRightMouseDown(S32 x, S32 y, MASK mask)
180{
181	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleRightMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y, true);
182	if (!handled)
183	{
184		handled = LLPanel::handleRightMouseDown(x, y, mask);
185	}
186	return handled;	
187}
188
189BOOL LLPopupView::handleRightMouseUp(S32 x, S32 y, MASK mask)
190{
191	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleRightMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y, false);
192	if (!handled)
193	{
194		handled = LLPanel::handleRightMouseUp(x, y, mask);
195	}
196	return handled;	
197}
198
199BOOL LLPopupView::handleDoubleClick(S32 x, S32 y, MASK mask)
200{
201	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleDoubleClick, _1, _2, _3, mask), view_visible_and_enabled, x, y, false);
202	if (!handled)
203	{
204		handled = LLPanel::handleDoubleClick(x, y, mask);
205	}
206	return handled;	
207}
208
209BOOL LLPopupView::handleHover(S32 x, S32 y, MASK mask)
210{
211	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleHover, _1, _2, _3, mask), view_visible_and_enabled, x, y, false);
212	if (!handled)
213	{
214		handled = LLPanel::handleHover(x, y, mask);
215	}
216	return handled;	
217}
218
219BOOL LLPopupView::handleScrollWheel(S32 x, S32 y, S32 clicks)
220{
221	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleScrollWheel, _1, _2, _3, clicks), view_visible_and_enabled, x, y, false);
222	if (!handled)
223	{
224		handled = LLPanel::handleScrollWheel(x, y, clicks);
225	}
226	return handled;	
227}
228
229BOOL LLPopupView::handleToolTip(S32 x, S32 y, MASK mask)
230{
231	BOOL handled = handleMouseEvent(boost::bind(&LLMouseHandler::handleToolTip, _1, _2, _3, mask), view_visible, x, y, false);
232	if (!handled)
233	{
234		handled = LLPanel::handleToolTip(x, y, mask);
235	}
236	return handled;
237}
238
239void LLPopupView::addPopup(LLView* popup)
240{
241	if (popup)
242	{
243		mPopups.remove(popup->getHandle());
244		mPopups.push_front(popup->getHandle());
245	}
246}
247
248void LLPopupView::removePopup(LLView* popup)
249{
250	if (popup)
251	{
252		mPopups.remove(popup->getHandle());
253		popup->onTopLost();
254	}
255}
256
257void LLPopupView::clearPopups()
258{
259	for (popup_list_t::iterator popup_it = mPopups.begin();
260		popup_it != mPopups.end();)
261	{
262		LLView* popup = popup_it->get();
263
264		popup_list_t::iterator cur_popup_it = popup_it;
265		++popup_it;
266
267		mPopups.erase(cur_popup_it);
268		popup->onTopLost();
269	}
270}
271