sc/source/ui/app/inputwin.cxx |  168 ++++++++++++++++++++++--------------------
 1 file changed, 89 insertions(+), 79 deletions(-)

New commits:
commit 470bde6e0cd94ac829ba08d9aa22a85cadcd4329
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sat Nov 22 22:12:08 2025 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sun Nov 23 15:34:36 2025 +0100

    Resolves: tdf#169521 forward IM events like KeyEvents for inputbar
    
    which should also fix tdf#155453 formatting lost when formula bar edited 
via IM
    
    Change-Id: Ifabc029808f54b123ca88f58b5d64e0afaf40392
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194368
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index 1b8b8a7d8038..8c4d12528865 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -1718,98 +1718,110 @@ bool ScTextWnd::Command( const CommandEvent& rCEvt )
     CommandEventId nCommand = rCEvt.GetCommand();
 
     ScModule* pScMod = ScModule::get();
-    ScTabViewShell* pStartViewSh = ScTabViewShell::GetActiveViewShell();
 
-    // don't modify the font defaults here - the right defaults are
-    // already set in StartEditEngine when the EditEngine is created
+    bool bExtInput = nCommand == CommandEventId::StartExtTextInput ||
+                     nCommand == CommandEventId::EndExtTextInput ||
+                     nCommand == CommandEventId::ExtTextInput ||
+                     nCommand == CommandEventId::CursorPos ||
+                     nCommand == CommandEventId::QueryCharPosition;
 
-    // Prevent that the EditView is lost when switching between Views
-    pScMod->SetInEditCommand( true );
-    m_xEditView->Command( rCEvt );
-    pScMod->SetInEditCommand( false );
-
-    //  CommandEventId::StartDrag does not mean by far that the content was 
actually changed,
-    //  so don't trigger an InputChanged.
-    //! Detect if dragged with Move or forbid Drag&Move somehow
-
-    if ( nCommand == CommandEventId::StartDrag )
+    if (bExtInput)
     {
-        // Is dragged onto another View?
-        ScTabViewShell* pEndViewSh = ScTabViewShell::GetActiveViewShell();
-        if ( pEndViewSh != pStartViewSh && pStartViewSh != nullptr )
+        if (ScInputHandler* pInputHdl = pScMod->GetInputHdl())
         {
-            ScViewData& rViewData = pStartViewSh->GetViewData();
-            ScInputHandler* pHdl = pScMod->GetInputHdl( pStartViewSh );
-            if ( pHdl && rViewData.HasEditView( rViewData.GetActivePart() ) )
-            {
-                pHdl->CancelHandler();
-                rViewData.GetView()->ShowCursor(); // Missing for 
KillEditView, due to being inactive
-            }
+            // Similar to ScGridWindow::Command (and ScTextWnd::KeyInput)
+            // forward the CommandEvent to both EditEngines, the inputbar one
+            // and the main document one.
+            pInputHdl->InputCommand(rCEvt);
+            bConsumed = true;
         }
     }
-    else if ( nCommand == CommandEventId::EndExtTextInput )
+    else
     {
-        if (bFormulaMode)
+        ScTabViewShell* pStartViewSh = ScTabViewShell::GetActiveViewShell();
+
+        // don't modify the font defaults here - the right defaults are
+        // already set in StartEditEngine when the EditEngine is created
+
+        // Prevent that the EditView is lost when switching between Views
+        pScMod->SetInEditCommand( true );
+        m_xEditView->Command( rCEvt );
+        pScMod->SetInEditCommand( false );
+
+        //  CommandEventId::StartDrag does not mean by far that the content 
was actually changed,
+        //  so don't trigger an InputChanged.
+        //! Detect if dragged with Move or forbid Drag&Move somehow
+
+        if ( nCommand == CommandEventId::StartDrag )
         {
-            ScInputHandler* pHdl = pScMod->GetInputHdl();
-            if (pHdl)
-                pHdl->InputCommand(rCEvt);
+            // Is dragged onto another View?
+            ScTabViewShell* pEndViewSh = ScTabViewShell::GetActiveViewShell();
+            if ( pEndViewSh != pStartViewSh && pStartViewSh != nullptr )
+            {
+                ScViewData& rViewData = pStartViewSh->GetViewData();
+                ScInputHandler* pHdl = pScMod->GetInputHdl( pStartViewSh );
+                if ( pHdl && rViewData.HasEditView( rViewData.GetActivePart() 
) )
+                {
+                    pHdl->CancelHandler();
+                    rViewData.GetView()->ShowCursor(); // Missing for 
KillEditView, due to being inactive
+                }
+            }
         }
-        pScMod->InputChanged(m_xEditView.get());
-    }
-    else if ( nCommand == CommandEventId::CursorPos )
-    {
-        //  don't call InputChanged for CommandEventId::CursorPos
-    }
-    else if ( nCommand == CommandEventId::InputLanguageChange )
-    {
-        // #i55929# Font and font size state depends on input language if 
nothing is selected,
-        // so the slots have to be invalidated when the input language is 
changed.
-
-        SfxViewFrame* pViewFrm = SfxViewFrame::Current();
-        if (pViewFrm)
+        else if ( nCommand == CommandEventId::InputLanguageChange )
         {
-            SfxBindings& rBindings = pViewFrm->GetBindings();
-            rBindings.Invalidate( SID_ATTR_CHAR_FONT );
-            rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
+            // #i55929# Font and font size state depends on input language if 
nothing is selected,
+            // so the slots have to be invalidated when the input language is 
changed.
+
+            SfxViewFrame* pViewFrm = SfxViewFrame::Current();
+            if (pViewFrm)
+            {
+                SfxBindings& rBindings = pViewFrm->GetBindings();
+                rBindings.Invalidate( SID_ATTR_CHAR_FONT );
+                rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
+            }
         }
-    }
-    else if ( nCommand == CommandEventId::ContextMenu )
-    {
-        bConsumed = true;
-        SfxViewFrame* pViewFrm = SfxViewFrame::Current();
-        if (pViewFrm)
+        else if ( nCommand == CommandEventId::ContextMenu )
         {
-            Point aPos = rCEvt.GetMousePosPixel();
-            if (!rCEvt.IsMouseEvent())
+            bConsumed = true;
+            SfxViewFrame* pViewFrm = SfxViewFrame::Current();
+            if (pViewFrm)
             {
-                Size aSize = GetOutputSizePixel();
-                aPos = Point(aSize.Width() / 2, aSize.Height() / 2);
+                Point aPos = rCEvt.GetMousePosPixel();
+                if (!rCEvt.IsMouseEvent())
+                {
+                    Size aSize = GetOutputSizePixel();
+                    aPos = Point(aSize.Width() / 2, aSize.Height() / 2);
+                }
+                if (IsMouseCaptured())
+                    ReleaseMouse();
+                UpdateFocus();
+                pViewFrm->GetDispatcher()->ExecutePopup(u"formulabar"_ustr, 
&mrGroupBar.GetVclParent(), &aPos);
             }
-            if (IsMouseCaptured())
-                ReleaseMouse();
-            UpdateFocus();
-            pViewFrm->GetDispatcher()->ExecutePopup(u"formulabar"_ustr, 
&mrGroupBar.GetVclParent(), &aPos);
+        }
+        else if ( nCommand == CommandEventId::Wheel )
+        {
+            //don't call InputChanged for CommandEventId::Wheel
+        }
+        else if ( nCommand == CommandEventId::GestureSwipe )
+        {
+            //don't call InputChanged for CommandEventId::GestureSwipe
+        }
+        else if ( nCommand == CommandEventId::GestureLongPress )
+        {
+            //don't call InputChanged for CommandEventId::GestureLongPress
+        }
+        else if ( nCommand == CommandEventId::ModKeyChange )
+        {
+            //pass alt press/release to parent impl
+        }
+        else
+        {
+            // I suspect this path doesn't get call anymore or its called
+            // and shouldn't be
+            SAL_WARN("sc.core", "Likely we lost input bar formatting");
+            pScMod->InputChanged(m_xEditView.get());
         }
     }
-    else if ( nCommand == CommandEventId::Wheel )
-    {
-        //don't call InputChanged for CommandEventId::Wheel
-    }
-    else if ( nCommand == CommandEventId::GestureSwipe )
-    {
-        //don't call InputChanged for CommandEventId::GestureSwipe
-    }
-    else if ( nCommand == CommandEventId::GestureLongPress )
-    {
-        //don't call InputChanged for CommandEventId::GestureLongPress
-    }
-    else if ( nCommand == CommandEventId::ModKeyChange )
-    {
-        //pass alt press/release to parent impl
-    }
-    else
-        pScMod->InputChanged(m_xEditView.get());
 
     if ( comphelper::LibreOfficeKit::isActive() && nCommand == 
CommandEventId::CursorPos )
     {
@@ -1819,8 +1831,6 @@ bool ScTextWnd::Command( const CommandEvent& rCEvt )
         StartEditEngine();
         TextGrabFocus();
 
-        ScModule* mod = ScModule::get();
-
         // information about paragraph is in additional data
         // information about position in a paragraph in a Mouse Pos
         // see vcl/jsdialog/executor.cxx "textselection" event
@@ -1835,7 +1845,7 @@ bool ScTextWnd::Command( const CommandEvent& rCEvt )
         nPosEnd = m_xEditView->GetPosNoField(nParaEnd, aSelectionStartEnd.Y());
 
         m_xEditView->SetSelection(ESelection(nParaStart, nPosStart, nParaEnd, 
nPosEnd));
-        mod->InputSelection(m_xEditView.get());
+        pScMod->InputSelection(m_xEditView.get());
 
         bConsumed = true;
     }

Reply via email to