From 46e1bb558e9071e48835dc9cc8d28bb1e2d89884 Mon Sep 17 00:00:00 2001
From: andreykproductengine <akleshchev@productengine.com>
Date: Fri, 13 Jan 2017 17:20:08 +0200
Subject: [PATCH] MAINT-1747 Fixed after switching Preferences tabs, radio
 buttons don't get focus on click

---
 indra/llui/llradiogroup.cpp | 53 ++++++++++++++++++++++++++++---------
 indra/llui/llradiogroup.h   |  4 +--
 2 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/indra/llui/llradiogroup.cpp b/indra/llui/llradiogroup.cpp
index 8cf72928ffc..2c7e7ab13d8 100644
--- a/indra/llui/llradiogroup.cpp
+++ b/indra/llui/llradiogroup.cpp
@@ -54,6 +54,7 @@ class LLRadioCtrl : public LLCheckBoxCtrl
 	/*virtual*/ void setValue(const LLSD& value);
 
 	/*virtual*/ BOOL postBuild();
+	/*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask);
 
 	LLSD getPayload() { return mPayload; }
 
@@ -224,6 +225,22 @@ BOOL LLRadioGroup::setSelectedIndex(S32 index, BOOL from_event)
 	return TRUE;
 }
 
+void LLRadioGroup::focusSelectedRadioBtn()
+{
+    if (mSelectedIndex >= 0)
+    {
+        LLRadioCtrl* radio_item = mRadioButtons[mSelectedIndex];
+        if (radio_item->hasTabStop() && radio_item->getEnabled())
+        {
+            radio_item->focusFirstItem(FALSE, FALSE);
+        }
+    }
+    else if (mRadioButtons[0]->hasTabStop() || hasTabStop())
+    {
+        focusFirstItem(FALSE, FALSE);
+    }
+}
+
 BOOL LLRadioGroup::handleKeyHere(KEY key, MASK mask)
 {
 	BOOL handled = FALSE;
@@ -283,19 +300,6 @@ BOOL LLRadioGroup::handleKeyHere(KEY key, MASK mask)
 	return handled;
 }
 
-BOOL LLRadioGroup::handleMouseDown(S32 x, S32 y, MASK mask)
-{
-	// grab focus preemptively, before child button takes mousecapture
-	// 
-	if (hasTabStop())
-	{
-		focusFirstItem(FALSE, FALSE);
-	}
-
-	return LLUICtrl::handleMouseDown(x, y, mask);
-}
-
-
 // Handle one button being clicked.  All child buttons must have this
 // function as their callback function.
 
@@ -466,6 +470,29 @@ BOOL LLRadioCtrl::postBuild()
 	return TRUE;
 }
 
+BOOL LLRadioCtrl::handleMouseDown(S32 x, S32 y, MASK mask)
+{
+    // Grab focus preemptively, before button takes mousecapture
+    if (hasTabStop() && getEnabled())
+    {
+        focusFirstItem(FALSE, FALSE);
+    }
+    else
+    {
+        // Only currently selected item in group has tab stop as result it is
+        // unclear how focus should behave on click, just let the group handle
+        // focus and LLRadioGroup::onClickButton() will set correct state later
+        // if needed
+        LLRadioGroup* parent = (LLRadioGroup*)getParent();
+        if (parent)
+        {
+            parent->focusSelectedRadioBtn();
+        }
+    }
+
+    return LLCheckBoxCtrl::handleMouseDown(x, y, mask);
+}
+
 LLRadioCtrl::~LLRadioCtrl()
 {
 }
diff --git a/indra/llui/llradiogroup.h b/indra/llui/llradiogroup.h
index 8bd56985389..dcb2f43bfec 100644
--- a/indra/llui/llradiogroup.h
+++ b/indra/llui/llradiogroup.h
@@ -66,8 +66,6 @@ class LLRadioGroup
 	
 	virtual BOOL postBuild();
 	
-	virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
-	
 	virtual BOOL handleKeyHere(KEY key, MASK mask);
 
 	void setIndexEnabled(S32 index, BOOL enabled);
@@ -75,6 +73,8 @@ class LLRadioGroup
 	S32 getSelectedIndex() const { return mSelectedIndex; }
 	// set the index value programatically
 	BOOL setSelectedIndex(S32 index, BOOL from_event = FALSE);
+	// foxus child by index if it can get focus
+	void focusSelectedRadioBtn();
 
 	// Accept and retrieve strings of the radio group control names
 	virtual void	setValue(const LLSD& value );
-- 
GitLab