vcl/inc/salwtype.hxx          |    1 
 vcl/source/window/winproc.cxx |   47 +++++++++++++++++-------------------------
 2 files changed, 21 insertions(+), 27 deletions(-)

New commits:
commit ba10746f37b6176d2fa4aca85fc1c786f8e812e2
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Sep 10 12:27:51 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Sep 10 20:45:29 2025 +0200

    tdf#152519 vcl: Report IM cursor position
    
    Based on previous commit
    
        Change-Id: I46fdff87e84fbbe62f9b60b50376b6123d59fdac
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Wed Sep 10 10:53:18 2025 +0200
    
            tdf#152519 Distinguish cursor/anchor for IM selection
    
    , add SalSurroundingTextRequestEvent::mnCursorPos to report
    the cursor position as well in such an IM request.
    
    Instead of normalizing the Selection, use Selection::End()
    for the cursor position (see above-mentioned commit for more
    details) and std::min/std::max to identify the start/end
    index of the selection. Semantic for start/end index of the
    remains the same, so this commit shouldn't result in any change
    of behavior yet.
    
    This commit prepares for porting
    QtWidget::inputMethodQuery/lcl_retrieveSurrounding
    from using a11y API to using SalEvent::SurroundingTextRequest,
    similar to what
    
        commit ce5e41ab99af350ca8f4b9fef3017d53f3526f83
        Author: Caolán McNamara <caol...@redhat.com>
        Date:   Sun Oct 25 15:14:56 2020 +0000
    
            Related: tdf#137620 use existing SalEvent::SurroundingTextRequest
    
    did for gtk3.
    
    Change-Id: I600b834737e4e46a60491b91e64f8f8bc4ad806c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190747
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx
index 8a61dd73562c..27240fca0baf 100644
--- a/vcl/inc/salwtype.hxx
+++ b/vcl/inc/salwtype.hxx
@@ -210,6 +210,7 @@ struct SalSurroundingTextRequestEvent
     OUString        maText;         // Text
     sal_uLong       mnStart;        // The beginning index of selected range
     sal_uLong       mnEnd;          // The end index of selected range
+    sal_uLong       mnCursorPos;    // The cursor index (either mnStart or 
mnEnd)
 };
 
 struct SalSurroundingTextSelectionChangeEvent
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index ca3ac37e8acf..a75eb6ada250 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -2567,21 +2567,26 @@ static void ImplHandleSalSurroundingTextRequest( 
vcl::Window *pWindow,
     pEvt->maText = pChild->GetSurroundingText();
     Selection aSelRange = pChild->GetSurroundingTextSelection();
 
-    aSelRange.Normalize();
+    sal_uLong nSelectionAnchorPos = 0;
+    sal_uLong nCursorPos = 0;
 
     if( aSelRange.Min() < 0 )
-        pEvt->mnStart = 0;
+        nSelectionAnchorPos = 0;
     else if( aSelRange.Min() > pEvt->maText.getLength() )
-        pEvt->mnStart = pEvt->maText.getLength();
+        nSelectionAnchorPos = pEvt->maText.getLength();
     else
-        pEvt->mnStart = aSelRange.Min();
+        nSelectionAnchorPos = aSelRange.Min();
 
     if( aSelRange.Max() < 0 )
-        pEvt->mnEnd = 0;
+        nCursorPos = 0;
     else if( aSelRange.Max() > pEvt->maText.getLength() )
-        pEvt->mnEnd = pEvt->maText.getLength();
+        nCursorPos = pEvt->maText.getLength();
     else
-        pEvt->mnEnd = aSelRange.Max();
+        nCursorPos = aSelRange.Max();
+
+    pEvt->mnCursorPos = nCursorPos;
+    pEvt->mnStart = std::min(nSelectionAnchorPos, nCursorPos);
+    pEvt->mnEnd = std::max(nSelectionAnchorPos, nCursorPos);
 }
 
 static void ImplHandleSalDeleteSurroundingTextRequest( vcl::Window *pWindow,
commit fc6e57f77e2ba0c6fd2523d8e23e68924963ed76
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Sep 10 11:32:36 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Sep 10 20:45:23 2025 +0200

    tdf#152519 vcl: Fix potential copy paste error in IM code
    
    Using SalSurroundingTextRequestEvent::mnStart instead
    of SalSurroundingTextRequestEvent::mnEnd here
    as in the above case looks like a copy paste error from
    
        commit 011bcd1ea1e8ce10f6b9946d8d44d05a59387b8c
        Author: Rüdiger Timm <r...@openoffice.org>
        Date:   Wed Oct 29 09:25:50 2008 +0000
    
            CWS-TOOLING: integrate CWS vcl95
    
    , so adjust it to use SalSurroundingTextRequestEvent::mnEnd.
    
    Change-Id: Ifec51825468cf52b0e91d8483b727336aea93f4e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190746
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index e106e15fff52..ca3ac37e8acf 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -2577,7 +2577,7 @@ static void ImplHandleSalSurroundingTextRequest( 
vcl::Window *pWindow,
         pEvt->mnStart = aSelRange.Min();
 
     if( aSelRange.Max() < 0 )
-        pEvt->mnStart = 0;
+        pEvt->mnEnd = 0;
     else if( aSelRange.Max() > pEvt->maText.getLength() )
         pEvt->mnEnd = pEvt->maText.getLength();
     else
commit 8ebbda5ebe1686f175ed00502d85655ac1977a8e
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Sep 10 11:21:21 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Sep 10 20:45:16 2025 +0200

    tdf#152519 vcl: Merge both ImplHandleSalSurroundingTextRequest
    
    Change-Id: I997bc20f988b50de3c040c4117818450c752a99c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190745
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index 801ef8499d9f..e106e15fff52 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -2552,32 +2552,20 @@ static bool ImplHandleShowDialog( vcl::Window* pWindow, 
ShowDialogId nDialogId )
     return ImplCallCommand( pWindow, CommandEventId::ShowDialog, &aCmdData );
 }
 
-static void ImplHandleSurroundingTextRequest( vcl::Window *pWindow,
-                          OUString& rText,
-                          Selection &rSelRange )
+static void ImplHandleSalSurroundingTextRequest( vcl::Window *pWindow,
+                         SalSurroundingTextRequestEvent *pEvt )
 {
     vcl::Window* pChild = ImplGetKeyInputWindow( pWindow );
-
     if ( !pChild )
     {
-        rText.clear();
-        rSelRange.setMin( 0 );
-        rSelRange.setMax( 0 );
-    }
-    else
-    {
-        rText = pChild->GetSurroundingText();
-        Selection aSel = pChild->GetSurroundingTextSelection();
-        rSelRange.setMin( aSel.Min() );
-        rSelRange.setMax( aSel.Max() );
+        pEvt->maText.clear();
+        pEvt->mnStart = 0;
+        pEvt->mnEnd = 0;
+        return;
     }
-}
 
-static void ImplHandleSalSurroundingTextRequest( vcl::Window *pWindow,
-                         SalSurroundingTextRequestEvent *pEvt )
-{
-    Selection aSelRange;
-    ImplHandleSurroundingTextRequest( pWindow, pEvt->maText, aSelRange );
+    pEvt->maText = pChild->GetSurroundingText();
+    Selection aSelRange = pChild->GetSurroundingTextSelection();
 
     aSelRange.Normalize();
 

Reply via email to