vcl/qt5/Qt5Widget.cxx |   54 ++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 46 insertions(+), 8 deletions(-)

New commits:
commit 6dcc1e233f248696165fc976513cdf3f09dac2bd
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Sat May 4 14:49:43 2019 +0000
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Wed May 15 23:21:33 2019 +0200

    Qt5 IM report selected text and anchor
    
    Implement the text selection IM queries. Never seen them, but
    since the text querying code is already there, it's easy to
    extend to include the selection. Anchor is the non-cursor
    position of the selection and should return the cursor in case
    of not selected text.
    
    Change-Id: I0e49a8593a5a6c6268395857748b5fc304372210
    Reviewed-on: https://gerrit.libreoffice.org/71797
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index 8db1e05e6cf2..a073ab67158d 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -559,7 +559,8 @@ void Qt5Widget::inputMethodEvent(QInputMethodEvent* pEvent)
     pEvent->accept();
 }
 
-static bool lcl_retrieveSurrounding(sal_Int32& rPosition, QString* pText)
+static bool lcl_retrieveSurrounding(sal_Int32& rPosition, sal_Int32& rAnchor, 
QString* pText,
+                                    QString* pSelection)
 {
     vcl::Window* pFocusWin = Application::GetFocusWindow();
     if (!pFocusWin)
@@ -576,17 +577,39 @@ static bool lcl_retrieveSurrounding(sal_Int32& rPosition, 
QString* pText)
     {
         SAL_WARN("vcl.qt5", "Exception in getting input method surrounding 
text: " << e);
     }
+
+    bool result = false;
     if (xText.is())
     {
         rPosition = xText->getCaretPosition();
-        if (rPosition != -1 && pText)
+        if (rPosition != -1)
         {
-            *pText = toQString(xText->getText());
+            result = true;
+            if (pText)
+                *pText = toQString(xText->getText());
+
+            sal_Int32 nSelStart = xText->getSelectionStart();
+            sal_Int32 nSelEnd = xText->getSelectionEnd();
+            if (nSelStart == nSelEnd)
+            {
+                rAnchor = rPosition;
+                if (pSelection)
+                    result = false;
+            }
+            else
+            {
+                if (rPosition == nSelStart)
+                    rAnchor = nSelEnd;
+                else
+                    rAnchor = nSelStart;
+                if (pSelection)
+                    *pSelection = toQString(xText->getSelectedText());
+            }
             return true;
         }
     }
 
-    return false;
+    return result;
 }
 
 QVariant Qt5Widget::inputMethodQuery(Qt::InputMethodQuery property) const
@@ -596,15 +619,15 @@ QVariant Qt5Widget::inputMethodQuery(Qt::InputMethodQuery 
property) const
         case Qt::ImSurroundingText:
         {
             QString aText;
-            sal_Int32 nCursorPos;
-            if (lcl_retrieveSurrounding(nCursorPos, &aText))
+            sal_Int32 nCursorPos, nAnchor;
+            if (lcl_retrieveSurrounding(nCursorPos, nAnchor, &aText, nullptr))
                 return QVariant(aText);
             [[fallthrough]];
         }
         case Qt::ImCursorPosition:
         {
-            sal_Int32 nCursorPos;
-            if (lcl_retrieveSurrounding(nCursorPos, nullptr))
+            sal_Int32 nCursorPos, nAnchor;
+            if (lcl_retrieveSurrounding(nCursorPos, nAnchor, nullptr, nullptr))
                 return QVariant(nCursorPos);
             [[fallthrough]];
         }
@@ -615,6 +638,21 @@ QVariant Qt5Widget::inputMethodQuery(Qt::InputMethodQuery 
property) const
             return QVariant(
                 QRect(aPosEvent.mnX, aPosEvent.mnY, aPosEvent.mnWidth, 
aPosEvent.mnHeight));
         }
+        case Qt::ImAnchorPosition:
+        {
+            sal_Int32 nCursorPos, nAnchor;
+            if (lcl_retrieveSurrounding(nCursorPos, nAnchor, nullptr, nullptr))
+                return QVariant(nAnchor);
+            [[fallthrough]];
+        }
+        case Qt::ImCurrentSelection:
+        {
+            QString aSelection;
+            sal_Int32 nCursorPos, nAnchor;
+            if (lcl_retrieveSurrounding(nCursorPos, nAnchor, nullptr, 
&aSelection))
+                return QVariant(aSelection);
+            [[fallthrough]];
+        }
         default:
             return QWidget::inputMethodQuery(property);
     }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to