sw/source/ui/index/cnttab.cxx       |   37 +++++++++++++++++++++++-------------
 sw/source/uibase/inc/swuicnttab.hxx |    5 ++--
 2 files changed, 27 insertions(+), 15 deletions(-)

New commits:
commit dbb054045fae8605794c17aae052a9d588fe33fc
Author:     Darshan-upadhyay1110 <darshan.upadh...@collabora.com>
AuthorDate: Thu Oct 3 18:31:22 2024 +0530
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Fri Oct 4 10:56:58 2024 +0200

    Refactor focus handling in `LevelHdl` and `SwTokenWindow`
    
    - Added a new `LevelHdlImpl` method with a `bool bGrabFocus` argument.
    - Refactored `LevelHdl` to call `LevelHdlImpl` with `true`.
    - Adjusted `SwTokenWindow::SetActiveControl` and `SwTokenWindow::SetForm` 
to skip `GrabFocus` when the argument is `false`.
    - Ensured focus behavior remains unchanged except for the initial 
"ActivatePage".
    
    Change-Id: If2f43e43f94c3762acd93974550ff0d2d66c6c21
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174423
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx
index 535dc298dd5a..287c117a217c 100644
--- a/sw/source/ui/index/cnttab.cxx
+++ b/sw/source/ui/index/cnttab.cxx
@@ -2263,7 +2263,7 @@ void SwTOXEntryTabPage::ActivatePage( const SfxItemSet& 
/*rSet*/)
 
     //invalidate PatternWindow
     m_xTokenWIN->SetInvalid();
-    LevelHdl(*m_xLevelLB);
+    LevelHdlImpl(*m_xLevelLB, false);
 }
 
 void SwTOXEntryTabPage::UpdateDescriptor()
@@ -2437,20 +2437,21 @@ void SwTOXEntryTabPage::WriteBackLevel()
     }
 }
 
-IMPL_LINK(SwTOXEntryTabPage, LevelHdl, weld::TreeView&, rBox, void)
+void SwTOXEntryTabPage::LevelHdlImpl(weld::TreeView& rBox, bool bGrabFocus)
 {
-    if(m_bInLevelHdl)
+    if (m_bInLevelHdl)
         return;
     m_bInLevelHdl = true;
     WriteBackLevel();
 
     const sal_uInt16 nLevel = rBox.get_selected_index();
-    m_xTokenWIN->SetForm(*m_pCurrentForm, nLevel);
+    m_xTokenWIN->SetForm(*m_pCurrentForm, nLevel, bGrabFocus);
+
     if(TOX_AUTHORITIES == m_pCurrentForm->GetTOXType())
     {
         //fill the types in
         m_xAuthFieldsLB->clear();
-        for( sal_uInt32 i = 0; i < AUTH_FIELD_END; i++)
+        for(sal_uInt32 i = 0; i < AUTH_FIELD_END; i++)
         {
             m_xAuthFieldsLB->append(OUString::number(i), 
SwResId(STR_AUTH_FIELD_ARY[i]));
         }
@@ -2471,9 +2472,19 @@ IMPL_LINK(SwTOXEntryTabPage, LevelHdl, weld::TreeView&, 
rBox, void)
         m_xAuthFieldsLB->set_active(0);
     }
     m_bInLevelHdl = false;
-    rBox.grab_focus();
+
+    if (bGrabFocus)
+    {
+        rBox.grab_focus();
+    }
 }
 
+IMPL_LINK(SwTOXEntryTabPage, LevelHdl, weld::TreeView&, rBox, void)
+{
+    LevelHdlImpl(rBox, true);
+}
+
+
 IMPL_LINK_NOARG(SwTOXEntryTabPage, SortKeyHdl, weld::Toggleable&, void)
 {
     bool bEnable = m_xSortContentRB->get_active();
@@ -2792,9 +2803,9 @@ SwTokenWindow::~SwTokenWindow()
 {
 }
 
-void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
+void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL, bool bGrabFocus)
 {
-    SetActiveControl(nullptr);
+    SetActiveControl(nullptr, bGrabFocus);
     m_bValid = true;
 
     if (m_pForm)
@@ -2821,7 +2832,7 @@ void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
                 SwTOXWidget* pCtrl = InsertItem(aToken.sText, aToken);
                 bLastWasText = true;
                 if (!GetActiveControl())
-                    SetActiveControl(pCtrl);
+                    SetActiveControl(pCtrl, bGrabFocus);
             }
             else
             {
@@ -2859,12 +2870,12 @@ void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 
nL)
             if(!pSetActiveControl)
                 pSetActiveControl = pCtrl;
         }
-        SetActiveControl(pSetActiveControl);
+        SetActiveControl(pSetActiveControl, bGrabFocus);
     }
     AdjustScrolling();
 }
 
-void SwTokenWindow::SetActiveControl(SwTOXWidget* pSet)
+void SwTokenWindow::SetActiveControl(SwTOXWidget* pSet, bool bGrabFocus)
 {
     if (pSet == m_pActiveCtrl)
         return;
@@ -2872,8 +2883,8 @@ void SwTokenWindow::SetActiveControl(SwTOXWidget* pSet)
     m_pActiveCtrl = pSet;
     if( !m_pActiveCtrl )
         return;
-
-    m_pActiveCtrl->GrabFocus();
+    if (bGrabFocus)
+        m_pActiveCtrl->GrabFocus();
     //it must be a SwTOXEdit
     const SwFormToken* pFToken;
     if( WindowType::EDIT == m_pActiveCtrl->GetType() )
diff --git a/sw/source/uibase/inc/swuicnttab.hxx 
b/sw/source/uibase/inc/swuicnttab.hxx
index 103f65e7cb93..8dfb3da9b6a7 100644
--- a/sw/source/uibase/inc/swuicnttab.hxx
+++ b/sw/source/uibase/inc/swuicnttab.hxx
@@ -261,7 +261,7 @@ class SwTokenWindow
     DECL_LINK(ScrollHdl, weld::ScrolledWindow&, void);
     DECL_LINK(AdjustPositionsHdl, const Size&, void);
 
-    void    SetActiveControl(SwTOXWidget* pSet);
+    void    SetActiveControl(SwTOXWidget* pSet, bool bGrabFocus = true);
 
     SwTOXWidget* InsertItem(const OUString& rText, const SwFormToken& aToken);
     void        AdjustPositions();
@@ -275,7 +275,7 @@ public:
 
     void SetTabPage(SwTOXEntryTabPage *pParent) { m_pParent = pParent; }
 
-    void        SetForm(SwForm& rForm, sal_uInt16 nLevel);
+    void        SetForm(SwForm& rForm, sal_uInt16 nLevel, bool bGrabFocus = 
true);
     sal_uInt16  GetLastLevel()const {return m_nLevel;};
 
     bool        IsValid() const {return m_bValid;}
@@ -388,6 +388,7 @@ class SwTOXEntryTabPage final : public SfxTabPage
     DECL_LINK(ModifyClickHdl, weld::Toggleable&, void);
 
     void ShowHideControls(int eType);
+    void LevelHdlImpl(weld::TreeView& rBox, bool bGrabFocus);
 
 public:
     SwTOXEntryTabPage(weld::Container* pPage, weld::DialogController* 
pController, const SfxItemSet& rAttrSet);

Reply via email to