From c3c04adaa56c895018e1d2dd32b94469aaf44347 Mon Sep 17 00:00:00 2001 From: Richard Nelson Date: Tue, 2 Mar 2010 15:11:56 -0800 Subject: added missing files --- indra/newview/llpopupview.cpp | 202 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 indra/newview/llpopupview.cpp (limited to 'indra/newview/llpopupview.cpp') diff --git a/indra/newview/llpopupview.cpp b/indra/newview/llpopupview.cpp new file mode 100644 index 0000000000..964ca4d361 --- /dev/null +++ b/indra/newview/llpopupview.cpp @@ -0,0 +1,202 @@ +/** + * @file llpopupview.cpp + * @brief Holds transient popups + * + * $LicenseInfo:firstyear=2001&license=viewergpl$ + * + * Copyright (c) 2001-2010, Linden Research, Inc. + * + * 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 + * + * 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 + * + * 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. + * + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. + * $/LicenseInfo$ + */ +#include "llviewerprecompiledheaders.h" + +#include "llpopupview.h" + +static LLRegisterPanelClassWrapper r("popup_holder"); + +bool view_visible_and_enabled(LLView* viewp) +{ + return viewp->getVisible() && viewp->getEnabled(); +} + +bool view_visible(LLView* viewp) +{ + return viewp->getVisible(); +} + + +LLPopupView::LLPopupView() +{ +} + +void LLPopupView::draw() +{ + S32 screen_x, screen_y; + + for (popup_list_t::iterator popup_it = mPopups.begin(); + popup_it != mPopups.end();) + { + LLView* popup = popup_it->get(); + if (!popup) + { + popup_list_t::iterator cur_popup_it = popup_it; + ++popup_it; + mPopups.erase(cur_popup_it); + continue; + } + + if (popup->getVisible()) + { + popup->localPointToScreen(0, 0, &screen_x, &screen_y); + + LLUI::pushMatrix(); + { + LLUI::translate( (F32) screen_x, (F32) screen_y, 0.f); + popup->draw(); + } + LLUI::popMatrix(); + } + ++popup_it; + } + + LLPanel::draw(); +} + +BOOL LLPopupView::handleMouseEvent(boost::function func, + boost::function predicate, + S32 x, S32 y) +{ + for (popup_list_t::reverse_iterator popup_it = mPopups.rbegin(); + popup_it != mPopups.rend(); + ++popup_it) + { + LLView* popup = popup_it->get(); + if (!popup + || !predicate(popup)) + { + continue; + } + + S32 popup_x, popup_y; + if (localPointToOtherView(x, y, &popup_x, &popup_y, popup) + && popup->getRect().pointInRect(popup_x, popup_y)) + { + if (func(popup, popup_x, popup_y)) + { + return TRUE; + } + } + } + + return FALSE; +} + + +BOOL LLPopupView::handleMouseDown(S32 x, S32 y, MASK mask) +{ + if (!handleMouseEvent(boost::bind(&LLMouseHandler::handleMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y)) + { + clearPopups(); + return FALSE; + } + return TRUE; +} + +BOOL LLPopupView::handleMouseUp(S32 x, S32 y, MASK mask) +{ + return handleMouseEvent(boost::bind(&LLMouseHandler::handleMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y); +} + +BOOL LLPopupView::handleMiddleMouseDown(S32 x, S32 y, MASK mask) +{ + if (!handleMouseEvent(boost::bind(&LLMouseHandler::handleMiddleMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y)) + { + clearPopups(); + return FALSE; + } + return TRUE; +} + +BOOL LLPopupView::handleMiddleMouseUp(S32 x, S32 y, MASK mask) +{ + return handleMouseEvent(boost::bind(&LLMouseHandler::handleMiddleMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y); +} + +BOOL LLPopupView::handleRightMouseDown(S32 x, S32 y, MASK mask) +{ + if (!handleMouseEvent(boost::bind(&LLMouseHandler::handleRightMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y)) + { + clearPopups(); + return FALSE; + } + return TRUE; +} + +BOOL LLPopupView::handleRightMouseUp(S32 x, S32 y, MASK mask) +{ + return handleMouseEvent(boost::bind(&LLMouseHandler::handleRightMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y); +} + +BOOL LLPopupView::handleDoubleClick(S32 x, S32 y, MASK mask) +{ + return handleMouseEvent(boost::bind(&LLMouseHandler::handleDoubleClick, _1, _2, _3, mask), view_visible_and_enabled, x, y); +} + +BOOL LLPopupView::handleHover(S32 x, S32 y, MASK mask) +{ + return handleMouseEvent(boost::bind(&LLMouseHandler::handleHover, _1, _2, _3, mask), view_visible_and_enabled, x, y); +} + +BOOL LLPopupView::handleScrollWheel(S32 x, S32 y, S32 clicks) +{ + return handleMouseEvent(boost::bind(&LLMouseHandler::handleScrollWheel, _1, _2, _3, clicks), view_visible_and_enabled, x, y); +} + +BOOL LLPopupView::handleToolTip(S32 x, S32 y, MASK mask) +{ + return handleMouseEvent(boost::bind(&LLMouseHandler::handleToolTip, _1, _2, _3, mask), view_visible, x, y); +} + +void LLPopupView::addPopup(LLView* popup) +{ + removePopup(popup); + if (popup) + { + mPopups.push_back(popup->getHandle()); + } +} + +void LLPopupView::removePopup(LLView* popup) +{ + if (popup) + { + mPopups.erase(std::find(mPopups.begin(), mPopups.end(), popup->getHandle())); + } +} + +void LLPopupView::clearPopups() +{ + mPopups.clear(); +} + -- cgit v1.2.3 From 69f9c0bcf9764a1b682bfdd5baa3f340922dcbaa Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 3 Mar 2010 19:37:41 -0800 Subject: WIP - replace top ctrl with LLPopupView --- indra/newview/llpopupview.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'indra/newview/llpopupview.cpp') diff --git a/indra/newview/llpopupview.cpp b/indra/newview/llpopupview.cpp index 964ca4d361..eb750a87e2 100644 --- a/indra/newview/llpopupview.cpp +++ b/indra/newview/llpopupview.cpp @@ -100,7 +100,7 @@ BOOL LLPopupView::handleMouseEvent(boost::function func S32 popup_x, popup_y; if (localPointToOtherView(x, y, &popup_x, &popup_y, popup) - && popup->getRect().pointInRect(popup_x, popup_y)) + && popup->pointInView(popup_x, popup_y)) { if (func(popup, popup_x, popup_y)) { @@ -180,9 +180,9 @@ BOOL LLPopupView::handleToolTip(S32 x, S32 y, MASK mask) void LLPopupView::addPopup(LLView* popup) { - removePopup(popup); if (popup) { + mPopups.erase(std::find(mPopups.begin(), mPopups.end(), popup->getHandle())); mPopups.push_back(popup->getHandle()); } } @@ -191,12 +191,26 @@ void LLPopupView::removePopup(LLView* popup) { if (popup) { + if (gFocusMgr.childHasKeyboardFocus(popup)) + { + gFocusMgr.setKeyboardFocus(NULL); + } + popup->onTopLost(); mPopups.erase(std::find(mPopups.begin(), mPopups.end(), popup->getHandle())); } } void LLPopupView::clearPopups() { + for (popup_list_t::iterator popup_it = mPopups.begin(); + popup_it != mPopups.end();) + { + LLView* popup = popup_it->get(); + ++popup_it; + + if (popup) popup->onTopLost(); + } + mPopups.clear(); } -- cgit v1.2.3 From 0bbcb0d22d2a215e0d8bf824b44a18a8bd948f20 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 3 Mar 2010 20:23:26 -0800 Subject: resizing and nesting of popups now work --- indra/newview/llpopupview.cpp | 64 +++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 27 deletions(-) (limited to 'indra/newview/llpopupview.cpp') diff --git a/indra/newview/llpopupview.cpp b/indra/newview/llpopupview.cpp index eb750a87e2..3494522969 100644 --- a/indra/newview/llpopupview.cpp +++ b/indra/newview/llpopupview.cpp @@ -54,17 +54,25 @@ void LLPopupView::draw() { S32 screen_x, screen_y; + // remove dead popups for (popup_list_t::iterator popup_it = mPopups.begin(); popup_it != mPopups.end();) { - LLView* popup = popup_it->get(); - if (!popup) + if (!popup_it->get()) { - popup_list_t::iterator cur_popup_it = popup_it; - ++popup_it; - mPopups.erase(cur_popup_it); - continue; + mPopups.erase(popup_it++); + } + else + { + popup_it++; } + } + + // draw in reverse order (most recent is on top) + for (popup_list_t::reverse_iterator popup_it = mPopups.rbegin(); + popup_it != mPopups.rend();) + { + LLView* popup = popup_it->get(); if (popup->getVisible()) { @@ -85,16 +93,17 @@ void LLPopupView::draw() BOOL LLPopupView::handleMouseEvent(boost::function func, boost::function predicate, - S32 x, S32 y) + S32 x, S32 y, + bool close_popups) { - for (popup_list_t::reverse_iterator popup_it = mPopups.rbegin(); - popup_it != mPopups.rend(); - ++popup_it) + for (popup_list_t::iterator popup_it = mPopups.begin(); + popup_it != mPopups.end();) { LLView* popup = popup_it->get(); if (!popup || !predicate(popup)) { + ++popup_it; continue; } @@ -107,6 +116,9 @@ BOOL LLPopupView::handleMouseEvent(boost::function func return TRUE; } } + + popup->onTopLost(); + mPopups.erase(popup_it++); } return FALSE; @@ -115,9 +127,8 @@ BOOL LLPopupView::handleMouseEvent(boost::function func BOOL LLPopupView::handleMouseDown(S32 x, S32 y, MASK mask) { - if (!handleMouseEvent(boost::bind(&LLMouseHandler::handleMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y)) + if (!handleMouseEvent(boost::bind(&LLMouseHandler::handleMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y, true)) { - clearPopups(); return FALSE; } return TRUE; @@ -125,14 +136,13 @@ BOOL LLPopupView::handleMouseDown(S32 x, S32 y, MASK mask) BOOL LLPopupView::handleMouseUp(S32 x, S32 y, MASK mask) { - return handleMouseEvent(boost::bind(&LLMouseHandler::handleMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y); + return handleMouseEvent(boost::bind(&LLMouseHandler::handleMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y, false); } BOOL LLPopupView::handleMiddleMouseDown(S32 x, S32 y, MASK mask) { - if (!handleMouseEvent(boost::bind(&LLMouseHandler::handleMiddleMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y)) + if (!handleMouseEvent(boost::bind(&LLMouseHandler::handleMiddleMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y, true)) { - clearPopups(); return FALSE; } return TRUE; @@ -140,14 +150,13 @@ BOOL LLPopupView::handleMiddleMouseDown(S32 x, S32 y, MASK mask) BOOL LLPopupView::handleMiddleMouseUp(S32 x, S32 y, MASK mask) { - return handleMouseEvent(boost::bind(&LLMouseHandler::handleMiddleMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y); + return handleMouseEvent(boost::bind(&LLMouseHandler::handleMiddleMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y, false); } BOOL LLPopupView::handleRightMouseDown(S32 x, S32 y, MASK mask) { - if (!handleMouseEvent(boost::bind(&LLMouseHandler::handleRightMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y)) + if (!handleMouseEvent(boost::bind(&LLMouseHandler::handleRightMouseDown, _1, _2, _3, mask), view_visible_and_enabled, x, y, true)) { - clearPopups(); return FALSE; } return TRUE; @@ -155,27 +164,27 @@ BOOL LLPopupView::handleRightMouseDown(S32 x, S32 y, MASK mask) BOOL LLPopupView::handleRightMouseUp(S32 x, S32 y, MASK mask) { - return handleMouseEvent(boost::bind(&LLMouseHandler::handleRightMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y); + return handleMouseEvent(boost::bind(&LLMouseHandler::handleRightMouseUp, _1, _2, _3, mask), view_visible_and_enabled, x, y, false); } BOOL LLPopupView::handleDoubleClick(S32 x, S32 y, MASK mask) { - return handleMouseEvent(boost::bind(&LLMouseHandler::handleDoubleClick, _1, _2, _3, mask), view_visible_and_enabled, x, y); + return handleMouseEvent(boost::bind(&LLMouseHandler::handleDoubleClick, _1, _2, _3, mask), view_visible_and_enabled, x, y, false); } BOOL LLPopupView::handleHover(S32 x, S32 y, MASK mask) { - return handleMouseEvent(boost::bind(&LLMouseHandler::handleHover, _1, _2, _3, mask), view_visible_and_enabled, x, y); + return handleMouseEvent(boost::bind(&LLMouseHandler::handleHover, _1, _2, _3, mask), view_visible_and_enabled, x, y, false); } BOOL LLPopupView::handleScrollWheel(S32 x, S32 y, S32 clicks) { - return handleMouseEvent(boost::bind(&LLMouseHandler::handleScrollWheel, _1, _2, _3, clicks), view_visible_and_enabled, x, y); + return handleMouseEvent(boost::bind(&LLMouseHandler::handleScrollWheel, _1, _2, _3, clicks), view_visible_and_enabled, x, y, false); } BOOL LLPopupView::handleToolTip(S32 x, S32 y, MASK mask) { - return handleMouseEvent(boost::bind(&LLMouseHandler::handleToolTip, _1, _2, _3, mask), view_visible, x, y); + return handleMouseEvent(boost::bind(&LLMouseHandler::handleToolTip, _1, _2, _3, mask), view_visible, x, y, false); } void LLPopupView::addPopup(LLView* popup) @@ -183,7 +192,7 @@ void LLPopupView::addPopup(LLView* popup) if (popup) { mPopups.erase(std::find(mPopups.begin(), mPopups.end(), popup->getHandle())); - mPopups.push_back(popup->getHandle()); + mPopups.push_front(popup->getHandle()); } } @@ -206,11 +215,12 @@ void LLPopupView::clearPopups() popup_it != mPopups.end();) { LLView* popup = popup_it->get(); + + popup_list_t::iterator cur_popup_it = popup_it; ++popup_it; - if (popup) popup->onTopLost(); + mPopups.erase(cur_popup_it); + popup->onTopLost(); } - - mPopups.clear(); } -- cgit v1.2.3 From 902548c55cce856633a74fe98f515ad4b1804c05 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 3 Mar 2010 20:58:00 -0800 Subject: nested popups close properly --- indra/newview/llpopupview.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'indra/newview/llpopupview.cpp') diff --git a/indra/newview/llpopupview.cpp b/indra/newview/llpopupview.cpp index 3494522969..d9e4ebcd3c 100644 --- a/indra/newview/llpopupview.cpp +++ b/indra/newview/llpopupview.cpp @@ -117,8 +117,16 @@ BOOL LLPopupView::handleMouseEvent(boost::function func } } - popup->onTopLost(); - mPopups.erase(popup_it++); + if (close_popups) + { + popup_list_t::iterator cur_popup_it = popup_it++; + mPopups.erase(cur_popup_it); + popup->onTopLost(); + } + else + { + ++popup_it; + } } return FALSE; -- cgit v1.2.3 From 485711e179e0ccf6351feb02318f41bbb5593662 Mon Sep 17 00:00:00 2001 From: Richard Nelson Date: Thu, 4 Mar 2010 16:35:52 -0800 Subject: removed extraneous updateBoundingRect() calls remove the login progress panel as a popup only after it has finished fading out popupview manages it's own registering and unregistering of popup callbacks --- indra/newview/llpopupview.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'indra/newview/llpopupview.cpp') diff --git a/indra/newview/llpopupview.cpp b/indra/newview/llpopupview.cpp index d9e4ebcd3c..590a45c96c 100644 --- a/indra/newview/llpopupview.cpp +++ b/indra/newview/llpopupview.cpp @@ -48,6 +48,14 @@ bool view_visible(LLView* viewp) LLPopupView::LLPopupView() { + // register ourself as handler of UI popups + LLUI::setPopupFuncs(boost::bind(&LLPopupView::addPopup, this, _1), boost::bind(&LLPopupView::removePopup, this, _1), boost::bind(&LLPopupView::clearPopups, this)); +} + +LLPopupView::~LLPopupView() +{ + // set empty callback function so we can't handle popups anymore + LLUI::setPopupFuncs(LLUI::add_popup_t(), LLUI::remove_popup_t(), LLUI::clear_popups_t()); } void LLPopupView::draw() @@ -212,8 +220,8 @@ void LLPopupView::removePopup(LLView* popup) { gFocusMgr.setKeyboardFocus(NULL); } - popup->onTopLost(); mPopups.erase(std::find(mPopups.begin(), mPopups.end(), popup->getHandle())); + popup->onTopLost(); } } -- cgit v1.2.3 From eee50d1401ff7dfcb9c9fdc2c6e61e6d6281f5e2 Mon Sep 17 00:00:00 2001 From: Monroe Linden Date: Fri, 5 Mar 2010 18:11:55 -0800 Subject: Fix for a crash on startup/shutdown introduced in the tip of viewer-2-0 very recently. list.erase(list.find()) is not safe, because erasing list.end() is undefined. Check to make sure the find succeeded before doing the erase. Reviewed by Richard at http://codereview.lindenlab.com/341001 --- indra/newview/llpopupview.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'indra/newview/llpopupview.cpp') diff --git a/indra/newview/llpopupview.cpp b/indra/newview/llpopupview.cpp index 590a45c96c..1668a91eed 100644 --- a/indra/newview/llpopupview.cpp +++ b/indra/newview/llpopupview.cpp @@ -207,7 +207,11 @@ void LLPopupView::addPopup(LLView* popup) { if (popup) { - mPopups.erase(std::find(mPopups.begin(), mPopups.end(), popup->getHandle())); + popup_list_t::iterator iter = std::find(mPopups.begin(), mPopups.end(), popup->getHandle()); + if(iter != mPopups.end()) + { + mPopups.erase(iter); + } mPopups.push_front(popup->getHandle()); } } @@ -220,7 +224,11 @@ void LLPopupView::removePopup(LLView* popup) { gFocusMgr.setKeyboardFocus(NULL); } - mPopups.erase(std::find(mPopups.begin(), mPopups.end(), popup->getHandle())); + popup_list_t::iterator iter = std::find(mPopups.begin(), mPopups.end(), popup->getHandle()); + if(iter != mPopups.end()) + { + mPopups.erase(iter); + } popup->onTopLost(); } } -- cgit v1.2.3