diff options
Diffstat (limited to 'indra/newview/llscreenchannel.cpp')
-rw-r--r-- | indra/newview/llscreenchannel.cpp | 458 |
1 files changed, 283 insertions, 175 deletions
diff --git a/indra/newview/llscreenchannel.cpp b/indra/newview/llscreenchannel.cpp index 1683d113a9..dffb5e5e12 100644 --- a/indra/newview/llscreenchannel.cpp +++ b/indra/newview/llscreenchannel.cpp @@ -44,9 +44,10 @@ #include "lltrans.h" #include "lldockablefloater.h" -#include "llimpanel.h" #include "llsyswellwindow.h" #include "llimfloater.h" +#include "llscriptfloater.h" +#include "llfontgl.h" #include <algorithm> @@ -59,17 +60,14 @@ bool LLScreenChannel::mWasStartUpToastShown = false; // LLScreenChannelBase ////////////////////// LLScreenChannelBase::LLScreenChannelBase(const LLUUID& id) : - mOverflowToastPanel(NULL) - ,mToastAlignment(NA_BOTTOM) + mToastAlignment(NA_BOTTOM) ,mCanStoreToasts(true) ,mHiddenToastsNum(0) - ,mOverflowToastHidden(false) - ,mIsHovering(false) + ,mHoveredToast(NULL) ,mControlHovering(false) ,mShowToasts(true) { mID = id; - mOverflowFormatString = LLTrans::getString("OverflowInfoChannelString"); mWorldViewRectConnection = gViewerWindow->setOnWorldViewRectUpdated(boost::bind(&LLScreenChannelBase::updatePositionAndSize, this, _1, _2)); setMouseOpaque( false ); setVisible(FALSE); @@ -78,6 +76,17 @@ LLScreenChannelBase::~LLScreenChannelBase() { mWorldViewRectConnection.disconnect(); } + +bool LLScreenChannelBase::isHovering() +{ + if (!mHoveredToast) + { + return false; + } + + return mHoveredToast->isHovered(); +} + void LLScreenChannelBase::updatePositionAndSize(LLRect old_world_rect, LLRect new_world_rect) { S32 top_delta = old_world_rect.mTop - new_world_rect.mTop; @@ -104,8 +113,8 @@ void LLScreenChannelBase::updatePositionAndSize(LLRect old_world_rect, LLRect ne void LLScreenChannelBase::init(S32 channel_left, S32 channel_right) { - S32 channel_top = gViewerWindow->getWorldViewRect().getHeight(); - S32 channel_bottom = gViewerWindow->getWorldViewRect().mBottom + gSavedSettings.getS32("ChannelBottomPanelMargin"); + S32 channel_top = gViewerWindow->getWorldViewRectScaled().getHeight(); + S32 channel_bottom = gViewerWindow->getWorldViewRectScaled().mBottom + gSavedSettings.getS32("ChannelBottomPanelMargin"); setRect(LLRect(channel_left, channel_top, channel_right, channel_bottom)); setVisible(TRUE); } @@ -115,7 +124,9 @@ void LLScreenChannelBase::init(S32 channel_left, S32 channel_right) // LLScreenChannel ////////////////////// //-------------------------------------------------------------------------- -LLScreenChannel::LLScreenChannel(LLUUID& id): LLScreenChannelBase(id) +LLScreenChannel::LLScreenChannel(LLUUID& id): +LLScreenChannelBase(id) +,mStartUpToastPanel(NULL) { } @@ -123,6 +134,8 @@ LLScreenChannel::LLScreenChannel(LLUUID& id): LLScreenChannelBase(id) void LLScreenChannel::init(S32 channel_left, S32 channel_right) { LLScreenChannelBase::init(channel_left, channel_right); + LLRect world_rect = gViewerWindow->getWorldViewRectScaled(); + updatePositionAndSize(world_rect, world_rect); } //-------------------------------------------------------------------------- @@ -131,10 +144,54 @@ LLScreenChannel::~LLScreenChannel() } +std::list<LLToast*> LLScreenChannel::findToasts(const Matcher& matcher) +{ + std::list<LLToast*> res; + + // collect stored toasts + for (std::vector<ToastElem>::iterator it = mStoredToastList.begin(); it + != mStoredToastList.end(); it++) + { + if (matcher.matches(it->toast->getNotification())) + { + res.push_back(it->toast); + } + } + + // collect displayed toasts + for (std::vector<ToastElem>::iterator it = mToastList.begin(); it + != mToastList.end(); it++) + { + if (matcher.matches(it->toast->getNotification())) + { + res.push_back(it->toast); + } + } + + return res; +} + //-------------------------------------------------------------------------- void LLScreenChannel::updatePositionAndSize(LLRect old_world_rect, LLRect new_world_rect) { - LLScreenChannelBase::updatePositionAndSize(old_world_rect, new_world_rect); + S32 right_delta = old_world_rect.mRight - new_world_rect.mRight; + LLRect this_rect = getRect(); + + switch(mChannelAlignment) + { + case CA_LEFT : + this_rect.mTop = (S32) (new_world_rect.getHeight() * getHeightRatio()); + break; + case CA_CENTRE : + LLScreenChannelBase::updatePositionAndSize(old_world_rect, new_world_rect); + return; + case CA_RIGHT : + this_rect.mTop = (S32) (new_world_rect.getHeight() * getHeightRatio()); + this_rect.mLeft -= right_delta; + this_rect.mRight -= right_delta; + } + setRect(this_rect); + redrawToasts(); } //-------------------------------------------------------------------------- @@ -153,18 +210,24 @@ void LLScreenChannel::addToast(const LLToast::Params& p) ToastElem new_toast_elem(p); - mOverflowToastHidden = false; - new_toast_elem.toast->setOnFadeCallback(boost::bind(&LLScreenChannel::onToastFade, this, _1)); new_toast_elem.toast->setOnToastDestroyedCallback(boost::bind(&LLScreenChannel::onToastDestroyed, this, _1)); if(mControlHovering) { new_toast_elem.toast->setOnToastHoverCallback(boost::bind(&LLScreenChannel::onToastHover, this, _1, _2)); + new_toast_elem.toast->setMouseEnterCallback(boost::bind(&LLScreenChannel::stopFadingToasts, this)); + new_toast_elem.toast->setMouseLeaveCallback(boost::bind(&LLScreenChannel::startFadingToasts, this)); } if(show_toast) { mToastList.push_back(new_toast_elem); + if(p.can_be_stored) + { + // store toasts immediately - EXT-3762 + storeToast(new_toast_elem); + } + updateShowToastsState(); redrawToasts(); } else // store_toast @@ -183,6 +246,13 @@ void LLScreenChannel::onToastDestroyed(LLToast* toast) { mToastList.erase(it); } + + it = find(mStoredToastList.begin(), mStoredToastList.end(), static_cast<LLPanel*>(toast)); + + if(it != mStoredToastList.end()) + { + mStoredToastList.erase(it); + } } @@ -191,31 +261,42 @@ void LLScreenChannel::onToastFade(LLToast* toast) { std::vector<ToastElem>::iterator it = find(mToastList.begin(), mToastList.end(), static_cast<LLPanel*>(toast)); - bool delete_toast = !mCanStoreToasts || !toast->getCanBeStored(); - if(delete_toast) - { - mToastList.erase(it); - deleteToast(toast); - } - else + if(it != mToastList.end()) { - storeToast((*it)); - mToastList.erase(it); - } + bool delete_toast = !mCanStoreToasts || !toast->getCanBeStored(); + if(delete_toast) + { + mToastList.erase(it); + deleteToast(toast); + } + else + { + storeToast((*it)); + mToastList.erase(it); + } - redrawToasts(); + redrawToasts(); + } } //-------------------------------------------------------------------------- void LLScreenChannel::deleteToast(LLToast* toast) { + if (toast->isDead()) + { + return; + } + // send signal to observers about destroying of a toast toast->mOnDeleteToastSignal(toast); // update channel's Hovering state // turning hovering off manually because onMouseLeave won't happen if a toast was closed using a keyboard - if(toast->hasFocus()) - setHovering(false); + if(mHoveredToast == toast) + { + mHoveredToast = NULL; + startFadingToasts(); + } // close the toast toast->closeFloater(); @@ -230,7 +311,6 @@ void LLScreenChannel::storeToast(ToastElem& toast_elem) if( it != mStoredToastList.end() ) return; - toast_elem.toast->stopTimer(); mStoredToastList.push_back(toast_elem); mOnStoreToast(toast_elem.toast->getPanel(), toast_elem.id); } @@ -242,11 +322,10 @@ void LLScreenChannel::loadStoredToastsToChannel() if(mStoredToastList.size() == 0) return; - - mOverflowToastHidden = false; for(it = mStoredToastList.begin(); it != mStoredToastList.end(); ++it) { + (*it).toast->setIsHidden(false); (*it).toast->resetTimer(); mToastList.push_back((*it)); } @@ -263,12 +342,17 @@ void LLScreenChannel::loadStoredToastByNotificationIDToChannel(LLUUID id) if( it == mStoredToastList.end() ) return; - mOverflowToastHidden = false; - LLToast* toast = (*it).toast; + + if(toast->getVisible()) + { + // toast is already in channel + return; + } + + toast->setIsHidden(false); toast->resetTimer(); mToastList.push_back((*it)); - mStoredToastList.erase(it); redrawToasts(); } @@ -328,6 +412,16 @@ void LLScreenChannel::killToastByNotificationID(LLUUID id) } } +void LLScreenChannel::killMatchedToasts(const Matcher& matcher) +{ + std::list<LLToast*> to_delete = findToasts(matcher); + for (std::list<LLToast*>::iterator it = to_delete.begin(); it + != to_delete.end(); it++) + { + killToastByNotificationID((*it)-> getNotificationID()); + } +} + //-------------------------------------------------------------------------- void LLScreenChannel::modifyToastByNotificationID(LLUUID id, LLPanel* panel) { @@ -348,11 +442,9 @@ void LLScreenChannel::modifyToastByNotificationID(LLUUID id, LLPanel* panel) //-------------------------------------------------------------------------- void LLScreenChannel::redrawToasts() { - if(mToastList.size() == 0 || mIsHovering) + if(mToastList.size() == 0 || isHovering()) return; - hideToastsFromScreen(); - switch(mToastAlignment) { case NA_TOP : @@ -376,11 +468,14 @@ void LLScreenChannel::showToastsBottom() S32 toast_margin = 0; std::vector<ToastElem>::reverse_iterator it; + LLDockableFloater* floater = dynamic_cast<LLDockableFloater*>(LLDockableFloater::getInstanceHandle().get()); + for(it = mToastList.rbegin(); it != mToastList.rend(); ++it) { if(it != mToastList.rbegin()) { - bottom = (*(it-1)).toast->getRect().mTop; + LLToast* toast = (*(it-1)).toast; + bottom = toast->getRect().mTop - toast->getTopPad(); toast_margin = gSavedSettings.getS32("ToastGap"); } @@ -388,32 +483,75 @@ void LLScreenChannel::showToastsBottom() toast_rect.setOriginAndSize(getRect().mLeft, bottom + toast_margin, toast_rect.getWidth() ,toast_rect.getHeight()); (*it).toast->setRect(toast_rect); + if(floater && floater->overlapsScreenChannel()) + { + if(it == mToastList.rbegin()) + { + // move first toast above docked floater + S32 shift = floater->getRect().getHeight(); + if(floater->getDockControl()) + { + shift += floater->getDockControl()->getTongueHeight(); + } + (*it).toast->translate(0, shift); + } + + LLRect world_rect = gViewerWindow->getWorldViewRectScaled(); + // don't show toasts if there is not enough space + if(toast_rect.mTop > world_rect.mTop) + { + break; + } + } + bool stop_showing_toasts = (*it).toast->getRect().mTop > getRect().mTop; if(!stop_showing_toasts) { if( it != mToastList.rend()-1) { - stop_showing_toasts = ((*it).toast->getRect().mTop + gSavedSettings.getS32("OverflowToastHeight") + gSavedSettings.getS32("ToastGap")) > getRect().mTop; + S32 toast_top = (*it).toast->getRect().mTop + gSavedSettings.getS32("ToastGap"); + stop_showing_toasts = toast_top > getRect().mTop; } } + // at least one toast should be visible + if(it == mToastList.rbegin()) + { + stop_showing_toasts = false; + } + if(stop_showing_toasts) break; - (*it).toast->setVisible(TRUE); + if( !(*it).toast->getVisible() ) + { + // HACK + // EXT-2653: it is necessary to prevent overlapping for secondary showed toasts + (*it).toast->setVisible(TRUE); + } + if(!(*it).toast->hasFocus()) + { + // Fixing Z-order of toasts (EXT-4862) + // Next toast will be positioned under this one. + gFloaterView->sendChildToBack((*it).toast); + } } - if(it != mToastList.rend() && !mOverflowToastHidden) + if(it != mToastList.rend()) { mHiddenToastsNum = 0; for(; it != mToastList.rend(); it++) { (*it).toast->stopTimer(); + (*it).toast->setVisible(FALSE); mHiddenToastsNum++; } - createOverflowToast(bottom, gSavedSettings.getS32("NotificationTipToastLifeTime")); - } + } + else + { + closeOverflowToastPanel(); + } } //-------------------------------------------------------------------------- @@ -439,86 +577,13 @@ void LLScreenChannel::showToastsTop() } //-------------------------------------------------------------------------- -void LLScreenChannel::createOverflowToast(S32 bottom, F32 timer) -{ - LLRect toast_rect; - LLToast::Params p; - p.lifetime_secs = timer; - mOverflowToastPanel = new LLToast(p); - - if(!mOverflowToastPanel) - return; - - mOverflowToastPanel->setOnFadeCallback(boost::bind(&LLScreenChannel::closeOverflowToastPanel, this)); - - LLTextBox* text_box = mOverflowToastPanel->getChild<LLTextBox>("toast_text"); - LLIconCtrl* icon = mOverflowToastPanel->getChild<LLIconCtrl>("icon"); - std::string text = llformat(mOverflowFormatString.c_str(),mHiddenToastsNum); - if(mHiddenToastsNum == 1) - { - text += "."; - } - else - { - text += "s."; - } - - toast_rect = mOverflowToastPanel->getRect(); - mOverflowToastPanel->reshape(getRect().getWidth(), toast_rect.getHeight(), true); - toast_rect.setLeftTopAndSize(getRect().mLeft, bottom + toast_rect.getHeight()+gSavedSettings.getS32("ToastGap"), getRect().getWidth(), toast_rect.getHeight()); - mOverflowToastPanel->setRect(toast_rect); - - text_box->setValue(text); - text_box->setVisible(TRUE); - icon->setVisible(TRUE); - - mOverflowToastPanel->setVisible(TRUE); -} - -//-------------------------------------------------------------------------- -void LLScreenChannel::onOverflowToastHide() -{ - mOverflowToastHidden = true; - - // remove all hidden toasts from channel and save interactive notifications - for(std::vector<ToastElem>::iterator it = mToastList.begin(); it != mToastList.end();) - { - if(!(*it).toast->getVisible()) - { - if((*it).toast->getCanBeStored()) - { - storeToast((*it)); - } - else - { - deleteToast((*it).toast); - } - - it = mToastList.erase(it); - } - else - { - ++it; - } - } -} - -//-------------------------------------------------------------------------- -void LLScreenChannel::closeOverflowToastPanel() -{ - if(mOverflowToastPanel != NULL) - { - mOverflowToastPanel->closeFloater(); - mOverflowToastPanel = NULL; - } -} - -//-------------------------------------------------------------------------- void LLScreenChannel::createStartUpToast(S32 notif_num, F32 timer) { LLRect toast_rect; + LLRect tbox_rect; LLToast::Params p; p.lifetime_secs = timer; + p.enable_hide_btn = false; mStartUpToastPanel = new LLToast(p); if(!mStartUpToastPanel) @@ -527,36 +592,53 @@ void LLScreenChannel::createStartUpToast(S32 notif_num, F32 timer) mStartUpToastPanel->setOnFadeCallback(boost::bind(&LLScreenChannel::onStartUpToastHide, this)); LLTextBox* text_box = mStartUpToastPanel->getChild<LLTextBox>("toast_text"); - LLIconCtrl* icon = mStartUpToastPanel->getChild<LLIconCtrl>("icon"); - std::string mStartUpFormatString; + std::string text = LLTrans::getString("StartUpNotifications"); - if(notif_num == 1) - { - mStartUpFormatString = LLTrans::getString("StartUpNotification"); - } - else - { - mStartUpFormatString = LLTrans::getString("StartUpNotifications"); - } - + tbox_rect = text_box->getRect(); + S32 tbox_width = tbox_rect.getWidth(); + S32 tbox_vpad = text_box->getVPad(); + S32 text_width = text_box->getDefaultFont()->getWidth(text); + S32 text_height = text_box->getTextPixelHeight(); + + // EXT - 3703 (Startup toast message doesn't fit toast width) + // Calculating TextBox HEIGHT needed to include the whole string according to the given WIDTH of the TextBox. + S32 new_tbox_height = (text_width/tbox_width + 1) * text_height; + // Calculating TOP position of TextBox + S32 new_tbox_top = new_tbox_height + tbox_vpad + gSavedSettings.getS32("ToastGap"); + // Calculating toast HEIGHT according to the new TextBox size + S32 toast_height = new_tbox_height + tbox_vpad * 2; - std::string text = llformat(mStartUpFormatString.c_str(), notif_num); + tbox_rect.setLeftTopAndSize(tbox_rect.mLeft, new_tbox_top, tbox_rect.getWidth(), new_tbox_height); + text_box->setRect(tbox_rect); toast_rect = mStartUpToastPanel->getRect(); mStartUpToastPanel->reshape(getRect().getWidth(), toast_rect.getHeight(), true); - toast_rect.setLeftTopAndSize(0, toast_rect.getHeight()+gSavedSettings.getS32("ToastGap"), getRect().getWidth(), toast_rect.getHeight()); + toast_rect.setLeftTopAndSize(0, toast_height + gSavedSettings.getS32("ToastGap"), getRect().getWidth(), toast_height); mStartUpToastPanel->setRect(toast_rect); text_box->setValue(text); text_box->setVisible(TRUE); - icon->setVisible(TRUE); - addChild(mStartUpToastPanel); mStartUpToastPanel->setVisible(TRUE); } +// static -------------------------------------------------------------------------- +F32 LLScreenChannel::getHeightRatio() +{ + F32 ratio = gSavedSettings.getF32("NotificationChannelHeightRatio"); + if(0.0f > ratio) + { + ratio = 0.0f; + } + else if(1.0f < ratio) + { + ratio = 1.0f; + } + return ratio; +} + //-------------------------------------------------------------------------- void LLScreenChannel::updateStartUpString(S32 num) { @@ -579,6 +661,40 @@ void LLScreenChannel::closeStartUpToast() } } +void LLNotificationsUI::LLScreenChannel::stopFadingToasts() +{ + if (!mToastList.size()) return; + + if (!mHoveredToast) return; + + std::vector<ToastElem>::iterator it = mToastList.begin(); + while (it != mToastList.end()) + { + ToastElem& elem = *it; + elem.toast->stopFading(); + ++it; + } +} + +void LLNotificationsUI::LLScreenChannel::startFadingToasts() +{ + if (!mToastList.size()) return; + + //because onMouseLeave is processed after onMouseEnter + if (isHovering()) return; + + std::vector<ToastElem>::iterator it = mToastList.begin(); + while (it != mToastList.end()) + { + ToastElem& elem = *it; + if (elem.toast->getVisible()) + { + elem.toast->startFading(); + } + ++it; + } +} + //-------------------------------------------------------------------------- void LLScreenChannel::hideToastsFromScreen() { @@ -588,6 +704,17 @@ void LLScreenChannel::hideToastsFromScreen() } //-------------------------------------------------------------------------- +void LLScreenChannel::hideToast(const LLUUID& notification_id) +{ + std::vector<ToastElem>::iterator it = find(mToastList.begin(), mToastList.end(), notification_id); + if(mToastList.end() != it) + { + ToastElem te = *it; + te.toast->hide(); + } +} + +//-------------------------------------------------------------------------- void LLScreenChannel::removeToastsFromChannel() { hideToastsFromScreen(); @@ -645,42 +772,31 @@ void LLScreenChannel::removeToastsBySessionID(LLUUID id) //-------------------------------------------------------------------------- void LLScreenChannel::onToastHover(LLToast* toast, bool mouse_enter) { - // because of LLViewerWindow::updateUI() that ALWAYS calls onMouseEnter BEFORE onMouseLeave - // we must check this to prevent incorrect setting for hovering in a channel - std::map<LLToast*, bool>::iterator it_first, it_second; - S32 stack_size = mToastEventStack.size(); - mIsHovering = mouse_enter; - - switch(stack_size) + // because of LLViewerWindow::updateUI() that NOT ALWAYS calls onMouseEnter BEFORE onMouseLeave + // we must check hovering directly to prevent incorrect setting for hovering in a channel + if (mouse_enter) { - case 0: - mToastEventStack.insert(std::pair<LLToast*, bool>(toast, mouse_enter)); - break; - case 1: - it_first = mToastEventStack.begin(); - if((*it_first).second && !mouse_enter && ((*it_first).first != toast) ) + if (toast->isHovered()) { - mToastEventStack.clear(); - mIsHovering = true; + mHoveredToast = toast; } - else + } + else if (mHoveredToast != NULL) + { + if (!mHoveredToast->isHovered()) { - mToastEventStack.clear(); - mToastEventStack.insert(std::pair<LLToast*, bool>(toast, mouse_enter)); + mHoveredToast = NULL; } - break; - default: - LL_ERRS ("LLScreenChannel::onToastHover: stack size error " ) << stack_size << llendl; } - if(!mIsHovering) + if(!isHovering()) redrawToasts(); } //-------------------------------------------------------------------------- void LLScreenChannel::updateShowToastsState() { - LLFloater* floater = LLDockableFloater::getInstanceHandle().get(); + LLDockableFloater* floater = dynamic_cast<LLDockableFloater*>(LLDockableFloater::getInstanceHandle().get()); if(!floater) { @@ -688,32 +804,24 @@ void LLScreenChannel::updateShowToastsState() return; } - // for IM floaters showed in a docked state - prohibit showing of ani toast - if(dynamic_cast<LLIMFloater*>(floater)) - { - setShowToasts(!(floater->getVisible() && floater->isDocked())); - if (!getShowToasts()) - { - removeAndStoreAllStorableToasts(); - } - } + S32 channel_bottom = gViewerWindow->getWorldViewRectScaled().mBottom + gSavedSettings.getS32("ChannelBottomPanelMargin");; + LLRect this_rect = getRect(); - // for Message Well floater showed in a docked state - adjust channel's height - if(dynamic_cast<LLSysWellWindow*>(floater)) + if(channel_bottom != this_rect.mBottom) { - S32 channel_bottom = gViewerWindow->getWorldViewRect().mBottom + gSavedSettings.getS32("ChannelBottomPanelMargin");; - LLRect this_rect = getRect(); - if(floater->getVisible() && floater->isDocked()) - { - channel_bottom += (floater->getRect().getHeight() + gSavedSettings.getS32("ToastGap")); - } - - if(channel_bottom != this_rect.mBottom) - { - setRect(LLRect(this_rect.mLeft, this_rect.mTop, this_rect.mRight, channel_bottom)); - } + setRect(LLRect(this_rect.mLeft, this_rect.mTop, this_rect.mRight, channel_bottom)); } } //-------------------------------------------------------------------------- +LLToast* LLScreenChannel::getToastByNotificationID(LLUUID id) +{ + std::vector<ToastElem>::iterator it = find(mStoredToastList.begin(), + mStoredToastList.end(), id); + + if (it == mStoredToastList.end()) + return NULL; + + return it->toast; +} |