diff options
Diffstat (limited to 'indra/newview/llchiclet.cpp')
-rw-r--r-- | indra/newview/llchiclet.cpp | 1501 |
1 files changed, 989 insertions, 512 deletions
diff --git a/indra/newview/llchiclet.cpp b/indra/newview/llchiclet.cpp index 61a60a24be..e39384b7b2 100644 --- a/indra/newview/llchiclet.cpp +++ b/indra/newview/llchiclet.cpp @@ -1,65 +1,69 @@ /** -* @file llchiclet.cpp -* @brief LLChiclet class implementation -* -* $LicenseInfo:firstyear=2002&license=viewergpl$ -* -* Copyright (c) 2002-2009, 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$ -*/ + * @file llchiclet.cpp + * @brief LLChiclet class implementation + * + * $LicenseInfo:firstyear=2002&license=viewergpl$ + * + * Copyright (c) 2002-2009, 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" // must be first include #include "llchiclet.h" + #include "llagent.h" #include "llavataractions.h" #include "llbottomtray.h" +#include "lleventtimer.h" #include "llgroupactions.h" #include "lliconctrl.h" -#include "llimpanel.h" // LLFloaterIMPanel #include "llimfloater.h" #include "llimview.h" #include "llfloaterreg.h" #include "lllocalcliprect.h" #include "llmenugl.h" +#include "llnotifications.h" +#include "llnotificationsutil.h" #include "lloutputmonitorctrl.h" +#include "llscriptfloater.h" +#include "llspeakers.h" #include "lltextbox.h" #include "llvoiceclient.h" -#include "llvoicecontrolpanel.h" #include "llgroupmgr.h" #include "llnotificationmanager.h" #include "lltransientfloatermgr.h" +#include "llsyswellwindow.h" static LLDefaultChildRegistry::Register<LLChicletPanel> t1("chiclet_panel"); -static LLDefaultChildRegistry::Register<LLTalkButton> t2("chiclet_talk"); -static LLDefaultChildRegistry::Register<LLNotificationChiclet> t3("chiclet_notification"); -static LLDefaultChildRegistry::Register<LLIMP2PChiclet> t4("chiclet_im_p2p"); -static LLDefaultChildRegistry::Register<LLIMGroupChiclet> t5("chiclet_im_group"); - -S32 LLNotificationChiclet::mUreadSystemNotifications = 0; -S32 LLNotificationChiclet::mUreadIMNotifications = 0; - +static LLDefaultChildRegistry::Register<LLIMWellChiclet> t2_0("chiclet_im_well"); +static LLDefaultChildRegistry::Register<LLNotificationChiclet> t2("chiclet_notification"); +static LLDefaultChildRegistry::Register<LLIMP2PChiclet> t3("chiclet_im_p2p"); +static LLDefaultChildRegistry::Register<LLIMGroupChiclet> t4("chiclet_im_group"); +static LLDefaultChildRegistry::Register<LLAdHocChiclet> t5("chiclet_im_adhoc"); +static LLDefaultChildRegistry::Register<LLScriptChiclet> t6("chiclet_script"); +static LLDefaultChildRegistry::Register<LLInvOfferChiclet> t7("chiclet_offer"); boost::signals2::signal<LLChiclet* (const LLUUID&), LLIMChiclet::CollectChicletCombiner<std::list<LLChiclet*> > > @@ -68,100 +72,333 @@ boost::signals2::signal<LLChiclet* (const LLUUID&), ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -LLNotificationChiclet::Params::Params() +/** + * Updates the Well's 'Lit' state to flash it when "new messages" are come. + * + * It gets callback which will be called 2*N times with passed period. See EXT-3147 + */ +class LLSysWellChiclet::FlashToLitTimer : public LLEventTimer +{ +public: + typedef boost::function<void()> callback_t; + + /** + * Constructor. + * + * @param count - how many times callback should be called (twice to not change original state) + * @param period - how frequently callback should be called + * @param cb - callback to be called each tick + */ + FlashToLitTimer(S32 count, F32 period, callback_t cb) + : LLEventTimer(period) + , mCallback(cb) + , mFlashCount(2 * count) + , mCurrentFlashCount(0) + { + mEventTimer.stop(); + } + + BOOL tick() + { + mCallback(); + + if (++mCurrentFlashCount == mFlashCount) mEventTimer.stop(); + return FALSE; + } + + void flash() + { + mCurrentFlashCount = 0; + mEventTimer.start(); + } + + void stopFlashing() + { + mEventTimer.stop(); + } + +private: + callback_t mCallback; + + /** + * How many times Well will blink. + */ + S32 mFlashCount; + S32 mCurrentFlashCount; +}; + +LLSysWellChiclet::Params::Params() : button("button") , unread_notifications("unread_notifications") +, max_displayed_count("max_displayed_count", 99) +, flash_to_lit_count("flash_to_lit_count", 3) +, flash_period("flash_period", 0.5F) { button.name("button"); button.tab_stop(FALSE); button.label(LLStringUtil::null); - - unread_notifications.name("unread"); - unread_notifications.font(LLFontGL::getFontSansSerif()); - unread_notifications.text_color=(LLColor4::white); - unread_notifications.font_halign(LLFontGL::HCENTER); - unread_notifications.mouse_opaque(FALSE); } -LLNotificationChiclet::LLNotificationChiclet(const Params& p) +LLSysWellChiclet::LLSysWellChiclet(const Params& p) : LLChiclet(p) , mButton(NULL) -, mCounterCtrl(NULL) +, mCounter(0) +, mMaxDisplayedCount(p.max_displayed_count) +, mIsNewMessagesState(false) +, mFlashToLitTimer(NULL) +, mContextMenu(NULL) { LLButton::Params button_params = p.button; - button_params.rect(p.rect()); mButton = LLUICtrlFactory::create<LLButton>(button_params); addChild(mButton); - LLChicletNotificationCounterCtrl::Params unread_params = p.unread_notifications; - mCounterCtrl = LLUICtrlFactory::create<LLChicletNotificationCounterCtrl>(unread_params); - addChild(mCounterCtrl); + mFlashToLitTimer = new FlashToLitTimer(p.flash_to_lit_count, p.flash_period, boost::bind(&LLSysWellChiclet::changeLitState, this)); +} - // connect counter handlers to the signals - connectCounterUpdatersToSignal("notify"); - connectCounterUpdatersToSignal("groupnotify"); - connectCounterUpdatersToSignal("notifytoast"); +LLSysWellChiclet::~LLSysWellChiclet() +{ + delete mFlashToLitTimer; +} + +void LLSysWellChiclet::setCounter(S32 counter) +{ + // do nothing if the same counter is coming. EXT-3678. + if (counter == mCounter) return; + + // note same code in LLChicletNotificationCounterCtrl::setCounter(S32 counter) + std::string s_count; + if(counter != 0) + { + static std::string more_messages_exist("+"); + std::string more_messages(counter > mMaxDisplayedCount ? more_messages_exist : ""); + s_count = llformat("%d%s" + , llmin(counter, mMaxDisplayedCount) + , more_messages.c_str() + ); + } + + mButton->setLabel(s_count); + + setNewMessagesState(counter > mCounter); + + // we have to flash to 'Lit' state each time new unread message is coming. + if (counter > mCounter) + { + mFlashToLitTimer->flash(); + } + else if (counter == 0) + { + // if notification is resolved while well is flashing it can leave in the 'Lit' state + // when flashing finishes itself. Let break flashing here. + mFlashToLitTimer->stopFlashing(); + } + + mCounter = counter; +} + +boost::signals2::connection LLSysWellChiclet::setClickCallback( + const commit_callback_t& cb) +{ + return mButton->setClickedCallback(cb); +} + +void LLSysWellChiclet::setToggleState(BOOL toggled) { + mButton->setToggleState(toggled); +} + +void LLSysWellChiclet::changeLitState() +{ + setNewMessagesState(!mIsNewMessagesState); +} + +void LLSysWellChiclet::setNewMessagesState(bool new_messages) +{ + /* + Emulate 4 states of button by background images, see detains in EXT-3147 + xml attribute Description + image_unselected "Unlit" - there are no new messages + image_selected "Unlit" + "Selected" - there are no new messages and the Well is open + image_pressed "Lit" - there are new messages + image_pressed_selected "Lit" + "Selected" - there are new messages and the Well is open + */ + mButton->setForcePressedState(new_messages); + + mIsNewMessagesState = new_messages; +} + +void LLSysWellChiclet::updateWidget(bool is_window_empty) +{ + mButton->setEnabled(!is_window_empty); + + LLSD params; + params["well_empty"] = is_window_empty; + params["well_name"] = getName(); + notifyParent(params); +} +// virtual +BOOL LLSysWellChiclet::handleRightMouseDown(S32 x, S32 y, MASK mask) +{ + if(!mContextMenu) + { + createMenu(); + } + if (mContextMenu) + { + mContextMenu->show(x, y); + LLMenuGL::showPopup(this, mContextMenu, x, y); + } + return TRUE; +} + +/************************************************************************/ +/* LLIMWellChiclet implementation */ +/************************************************************************/ +LLIMWellChiclet::LLIMWellChiclet(const Params& p) +: LLSysWellChiclet(p) +{ + LLIMModel::instance().addNewMsgCallback(boost::bind(&LLIMWellChiclet::messageCountChanged, this, _1)); + LLIMModel::instance().addNoUnreadMsgsCallback(boost::bind(&LLIMWellChiclet::messageCountChanged, this, _1)); + + LLIMMgr::getInstance()->addSessionObserver(this); + + LLIMWellWindow::getInstance()->setSysWellChiclet(this); } -LLNotificationChiclet::~LLNotificationChiclet() +LLIMWellChiclet::~LLIMWellChiclet() { + LLIMMgr::getInstance()->removeSessionObserver(this); +} +void LLIMWellChiclet::onMenuItemClicked(const LLSD& user_data) +{ + std::string action = user_data.asString(); + if("close all" == action) + { + LLIMWellWindow::getInstance()->closeAll(); + } } -void LLNotificationChiclet::connectCounterUpdatersToSignal(std::string notification_type) +bool LLIMWellChiclet::enableMenuItem(const LLSD& user_data) +{ + std::string item = user_data.asString(); + if (item == "can close all") + { + return !LLIMWellWindow::getInstance()->isWindowEmpty(); + } + return true; +} + +void LLIMWellChiclet::createMenu() +{ + if(mContextMenu) + { + llwarns << "Menu already exists" << llendl; + return; + } + + LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; + registrar.add("IMWellChicletMenu.Action", + boost::bind(&LLIMWellChiclet::onMenuItemClicked, this, _2)); + + LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar; + enable_registrar.add("IMWellChicletMenu.EnableItem", + boost::bind(&LLIMWellChiclet::enableMenuItem, this, _2)); + + mContextMenu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu> + ("menu_im_well_button.xml", + LLMenuGL::sMenuContainer, + LLViewerMenuHolderGL::child_registry_t::instance()); +} + +void LLIMWellChiclet::messageCountChanged(const LLSD& session_data) +{ + setCounter(LLBottomTray::getInstance()->getTotalUnreadIMCount()); +} + +/************************************************************************/ +/* LLNotificationChiclet implementation */ +/************************************************************************/ +LLNotificationChiclet::LLNotificationChiclet(const Params& p) +: LLSysWellChiclet(p) +, mUreadSystemNotifications(0) +{ + // connect counter handlers to the signals + connectCounterUpdatersToSignal("notify"); + connectCounterUpdatersToSignal("groupnotify"); + connectCounterUpdatersToSignal("offer"); + + // ensure that notification well window exists, to synchronously + // handle toast add/delete events. + LLNotificationWellWindow::getInstance()->setSysWellChiclet(this); +} + +void LLNotificationChiclet::connectCounterUpdatersToSignal(const std::string& notification_type) { LLNotificationsUI::LLNotificationManager* manager = LLNotificationsUI::LLNotificationManager::getInstance(); LLNotificationsUI::LLEventHandler* n_handler = manager->getHandlerForNotification(notification_type); if(n_handler) { - if(notification_type == "notifytoast") - { - n_handler->setNewNotificationCallback(boost::bind(&LLNotificationChiclet::updateUreadIMNotifications, this)); - n_handler->setDelNotification(boost::bind(&LLNotificationChiclet::updateUreadIMNotifications, this)); - } - else - { - n_handler->setNewNotificationCallback(boost::bind(&LLNotificationChiclet::incUreadSystemNotifications, this)); - n_handler->setDelNotification(boost::bind(&LLNotificationChiclet::decUreadSystemNotifications, this)); - } + n_handler->setNewNotificationCallback(boost::bind(&LLNotificationChiclet::incUreadSystemNotifications, this)); + n_handler->setDelNotification(boost::bind(&LLNotificationChiclet::decUreadSystemNotifications, this)); } } -void LLNotificationChiclet::setCounter(S32 counter) +void LLNotificationChiclet::onMenuItemClicked(const LLSD& user_data) { - mCounterCtrl->setCounter(counter); + std::string action = user_data.asString(); + if("close all" == action) + { + LLNotificationWellWindow::getInstance()->closeAll(); + } } -void LLNotificationChiclet::setShowCounter(bool show) +bool LLNotificationChiclet::enableMenuItem(const LLSD& user_data) { - LLChiclet::setShowCounter(show); - mCounterCtrl->setVisible(getShowCounter()); + std::string item = user_data.asString(); + if (item == "can close all") + { + return mUreadSystemNotifications != 0; + } + return true; } -boost::signals2::connection LLNotificationChiclet::setClickCallback( - const commit_callback_t& cb) +void LLNotificationChiclet::createMenu() { - return mButton->setClickedCallback(cb); -} + if(mContextMenu) + { + llwarns << "Menu already exists" << llendl; + return; + } -void LLNotificationChiclet::setToggleState(BOOL toggled) { - mButton->setToggleState(toggled); + LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; + registrar.add("NotificationWellChicletMenu.Action", + boost::bind(&LLNotificationChiclet::onMenuItemClicked, this, _2)); + + LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar; + enable_registrar.add("NotificationWellChicletMenu.EnableItem", + boost::bind(&LLNotificationChiclet::enableMenuItem, this, _2)); + + mContextMenu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu> + ("menu_notification_well_button.xml", + LLMenuGL::sMenuContainer, + LLViewerMenuHolderGL::child_registry_t::instance()); } -void LLNotificationChiclet::updateUreadIMNotifications() +/*virtual*/ +void LLNotificationChiclet::setCounter(S32 counter) { - mUreadIMNotifications = gIMMgr->getNumberOfUnreadIM(); - setCounter(mUreadSystemNotifications + mUreadIMNotifications); + LLSysWellChiclet::setCounter(counter); + updateWidget(getCounter() == 0); + } - ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// LLChiclet::Params::Params() - : show_counter("show_counter") + : show_counter("show_counter", true) + , enable_counter("enable_counter", false) { - show_counter = true; } LLChiclet::LLChiclet(const Params& p) @@ -180,7 +417,7 @@ LLChiclet::~LLChiclet() boost::signals2::connection LLChiclet::setLeftButtonClickCallback( const commit_callback_t& cb) { - return mCommitSignal.connect(cb); + return setCommitCallback(cb); } BOOL LLChiclet::handleMouseDown(S32 x, S32 y, MASK mask) @@ -216,9 +453,138 @@ void LLChiclet::setValue(const LLSD& value) ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -LLIMChiclet::LLIMChiclet(const LLChiclet::Params& p) +LLIMChiclet::LLIMChiclet(const LLIMChiclet::Params& p) : LLChiclet(p) +, mShowSpeaker(false) +, mDefaultWidth(p.rect().getWidth()) +, mNewMessagesIcon(NULL) +, mSpeakerCtrl(NULL) +, mCounterCtrl(NULL) +, mChicletButton(NULL) +{ + enableCounterControl(p.enable_counter); +} + +/* virtual*/ +BOOL LLIMChiclet::postBuild() +{ + mChicletButton = getChild<LLButton>("chiclet_button"); + mChicletButton->setCommitCallback(boost::bind(&LLIMChiclet::onMouseDown, this)); + mChicletButton->setDoubleClickCallback(boost::bind(&LLIMChiclet::onMouseDown, this)); + return TRUE; +} +void LLIMChiclet::setShowSpeaker(bool show) +{ + bool needs_resize = getShowSpeaker() != show; + if(needs_resize) + { + mShowSpeaker = show; + toggleSpeakerControl(); + } +} + +void LLIMChiclet::enableCounterControl(bool enable) { + mCounterEnabled = enable; + if(!enable) + { + LLChiclet::setShowCounter(false); + } +} + +void LLIMChiclet::setShowCounter(bool show) +{ + if(!mCounterEnabled) + { + return; + } + + bool needs_resize = getShowCounter() != show; + if(needs_resize) + { + LLChiclet::setShowCounter(show); + toggleCounterControl(); + } +} + +void LLIMChiclet::initSpeakerControl() +{ + // virtual +} + +void LLIMChiclet::setRequiredWidth() +{ + bool show_speaker = getShowSpeaker(); + bool show_counter = getShowCounter(); + S32 required_width = mDefaultWidth; + + if (show_counter) + { + required_width += mCounterCtrl->getRect().getWidth(); + } + if (show_speaker) + { + required_width += mSpeakerCtrl->getRect().getWidth(); + } + + reshape(required_width, getRect().getHeight()); + + onChicletSizeChanged(); +} + +void LLIMChiclet::toggleSpeakerControl() +{ + if(getShowSpeaker()) + { + // move speaker to the right of chiclet icon + LLRect speaker_rc = mSpeakerCtrl->getRect(); + speaker_rc.setLeftTopAndSize(mDefaultWidth, speaker_rc.mTop, speaker_rc.getWidth(), speaker_rc.getHeight()); + mSpeakerCtrl->setRect(speaker_rc); + + if(getShowCounter()) + { + // move speaker to the right of counter + mSpeakerCtrl->translate(mCounterCtrl->getRect().getWidth(), 0); + } + + initSpeakerControl(); + } + + setRequiredWidth(); + mSpeakerCtrl->setSpeakerId(LLUUID::null); + mSpeakerCtrl->setVisible(getShowSpeaker()); +} + +void LLIMChiclet::setCounter(S32 counter) +{ + if (mCounterCtrl->getCounter() == counter) + { + return; + } + + mCounterCtrl->setCounter(counter); + setShowCounter(counter); + setShowNewMessagesIcon(counter); +} + +void LLIMChiclet::toggleCounterControl() +{ + setRequiredWidth(); + mCounterCtrl->setVisible(getShowCounter()); +} + +void LLIMChiclet::setShowNewMessagesIcon(bool show) +{ + if(mNewMessagesIcon) + { + mNewMessagesIcon->setVisible(show); + } + setRequiredWidth(); +} + +bool LLIMChiclet::getShowNewMessagesIcon() +{ + return mNewMessagesIcon->getVisible(); } void LLIMChiclet::onMouseDown() @@ -227,17 +593,14 @@ void LLIMChiclet::onMouseDown() setCounter(0); } -BOOL LLIMChiclet::handleMouseDown(S32 x, S32 y, MASK mask) +void LLIMChiclet::setToggleState(bool toggle) { - onMouseDown(); - return LLChiclet::handleMouseDown(x, y, mask); + mChicletButton->setToggleState(toggle); } void LLIMChiclet::draw() { LLUICtrl::draw(); - - gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4(0.0f,0.0f,0.0f,1.f), FALSE); } // static @@ -287,44 +650,27 @@ LLIMChiclet::EType LLIMChiclet::getIMSessionType(const LLUUID& session_id) LLIMP2PChiclet::Params::Params() : avatar_icon("avatar_icon") +, chiclet_button("chiclet_button") , unread_notifications("unread_notifications") , speaker("speaker") +, new_message_icon("new_message_icon") , show_speaker("show_speaker") { - // *TODO Vadim: Get rid of hardcoded values. - rect(LLRect(0, 25, 45, 0)); - - avatar_icon.name("avatar_icon"); - avatar_icon.follows.flags(FOLLOWS_LEFT | FOLLOWS_TOP | FOLLOWS_BOTTOM); - - // *NOTE dzaporozhan - // Changed icon height from 25 to 24 to fix ticket EXT-794. - // In some cases(after changing UI scale) 25 pixel height icon was - // drawn incorrectly, i'm not sure why. - avatar_icon.rect(LLRect(0, 24, 25, 0)); - avatar_icon.mouse_opaque(false); - - unread_notifications.name("unread"); - unread_notifications.rect(LLRect(25, 25, 45, 0)); - unread_notifications.font(LLFontGL::getFontSansSerif()); - unread_notifications.font_halign(LLFontGL::HCENTER); - unread_notifications.v_pad(5); - unread_notifications.text_color(LLColor4::white); - unread_notifications.mouse_opaque(false); - - speaker.name("speaker"); - speaker.rect(LLRect(45, 25, 65, 0)); - - show_speaker = false; } LLIMP2PChiclet::LLIMP2PChiclet(const Params& p) : LLIMChiclet(p) , mChicletIconCtrl(NULL) -, mCounterCtrl(NULL) -, mSpeakerCtrl(NULL) , mPopupMenu(NULL) { + LLButton::Params button_params = p.chiclet_button; + mChicletButton = LLUICtrlFactory::create<LLButton>(button_params); + addChild(mChicletButton); + + LLIconCtrl::Params new_msg_params = p.new_message_icon; + mNewMessagesIcon = LLUICtrlFactory::create<LLIconCtrl>(new_msg_params); + addChild(mNewMessagesIcon); + LLChicletAvatarIconCtrl::Params avatar_params = p.avatar_icon; mChicletIconCtrl = LLUICtrlFactory::create<LLChicletAvatarIconCtrl>(avatar_params); addChild(mChicletIconCtrl); @@ -340,42 +686,13 @@ LLIMP2PChiclet::LLIMP2PChiclet(const Params& p) mSpeakerCtrl = LLUICtrlFactory::create<LLChicletSpeakerCtrl>(speaker_params); addChild(mSpeakerCtrl); + sendChildToFront(mNewMessagesIcon); setShowSpeaker(p.show_speaker); } -void LLIMP2PChiclet::setCounter(S32 counter) -{ - mCounterCtrl->setCounter(counter); - - if(getShowCounter()) - { - LLRect counter_rect = mCounterCtrl->getRect(); - LLRect required_rect = mCounterCtrl->getRequiredRect(); - bool needs_resize = required_rect.getWidth() != counter_rect.getWidth(); - - if(needs_resize) - { - counter_rect.mRight = counter_rect.mLeft + required_rect.getWidth(); - mCounterCtrl->reshape(counter_rect.getWidth(), counter_rect.getHeight()); - mCounterCtrl->setRect(counter_rect); - - onChicletSizeChanged(); - } - } -} - -LLRect LLIMP2PChiclet::getRequiredRect() +void LLIMP2PChiclet::initSpeakerControl() { - LLRect rect(0, 0, mChicletIconCtrl->getRect().getWidth(), 0); - if(getShowCounter()) - { - rect.mRight += mCounterCtrl->getRequiredRect().getWidth(); - } - if(getShowSpeaker()) - { - rect.mRight += mSpeakerCtrl->getRect().getWidth(); - } - return rect; + mSpeakerCtrl->setSpeakerId(getOtherParticipantId()); } void LLIMP2PChiclet::setOtherParticipantId(const LLUUID& other_participant_id) @@ -391,10 +708,12 @@ void LLIMP2PChiclet::updateMenuItems() if(getSessionId().isNull()) return; + LLIMFloater* open_im_floater = LLIMFloater::findInstance(getSessionId()); + bool open_window_exists = open_im_floater && open_im_floater->getVisible(); + mPopupMenu->getChild<LLUICtrl>("Send IM")->setEnabled(!open_window_exists); + bool is_friend = LLAvatarActions::isFriend(getOtherParticipantId()); - mPopupMenu->getChild<LLUICtrl>("Add Friend")->setEnabled(!is_friend); - mPopupMenu->getChild<LLUICtrl>("Remove Friend")->setEnabled(is_friend); } BOOL LLIMP2PChiclet::handleRightMouseDown(S32 x, S32 y, MASK mask) @@ -450,17 +769,9 @@ void LLIMP2PChiclet::onMenuItemClicked(const LLSD& user_data) { LLAvatarActions::requestFriendshipDialog(other_participant_id); } -} - -void LLIMP2PChiclet::setShowSpeaker(bool show) -{ - LLIMChiclet::setShowSpeaker(show); - - bool needs_resize = getShowSpeaker() != show; - mSpeakerCtrl->setVisible(getShowSpeaker()); - if(needs_resize) + else if("end" == level) { - onChicletSizeChanged(); + LLAvatarActions::endIM(other_participant_id); } } @@ -470,46 +781,32 @@ void LLIMP2PChiclet::setShowSpeaker(bool show) LLAdHocChiclet::Params::Params() : avatar_icon("avatar_icon") +, chiclet_button("chiclet_button") , unread_notifications("unread_notifications") , speaker("speaker") +, new_message_icon("new_message_icon") , show_speaker("show_speaker") +, avatar_icon_color("avatar_icon_color", LLColor4::green) { - // *TODO Vadim: Get rid of hardcoded values. - rect(LLRect(0, 25, 45, 0)); - - avatar_icon.name("avatar_icon"); - avatar_icon.follows.flags(FOLLOWS_LEFT | FOLLOWS_TOP | FOLLOWS_BOTTOM); - - // *NOTE dzaporozhan - // Changed icon height from 25 to 24 to fix ticket EXT-794. - // In some cases(after changing UI scale) 25 pixel height icon was - // drawn incorrectly, i'm not sure why. - avatar_icon.rect(LLRect(0, 24, 25, 0)); - avatar_icon.mouse_opaque(false); - - unread_notifications.name("unread"); - unread_notifications.rect(LLRect(25, 25, 45, 0)); - unread_notifications.font(LLFontGL::getFontSansSerif()); - unread_notifications.font_halign(LLFontGL::HCENTER); - unread_notifications.v_pad(5); - unread_notifications.text_color(LLColor4::white); - unread_notifications.mouse_opaque(false); - - speaker.name("speaker"); - speaker.rect(LLRect(45, 25, 65, 0)); - - show_speaker = false; } LLAdHocChiclet::LLAdHocChiclet(const Params& p) : LLIMChiclet(p) , mChicletIconCtrl(NULL) -, mCounterCtrl(NULL) -, mSpeakerCtrl(NULL) , mPopupMenu(NULL) { + LLButton::Params button_params = p.chiclet_button; + mChicletButton = LLUICtrlFactory::create<LLButton>(button_params); + addChild(mChicletButton); + + LLIconCtrl::Params new_msg_params = p.new_message_icon; + mNewMessagesIcon = LLUICtrlFactory::create<LLIconCtrl>(new_msg_params); + addChild(mNewMessagesIcon); + LLChicletAvatarIconCtrl::Params avatar_params = p.avatar_icon; mChicletIconCtrl = LLUICtrlFactory::create<LLChicletAvatarIconCtrl>(avatar_params); + //Make the avatar modified + mChicletIconCtrl->setColor(p.avatar_icon_color); addChild(mChicletIconCtrl); LLChicletNotificationCounterCtrl::Params unread_params = p.unread_notifications; @@ -523,6 +820,7 @@ LLAdHocChiclet::LLAdHocChiclet(const Params& p) mSpeakerCtrl = LLUICtrlFactory::create<LLChicletSpeakerCtrl>(speaker_params); addChild(mSpeakerCtrl); + sendChildToFront(mNewMessagesIcon); setShowSpeaker(p.show_speaker); } @@ -533,43 +831,79 @@ void LLAdHocChiclet::setSessionId(const LLUUID& session_id) mChicletIconCtrl->setValue(im_session->mOtherParticipantID); } -void LLAdHocChiclet::setCounter(S32 counter) +void LLAdHocChiclet::draw() { - mCounterCtrl->setCounter(counter); + switchToCurrentSpeaker(); + LLIMChiclet::draw(); +} - if(getShowCounter()) - { - LLRect counter_rect = mCounterCtrl->getRect(); - LLRect required_rect = mCounterCtrl->getRequiredRect(); - bool needs_resize = required_rect.getWidth() != counter_rect.getWidth(); +void LLAdHocChiclet::initSpeakerControl() +{ + switchToCurrentSpeaker(); +} - if(needs_resize) - { - counter_rect.mRight = counter_rect.mLeft + required_rect.getWidth(); - mCounterCtrl->reshape(counter_rect.getWidth(), counter_rect.getHeight()); - mCounterCtrl->setRect(counter_rect); +void LLAdHocChiclet::switchToCurrentSpeaker() +{ + LLUUID speaker_id; + LLSpeakerMgr::speaker_list_t speaker_list; - onChicletSizeChanged(); + LLIMModel::getInstance()->findIMSession(getSessionId())->mSpeakers->getSpeakerList(&speaker_list, FALSE); + for (LLSpeakerMgr::speaker_list_t::iterator i = speaker_list.begin(); i != speaker_list.end(); ++i) + { + LLPointer<LLSpeaker> s = *i; + if (s->mSpeechVolume > 0 || s->mStatus == LLSpeaker::STATUS_SPEAKING) + { + speaker_id = s->mID; + break; } } + + mSpeakerCtrl->setSpeakerId(speaker_id); } -LLRect LLAdHocChiclet::getRequiredRect() +void LLAdHocChiclet::createPopupMenu() { - LLRect rect(0, 0, mChicletIconCtrl->getRect().getWidth(), 0); - if(getShowCounter()) + if(mPopupMenu) { - rect.mRight += mCounterCtrl->getRequiredRect().getWidth(); + llwarns << "Menu already exists" << llendl; + return; } - if(getShowSpeaker()) + if(getSessionId().isNull()) + { + return; + } + + LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; + registrar.add("IMChicletMenu.Action", boost::bind(&LLAdHocChiclet::onMenuItemClicked, this, _2)); + + mPopupMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL> + ("menu_imchiclet_adhoc.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); +} + +void LLAdHocChiclet::onMenuItemClicked(const LLSD& user_data) +{ + std::string level = user_data.asString(); + LLUUID group_id = getSessionId(); + + if("end" == level) { - rect.mRight += mSpeakerCtrl->getRect().getWidth(); + LLGroupActions::endIM(group_id); } - return rect; } BOOL LLAdHocChiclet::handleRightMouseDown(S32 x, S32 y, MASK mask) { + if(!mPopupMenu) + { + createPopupMenu(); + } + + if (mPopupMenu) + { + mPopupMenu->arrangeAndClear(); + LLMenuGL::showPopup(this, mPopupMenu, x, y); + } + return TRUE; } @@ -579,38 +913,28 @@ BOOL LLAdHocChiclet::handleRightMouseDown(S32 x, S32 y, MASK mask) LLIMGroupChiclet::Params::Params() : group_icon("group_icon") +, chiclet_button("chiclet_button") +, unread_notifications("unread_notifications") +, speaker("speaker") +, new_message_icon("new_message_icon") +, show_speaker("show_speaker") { - rect(LLRect(0, 25, 45, 0)); - - group_icon.name("group_icon"); - - // *NOTE dzaporozhan - // Changed icon height from 25 to 24 to fix ticket EXT-794. - // In some cases(after changing UI scale) 25 pixel height icon was - // drawn incorrectly, i'm not sure why. - group_icon.rect(LLRect(0, 24, 25, 0)); - - unread_notifications.name("unread"); - unread_notifications.rect(LLRect(25, 25, 45, 0)); - unread_notifications.font(LLFontGL::getFontSansSerif()); - unread_notifications.font_halign(LLFontGL::HCENTER); - unread_notifications.v_pad(5); - unread_notifications.text_color(LLColor4::white); - - speaker.name("speaker"); - speaker.rect(LLRect(45, 25, 65, 0)); - - show_speaker = false; } LLIMGroupChiclet::LLIMGroupChiclet(const Params& p) : LLIMChiclet(p) , LLGroupMgrObserver(LLUUID::null) , mChicletIconCtrl(NULL) -, mCounterCtrl(NULL) -, mSpeakerCtrl(NULL) , mPopupMenu(NULL) { + LLButton::Params button_params = p.chiclet_button; + mChicletButton = LLUICtrlFactory::create<LLButton>(button_params); + addChild(mChicletButton); + + LLIconCtrl::Params new_msg_params = p.new_message_icon; + mNewMessagesIcon = LLUICtrlFactory::create<LLIconCtrl>(new_msg_params); + addChild(mNewMessagesIcon); + LLChicletGroupIconCtrl::Params avatar_params = p.group_icon; mChicletIconCtrl = LLUICtrlFactory::create<LLChicletGroupIconCtrl>(avatar_params); addChild(mChicletIconCtrl); @@ -626,6 +950,7 @@ LLIMGroupChiclet::LLIMGroupChiclet(const Params& p) mSpeakerCtrl = LLUICtrlFactory::create<LLChicletSpeakerCtrl>(speaker_params); addChild(mSpeakerCtrl); + sendChildToFront(mNewMessagesIcon); setShowSpeaker(p.show_speaker); } @@ -634,39 +959,37 @@ LLIMGroupChiclet::~LLIMGroupChiclet() LLGroupMgr::getInstance()->removeObserver(this); } -void LLIMGroupChiclet::setCounter(S32 counter) +void LLIMGroupChiclet::draw() { - mCounterCtrl->setCounter(counter); - - if(getShowCounter()) + if(getShowSpeaker()) { - LLRect counter_rect = mCounterCtrl->getRect(); - LLRect required_rect = mCounterCtrl->getRequiredRect(); - bool needs_resize = required_rect.getWidth() != counter_rect.getWidth(); - - if(needs_resize) - { - counter_rect.mRight = counter_rect.mLeft + required_rect.getWidth(); - mCounterCtrl->reshape(counter_rect.getWidth(), counter_rect.getHeight()); - mCounterCtrl->setRect(counter_rect); - - onChicletSizeChanged(); - } + switchToCurrentSpeaker(); } + LLIMChiclet::draw(); } -LLRect LLIMGroupChiclet::getRequiredRect() +void LLIMGroupChiclet::initSpeakerControl() { - LLRect rect(0, 0, mChicletIconCtrl->getRect().getWidth(), 0); - if(getShowCounter()) - { - rect.mRight += mCounterCtrl->getRequiredRect().getWidth(); - } - if(getShowSpeaker()) + switchToCurrentSpeaker(); +} + +void LLIMGroupChiclet::switchToCurrentSpeaker() +{ + LLUUID speaker_id; + LLSpeakerMgr::speaker_list_t speaker_list; + + LLIMModel::getInstance()->findIMSession(getSessionId())->mSpeakers->getSpeakerList(&speaker_list, FALSE); + for (LLSpeakerMgr::speaker_list_t::iterator i = speaker_list.begin(); i != speaker_list.end(); ++i) { - rect.mRight += mSpeakerCtrl->getRect().getWidth(); + LLPointer<LLSpeaker> s = *i; + if (s->mSpeechVolume > 0 || s->mStatus == LLSpeaker::STATUS_SPEAKING) + { + speaker_id = s->mID; + break; + } } - return rect; + + mSpeakerCtrl->setSpeakerId(speaker_id); } void LLIMGroupChiclet::setSessionId(const LLUUID& session_id) @@ -703,6 +1026,18 @@ void LLIMGroupChiclet::changed(LLGroupChange gc) } } +void LLIMGroupChiclet::updateMenuItems() +{ + if(!mPopupMenu) + return; + if(getSessionId().isNull()) + return; + + LLIMFloater* open_im_floater = LLIMFloater::findInstance(getSessionId()); + bool open_window_exists = open_im_floater && open_im_floater->getVisible(); + mPopupMenu->getChild<LLUICtrl>("Chat")->setEnabled(!open_window_exists); +} + BOOL LLIMGroupChiclet::handleRightMouseDown(S32 x, S32 y, MASK mask) { if(!mPopupMenu) @@ -712,6 +1047,7 @@ BOOL LLIMGroupChiclet::handleRightMouseDown(S32 x, S32 y, MASK mask) if (mPopupMenu) { + updateMenuItems(); mPopupMenu->arrangeAndClear(); LLMenuGL::showPopup(this, mPopupMenu, x, y); } @@ -745,26 +1081,19 @@ void LLIMGroupChiclet::onMenuItemClicked(const LLSD& user_data) if("group chat" == level) { - LLGroupActions::startChat(group_id); + LLGroupActions::startIM(group_id); } else if("info" == level) { LLGroupActions::show(group_id); } -} - -void LLIMGroupChiclet::setShowSpeaker(bool show) -{ - LLIMChiclet::setShowSpeaker(show); - - bool needs_resize = getShowSpeaker() != show; - mSpeakerCtrl->setVisible(getShowSpeaker()); - if(needs_resize) + else if("end" == level) { - onChicletSizeChanged(); + LLGroupActions::endIM(group_id); } } + ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// @@ -772,36 +1101,10 @@ void LLIMGroupChiclet::setShowSpeaker(bool show) LLChicletPanel::Params::Params() : chiclet_padding("chiclet_padding") , scrolling_offset("scrolling_offset") -, left_scroll_button("left_scroll_button") -, right_scroll_button("right_scroll_button") +, scroll_button_hpad("scroll_button_hpad") +, scroll_ratio("scroll_ratio") , min_width("min_width") { - chiclet_padding = 3; - scrolling_offset = 40; - - if (!min_width.isProvided()) - { - // min_width = 4 chiclets + 3 paddings - min_width = 179 + 3*chiclet_padding; - } - - LLRect scroll_button_rect(0, 25, 19, 5); - - left_scroll_button.name("left_scroll"); - left_scroll_button.label(LLStringUtil::null); - left_scroll_button.rect(scroll_button_rect); - left_scroll_button.tab_stop(false); - left_scroll_button.image_selected(LLUI::getUIImage("bottom_tray_scroll_left.tga")); - left_scroll_button.image_unselected(LLUI::getUIImage("bottom_tray_scroll_left.tga")); - left_scroll_button.image_hover_selected(LLUI::getUIImage("bottom_tray_scroll_left.tga")); - - right_scroll_button.name("right_scroll"); - right_scroll_button.label(LLStringUtil::null); - right_scroll_button.rect(scroll_button_rect); - right_scroll_button.tab_stop(false); - right_scroll_button.image_selected(LLUI::getUIImage("bottom_tray_scroll_right.tga")); - right_scroll_button.image_unselected(LLUI::getUIImage("bottom_tray_scroll_right.tga")); - right_scroll_button.image_hover_selected(LLUI::getUIImage("bottom_tray_scroll_right.tga")); }; LLChicletPanel::LLChicletPanel(const Params&p) @@ -811,27 +1114,13 @@ LLChicletPanel::LLChicletPanel(const Params&p) , mRightScrollButton(NULL) , mChicletPadding(p.chiclet_padding) , mScrollingOffset(p.scrolling_offset) +, mScrollButtonHPad(p.scroll_button_hpad) +, mScrollRatio(p.scroll_ratio) , mMinWidth(p.min_width) , mShowControls(true) { - LLButton::Params scroll_button_params = p.left_scroll_button; - - mLeftScrollButton = LLUICtrlFactory::create<LLButton>(scroll_button_params); - addChild(mLeftScrollButton); - LLTransientFloaterMgr::getInstance()->addControlView(mLeftScrollButton); - - mLeftScrollButton->setClickedCallback(boost::bind(&LLChicletPanel::onLeftScrollClick,this)); - mLeftScrollButton->setEnabled(false); - - scroll_button_params = p.right_scroll_button; - mRightScrollButton = LLUICtrlFactory::create<LLButton>(scroll_button_params); - addChild(mRightScrollButton); - LLTransientFloaterMgr::getInstance()->addControlView(mRightScrollButton); - - mRightScrollButton->setClickedCallback(boost::bind(&LLChicletPanel::onRightScrollClick,this)); - mRightScrollButton->setEnabled(false); - LLPanel::Params panel_params; + panel_params.follows.flags(FOLLOWS_LEFT | FOLLOWS_RIGHT); mScrollArea = LLUICtrlFactory::create<LLPanel>(panel_params,this); // important for Show/Hide Camera and Move controls menu in bottom tray to work properly @@ -842,73 +1131,160 @@ LLChicletPanel::LLChicletPanel(const Params&p) LLChicletPanel::~LLChicletPanel() { + LLTransientFloaterMgr::getInstance()->removeControlView(mLeftScrollButton); + LLTransientFloaterMgr::getInstance()->removeControlView(mRightScrollButton); } void im_chiclet_callback(LLChicletPanel* panel, const LLSD& data){ LLUUID session_id = data["session_id"].asUUID(); + S32 unread = data["participant_unread"].asInteger(); + + LLIMFloater* im_floater = LLIMFloater::findInstance(session_id); + if (im_floater && im_floater->getVisible() && im_floater->hasFocus()) + { + unread = 0; + } + std::list<LLChiclet*> chiclets = LLIMChiclet::sFindChicletsSignal(session_id); std::list<LLChiclet *>::iterator iter; for (iter = chiclets.begin(); iter != chiclets.end(); iter++) { LLChiclet* chiclet = *iter; if (chiclet != NULL) { - chiclet->setCounter(data["num_unread"].asInteger()); + chiclet->setCounter(unread); } else { llwarns << "Unable to set counter for chiclet " << session_id << llendl; } } - } +void object_chiclet_callback(const LLSD& data) +{ + LLUUID notification_id = data["notification_id"]; + bool new_message = data["new_message"]; + + std::list<LLChiclet*> chiclets = LLIMChiclet::sFindChicletsSignal(notification_id); + std::list<LLChiclet *>::iterator iter; + for (iter = chiclets.begin(); iter != chiclets.end(); iter++) + { + LLIMChiclet* chiclet = dynamic_cast<LLIMChiclet*>(*iter); + if (chiclet != NULL) + { + if(data.has("unread")) + { + chiclet->setCounter(data["unread"]); + } + chiclet->setShowNewMessagesIcon(new_message); + } + } +} BOOL LLChicletPanel::postBuild() { LLPanel::postBuild(); LLIMModel::instance().addNewMsgCallback(boost::bind(im_chiclet_callback, this, _1)); LLIMModel::instance().addNoUnreadMsgsCallback(boost::bind(im_chiclet_callback, this, _1)); + LLScriptFloaterManager::getInstance()->addNewObjectCallback(boost::bind(object_chiclet_callback, _1)); + LLScriptFloaterManager::getInstance()->addToggleObjectFloaterCallback(boost::bind(object_chiclet_callback, _1)); LLIMChiclet::sFindChicletsSignal.connect(boost::bind(&LLChicletPanel::findChiclet<LLChiclet>, this, _1)); + LLVoiceChannel::setCurrentVoiceChannelChangedCallback(boost::bind(&LLChicletPanel::onCurrentVoiceChannelChanged, this, _1)); + + mLeftScrollButton=getChild<LLButton>("chicklet_left_scroll_button"); + LLTransientFloaterMgr::getInstance()->addControlView(mLeftScrollButton); + mLeftScrollButton->setMouseDownCallback(boost::bind(&LLChicletPanel::onLeftScrollClick,this)); + mLeftScrollButton->setHeldDownCallback(boost::bind(&LLChicletPanel::onLeftScrollHeldDown,this)); + mLeftScrollButton->setEnabled(false); + + mRightScrollButton=getChild<LLButton>("chicklet_right_scroll_button"); + LLTransientFloaterMgr::getInstance()->addControlView(mRightScrollButton); + mRightScrollButton->setMouseDownCallback(boost::bind(&LLChicletPanel::onRightScrollClick,this)); + mRightScrollButton->setHeldDownCallback(boost::bind(&LLChicletPanel::onRightScrollHeldDown,this)); + mRightScrollButton->setEnabled(false); return TRUE; } -S32 LLChicletPanel::calcChickletPanleWidth() +void LLChicletPanel::onCurrentVoiceChannelChanged(const LLUUID& session_id) { - S32 res = 0; + static LLUUID s_previous_active_voice_session_id; - for (chiclet_list_t::iterator it = mChicletList.begin(); it - != mChicletList.end(); it++) + std::list<LLChiclet*> chiclets = LLIMChiclet::sFindChicletsSignal(session_id); + + for(std::list<LLChiclet *>::iterator it = chiclets.begin(); it != chiclets.end(); ++it) { - res = (*it)->getRect().getWidth() + getChicletPadding(); + LLIMChiclet* chiclet = dynamic_cast<LLIMChiclet*>(*it); + if(chiclet) + { + chiclet->setShowSpeaker(true); + } } - return res; + + if(!s_previous_active_voice_session_id.isNull() && s_previous_active_voice_session_id != session_id) + { + chiclets = LLIMChiclet::sFindChicletsSignal(s_previous_active_voice_session_id); + + for(std::list<LLChiclet *>::iterator it = chiclets.begin(); it != chiclets.end(); ++it) + { + LLIMChiclet* chiclet = dynamic_cast<LLIMChiclet*>(*it); + if(chiclet) + { + chiclet->setShowSpeaker(false); + } + } + } + + s_previous_active_voice_session_id = session_id; } bool LLChicletPanel::addChiclet(LLChiclet* chiclet, S32 index) { if(mScrollArea->addChild(chiclet)) { - // chicklets should be aligned to right edge of scroll panel - S32 offset = 0; + // chiclets should be aligned to right edge of scroll panel + S32 left_shift = 0; if (!canScrollLeft()) { - offset = mScrollArea->getRect().getWidth() - - chiclet->getRect().getWidth() - calcChickletPanleWidth(); + // init left shift for the first chiclet in the list... + if (mChicletList.empty()) + { + // ...start from the right border of the scroll area for the first added chiclet + left_shift = mScrollArea->getRect().getWidth(); + } + else + { + // ... start from the left border of the first chiclet minus padding + left_shift = getChiclet(0)->getRect().mLeft - getChicletPadding(); + } + + // take into account width of the being added chiclet + left_shift -= chiclet->getRequiredRect().getWidth(); + + // if we overflow the scroll area we do not need to shift chiclets + if (left_shift < 0) + { + left_shift = 0; + } } mChicletList.insert(mChicletList.begin() + index, chiclet); - getChiclet(0)->translate(offset, 0); + // shift first chiclet to place it in correct position. + // rest ones will be placed in arrange() + if (!canScrollLeft()) + { + getChiclet(0)->translate(left_shift - getChiclet(0)->getRect().mLeft, 0); + } chiclet->setLeftButtonClickCallback(boost::bind(&LLChicletPanel::onChicletClick, this, _1, _2)); chiclet->setChicletSizeChangedCallback(boost::bind(&LLChicletPanel::onChicletSizeChanged, this, _1, index)); arrange(); - showScrollButtonsIfNeeded(); + LLTransientFloaterMgr::getInstance()->addControlView(LLTransientFloaterMgr::IM, chiclet); return true; } @@ -918,40 +1294,26 @@ bool LLChicletPanel::addChiclet(LLChiclet* chiclet, S32 index) void LLChicletPanel::onChicletSizeChanged(LLChiclet* ctrl, const LLSD& param) { - S32 chiclet_width = ctrl->getRect().getWidth(); - S32 chiclet_new_width = ctrl->getRequiredRect().getWidth(); - - if(chiclet_new_width == chiclet_width) - { - return; - } - - LLRect chiclet_rect = ctrl->getRect(); - chiclet_rect.mRight = chiclet_rect.mLeft + chiclet_new_width; - - ctrl->setRect(chiclet_rect); - - S32 offset = chiclet_new_width - chiclet_width; - S32 index = getChicletIndex(ctrl); - - shiftChiclets(offset, index + 1); - trimChiclets(); - showScrollButtonsIfNeeded(); + arrange(); } void LLChicletPanel::onChicletClick(LLUICtrl*ctrl,const LLSD¶m) { - mCommitSignal(ctrl,param); + if (mCommitSignal) + { + (*mCommitSignal)(ctrl,param); + } } void LLChicletPanel::removeChiclet(chiclet_list_t::iterator it) { - mScrollArea->removeChild(*it); + LLChiclet* chiclet = *it; + mScrollArea->removeChild(chiclet); mChicletList.erase(it); arrange(); - trimChiclets(); - showScrollButtonsIfNeeded(); + LLTransientFloaterMgr::getInstance()->removeControlView(LLTransientFloaterMgr::IM, chiclet); + chiclet->die(); } void LLChicletPanel::removeChiclet(S32 index) @@ -1044,25 +1406,76 @@ void LLChicletPanel::reshape(S32 width, S32 height, BOOL called_from_parent ) { LLPanel::reshape(width,height,called_from_parent); - static const S32 SCROLL_BUTTON_PAD = 5; - + //Needed once- to avoid error at first call of reshape() before postBuild() + if(!mLeftScrollButton||!mRightScrollButton) + return; + LLRect scroll_button_rect = mLeftScrollButton->getRect(); - mLeftScrollButton->setRect(LLRect(0,height,scroll_button_rect.getWidth(), - height - scroll_button_rect.getHeight())); - + mLeftScrollButton->setRect(LLRect(0,scroll_button_rect.mTop,scroll_button_rect.getWidth(), + scroll_button_rect.mBottom)); scroll_button_rect = mRightScrollButton->getRect(); - mRightScrollButton->setRect(LLRect(width - scroll_button_rect.getWidth(),height, - width, height - scroll_button_rect.getHeight())); - - mScrollArea->setRect(LLRect(scroll_button_rect.getWidth() + SCROLL_BUTTON_PAD, - height, width - scroll_button_rect.getWidth() - SCROLL_BUTTON_PAD, 0)); + mRightScrollButton->setRect(LLRect(width - scroll_button_rect.getWidth(),scroll_button_rect.mTop, + width, scroll_button_rect.mBottom)); + - mShowControls = width > mMinWidth; + bool need_show_scroll = needShowScroll(); + if(need_show_scroll) + { + mScrollArea->setRect(LLRect(scroll_button_rect.getWidth() + mScrollButtonHPad, + height, width - scroll_button_rect.getWidth() - mScrollButtonHPad, 0)); + } + else + { + mScrollArea->setRect(LLRect(0,height, width, 0)); + } + + mShowControls = width >= mMinWidth; + mScrollArea->setVisible(mShowControls); trimChiclets(); - showScrollButtonsIfNeeded(); + +} + +S32 LLChicletPanel::notifyParent(const LLSD& info) +{ + if(info.has("notification")) + { + std::string str_notification = info["notification"]; + if(str_notification == "size_changes") + { + arrange(); + return 1; + } + } + return LLPanel::notifyParent(info); +} + +void LLChicletPanel::setChicletToggleState(const LLUUID& session_id, bool toggle) +{ + if(session_id.isNull()) + { + llwarns << "Null Session ID" << llendl; + } + + // toggle off all chiclets, except specified + S32 size = getChicletCount(); + for(int n = 0; n < size; ++n) + { + LLIMChiclet* chiclet = getChiclet<LLIMChiclet>(n); + if(chiclet && chiclet->getSessionId() != session_id) + { + chiclet->setToggleState(false); + } + } + + // toggle specified chiclet + LLIMChiclet* chiclet = findChiclet<LLIMChiclet>(session_id); + if(chiclet) + { + chiclet->setToggleState(toggle); + } } void LLChicletPanel::arrange() @@ -1070,8 +1483,8 @@ void LLChicletPanel::arrange() if(mChicletList.empty()) return; + //initial arrange of chicklets positions S32 chiclet_left = getChiclet(0)->getRect().mLeft; - S32 size = getChicletCount(); for( int n = 0; n < size; ++n) { @@ -1085,6 +1498,24 @@ void LLChicletPanel::arrange() chiclet_left += chiclet_width + getChicletPadding(); } + + //reset size and pos on mScrollArea + LLRect rect = getRect(); + LLRect scroll_button_rect = mLeftScrollButton->getRect(); + + bool need_show_scroll = needShowScroll(); + if(need_show_scroll) + { + mScrollArea->setRect(LLRect(scroll_button_rect.getWidth() + mScrollButtonHPad, + rect.getHeight(), rect.getWidth() - scroll_button_rect.getWidth() - mScrollButtonHPad, 0)); + } + else + { + mScrollArea->setRect(LLRect(0,rect.getHeight(), rect.getWidth(), 0)); + } + + trimChiclets(); + showScrollButtonsIfNeeded(); } void LLChicletPanel::trimChiclets() @@ -1102,6 +1533,17 @@ void LLChicletPanel::trimChiclets() } } +bool LLChicletPanel::needShowScroll() +{ + if(mChicletList.empty()) + return false; + + S32 chicklet_width = (*mChicletList.rbegin())->getRect().mRight - (*mChicletList.begin())->getRect().mLeft; + + return chicklet_width>getRect().getWidth(); +} + + void LLChicletPanel::showScrollButtonsIfNeeded() { bool can_scroll_left = canScrollLeft(); @@ -1226,10 +1668,26 @@ void LLChicletPanel::onRightScrollClick() scrollRight(); } +void LLChicletPanel::onLeftScrollHeldDown() +{ + S32 offset = mScrollingOffset; + mScrollingOffset = mScrollingOffset / mScrollRatio; + scrollLeft(); + mScrollingOffset = offset; +} + +void LLChicletPanel::onRightScrollHeldDown() +{ + S32 offset = mScrollingOffset; + mScrollingOffset = mScrollingOffset / mScrollRatio; + scrollRight(); + mScrollingOffset = offset; +} + boost::signals2::connection LLChicletPanel::setChicletClickedCallback( const commit_callback_t& cb) { - return mCommitSignal.connect(cb); + return setCommitCallback(cb); } BOOL LLChicletPanel::handleScrollWheel(S32 x, S32 y, S32 clicks) @@ -1264,160 +1722,34 @@ bool LLChicletPanel::isAnyIMFloaterDoked() return res; } -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// - -// *TODO Vadim: Move this out of llchiclet.cpp. - -LLTalkButton::Params::Params() - : speak_button("speak_button") - , show_button("show_button") - , monitor("monitor") -{ - // *TODO Vadim: move hardcoded labels (!) and other params to XUI. - speak_button.name("left"); - speak_button.label("Speak"); - speak_button.label_selected("Speak"); - speak_button.font(LLFontGL::getFontSansSerifSmall()); - speak_button.tab_stop(false); - speak_button.is_toggle(true); - speak_button.picture_style(true); - // Use default button art. JC - //speak_button.image_selected(LLUI::getUIImage("SegmentedBtn_Left_Selected")); - //speak_button.image_unselected(LLUI::getUIImage("SegmentedBtn_Left_Off")); - - show_button.name("right"); - show_button.label(LLStringUtil::null); - show_button.rect(LLRect(0, 0, 20, 0)); - show_button.tab_stop(false); - show_button.is_toggle(true); - show_button.picture_style(true); - show_button.image_selected(LLUI::getUIImage("ComboButton_Selected")); - show_button.image_unselected(LLUI::getUIImage("ComboButton_Off")); - - monitor.name("monitor"); - // *TODO: Make this data driven. - monitor.rect(LLRect(0, 18, 18, 0)); -} - -LLTalkButton::LLTalkButton(const Params& p) -: LLUICtrl(p) -, mPrivateCallPanel(NULL) -, mOutputMonitor(NULL) -, mSpeakBtn(NULL) -, mShowBtn(NULL) +S32 LLChicletPanel::getTotalUnreadIMCount() { - LLRect rect = p.rect(); - LLRect speak_rect(0, rect.getHeight(), rect.getWidth(), 0); - LLRect show_rect = p.show_button.rect(); - show_rect.set(0, rect.getHeight(), show_rect.getWidth(), 0); - - speak_rect.mRight -= show_rect.getWidth(); - show_rect.mLeft = speak_rect.getWidth(); - show_rect.mRight = rect.getWidth(); - - LLButton::Params speak_params = p.speak_button; - speak_params.rect(speak_rect); - mSpeakBtn = LLUICtrlFactory::create<LLButton>(speak_params); - addChild(mSpeakBtn); - LLTransientFloaterMgr::getInstance()->addControlView(mSpeakBtn); - - mSpeakBtn->setClickedCallback(boost::bind(&LLTalkButton::onClick_SpeakBtn, this)); - mSpeakBtn->setToggleState(FALSE); - - LLButton::Params show_params = p.show_button; - show_params.rect(show_rect); - mShowBtn = LLUICtrlFactory::create<LLButton>(show_params); - addChild(mShowBtn); - LLTransientFloaterMgr::getInstance()->addControlView(mShowBtn); - - mShowBtn->setClickedCallback(boost::bind(&LLTalkButton::onClick_ShowBtn, this)); - mShowBtn->setToggleState(FALSE); - - static const S32 MONITOR_RIGHT_PAD = 2; - - LLRect monitor_rect = p.monitor.rect(); - S32 monitor_height = monitor_rect.getHeight(); - monitor_rect.mLeft = speak_rect.getWidth() - monitor_rect.getWidth() - MONITOR_RIGHT_PAD; - monitor_rect.mRight = speak_rect.getWidth() - MONITOR_RIGHT_PAD; - monitor_rect.mBottom = (rect.getHeight() / 2) - (monitor_height / 2); - monitor_rect.mTop = monitor_rect.mBottom + monitor_height; - - LLOutputMonitorCtrl::Params monitor_params = p.monitor; - monitor_params.draw_border(false); - monitor_params.rect(monitor_rect); - monitor_params.auto_update(true); - monitor_params.speaker_id(gAgentID); - mOutputMonitor = LLUICtrlFactory::create<LLOutputMonitorCtrl>(monitor_params); - mSpeakBtn->addChild(mOutputMonitor); - - // never show "muted" because you can't mute yourself - mOutputMonitor->setIsMuted(false); -} - -LLTalkButton::~LLTalkButton() -{ -} - -void LLTalkButton::setSpeakBtnToggleState(bool state) -{ - mSpeakBtn->setToggleState(state); -} - -void LLTalkButton::onClick_SpeakBtn() -{ - bool speaking = mSpeakBtn->getToggleState(); - gVoiceClient->setUserPTTState(speaking); -} - -void LLTalkButton::onClick_ShowBtn() -{ - if(!mShowBtn->getToggleState()) + S32 count = 0; + chiclet_list_t::const_iterator it = mChicletList.begin(); + for( ; mChicletList.end() != it; ++it) { - mPrivateCallPanel->onClickClose(mPrivateCallPanel); - delete mPrivateCallPanel; - mPrivateCallPanel = NULL; - mShowBtn->setToggleState(FALSE); - return; + LLIMChiclet* chiclet = dynamic_cast<LLIMChiclet*>(*it); + if(chiclet) + { + count += chiclet->getCounter(); + } } - - S32 x = mSpeakBtn->getRect().mLeft; - S32 y = 0; - - localPointToScreen(x, y, &x, &y); - - mPrivateCallPanel = new LLVoiceControlPanel; - getRootView()->addChild(mPrivateCallPanel); - - y = LLBottomTray::getInstance()->getRect().getHeight() + mPrivateCallPanel->getRect().getHeight(); - - LLRect rect; - rect.setLeftTopAndSize(x, y, mPrivateCallPanel->getRect().getWidth(), mPrivateCallPanel->getRect().getHeight()); - mPrivateCallPanel->setRect(rect); - - - LLAvatarListItem* item = new LLAvatarListItem(); - item->showStatus(true); - item->showInfoBtn(true); - item->showSpeakingIndicator(true); - item->reshape(mPrivateCallPanel->getRect().getWidth(), item->getRect().getHeight(), FALSE); - - mPrivateCallPanel->addItem(item); - mPrivateCallPanel->setVisible(TRUE); - mPrivateCallPanel->setFrontmost(TRUE); - - mShowBtn->setToggleState(TRUE); + return count; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// +LLChicletNotificationCounterCtrl::Params::Params() +: max_displayed_count("max_displayed_count", 99) +{ +} LLChicletNotificationCounterCtrl::LLChicletNotificationCounterCtrl(const Params& p) : LLTextBox(p) , mCounter(0) , mInitialWidth(0) + , mMaxDisplayedCount(p.max_displayed_count) { mInitialWidth = getRect().getWidth(); } @@ -1426,11 +1758,21 @@ void LLChicletNotificationCounterCtrl::setCounter(S32 counter) { mCounter = counter; - std::stringstream stream; - stream << getCounter(); + // note same code in LLSysWellChiclet::setCounter(S32 counter) + std::string s_count; + if(counter != 0) + { + static std::string more_messages_exist("+"); + std::string more_messages(counter > mMaxDisplayedCount ? more_messages_exist : ""); + s_count = llformat("%d%s" + , llmin(counter, mMaxDisplayedCount) + , more_messages.c_str() + ); + } + if(mCounter != 0) { - setText(stream.str()); + setText(s_count); } else { @@ -1441,7 +1783,7 @@ void LLChicletNotificationCounterCtrl::setCounter(S32 counter) LLRect LLChicletNotificationCounterCtrl::getRequiredRect() { LLRect rc; - S32 text_width = getContentsRect().getWidth(); + S32 text_width = getTextPixelWidth(); rc.mRight = rc.mLeft + llmax(text_width, mInitialWidth); @@ -1476,6 +1818,7 @@ LLChicletGroupIconCtrl::LLChicletGroupIconCtrl(const Params& p) : LLIconCtrl(p) , mDefaultIcon(p.default_icon) { + setValue(LLUUID::null); } void LLChicletGroupIconCtrl::setValue(const LLSD& value ) @@ -1494,7 +1837,141 @@ void LLChicletGroupIconCtrl::setValue(const LLSD& value ) ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// +LLChicletInvOfferIconCtrl::LLChicletInvOfferIconCtrl(const Params& p) +: LLChicletAvatarIconCtrl(p) + , mDefaultIcon(p.default_icon) +{ +} + +void LLChicletInvOfferIconCtrl::setValue(const LLSD& value ) +{ + if(value.asUUID().isNull()) + { + LLIconCtrl::setValue(mDefaultIcon); + } + else + { + LLChicletAvatarIconCtrl::setValue(value); + } +} + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + LLChicletSpeakerCtrl::LLChicletSpeakerCtrl(const Params&p) - : LLIconCtrl(p) + : LLOutputMonitorCtrl(p) +{ +} + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +LLScriptChiclet::Params::Params() + : icon("icon") + , chiclet_button("chiclet_button") + , new_message_icon("new_message_icon") +{ +} + +LLScriptChiclet::LLScriptChiclet(const Params&p) + : LLIMChiclet(p) + , mChicletIconCtrl(NULL) +{ + LLButton::Params button_params = p.chiclet_button; + mChicletButton = LLUICtrlFactory::create<LLButton>(button_params); + addChild(mChicletButton); + + LLIconCtrl::Params new_msg_params = p.new_message_icon; + mNewMessagesIcon = LLUICtrlFactory::create<LLIconCtrl>(new_msg_params); + addChild(mNewMessagesIcon); + + LLIconCtrl::Params icon_params = p.icon; + mChicletIconCtrl = LLUICtrlFactory::create<LLIconCtrl>(icon_params); + addChild(mChicletIconCtrl); + + sendChildToFront(mNewMessagesIcon); +} + +void LLScriptChiclet::setSessionId(const LLUUID& session_id) +{ + setShowNewMessagesIcon( getSessionId() != session_id ); + + LLIMChiclet::setSessionId(session_id); + + setToolTip(LLScriptFloaterManager::getObjectName(session_id)); +} + +void LLScriptChiclet::setCounter(S32 counter) { + setShowNewMessagesIcon( counter > 0 ); } + +void LLScriptChiclet::onMouseDown() +{ + LLScriptFloaterManager::getInstance()->toggleScriptFloater(getSessionId()); +} + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +static const std::string INVENTORY_USER_OFFER ("UserGiveItem"); + +LLInvOfferChiclet::Params::Params() + : icon("icon") + , chiclet_button("chiclet_button") + , new_message_icon("new_message_icon") +{ +} + +LLInvOfferChiclet::LLInvOfferChiclet(const Params&p) + : LLIMChiclet(p) + , mChicletIconCtrl(NULL) +{ + LLButton::Params button_params = p.chiclet_button; + mChicletButton = LLUICtrlFactory::create<LLButton>(button_params); + addChild(mChicletButton); + + LLIconCtrl::Params new_msg_params = p.new_message_icon; + mNewMessagesIcon = LLUICtrlFactory::create<LLIconCtrl>(new_msg_params); + addChild(mNewMessagesIcon); + + LLChicletInvOfferIconCtrl::Params icon_params = p.icon; + mChicletIconCtrl = LLUICtrlFactory::create<LLChicletInvOfferIconCtrl>(icon_params); + addChild(mChicletIconCtrl); + + sendChildToFront(mNewMessagesIcon); +} + +void LLInvOfferChiclet::setSessionId(const LLUUID& session_id) +{ + setShowNewMessagesIcon( getSessionId() != session_id ); + + setToolTip(LLScriptFloaterManager::getObjectName(session_id)); + + LLIMChiclet::setSessionId(session_id); + LLNotificationPtr notification = LLNotifications::getInstance()->find(session_id); + + if ( notification && notification->getName() == INVENTORY_USER_OFFER ) + { + mChicletIconCtrl->setValue(notification->getPayload()["from_id"]); + } + else + { + mChicletIconCtrl->setValue(LLUUID::null); + } +} + +void LLInvOfferChiclet::setCounter(S32 counter) +{ + setShowNewMessagesIcon( counter > 0 ); +} + +void LLInvOfferChiclet::onMouseDown() +{ + LLScriptFloaterManager::instance().toggleScriptFloater(getSessionId()); +} + +// EOF |