From 881fe0a11712150972fea4a65d1082149fb3e6ec Mon Sep 17 00:00:00 2001
From: andreykproductengine <none@none>
Date: Tue, 18 Oct 2016 01:29:27 +0300
Subject: Restored MAINT-4488 (perviosly reverted in MAINT-6242)

---
 indra/newview/llagent.cpp    | 18 ++++++++++++++++--
 indra/newview/llagent.h      |  8 +++++---
 indra/newview/lltool.cpp     | 21 ++++++++++++++++++---
 indra/newview/lltoolcomp.cpp | 26 ++++++++++++++------------
 indra/newview/lltoolgrab.cpp |  2 +-
 5 files changed, 54 insertions(+), 21 deletions(-)

(limited to 'indra/newview')

diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 6a1215c3af..d8b0787852 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -3191,7 +3191,7 @@ void LLAgent::initOriginGlobal(const LLVector3d &origin_global)
 }
 
 BOOL LLAgent::leftButtonGrabbed() const	
-{ 
+{
 	const BOOL camera_mouse_look = gAgentCamera.cameraMouselook();
 	return (!camera_mouse_look && mControlsTakenCount[CONTROL_LBUTTON_DOWN_INDEX] > 0) 
 		|| (camera_mouse_look && mControlsTakenCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0)
@@ -3199,6 +3199,13 @@ BOOL LLAgent::leftButtonGrabbed() const
 		|| (camera_mouse_look && mControlsTakenPassedOnCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0);
 }
 
+BOOL LLAgent::leftButtonBlocked() const
+{
+    const BOOL camera_mouse_look = gAgentCamera.cameraMouselook();
+    return (!camera_mouse_look && mControlsTakenCount[CONTROL_LBUTTON_DOWN_INDEX] > 0)
+        || (camera_mouse_look && mControlsTakenCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0);
+}
+
 BOOL LLAgent::rotateGrabbed() const		
 { 
 	return (mControlsTakenCount[CONTROL_YAW_POS_INDEX] > 0)
@@ -3656,7 +3663,14 @@ BOOL LLAgent::anyControlGrabbed() const
 
 BOOL LLAgent::isControlGrabbed(S32 control_index) const
 {
-	return mControlsTakenCount[control_index] > 0;
+    if (gAgent.mControlsTakenCount[control_index] > 0)
+        return TRUE;
+    return gAgent.mControlsTakenPassedOnCount[control_index] > 0;
+}
+
+BOOL LLAgent::isControlBlocked(S32 control_index) const
+{
+    return mControlsTakenCount[control_index] > 0;
 }
 
 void LLAgent::forceReleaseControls()
diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h
index b5da5e9062..d82ff7a67f 100644
--- a/indra/newview/llagent.h
+++ b/indra/newview/llagent.h
@@ -444,7 +444,8 @@ private:
 	// Grab
 	//--------------------------------------------------------------------
 public:
-	BOOL 			leftButtonGrabbed() const;
+    BOOL 			leftButtonGrabbed() const;
+    BOOL 			leftButtonBlocked() const;
 	BOOL 			rotateGrabbed() const;
 	BOOL 			forwardGrabbed() const;
 	BOOL 			backwardGrabbed() const;
@@ -461,8 +462,9 @@ public:
 	BOOL			controlFlagsDirty() const;
 	void			enableControlFlagReset();
 	void 			resetControlFlags();
-	BOOL			anyControlGrabbed() const; 		// True iff a script has taken over a control
-	BOOL			isControlGrabbed(S32 control_index) const;
+	BOOL			anyControlGrabbed() const; 		// True if a script has taken over any control
+    BOOL			isControlGrabbed(S32 control_index) const; // True if a script has taken over a control
+    BOOL			isControlBlocked(S32 control_index) const; // Control should be ignored or won't be passed
 	// Send message to simulator to force grabbed controls to be
 	// released, in case of a poorly written script.
 	void			forceReleaseControls();
diff --git a/indra/newview/lltool.cpp b/indra/newview/lltool.cpp
index 4aad650b68..5e703933ca 100644
--- a/indra/newview/lltool.cpp
+++ b/indra/newview/lltool.cpp
@@ -38,6 +38,7 @@
 #include "lltoolfocus.h"
 #include "llfocusmgr.h"
 #include "llagent.h"
+#include "llagentcamera.h"
 #include "llviewerjoystick.h"
 
 extern BOOL gDebugClicks;
@@ -84,7 +85,14 @@ BOOL LLTool::handleMouseDown(S32 x, S32 y, MASK mask)
 	}
 	// by default, didn't handle it
 	// LL_INFOS() << "LLTool::handleMouseDown" << LL_ENDL;
-	gAgent.setControlFlags(AGENT_CONTROL_LBUTTON_DOWN);
+    if (gAgentCamera.cameraMouselook())
+    {
+        gAgent.setControlFlags(AGENT_CONTROL_ML_LBUTTON_DOWN);
+    }
+    else
+    {
+        gAgent.setControlFlags(AGENT_CONTROL_LBUTTON_DOWN);
+    }
 	return TRUE;
 }
 
@@ -95,8 +103,15 @@ BOOL LLTool::handleMouseUp(S32 x, S32 y, MASK mask)
 		LL_INFOS() << "LLTool left mouse up" << LL_ENDL;
 	}
 	// by default, didn't handle it
-	// LL_INFOS() << "LLTool::handleMouseUp" << LL_ENDL;
-	gAgent.setControlFlags(AGENT_CONTROL_LBUTTON_UP);
+    // LL_INFOS() << "LLTool::handleMouseUp" << LL_ENDL;
+    if (gAgentCamera.cameraMouselook())
+    {
+        gAgent.setControlFlags(AGENT_CONTROL_ML_LBUTTON_UP);
+    }
+    else
+    {
+        gAgent.setControlFlags(AGENT_CONTROL_LBUTTON_UP);
+    }
 	return TRUE;
 }
 
diff --git a/indra/newview/lltoolcomp.cpp b/indra/newview/lltoolcomp.cpp
index 76a791c6e9..2b4fa757f6 100644
--- a/indra/newview/lltoolcomp.cpp
+++ b/indra/newview/lltoolcomp.cpp
@@ -742,12 +742,13 @@ BOOL LLToolCompGun::handleHover(S32 x, S32 y, MASK mask)
 
 BOOL LLToolCompGun::handleMouseDown(S32 x, S32 y, MASK mask)
 { 
-	// if the left button is grabbed, don't put up the pie menu
-	if (gAgent.leftButtonGrabbed())
-	{
-		gAgent.setControlFlags(AGENT_CONTROL_ML_LBUTTON_DOWN);
-		return FALSE;
-	}
+    // if the left button is blocked, don't put up the pie menu
+    if (gAgent.leftButtonBlocked())
+    {
+        // in case of "grabbed" control flag will be set later
+        gAgent.setControlFlags(AGENT_CONTROL_ML_LBUTTON_DOWN);
+        return FALSE;
+    }
 
 	// On mousedown, start grabbing
 	gGrabTransientTool = this;
@@ -759,12 +760,13 @@ BOOL LLToolCompGun::handleMouseDown(S32 x, S32 y, MASK mask)
 
 BOOL LLToolCompGun::handleDoubleClick(S32 x, S32 y, MASK mask)
 {
-	// if the left button is grabbed, don't put up the pie menu
-	if (gAgent.leftButtonGrabbed())
-	{
-		gAgent.setControlFlags(AGENT_CONTROL_ML_LBUTTON_DOWN);
-		return FALSE;
-	}
+    // if the left button is blocked, don't put up the pie menu
+    if (gAgent.leftButtonBlocked())
+    {
+        // in case of "grabbed" control flag will be set later
+        gAgent.setControlFlags(AGENT_CONTROL_ML_LBUTTON_DOWN);
+        return FALSE;
+    }
 
 	// On mousedown, start grabbing
 	gGrabTransientTool = this;
diff --git a/indra/newview/lltoolgrab.cpp b/indra/newview/lltoolgrab.cpp
index 92e8af985b..c0ca4d7a9a 100644
--- a/indra/newview/lltoolgrab.cpp
+++ b/indra/newview/lltoolgrab.cpp
@@ -143,7 +143,7 @@ BOOL LLToolGrab::handleMouseDown(S32 x, S32 y, MASK mask)
 	// call the base class to propogate info to sim
 	LLTool::handleMouseDown(x, y, mask);
 	
-	if (!gAgent.leftButtonGrabbed())
+	if (!gAgent.leftButtonBlocked())
 	{
 		// can grab transparent objects (how touch event propagates, scripters rely on this)
 		gViewerWindow->pickAsync(x, y, mask, pickCallback, /*BOOL pick_transparent*/ TRUE);
-- 
cgit v1.2.3