From 14708a3ace184b0654ca7923732be6e06962d583 Mon Sep 17 00:00:00 2001
From: AlexanderP ProductEngine <apaschenko@productengine.com>
Date: Wed, 22 Aug 2012 18:27:29 +0300
Subject: CHUI_310 make NearbyChat a singletone

---
 indra/newview/llagent.cpp                          |  4 +-
 indra/newview/llchatitemscontainerctrl.cpp         |  4 +-
 indra/newview/llfirstuse.cpp                       |  2 +-
 indra/newview/llfloatertranslationsettings.cpp     |  2 +-
 indra/newview/llgesturemgr.cpp                     |  2 +-
 indra/newview/llimconversation.cpp                 | 32 +++++++++--
 indra/newview/llimfloatercontainer.cpp             |  6 +--
 indra/newview/llimview.cpp                         |  7 +--
 indra/newview/llnearbychat.cpp                     | 41 ++++++--------
 indra/newview/llnearbychat.h                       |  8 +--
 indra/newview/llnearbychathandler.cpp              |  6 +--
 indra/newview/llnotificationhandlerutil.cpp        |  5 +-
 indra/newview/llnotificationtiphandler.cpp         |  3 +-
 indra/newview/llstartup.cpp                        |  1 +
 indra/newview/llviewerfloaterreg.cpp               |  2 +-
 indra/newview/llviewergesture.cpp                  |  2 +-
 indra/newview/llviewerkeyboard.cpp                 |  2 +-
 indra/newview/llviewermessage.cpp                  |  9 ++--
 indra/newview/llviewerwindow.cpp                   | 62 +++++++++++-----------
 .../skins/default/xui/da/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/de/floater_chat_bar.xml      |  2 +-
 .../skins/default/xui/de/panel_nearby_chat_bar.xml |  2 +-
 indra/newview/skins/default/xui/en/menu_viewer.xml |  4 +-
 .../skins/default/xui/en/panel_bottomtray_lite.xml |  2 +-
 .../skins/default/xui/en/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/es/floater_chat_bar.xml      |  2 +-
 .../skins/default/xui/es/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/fr/floater_chat_bar.xml      |  2 +-
 .../skins/default/xui/fr/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/it/floater_chat_bar.xml      |  2 +-
 .../skins/default/xui/it/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/ja/floater_chat_bar.xml      |  2 +-
 .../skins/default/xui/ja/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/pl/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/pt/floater_chat_bar.xml      |  2 +-
 .../skins/default/xui/pt/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/ru/floater_chat_bar.xml      |  2 +-
 .../skins/default/xui/ru/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/tr/floater_chat_bar.xml      |  2 +-
 .../skins/default/xui/tr/panel_nearby_chat_bar.xml |  2 +-
 .../skins/default/xui/zh/panel_nearby_chat_bar.xml |  2 +-
 41 files changed, 125 insertions(+), 121 deletions(-)

(limited to 'indra')

diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index f187318c0f..be6901c36a 100755
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -1911,7 +1911,7 @@ void LLAgent::startTyping()
 	{
 		sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_START);
 	}
-	LLNearbyChat::getInstance()->sendChatFromViewer("", CHAT_TYPE_START, FALSE);
+	(LLNearbyChat::instance()).sendChatFromViewer("", CHAT_TYPE_START, FALSE);
 }
 
 //-----------------------------------------------------------------------------
@@ -1923,7 +1923,7 @@ void LLAgent::stopTyping()
 	{
 		clearRenderState(AGENT_STATE_TYPING);
 		sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_STOP);
-		LLNearbyChat::getInstance()->sendChatFromViewer("", CHAT_TYPE_STOP, FALSE);
+		(LLNearbyChat::instance()).sendChatFromViewer("", CHAT_TYPE_STOP, FALSE);
 	}
 }
 
diff --git a/indra/newview/llchatitemscontainerctrl.cpp b/indra/newview/llchatitemscontainerctrl.cpp
index 61772b4bb7..e6340e0fa3 100644
--- a/indra/newview/llchatitemscontainerctrl.cpp
+++ b/indra/newview/llchatitemscontainerctrl.cpp
@@ -323,12 +323,12 @@ BOOL	LLNearbyChatToastPanel::handleMouseUp	(S32 x, S32 y, MASK mask)
 			return TRUE;
 		else
 		{
-			LLNearbyChat::getInstance()->showHistory();
+			LLNearbyChat::instance().showHistory();
 			return FALSE;
 		}
 	}
 
-	LLNearbyChat::getInstance()->showHistory();
+	LLNearbyChat::instance().showHistory();
 	return LLPanel::handleMouseUp(x,y,mask);
 }
 
diff --git a/indra/newview/llfirstuse.cpp b/indra/newview/llfirstuse.cpp
index a9f52282a5..e2850f5181 100644
--- a/indra/newview/llfirstuse.cpp
+++ b/indra/newview/llfirstuse.cpp
@@ -74,7 +74,7 @@ void LLFirstUse::resetFirstUse()
 // static
 void LLFirstUse::otherAvatarChatFirst(bool enable)
 {
-	firstUseNotification("FirstOtherChatBeforeUser", enable, "HintChat", LLSD(), LLSD().with("target", "chat_bar").with("direction", "top_right").with("distance", 24));
+	firstUseNotification("FirstOtherChatBeforeUser", enable, "HintChat", LLSD(), LLSD().with("target", "nearby_chat").with("direction", "top_right").with("distance", 24));
 }
 
 // static
diff --git a/indra/newview/llfloatertranslationsettings.cpp b/indra/newview/llfloatertranslationsettings.cpp
index bb01ce5a7e..b5b86dadc2 100644
--- a/indra/newview/llfloatertranslationsettings.cpp
+++ b/indra/newview/llfloatertranslationsettings.cpp
@@ -293,6 +293,6 @@ void LLFloaterTranslationSettings::onBtnOK()
 	gSavedSettings.setString("TranslationService", getSelectedService());
 	gSavedSettings.setString("BingTranslateAPIKey", getEnteredBingKey());
 	gSavedSettings.setString("GoogleTranslateAPIKey", getEnteredGoogleKey());
-	LLNearbyChat::getInstance()->showTranslationCheckbox(LLTranslate::isTranslationConfigured());
+	LLNearbyChat::instance().showTranslationCheckbox(LLTranslate::isTranslationConfigured());
 	closeFloater(false);
 }
diff --git a/indra/newview/llgesturemgr.cpp b/indra/newview/llgesturemgr.cpp
index 26b63bdacb..0377337af6 100644
--- a/indra/newview/llgesturemgr.cpp
+++ b/indra/newview/llgesturemgr.cpp
@@ -997,7 +997,7 @@ void LLGestureMgr::runStep(LLMultiGesture* gesture, LLGestureStep* step)
 
 			const BOOL animate = FALSE;
 
-			LLNearbyChat::getInstance()->sendChatFromViewer(chat_text, CHAT_TYPE_NORMAL, animate);
+			LLNearbyChat::instance().sendChatFromViewer(chat_text, CHAT_TYPE_NORMAL, animate);
 
 			gesture->mCurrentStep++;
 			break;
diff --git a/indra/newview/llimconversation.cpp b/indra/newview/llimconversation.cpp
index ee7f58b01f..2212673d3a 100644
--- a/indra/newview/llimconversation.cpp
+++ b/indra/newview/llimconversation.cpp
@@ -81,13 +81,35 @@ LLIMConversation::~LLIMConversation()
 //static
 LLIMConversation* LLIMConversation::findConversation(const LLUUID& uuid)
 {
-    return LLFloaterReg::findTypedInstance<LLIMConversation>(uuid.isNull()? "chat_bar" : "impanel", LLSD(uuid));
+	LLIMConversation* conv;
+
+	if (uuid.isNull())
+	{
+		conv = LLFloaterReg::findTypedInstance<LLIMConversation>("nearby_chat");
+	}
+	else
+	{
+		conv = LLFloaterReg::findTypedInstance<LLIMConversation>("impanel", LLSD(uuid));
+	}
+
+	return conv;
 };
 
 //static
 LLIMConversation* LLIMConversation::getConversation(const LLUUID& uuid)
 {
-	return LLFloaterReg::getTypedInstance<LLIMConversation>(uuid.isNull()? "chat_bar" : "impanel", LLSD(uuid));
+	LLIMConversation* conv;
+
+	if (uuid.isNull())
+	{
+		conv = LLFloaterReg::getTypedInstance<LLIMConversation>("nearby_chat");
+	}
+	else
+	{
+		conv = LLFloaterReg::getTypedInstance<LLIMConversation>("impanel", LLSD(uuid));
+	}
+
+	return conv;
 };
 
 
@@ -336,15 +358,15 @@ void LLIMConversation::processChatHistoryStyleUpdate()
 		}
 	}
 
-	LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
-	if (nearby_chat)
+	if (LLNearbyChat::instanceExists())
 	{
-		nearby_chat->reloadMessages();
+		LLNearbyChat::instance().reloadMessages();
 	}
 }
 
 void LLIMConversation::updateCallBtnState(bool callIsActive)
 {
+llwarns<<(this->getName())<<llendl;
 	getChild<LLButton>("voice_call_btn")->setImageOverlay(
 			callIsActive? getString("call_btn_stop") : getString("call_btn_start"));
     enableDisableCallBtn();
diff --git a/indra/newview/llimfloatercontainer.cpp b/indra/newview/llimfloatercontainer.cpp
index 4d0bd623f8..a3f5e357c9 100644
--- a/indra/newview/llimfloatercontainer.cpp
+++ b/indra/newview/llimfloatercontainer.cpp
@@ -315,13 +315,13 @@ void LLIMFloaterContainer::setVisible(BOOL visible)
 	if (visible)
 	{
 		// Make sure we have the Nearby Chat present when showing the conversation container
-		LLIMConversation* nearby_chat = LLIMConversation::findConversation(LLUUID::null);
+		LLIMConversation* nearby_chat = LLFloaterReg::findTypedInstance<LLIMConversation>("nearby_chat");
 		if (nearby_chat == NULL)
 		{
 			// If not found, force the creation of the nearby chat conversation panel
 			// *TODO: find a way to move this to XML as a default panel or something like that
-			LLSD name("chat_bar");
-			LLFloaterReg::toggleInstanceOrBringToFront(name, LLSD(LLUUID::null));
+			LLSD name("nearby_chat");
+			LLFloaterReg::toggleInstanceOrBringToFront(name);
 		}
 	}
 
diff --git a/indra/newview/llimview.cpp b/indra/newview/llimview.cpp
index d88a558125..216db15c94 100644
--- a/indra/newview/llimview.cpp
+++ b/indra/newview/llimview.cpp
@@ -2486,12 +2486,9 @@ void LLIMMgr::addSystemMessage(const LLUUID& session_id, const std::string& mess
 
 		LLChat chat(message);
 		chat.mSourceType = CHAT_SOURCE_SYSTEM;
-		
-		LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
-
-		if(nearby_chat)
+		if (LLNearbyChat::instanceExists())
 		{
-			nearby_chat->addMessage(chat);
+			LLNearbyChat::instance().addMessage(chat);
 		}
 	}
 	else // going to IM session
diff --git a/indra/newview/llnearbychat.cpp b/indra/newview/llnearbychat.cpp
index e1454fb5dc..a723748094 100644
--- a/indra/newview/llnearbychat.cpp
+++ b/indra/newview/llnearbychat.cpp
@@ -123,8 +123,8 @@ static LLChatTypeTrigger sChatTypeTriggers[] = {
 };
 
 
-LLNearbyChat::LLNearbyChat(const LLSD& key)
-:	LLIMConversation(key),
+LLNearbyChat::LLNearbyChat(const LLSD& llsd)
+:	LLIMConversation(LLSD()),
 	//mOutputMonitor(NULL),
 	mSpeakerMgr(NULL),
 	mExpandedHeight(COLLAPSED_HEIGHT + EXPANDED_HEIGHT)
@@ -133,6 +133,7 @@ LLNearbyChat::LLNearbyChat(const LLSD& key)
 	setIsChrome(TRUE);
 	mKey = LLSD();
 	mSpeakerMgr = LLLocalSpeakerMgr::getInstance();
+	setName("nearby_chat");
 }
 
 //virtual
@@ -379,11 +380,6 @@ void LLNearbyChat::onChatFontChange(LLFontGL* fontp)
 	}
 }
 
-//static
-LLNearbyChat* LLNearbyChat::getInstance()
-{
-	return LLFloaterReg::getTypedInstance<LLNearbyChat>("chat_bar", LLSD(LLUUID::null));
-}
 
 void LLNearbyChat::show()
 {
@@ -646,7 +642,10 @@ void LLNearbyChat::appendMessage(const LLChat& chat, const LLSD &args)
 		chat_args["show_time"] = gSavedSettings.getBOOL("IMShowTime");
 		chat_args["show_names_for_p2p_conv"] = true;
 
-		mChatHistory->appendMessage(chat, chat_args);
+		if (mChatHistory)
+		{
+			mChatHistory->appendMessage(chat, chat_args);
+		}
 	}
 }
 
@@ -781,22 +780,20 @@ void LLNearbyChat::sendChatFromViewer(const LLWString &wtext, EChatType type, BO
 // static 
 void LLNearbyChat::startChat(const char* line)
 {
-	LLNearbyChat* cb = LLNearbyChat::getInstance();
-
-	if (cb )
+	if (LLNearbyChat::instanceExists())
 	{
-		cb->show();
-		cb->setVisible(TRUE);
-		cb->setFocus(TRUE);
-		cb->mInputEditor->setFocus(TRUE);
+		(LLNearbyChat::instance()).show();
+		(LLNearbyChat::instance()).setVisible(TRUE);
+		(LLNearbyChat::instance()).setFocus(TRUE);
+		(LLNearbyChat::instance().mInputEditor)->setFocus(TRUE);
 
 		if (line)
 		{
 			std::string line_string(line);
-			cb->mInputEditor->setText(line_string);
+			(LLNearbyChat::instance().mInputEditor)->setText(line_string);
 		}
 
-		cb->mInputEditor->endOfDoc();
+		(LLNearbyChat::instance().mInputEditor)->endOfDoc();
 	}
 }
 
@@ -804,14 +801,10 @@ void LLNearbyChat::startChat(const char* line)
 // static
 void LLNearbyChat::stopChat()
 {
-	LLNearbyChat* cb = LLNearbyChat::getInstance();
-
-	if (cb)
+	if (LLNearbyChat::instanceExists())
 	{
-		cb->mInputEditor->setFocus(FALSE);
-
-		// stop typing animation
-		gAgent.stopTyping();
+		(LLNearbyChat::instance().mInputEditor)->setFocus(FALSE);
+	    gAgent.stopTyping();
 	}
 }
 
diff --git a/indra/newview/llnearbychat.h b/indra/newview/llnearbychat.h
index 7c58e3037e..379bfbee4b 100644
--- a/indra/newview/llnearbychat.h
+++ b/indra/newview/llnearbychat.h
@@ -35,17 +35,19 @@
 #include "lloutputmonitorctrl.h"
 #include "llspeakers.h"
 #include "llscrollbar.h"
+#include "llsingleton.h"
 #include "llviewerchat.h"
 #include "llpanel.h"
 
 class LLResizeBar;
 
 class LLNearbyChat
-	:	public LLIMConversation
+	:	public LLIMConversation,
+	 	public LLSingleton<LLNearbyChat>
 {
 public:
 	// constructor for inline chat-bars (e.g. hosted in chat history window)
-	LLNearbyChat(const LLSD& key);
+	LLNearbyChat(const LLSD& key = LLSD());
 	~LLNearbyChat() {}
 
 	/*virtual*/ BOOL postBuild();
@@ -61,8 +63,6 @@ public:
     void reloadMessages();
 	void removeScreenChat();
 
-	static LLNearbyChat* getInstance();
-
 	void addToHost();
 	void show();
 	bool isChatVisible() const;
diff --git a/indra/newview/llnearbychathandler.cpp b/indra/newview/llnearbychathandler.cpp
index c97e3585e1..37f4cc4c19 100644
--- a/indra/newview/llnearbychathandler.cpp
+++ b/indra/newview/llnearbychathandler.cpp
@@ -487,8 +487,6 @@ void LLNearbyChatHandler::processChat(const LLChat& chat_msg,
 	if(chat_msg.mText.empty())
 		return;//don't process empty messages
 
-	LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
-
 	// Build notification data 
 	LLSD chat;
 	chat["message"] = chat_msg.mText;
@@ -539,7 +537,7 @@ void LLNearbyChatHandler::processChat(const LLChat& chat_msg,
 		}
 	}
 
-	nearby_chat->addMessage(chat_msg, true, args);
+	LLNearbyChat::instance().addMessage(chat_msg, true, args);
 
 	if(chat_msg.mSourceType == CHAT_SOURCE_AGENT 
 		&& chat_msg.mFromID.notNull() 
@@ -555,7 +553,7 @@ void LLNearbyChatHandler::processChat(const LLChat& chat_msg,
 	// Send event on to LLEventStream
 	sChatWatcher->post(chat);
 
-	if( nearby_chat->isInVisibleChain()
+	if( LLNearbyChat::instance().isInVisibleChain()
 		|| ( chat_msg.mSourceType == CHAT_SOURCE_AGENT
 			&& gSavedSettings.getBOOL("UseChatBubbles") )
 		|| mChannel.isDead()
diff --git a/indra/newview/llnotificationhandlerutil.cpp b/indra/newview/llnotificationhandlerutil.cpp
index cba22b233b..db8e917435 100644
--- a/indra/newview/llnotificationhandlerutil.cpp
+++ b/indra/newview/llnotificationhandlerutil.cpp
@@ -181,14 +181,13 @@ void LLHandlerUtil::logGroupNoticeToIMGroup(
 // static
 void LLHandlerUtil::logToNearbyChat(const LLNotificationPtr& notification, EChatSourceType type)
 {
-	LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
-	if(nearby_chat)
+	if (LLNearbyChat::instanceExists())
 	{
 		LLChat chat_msg(notification->getMessage());
 		chat_msg.mSourceType = type;
 		chat_msg.mFromName = SYSTEM_FROM;
 		chat_msg.mFromID = LLUUID::null;
-		nearby_chat->addMessage(chat_msg);
+		LLNearbyChat::instance().addMessage(chat_msg);
 	}
 }
 
diff --git a/indra/newview/llnotificationtiphandler.cpp b/indra/newview/llnotificationtiphandler.cpp
index a420c0d2ed..67fc9b27dc 100644
--- a/indra/newview/llnotificationtiphandler.cpp
+++ b/indra/newview/llnotificationtiphandler.cpp
@@ -85,8 +85,7 @@ bool LLTipHandler::processNotification(const LLNotificationPtr& notification)
 		LLHandlerUtil::logToNearbyChat(notification, CHAT_SOURCE_SYSTEM);
 
 		// don't show toast if Nearby Chat is opened
-		LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
-		if (nearby_chat->isChatVisible())
+		if (LLNearbyChat::instance().isChatVisible())
 		{
 			return false;
 		}
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index ab72b4e512..c827b39d0e 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -64,6 +64,7 @@
 #include "llmessageconfig.h"
 #include "llmoveview.h"
 #include "llimfloatercontainer.h"
+#include "llnearbychat.h"
 #include "llnotifications.h"
 #include "llnotificationsutil.h"
 #include "llteleporthistory.h"
diff --git a/indra/newview/llviewerfloaterreg.cpp b/indra/newview/llviewerfloaterreg.cpp
index 50735d10bd..927ee8f380 100644
--- a/indra/newview/llviewerfloaterreg.cpp
+++ b/indra/newview/llviewerfloaterreg.cpp
@@ -192,7 +192,7 @@ void LLViewerFloaterReg::registerFloaters()
 	LLFloaterReg::add("bumps", "floater_bumps.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterBump>);
 
 	LLFloaterReg::add("camera", "floater_camera.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterCamera>);
-	LLFloaterReg::add("chat_bar", "floater_im_session.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLNearbyChat>);
+	LLFloaterReg::add("nearby_chat", "floater_im_session.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLNearbyChat>);
 	LLFloaterReg::add("compile_queue", "floater_script_queue.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterCompileQueue>);
 	LLFloaterReg::add("conversation", "floater_conversation_log.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterConversationLog>);
 
diff --git a/indra/newview/llviewergesture.cpp b/indra/newview/llviewergesture.cpp
index c7d37e102e..a2dea31d9b 100644
--- a/indra/newview/llviewergesture.cpp
+++ b/indra/newview/llviewergesture.cpp
@@ -130,7 +130,7 @@ void LLViewerGesture::doTrigger( BOOL send_chat )
 	{
 		// Don't play nodding animation, since that might not blend
 		// with the gesture animation.
-		LLNearbyChat::getInstance()->sendChatFromViewer(mOutputString, CHAT_TYPE_NORMAL, FALSE);
+		LLNearbyChat::instance().sendChatFromViewer(mOutputString, CHAT_TYPE_NORMAL, FALSE);
 	}
 }
 
diff --git a/indra/newview/llviewerkeyboard.cpp b/indra/newview/llviewerkeyboard.cpp
index 385d3cd29a..7105720eb4 100644
--- a/indra/newview/llviewerkeyboard.cpp
+++ b/indra/newview/llviewerkeyboard.cpp
@@ -543,7 +543,7 @@ void start_gesture( EKeystate s )
 	if (KEYSTATE_UP == s &&
 		! (focus_ctrlp && focus_ctrlp->acceptsTextInput()))
 	{
- 		if (LLNearbyChat::getInstance()->getCurrentChat().empty())
+ 		if (LLNearbyChat::instance().getCurrentChat().empty())
  		{
  			// No existing chat in chat editor, insert '/'
  			LLNearbyChat::startChat("/");
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index b20b86a582..9abd269f0f 100755
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -2297,12 +2297,10 @@ void god_message_name_cb(const LLAvatarName& av_name, LLChat chat, std::string m
 	// Treat like a system message and put in chat history.
 	chat.mText = av_name.getCompleteName() + ": " + message;
 
-	LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
-	if(nearby_chat)
+	if (LLNearbyChat::instanceExists())
 	{
-		nearby_chat->addMessage(chat);
+		LLNearbyChat::instance().addMessage(chat);
 	}
-
 }
 
 void process_improved_im(LLMessageSystem *msg, void **user_data)
@@ -2897,8 +2895,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
 
 			// Note: lie to Nearby Chat, pretending that this is NOT an IM, because
 			// IMs from obejcts don't open IM sessions.
-			LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
-			if(!chat_from_system && nearby_chat)
+			if(!chat_from_system && LLNearbyChat::instanceExists())
 			{
 				chat.mOwnerID = from_id;
 				LLSD args;
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index 1bcf15913f..23d2b1633d 100755
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -198,7 +198,6 @@
 
 #include "llfloaternotificationsconsole.h"
 
-#include "llnearbychat.h"
 #include "llwindowlistener.h"
 #include "llviewerwindowlistener.h"
 #include "llpaneltopinfobar.h"
@@ -2497,43 +2496,42 @@ BOOL LLViewerWindow::handleKey(KEY key, MASK mask)
 	// Traverses up the hierarchy
 	if( keyboard_focus )
 	{
-		LLNearbyChat* nearby_chat = LLFloaterReg::findTypedInstance<LLNearbyChat>("chat_bar");
-
-		if (nearby_chat)
+		if (LLNearbyChat::instanceExists())
 		{
-			LLChatEntry* chat_editor = nearby_chat->getChatBox();
-		
-		// arrow keys move avatar while chatting hack
-		if (chat_editor && chat_editor->hasFocus())
-		{
-			// If text field is empty, there's no point in trying to move
-			// cursor with arrow keys, so allow movement
-			if (chat_editor->getText().empty() 
-				|| gSavedSettings.getBOOL("ArrowKeysAlwaysMove"))
+			LLChatEntry* chat_editor = LLNearbyChat::instance().getChatBox();
+
+			// arrow keys move avatar while chatting hack
+			if (chat_editor && chat_editor->hasFocus())
 			{
-				// let Control-Up and Control-Down through for chat line history,
-				if (!(key == KEY_UP && mask == MASK_CONTROL)
-					&& !(key == KEY_DOWN && mask == MASK_CONTROL))
+				// If text field is empty, there's no point in trying to move
+				// cursor with arrow keys, so allow movement
+				if (chat_editor->getText().empty()
+					|| gSavedSettings.getBOOL("ArrowKeysAlwaysMove"))
 				{
-					switch(key)
+					// let Control-Up and Control-Down through for chat line history,
+					if (!(key == KEY_UP && mask == MASK_CONTROL)
+						&& !(key == KEY_DOWN && mask == MASK_CONTROL))
 					{
-					case KEY_LEFT:
-					case KEY_RIGHT:
-					case KEY_UP:
-					case KEY_DOWN:
-					case KEY_PAGE_UP:
-					case KEY_PAGE_DOWN:
-					case KEY_HOME:
-						// when chatbar is empty or ArrowKeysAlwaysMove set,
-						// pass arrow keys on to avatar...
-						return FALSE;
-					default:
-						break;
+						switch(key)
+						{
+						case KEY_LEFT:
+						case KEY_RIGHT:
+						case KEY_UP:
+						case KEY_DOWN:
+						case KEY_PAGE_UP:
+						case KEY_PAGE_DOWN:
+						case KEY_HOME:
+							// when chatbar is empty or ArrowKeysAlwaysMove set,
+							// pass arrow keys on to avatar...
+							return FALSE;
+						default:
+							break;
+						}
 					}
 				}
 			}
 		}
-		}
+
 		if (keyboard_focus->handleKey(key, mask, FALSE))
 		{
 			return TRUE;
@@ -2564,11 +2562,11 @@ BOOL LLViewerWindow::handleKey(KEY key, MASK mask)
 	if ( gSavedSettings.getS32("LetterKeysFocusChatBar") && !gAgentCamera.cameraMouselook() && 
 		!keyboard_focus && key < 0x80 && (mask == MASK_NONE || mask == MASK_SHIFT) )
 	{
-		LLChatEntry* chat_editor = LLNearbyChat::getInstance()->getChatBox();
+		LLChatEntry* chat_editor = LLNearbyChat::instance().getChatBox();
 		if (chat_editor)
 		{
 			// passing NULL here, character will be added later when it is handled by character handler.
-			LLNearbyChat::getInstance()->startChat(NULL);
+			LLNearbyChat::instance().startChat(NULL);
 			return TRUE;
 		}
 	}
diff --git a/indra/newview/skins/default/xui/da/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/da/panel_nearby_chat_bar.xml
index 949cbcbd7b..eb104201f8 100644
--- a/indra/newview/skins/default/xui/da/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/da/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<line_editor label="Klik her for at chatte." name="chat_box" tool_tip="Tryk på enter for at tale, Ctrl-Enter for at råbe."/>
 	<button name="show_nearby_chat" tool_tip="Viser/skjuler log for chat nærved"/>
 </panel>
diff --git a/indra/newview/skins/default/xui/de/floater_chat_bar.xml b/indra/newview/skins/default/xui/de/floater_chat_bar.xml
index 2464a55665..ab77d4dae5 100644
--- a/indra/newview/skins/default/xui/de/floater_chat_bar.xml
+++ b/indra/newview/skins/default/xui/de/floater_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<floater name="chat_bar" title="CHAT IN DER NÄHE">
+<floater name="nearby_chat" title="CHAT IN DER NÄHE">
 	<panel name="bottom_panel">
 		<line_editor label="Zum Chatten hier klicken." name="chat_box" tool_tip="Eingabetaste zum Sprechen, Strg+Eingabe zum Rufen"/>
 		<button name="show_nearby_chat" tool_tip="Chatprotokoll in der Nähe ein-/ausblenden"/>
diff --git a/indra/newview/skins/default/xui/de/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/de/panel_nearby_chat_bar.xml
index 08cc0b0ec8..69cf6d98de 100644
--- a/indra/newview/skins/default/xui/de/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/de/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<line_editor label="Zum Chatten hier klicken." name="chat_box" tool_tip="Eingabe drücken, um zu sprechen, Strg-Eingabe drücken, um zu Rufen."/>
 	<button name="show_nearby_chat" tool_tip="Protokoll des Chats in der Nähe anzeigen/ausblenden"/>
 </panel>
diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml
index 1aa55acf2d..aa131035ed 100644
--- a/indra/newview/skins/default/xui/en/menu_viewer.xml
+++ b/indra/newview/skins/default/xui/en/menu_viewer.xml
@@ -225,10 +225,10 @@
          use_mac_ctrl="true">
             <menu_item_check.on_check
              function="Floater.Visible"
-             parameter="chat_bar" />
+             parameter="nearby_chat" />
             <menu_item_check.on_click
              function="Floater.Toggle"
-             parameter="chat_bar" />
+             parameter="nearby_chat" />
         </menu_item_check>
         <menu_item_check
          label="Speak"
diff --git a/indra/newview/skins/default/xui/en/panel_bottomtray_lite.xml b/indra/newview/skins/default/xui/en/panel_bottomtray_lite.xml
index f4722b05d6..27a27473d8 100644
--- a/indra/newview/skins/default/xui/en/panel_bottomtray_lite.xml
+++ b/indra/newview/skins/default/xui/en/panel_bottomtray_lite.xml
@@ -46,7 +46,7 @@
             follows="left|right"
             top="4"
             width="310"
-            name="chat_bar"
+            name="nearby_chat"
             mouse_opaque="false"/>
         </layout_panel>
         <layout_panel
diff --git a/indra/newview/skins/default/xui/en/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/en/panel_nearby_chat_bar.xml
index 6bc9c48729..19143cef89 100644
--- a/indra/newview/skins/default/xui/en/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/en/panel_nearby_chat_bar.xml
@@ -5,7 +5,7 @@
  height="25"
  layout="topleft"
  left="0"
- name="chat_bar"
+ name="nearby_chat"
  top="21"
  width="308">
     <line_editor
diff --git a/indra/newview/skins/default/xui/es/floater_chat_bar.xml b/indra/newview/skins/default/xui/es/floater_chat_bar.xml
index 2e94805057..02369c9a43 100644
--- a/indra/newview/skins/default/xui/es/floater_chat_bar.xml
+++ b/indra/newview/skins/default/xui/es/floater_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<floater name="chat_bar" title="CHAT">
+<floater name="nearby_chat" title="CHAT">
 	<panel name="bottom_panel">
 		<line_editor label="Pulsa aquí para chatear." name="chat_box" tool_tip="Pulsa Enter para decirlo o Ctrl+Enter para gritarlo"/>
 		<button name="show_nearby_chat" tool_tip="Muestra o esconde el registro del chat"/>
diff --git a/indra/newview/skins/default/xui/es/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/es/panel_nearby_chat_bar.xml
index af2b6e920b..e6ca59f912 100644
--- a/indra/newview/skins/default/xui/es/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/es/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<line_editor label="Pulsa aquí para chatear." name="chat_box" tool_tip="Pulsa Enter para decirlo o Ctrl+Enter para gritarlo"/>
 	<button name="show_nearby_chat" tool_tip="Muestra o esconde el registro del chat"/>
 </panel>
diff --git a/indra/newview/skins/default/xui/fr/floater_chat_bar.xml b/indra/newview/skins/default/xui/fr/floater_chat_bar.xml
index 890411d091..7dcb9a280d 100644
--- a/indra/newview/skins/default/xui/fr/floater_chat_bar.xml
+++ b/indra/newview/skins/default/xui/fr/floater_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<floater name="chat_bar" title="CHAT PRÈS DE MOI">
+<floater name="nearby_chat" title="CHAT PRÈS DE MOI">
 	<panel name="bottom_panel">
 		<line_editor label="Cliquer ici pour chatter." name="chat_box" tool_tip="Appuyer sur Entrée pour dire, Ctrl+Entrée pour crier"/>
 		<button name="show_nearby_chat" tool_tip="Afficher/masquer le journal de chat près de vous."/>
diff --git a/indra/newview/skins/default/xui/fr/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/fr/panel_nearby_chat_bar.xml
index 82cdf292ab..762dee01bb 100644
--- a/indra/newview/skins/default/xui/fr/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/fr/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<line_editor label="Cliquer ici pour chatter." name="chat_box" tool_tip="Appuyer sur Entrée pour dire, Ctrl-Entrée pour crier"/>
 	<button name="show_nearby_chat" tool_tip="Affiche/Masque le journal de chats près de vous"/>
 </panel>
diff --git a/indra/newview/skins/default/xui/it/floater_chat_bar.xml b/indra/newview/skins/default/xui/it/floater_chat_bar.xml
index 94c85b50c8..b47e32ce90 100644
--- a/indra/newview/skins/default/xui/it/floater_chat_bar.xml
+++ b/indra/newview/skins/default/xui/it/floater_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<floater name="chat_bar" title="CHAT NEI DINTORNI">
+<floater name="nearby_chat" title="CHAT NEI DINTORNI">
 	<panel name="bottom_panel">
 		<line_editor label="Clicca qui per la chat." name="chat_box" tool_tip="Premi Invio per parlare, Ctrl+Invio per gridare"/>
 		<button name="show_nearby_chat" tool_tip="Mostra/Nasconde il registro della chat nei dintorni"/>
diff --git a/indra/newview/skins/default/xui/it/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/it/panel_nearby_chat_bar.xml
index 6317d3192e..1fef88870a 100644
--- a/indra/newview/skins/default/xui/it/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/it/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<string name="min_width">
 		192
 	</string>
diff --git a/indra/newview/skins/default/xui/ja/floater_chat_bar.xml b/indra/newview/skins/default/xui/ja/floater_chat_bar.xml
index 11f223ade6..9f5df6fb85 100644
--- a/indra/newview/skins/default/xui/ja/floater_chat_bar.xml
+++ b/indra/newview/skins/default/xui/ja/floater_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<floater name="chat_bar" title="近くのチャット">
+<floater name="nearby_chat" title="近くのチャット">
 	<panel name="bottom_panel">
 		<line_editor label="ここをクリックしてチャットを開始します。" name="chat_box" tool_tip="Enter キーを押して話し、Ctrl + Enter キーで叫びます。"/>
 		<button name="show_nearby_chat" tool_tip="近くのチャットログを表示/非表示"/>
diff --git a/indra/newview/skins/default/xui/ja/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/ja/panel_nearby_chat_bar.xml
index 5998206f27..201fb0a376 100644
--- a/indra/newview/skins/default/xui/ja/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/ja/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<line_editor label="ここをクリックしてチャットを開始します。" name="chat_box" tool_tip="Enter キーを押して発言し、Ctrl + Enter キーで叫びます。"/>
 	<button name="show_nearby_chat" tool_tip="近くのチャットログを表示・非表示"/>
 </panel>
diff --git a/indra/newview/skins/default/xui/pl/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/pl/panel_nearby_chat_bar.xml
index 63cf96b571..4ed3ff669b 100644
--- a/indra/newview/skins/default/xui/pl/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/pl/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<string name="min_width">
 		192
 	</string>
diff --git a/indra/newview/skins/default/xui/pt/floater_chat_bar.xml b/indra/newview/skins/default/xui/pt/floater_chat_bar.xml
index 72016c6b40..2eb2c94940 100644
--- a/indra/newview/skins/default/xui/pt/floater_chat_bar.xml
+++ b/indra/newview/skins/default/xui/pt/floater_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<floater name="chat_bar" title="BATE-PAPO LOCAL">
+<floater name="nearby_chat" title="BATE-PAPO LOCAL">
 	<panel name="bottom_panel">
 		<line_editor label="Clique aqui para bater papo." name="chat_box" tool_tip="Tecle Enter para falar, Ctrl+Enter para gritar"/>
 		<button name="show_nearby_chat" tool_tip="Mostra/oculta o histórico do bate-papo local"/>
diff --git a/indra/newview/skins/default/xui/pt/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/pt/panel_nearby_chat_bar.xml
index 9b993488be..5628a87109 100644
--- a/indra/newview/skins/default/xui/pt/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/pt/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<line_editor label="Clique aqui para bater papo." name="chat_box" tool_tip="Tecle Enter para falar, Ctrl+Enter para gritar"/>
 	<button name="show_nearby_chat" tool_tip="Mostra/oculta o histórico do bate-papo local"/>
 </panel>
diff --git a/indra/newview/skins/default/xui/ru/floater_chat_bar.xml b/indra/newview/skins/default/xui/ru/floater_chat_bar.xml
index 79b7b033fb..f6b2fc81e1 100644
--- a/indra/newview/skins/default/xui/ru/floater_chat_bar.xml
+++ b/indra/newview/skins/default/xui/ru/floater_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<floater name="chat_bar" title="ЛОКАЛЬНЫЙ ЧАТ">
+<floater name="nearby_chat" title="ЛОКАЛЬНЫЙ ЧАТ">
 	<panel name="bottom_panel">
 		<line_editor label="Щелкните здесь для общения." name="chat_box" tool_tip="Нажмите Enter, чтобы сказать, Ctrl+Enter, чтобы прокричать"/>
 		<button name="show_nearby_chat" tool_tip="Показать/скрыть лог локального чата"/>
diff --git a/indra/newview/skins/default/xui/ru/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/ru/panel_nearby_chat_bar.xml
index 804ba7def7..395c643b0b 100644
--- a/indra/newview/skins/default/xui/ru/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/ru/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<line_editor label="Щелкните здесь для общения" name="chat_box" tool_tip="Нажмите Enter, чтобы сказать, Ctrl+Enter, чтобы прокричать"/>
 	<button name="show_nearby_chat" tool_tip="Показать/скрыть лог локального чата"/>
 </panel>
diff --git a/indra/newview/skins/default/xui/tr/floater_chat_bar.xml b/indra/newview/skins/default/xui/tr/floater_chat_bar.xml
index 988c845982..cd999b4b7a 100644
--- a/indra/newview/skins/default/xui/tr/floater_chat_bar.xml
+++ b/indra/newview/skins/default/xui/tr/floater_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<floater name="chat_bar" title="YAKINDAKİ SOHBET">
+<floater name="nearby_chat" title="YAKINDAKİ SOHBET">
 	<panel name="bottom_panel">
 		<line_editor label="Sohbet etmek için buraya tıklayın." name="chat_box" tool_tip="Söylemek için Enter, bağırmak için Ctrl+Enter yapın"/>
 		<button name="show_nearby_chat" tool_tip="Yakın sohbet günlüğünü gösterir/gizler"/>
diff --git a/indra/newview/skins/default/xui/tr/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/tr/panel_nearby_chat_bar.xml
index fd954475ac..7d191191c4 100644
--- a/indra/newview/skins/default/xui/tr/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/tr/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<line_editor label="Sohbet etmek için buraya tıklayın." name="chat_box" tool_tip="Söylemek için Enter, bağırmak için Ctrl+Enter yapın"/>
 	<button name="show_nearby_chat" tool_tip="yakın sohbet günlüğünü gösterir/gizler"/>
 </panel>
diff --git a/indra/newview/skins/default/xui/zh/panel_nearby_chat_bar.xml b/indra/newview/skins/default/xui/zh/panel_nearby_chat_bar.xml
index 3cabfcfaba..f27f205c44 100644
--- a/indra/newview/skins/default/xui/zh/panel_nearby_chat_bar.xml
+++ b/indra/newview/skins/default/xui/zh/panel_nearby_chat_bar.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<panel name="chat_bar">
+<panel name="nearby_chat">
 	<line_editor label="點擊此處開始聊天。" name="chat_box" tool_tip="按下 Enter 鍵來說或按下 Ctrl+Enter 來喊叫"/>
 	<button name="show_nearby_chat" tool_tip="顯示 / 隱藏 附近的聊天紀錄"/>
 </panel>
-- 
cgit v1.2.3