diff options
author | andreykproductengine <andreykproductengine@lindenlab.com> | 2019-09-05 17:15:23 +0300 |
---|---|---|
committer | andreykproductengine <andreykproductengine@lindenlab.com> | 2019-09-05 17:15:23 +0300 |
commit | 894725f3314d24c20414a9a2491cf0cd59882788 (patch) | |
tree | 595bb53dc9bf5ee63afba6813de36bb7ae7d1c83 | |
parent | c54c9dd75d4405f89b1f1be16bdb4430a98c36f2 (diff) |
SL-11315 Checkbox support for notifications
-rw-r--r-- | indra/newview/lltoastalertpanel.cpp | 71 | ||||
-rw-r--r-- | indra/newview/lltoastalertpanel.h | 5 | ||||
-rw-r--r-- | indra/newview/lltoastnotifypanel.cpp | 15 | ||||
-rw-r--r-- | indra/newview/lltoastnotifypanel.h | 2 | ||||
-rw-r--r-- | indra/newview/lltoastpanel.cpp | 97 | ||||
-rw-r--r-- | indra/newview/lltoastpanel.h | 19 |
6 files changed, 133 insertions, 76 deletions
diff --git a/indra/newview/lltoastalertpanel.cpp b/indra/newview/lltoastalertpanel.cpp index 495c9c1f44..023d1a685c 100644 --- a/indra/newview/lltoastalertpanel.cpp +++ b/indra/newview/lltoastalertpanel.cpp @@ -62,9 +62,8 @@ static const S32 HPAD = 25; static const S32 BTN_HPAD = 8; LLToastAlertPanel::LLToastAlertPanel( LLNotificationPtr notification, bool modal) - : LLToastPanel(notification), + : LLCheckBoxToastPanel(notification), mDefaultOption( 0 ), - mCheck(NULL), mCaution(notification->getPriority() >= NOTIFICATION_PRIORITY_HIGH), mLabel(notification->getName()), mLineEditor(NULL) @@ -347,20 +346,7 @@ LLToastAlertPanel::LLToastAlertPanel( LLNotificationPtr notification, bool modal button_left += button_width + BTN_HPAD; } - std::string ignore_label; - - if (form->getIgnoreType() == LLNotificationForm::IGNORE_WITH_DEFAULT_RESPONSE) - { - setCheckBox(LLNotifications::instance().getGlobalString("skipnexttime"), ignore_label); - } - if (form->getIgnoreType() == LLNotificationForm::IGNORE_WITH_DEFAULT_RESPONSE_SESSION_ONLY) - { - setCheckBox(LLNotifications::instance().getGlobalString("skipnexttimesessiononly"), ignore_label); - } - else if (form->getIgnoreType() == LLNotificationForm::IGNORE_WITH_LAST_RESPONSE) - { - setCheckBox(LLNotifications::instance().getGlobalString("alwayschoose"), ignore_label); - } + setCheckBoxes(HPAD, VPAD); // *TODO: check necessity of this code //gFloaterView->adjustToFitScreen(this, FALSE); @@ -380,46 +366,6 @@ LLToastAlertPanel::LLToastAlertPanel( LLNotificationPtr notification, bool modal LLTransientFloaterMgr::GLOBAL, this); } -bool LLToastAlertPanel::setCheckBox( const std::string& check_title, const std::string& check_control ) -{ - 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 * HPAD; - 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 * HPAD; - - 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; - mCheck->setRect(check_rect.setOriginAndSize(msg_x, VPAD+BTN_HEIGHT+LINE_HEIGHT/2, max_msg_width, LINE_HEIGHT*lines.size())); - mCheck->setLabel(check_title); - mCheck->setCommitCallback(boost::bind(&LLToastAlertPanel::onClickIgnore, this, _1)); - - LLToastPanel::addChild(mCheck); - - return true; -} - void LLToastAlertPanel::setVisible( BOOL visible ) { // only make the "ding" sound if it's newly visible @@ -562,16 +508,3 @@ void LLToastAlertPanel::onButtonPressed( const LLSD& data, S32 button ) mNotification->respond(response); // new notification reponse } - -void LLToastAlertPanel::onClickIgnore(LLUICtrl* ctrl) -{ - // checkbox sometimes means "hide and do the default" and - // other times means "warn me again". Yuck. JC - 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); -} diff --git a/indra/newview/lltoastalertpanel.h b/indra/newview/lltoastalertpanel.h index d1be5e018e..21310822c4 100644 --- a/indra/newview/lltoastalertpanel.h +++ b/indra/newview/lltoastalertpanel.h @@ -46,7 +46,7 @@ class LLLineEditor; */ class LLToastAlertPanel - : public LLToastPanel + : public LLCheckBoxToastPanel { LOG_CLASS(LLToastAlertPanel); public: @@ -75,13 +75,11 @@ public: virtual void draw(); virtual void setVisible( BOOL visible ); - bool setCheckBox( const std::string&, const std::string& ); void setCaution(BOOL val = TRUE) { mCaution = val; } // If mUnique==TRUE only one copy of this message should exist void setUnique(BOOL val = TRUE) { mUnique = val; } void setEditTextArgs(const LLSD& edit_args); - void onClickIgnore(LLUICtrl* ctrl); void onButtonPressed(const LLSD& data, S32 button); private: @@ -106,7 +104,6 @@ private: std::vector<ButtonData> mButtonData; S32 mDefaultOption; - LLCheckBoxCtrl* mCheck; BOOL mCaution; BOOL mUnique; LLUIString mLabel; diff --git a/indra/newview/lltoastnotifypanel.cpp b/indra/newview/lltoastnotifypanel.cpp index a2116817a2..65684dc2fd 100644 --- a/indra/newview/lltoastnotifypanel.cpp +++ b/indra/newview/lltoastnotifypanel.cpp @@ -33,6 +33,7 @@ // library includes #include "lldbstrings.h" +#include "llcheckboxctrl.h" #include "lllslconstants.h" #include "llnotifications.h" #include "lluiconstants.h" @@ -55,7 +56,7 @@ const LLFontGL* LLToastNotifyPanel::sFontSmall = NULL; LLToastNotifyPanel::button_click_signal_t LLToastNotifyPanel::sButtonClickSignal; LLToastNotifyPanel::LLToastNotifyPanel(const LLNotificationPtr& notification, const LLRect& rect, bool show_images) -: LLToastPanel(notification), +: LLCheckBoxToastPanel(notification), LLInstanceTracker<LLToastNotifyPanel, LLUUID, LLInstanceTrackerReplaceOnCollision>(notification->getID()) { init(rect, show_images); @@ -409,7 +410,17 @@ void LLToastNotifyPanel::init( LLRect rect, bool show_images ) //.xml file intially makes info panel only follow left/right/top. This is so that when control buttons are added the info panel //can shift upward making room for the buttons inside mControlPanel. After the buttons are added, the info panel can then be set to follow 'all'. mInfoPanel->setFollowsAll(); - snapToMessageHeight(mTextBox, LLToastPanel::MAX_TEXT_LENGTH); + + // Add checkboxes if nessesary. + setCheckBoxes(HPAD * 3, VPAD * 4, mInfoPanel); + + // Snap to message, then to checkbox if present + snapToMessageHeight(mTextBox, LLToastPanel::MAX_TEXT_LENGTH); + if (mCheck) + { + S32 new_panel_height = mCheck->getRect().getHeight() + getRect().getHeight(); + reshape(getRect().getWidth(), new_panel_height); + } // reshape the panel to its previous size if (current_rect.notEmpty()) diff --git a/indra/newview/lltoastnotifypanel.h b/indra/newview/lltoastnotifypanel.h index e4a75acfda..a5a637c6fa 100644 --- a/indra/newview/lltoastnotifypanel.h +++ b/indra/newview/lltoastnotifypanel.h @@ -47,7 +47,7 @@ class LLNotificationForm; * @deprecated this class will be removed after all toast panel types are * implemented in separate classes. */ -class LLToastNotifyPanel: public LLToastPanel, public LLInstanceTracker<LLToastNotifyPanel, LLUUID, LLInstanceTrackerReplaceOnCollision> +class LLToastNotifyPanel: public LLCheckBoxToastPanel, public LLInstanceTracker<LLToastNotifyPanel, LLUUID, LLInstanceTrackerReplaceOnCollision> { public: /** diff --git a/indra/newview/lltoastpanel.cpp b/indra/newview/lltoastpanel.cpp index 7c624d5b50..977c6ac802 100644 --- a/indra/newview/lltoastpanel.cpp +++ b/indra/newview/lltoastpanel.cpp @@ -27,6 +27,7 @@ #include "llviewerprecompiledheaders.h" #include "lldbstrings.h" +#include "llcheckboxctrl.h" #include "llpanelgenerictip.h" #include "llpanelonlinestatus.h" #include "llnotifications.h" @@ -34,6 +35,8 @@ #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 @@ -145,3 +148,97 @@ LLToastPanel* LLToastPanel::buidPanelFromNotification( 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_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); + } + else if (form->getIgnoreType() == LLNotificationForm::IGNORE_MEDIA_PLAYMUTE) + { + 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; + mCheck->setRect(check_rect.setOriginAndSize(msg_x, v_pad + BTN_HEIGHT + LINE_HEIGHT / 2, 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); +} diff --git a/indra/newview/lltoastpanel.h b/indra/newview/lltoastpanel.h index 6a9b72a5ae..f4c758ade9 100644 --- a/indra/newview/lltoastpanel.h +++ b/indra/newview/lltoastpanel.h @@ -64,4 +64,23 @@ protected: S32 computeSnappedToMessageHeight(LLTextBase* message, S32 maxLineCount); }; +class LLCheckBoxCtrl; + +// Wrapper with support for 'don't ask again' checkbox +class LLCheckBoxToastPanel : public LLToastPanel +{ +public: + LLCheckBoxToastPanel(const LLNotificationPtr& p_ntf); + virtual ~LLCheckBoxToastPanel() {}; + + // set checkboxes acording to defaults from form + void setCheckBoxes(const S32 &h_pad, const S32 &v_pad, LLView *parent_view = NULL); + // set single checkbox + bool setCheckBox(const std::string&, const std::string&, const commit_signal_t::slot_type& cb, const S32 &h_pad, const S32 &v_pad, LLView *parent_view = NULL); +protected: + void onCommitCheckbox(LLUICtrl* ctrl); + + LLCheckBoxCtrl* mCheck; +}; + #endif /* LL_TOASTPANEL_H */ |