diff options
author | Ansariel <ansariel.hiller@phoenixviewer.com> | 2024-05-22 19:04:52 +0200 |
---|---|---|
committer | Ansariel <ansariel.hiller@phoenixviewer.com> | 2024-05-22 19:04:52 +0200 |
commit | 1b67dd855c41f5a0cda7ec2a68d98071986ca703 (patch) | |
tree | ab243607f74f78200787bba5b9b88f07ef1b966f /indra/newview/lltoastpanel.cpp | |
parent | 6d6eabca44d08d5b97bfe3e941d2b9687c2246ea (diff) | |
parent | e1623bb276f83a43ce7a197e388720c05bdefe61 (diff) |
Merge remote-tracking branch 'origin/main' into DRTVWR-600-maint-A
# Conflicts:
# autobuild.xml
# indra/cmake/CMakeLists.txt
# indra/cmake/GoogleMock.cmake
# indra/llaudio/llaudioengine_fmodstudio.cpp
# indra/llaudio/llaudioengine_fmodstudio.h
# indra/llaudio/lllistener_fmodstudio.cpp
# indra/llaudio/lllistener_fmodstudio.h
# indra/llaudio/llstreamingaudio_fmodstudio.cpp
# indra/llaudio/llstreamingaudio_fmodstudio.h
# indra/llcharacter/llmultigesture.cpp
# indra/llcharacter/llmultigesture.h
# indra/llimage/llimage.cpp
# indra/llimage/llimagepng.cpp
# indra/llimage/llimageworker.cpp
# indra/llimage/tests/llimageworker_test.cpp
# indra/llmessage/tests/llmockhttpclient.h
# indra/llprimitive/llgltfmaterial.h
# indra/llrender/llfontfreetype.cpp
# indra/llui/llcombobox.cpp
# indra/llui/llfolderview.cpp
# indra/llui/llfolderviewmodel.h
# indra/llui/lllineeditor.cpp
# indra/llui/lllineeditor.h
# indra/llui/lltextbase.cpp
# indra/llui/lltextbase.h
# indra/llui/lltexteditor.cpp
# indra/llui/lltextvalidate.cpp
# indra/llui/lltextvalidate.h
# indra/llui/lluictrl.h
# indra/llui/llview.cpp
# indra/llwindow/llwindowmacosx.cpp
# indra/newview/app_settings/settings.xml
# indra/newview/llappearancemgr.cpp
# indra/newview/llappearancemgr.h
# indra/newview/llavatarpropertiesprocessor.cpp
# indra/newview/llavatarpropertiesprocessor.h
# indra/newview/llbreadcrumbview.cpp
# indra/newview/llbreadcrumbview.h
# indra/newview/llbreastmotion.cpp
# indra/newview/llbreastmotion.h
# indra/newview/llconversationmodel.h
# indra/newview/lldensityctrl.cpp
# indra/newview/lldensityctrl.h
# indra/newview/llface.inl
# indra/newview/llfloatereditsky.cpp
# indra/newview/llfloatereditwater.cpp
# indra/newview/llfloateremojipicker.h
# indra/newview/llfloaterimsessiontab.cpp
# indra/newview/llfloaterprofiletexture.cpp
# indra/newview/llfloaterprofiletexture.h
# indra/newview/llgesturemgr.cpp
# indra/newview/llgesturemgr.h
# indra/newview/llimpanel.cpp
# indra/newview/llimpanel.h
# indra/newview/llinventorybridge.cpp
# indra/newview/llinventorybridge.h
# indra/newview/llinventoryclipboard.cpp
# indra/newview/llinventoryclipboard.h
# indra/newview/llinventoryfunctions.cpp
# indra/newview/llinventoryfunctions.h
# indra/newview/llinventorygallery.cpp
# indra/newview/lllistbrowser.cpp
# indra/newview/lllistbrowser.h
# indra/newview/llpanelobjectinventory.cpp
# indra/newview/llpanelprofile.cpp
# indra/newview/llpanelprofile.h
# indra/newview/llpreviewgesture.cpp
# indra/newview/llsavedsettingsglue.cpp
# indra/newview/llsavedsettingsglue.h
# indra/newview/lltooldraganddrop.cpp
# indra/newview/llurllineeditorctrl.cpp
# indra/newview/llvectorperfoptions.cpp
# indra/newview/llvectorperfoptions.h
# indra/newview/llviewerparceloverlay.cpp
# indra/newview/llviewertexlayer.cpp
# indra/newview/llviewertexturelist.cpp
# indra/newview/macmain.h
# indra/test/test.cpp
Diffstat (limited to 'indra/newview/lltoastpanel.cpp')
-rw-r--r-- | indra/newview/lltoastpanel.cpp | 512 |
1 files changed, 256 insertions, 256 deletions
diff --git a/indra/newview/lltoastpanel.cpp b/indra/newview/lltoastpanel.cpp index 28e7ce43d8..a0d0d6590a 100644 --- a/indra/newview/lltoastpanel.cpp +++ b/indra/newview/lltoastpanel.cpp @@ -1,256 +1,256 @@ -/** - * @file lltoastpanel.cpp - * @brief Creates a panel of a specific kind for a toast - * - * $LicenseInfo:firstyear=2000&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * 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. - * - * 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. - * - * 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$ - */ - -#include "llviewerprecompiledheaders.h" - -#include "lldbstrings.h" -#include "llcheckboxctrl.h" -#include "llpanelgenerictip.h" -#include "llpanelonlinestatus.h" -#include "llnotifications.h" -#include "lltoastnotifypanel.h" -#include "lltoastpanel.h" -#include "lltoastscriptquestion.h" - -#include <boost/algorithm/string.hpp> - -//static -const S32 LLToastPanel::MIN_PANEL_HEIGHT = 40; // VPAD(4)*2 + ICON_HEIGHT(32) -// 'magic numbers', consider initializing (512+20) part from xml/notifications -const S32 LLToastPanel::MAX_TEXT_LENGTH = 512 + 20 + DB_FIRST_NAME_BUF_SIZE + DB_LAST_NAME_BUF_SIZE + DB_INV_ITEM_NAME_BUF_SIZE; - -LLToastPanel::LLToastPanel(const LLNotificationPtr& notification) -{ - mNotification = notification; -} - -LLToastPanel::~LLToastPanel() -{ -} - -//virtual -std::string LLToastPanel::getTitle() -{ - // *TODO: create Title and localize it. If it will be required. - return mNotification->getMessage(); -} - -//virtual -const std::string& LLToastPanel::getNotificationName() -{ - return mNotification->getName(); -} - -//virtual -const LLUUID& LLToastPanel::getID() -{ - return mNotification->id(); -} - -S32 LLToastPanel::computeSnappedToMessageHeight(LLTextBase* message, S32 maxLineCount) -{ - S32 heightDelta = 0; - S32 maxTextHeight = message->getFont()->getLineHeight() * maxLineCount; - - LLRect messageRect = message->getRect(); - S32 oldTextHeight = messageRect.getHeight(); - - //Knowing the height is set to max allowed, getTextPixelHeight returns needed text height - //Perhaps we need to pass maxLineCount as parameter to getTextPixelHeight to avoid previous reshape. - S32 requiredTextHeight = message->getTextBoundingRect().getHeight(); - S32 newTextHeight = llmin(requiredTextHeight, maxTextHeight); - - heightDelta = newTextHeight - oldTextHeight; - S32 new_panel_height = llmax(getRect().getHeight() + heightDelta, MIN_PANEL_HEIGHT); - - return new_panel_height; -} - -//snap to the message height if it is visible -void LLToastPanel::snapToMessageHeight(LLTextBase* message, S32 maxLineCount) -{ - if(!message) - { - return; - } - - //Add message height if it is visible - if (message->getVisible()) - { - S32 new_panel_height = computeSnappedToMessageHeight(message, maxLineCount); - - //reshape the panel with new height - if (new_panel_height != getRect().getHeight()) - { - reshape( getRect().getWidth(), new_panel_height); - } - } -} - -// static -LLToastPanel* LLToastPanel::buidPanelFromNotification( - const LLNotificationPtr& notification) -{ - LL_PROFILE_ZONE_SCOPED - LLToastPanel* res = NULL; - - //process tip toast panels - if ("notifytip" == notification->getType()) - { - // if it is online/offline notification - if ("FriendOnlineOffline" == notification->getName()) - { - res = new LLPanelOnlineStatus(notification); - } - // in all other case we use generic tip panel - else - { - res = new LLPanelGenericTip(notification); - } - } - else if("notify" == notification->getType()) - { - if (notification->getPriority() == NOTIFICATION_PRIORITY_CRITICAL) - { - res = new LLToastScriptQuestion(notification); - } - else - { - res = new LLToastNotifyPanel(notification); - } - } - /* - else if(...) - create all other specific non-public toast panel - */ - - return res; -} - -LLCheckBoxToastPanel::LLCheckBoxToastPanel(const LLNotificationPtr& p_ntf) -: LLToastPanel(p_ntf), -mCheck(NULL) -{ - -} - -void LLCheckBoxToastPanel::setCheckBoxes(const S32 &h_pad, const S32 &v_pad, LLView *parent_view) -{ - std::string ignore_label; - LLNotificationFormPtr form = mNotification->getForm(); - - if (form->getIgnoreType() == LLNotificationForm::IGNORE_CHECKBOX_ONLY) - { - // Normally text is only used to describe notification in preferences, - // but this one is not displayed in preferences and works on case by case - // basis. - // Display text if present, display 'always chose' if not. - std::string ignore_message = form->getIgnoreMessage(); - if (ignore_message.empty()) - { - ignore_message = LLNotifications::instance().getGlobalString("alwayschoose"); - } - setCheckBox(ignore_message, ignore_label, boost::bind(&LLCheckBoxToastPanel::onCommitCheckbox, this, _1), h_pad, v_pad, parent_view); - } - else if (form->getIgnoreType() == LLNotificationForm::IGNORE_WITH_DEFAULT_RESPONSE) - { - setCheckBox(LLNotifications::instance().getGlobalString("skipnexttime"), ignore_label, boost::bind(&LLCheckBoxToastPanel::onCommitCheckbox, this, _1), h_pad, v_pad, parent_view); - } - if (form->getIgnoreType() == LLNotificationForm::IGNORE_WITH_DEFAULT_RESPONSE_SESSION_ONLY) - { - setCheckBox(LLNotifications::instance().getGlobalString("skipnexttimesessiononly"), ignore_label, boost::bind(&LLCheckBoxToastPanel::onCommitCheckbox, this, _1), h_pad, v_pad, parent_view); - } - else if (form->getIgnoreType() == LLNotificationForm::IGNORE_WITH_LAST_RESPONSE) - { - setCheckBox(LLNotifications::instance().getGlobalString("alwayschoose"), ignore_label, boost::bind(&LLCheckBoxToastPanel::onCommitCheckbox, this, _1), h_pad, v_pad, parent_view); - } -} - -bool LLCheckBoxToastPanel::setCheckBox(const std::string& check_title, - const std::string& check_control, - const commit_signal_t::slot_type& cb, - const S32 &h_pad, - const S32 &v_pad, - LLView *parent_view) -{ - mCheck = LLUICtrlFactory::getInstance()->createFromFile<LLCheckBoxCtrl>("alert_check_box.xml", this, LLPanel::child_registry_t::instance()); - - if (!mCheck) - { - return false; - } - - const LLFontGL* font = mCheck->getFont(); - const S32 LINE_HEIGHT = font->getLineHeight(); - - std::vector<std::string> lines; - boost::split(lines, check_title, boost::is_any_of("\n")); - - // Extend dialog for "check next time" - S32 max_msg_width = LLToastPanel::getRect().getWidth() - 2 * h_pad; - S32 check_width = S32(font->getWidth(lines[0]) + 0.99f) + 16; // use width of the first line - max_msg_width = llmax(max_msg_width, check_width); - S32 dialog_width = max_msg_width + 2 * h_pad; - - S32 dialog_height = LLToastPanel::getRect().getHeight(); - dialog_height += LINE_HEIGHT * lines.size(); - dialog_height += LINE_HEIGHT / 2; - - LLToastPanel::reshape(dialog_width, dialog_height, false); - - S32 msg_x = (LLToastPanel::getRect().getWidth() - max_msg_width) / 2; - - // set check_box's attributes - LLRect check_rect; - // if we are part of the toast, we need to leave space for buttons - S32 msg_y = v_pad + (parent_view ? 0 : (BTN_HEIGHT + LINE_HEIGHT / 2)); - mCheck->setRect(check_rect.setOriginAndSize(msg_x, msg_y, max_msg_width, LINE_HEIGHT*lines.size())); - mCheck->setLabel(check_title); - mCheck->setCommitCallback(cb); - - if (parent_view) - { - // assume that width and height autoadjusts to toast - parent_view->addChild(mCheck); - } - else - { - LLToastPanel::addChild(mCheck); - } - - return true; -} - -void LLCheckBoxToastPanel::onCommitCheckbox(LLUICtrl* ctrl) -{ - bool check = ctrl->getValue().asBoolean(); - if (mNotification->getForm()->getIgnoreType() == LLNotificationForm::IGNORE_SHOW_AGAIN) - { - // question was "show again" so invert value to get "ignore" - check = !check; - } - mNotification->setIgnored(check); -} +/**
+ * @file lltoastpanel.cpp
+ * @brief Creates a panel of a specific kind for a toast
+ *
+ * $LicenseInfo:firstyear=2000&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "lldbstrings.h"
+#include "llcheckboxctrl.h"
+#include "llpanelgenerictip.h"
+#include "llpanelonlinestatus.h"
+#include "llnotifications.h"
+#include "lltoastnotifypanel.h"
+#include "lltoastpanel.h"
+#include "lltoastscriptquestion.h"
+
+#include <boost/algorithm/string.hpp>
+
+//static
+const S32 LLToastPanel::MIN_PANEL_HEIGHT = 40; // VPAD(4)*2 + ICON_HEIGHT(32)
+// 'magic numbers', consider initializing (512+20) part from xml/notifications
+const S32 LLToastPanel::MAX_TEXT_LENGTH = 512 + 20 + DB_FIRST_NAME_BUF_SIZE + DB_LAST_NAME_BUF_SIZE + DB_INV_ITEM_NAME_BUF_SIZE;
+
+LLToastPanel::LLToastPanel(const LLNotificationPtr& notification)
+{
+ mNotification = notification;
+}
+
+LLToastPanel::~LLToastPanel()
+{
+}
+
+//virtual
+std::string LLToastPanel::getTitle()
+{
+ // *TODO: create Title and localize it. If it will be required.
+ return mNotification->getMessage();
+}
+
+//virtual
+const std::string& LLToastPanel::getNotificationName()
+{
+ return mNotification->getName();
+}
+
+//virtual
+const LLUUID& LLToastPanel::getID()
+{
+ return mNotification->id();
+}
+
+S32 LLToastPanel::computeSnappedToMessageHeight(LLTextBase* message, S32 maxLineCount)
+{
+ S32 heightDelta = 0;
+ S32 maxTextHeight = message->getFont()->getLineHeight() * maxLineCount;
+
+ LLRect messageRect = message->getRect();
+ S32 oldTextHeight = messageRect.getHeight();
+
+ //Knowing the height is set to max allowed, getTextPixelHeight returns needed text height
+ //Perhaps we need to pass maxLineCount as parameter to getTextPixelHeight to avoid previous reshape.
+ S32 requiredTextHeight = message->getTextBoundingRect().getHeight();
+ S32 newTextHeight = llmin(requiredTextHeight, maxTextHeight);
+
+ heightDelta = newTextHeight - oldTextHeight;
+ S32 new_panel_height = llmax(getRect().getHeight() + heightDelta, MIN_PANEL_HEIGHT);
+
+ return new_panel_height;
+}
+
+//snap to the message height if it is visible
+void LLToastPanel::snapToMessageHeight(LLTextBase* message, S32 maxLineCount)
+{
+ if(!message)
+ {
+ return;
+ }
+
+ //Add message height if it is visible
+ if (message->getVisible())
+ {
+ S32 new_panel_height = computeSnappedToMessageHeight(message, maxLineCount);
+
+ //reshape the panel with new height
+ if (new_panel_height != getRect().getHeight())
+ {
+ reshape( getRect().getWidth(), new_panel_height);
+ }
+ }
+}
+
+// static
+LLToastPanel* LLToastPanel::buidPanelFromNotification(
+ const LLNotificationPtr& notification)
+{
+ LL_PROFILE_ZONE_SCOPED
+ LLToastPanel* res = NULL;
+
+ //process tip toast panels
+ if ("notifytip" == notification->getType())
+ {
+ // if it is online/offline notification
+ if ("FriendOnlineOffline" == notification->getName())
+ {
+ res = new LLPanelOnlineStatus(notification);
+ }
+ // in all other case we use generic tip panel
+ else
+ {
+ res = new LLPanelGenericTip(notification);
+ }
+ }
+ else if("notify" == notification->getType())
+ {
+ if (notification->getPriority() == NOTIFICATION_PRIORITY_CRITICAL)
+ {
+ res = new LLToastScriptQuestion(notification);
+ }
+ else
+ {
+ res = new LLToastNotifyPanel(notification);
+ }
+ }
+ /*
+ else if(...)
+ create all other specific non-public toast panel
+ */
+
+ return res;
+}
+
+LLCheckBoxToastPanel::LLCheckBoxToastPanel(const LLNotificationPtr& p_ntf)
+: LLToastPanel(p_ntf),
+mCheck(NULL)
+{
+
+}
+
+void LLCheckBoxToastPanel::setCheckBoxes(const S32 &h_pad, const S32 &v_pad, LLView *parent_view)
+{
+ std::string ignore_label;
+ LLNotificationFormPtr form = mNotification->getForm();
+
+ if (form->getIgnoreType() == LLNotificationForm::IGNORE_CHECKBOX_ONLY)
+ {
+ // Normally text is only used to describe notification in preferences,
+ // but this one is not displayed in preferences and works on case by case
+ // basis.
+ // Display text if present, display 'always chose' if not.
+ std::string ignore_message = form->getIgnoreMessage();
+ if (ignore_message.empty())
+ {
+ ignore_message = LLNotifications::instance().getGlobalString("alwayschoose");
+ }
+ setCheckBox(ignore_message, ignore_label, boost::bind(&LLCheckBoxToastPanel::onCommitCheckbox, this, _1), h_pad, v_pad, parent_view);
+ }
+ else if (form->getIgnoreType() == LLNotificationForm::IGNORE_WITH_DEFAULT_RESPONSE)
+ {
+ setCheckBox(LLNotifications::instance().getGlobalString("skipnexttime"), ignore_label, boost::bind(&LLCheckBoxToastPanel::onCommitCheckbox, this, _1), h_pad, v_pad, parent_view);
+ }
+ if (form->getIgnoreType() == LLNotificationForm::IGNORE_WITH_DEFAULT_RESPONSE_SESSION_ONLY)
+ {
+ setCheckBox(LLNotifications::instance().getGlobalString("skipnexttimesessiononly"), ignore_label, boost::bind(&LLCheckBoxToastPanel::onCommitCheckbox, this, _1), h_pad, v_pad, parent_view);
+ }
+ else if (form->getIgnoreType() == LLNotificationForm::IGNORE_WITH_LAST_RESPONSE)
+ {
+ setCheckBox(LLNotifications::instance().getGlobalString("alwayschoose"), ignore_label, boost::bind(&LLCheckBoxToastPanel::onCommitCheckbox, this, _1), h_pad, v_pad, parent_view);
+ }
+}
+
+bool LLCheckBoxToastPanel::setCheckBox(const std::string& check_title,
+ const std::string& check_control,
+ const commit_signal_t::slot_type& cb,
+ const S32 &h_pad,
+ const S32 &v_pad,
+ LLView *parent_view)
+{
+ mCheck = LLUICtrlFactory::getInstance()->createFromFile<LLCheckBoxCtrl>("alert_check_box.xml", this, LLPanel::child_registry_t::instance());
+
+ if (!mCheck)
+ {
+ return false;
+ }
+
+ const LLFontGL* font = mCheck->getFont();
+ const S32 LINE_HEIGHT = font->getLineHeight();
+
+ std::vector<std::string> lines;
+ boost::split(lines, check_title, boost::is_any_of("\n"));
+
+ // Extend dialog for "check next time"
+ S32 max_msg_width = LLToastPanel::getRect().getWidth() - 2 * h_pad;
+ S32 check_width = S32(font->getWidth(lines[0]) + 0.99f) + 16; // use width of the first line
+ max_msg_width = llmax(max_msg_width, check_width);
+ S32 dialog_width = max_msg_width + 2 * h_pad;
+
+ S32 dialog_height = LLToastPanel::getRect().getHeight();
+ dialog_height += LINE_HEIGHT * lines.size();
+ dialog_height += LINE_HEIGHT / 2;
+
+ LLToastPanel::reshape(dialog_width, dialog_height, false);
+
+ S32 msg_x = (LLToastPanel::getRect().getWidth() - max_msg_width) / 2;
+
+ // set check_box's attributes
+ LLRect check_rect;
+ // if we are part of the toast, we need to leave space for buttons
+ S32 msg_y = v_pad + (parent_view ? 0 : (BTN_HEIGHT + LINE_HEIGHT / 2));
+ mCheck->setRect(check_rect.setOriginAndSize(msg_x, msg_y, max_msg_width, LINE_HEIGHT*lines.size()));
+ mCheck->setLabel(check_title);
+ mCheck->setCommitCallback(cb);
+
+ if (parent_view)
+ {
+ // assume that width and height autoadjusts to toast
+ parent_view->addChild(mCheck);
+ }
+ else
+ {
+ LLToastPanel::addChild(mCheck);
+ }
+
+ return true;
+}
+
+void LLCheckBoxToastPanel::onCommitCheckbox(LLUICtrl* ctrl)
+{
+ bool check = ctrl->getValue().asBoolean();
+ if (mNotification->getForm()->getIgnoreType() == LLNotificationForm::IGNORE_SHOW_AGAIN)
+ {
+ // question was "show again" so invert value to get "ignore"
+ check = !check;
+ }
+ mNotification->setIgnored(check);
+}
|