summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2019-05-04 14:49:43 +0000
committerJan-Marek Glogowski <glogow@fbihome.de>2019-05-15 23:21:33 +0200
commit6dcc1e233f248696165fc976513cdf3f09dac2bd (patch)
tree9ce0d2376ee0207ba564c752a880aef535831cda /vcl
parent7dc35d13e375cac1371ea491ee3bc46ef5ebf8a6 (diff)
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 <glogow@fbihome.de>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qt5/Qt5Widget.cxx54
1 files changed, 46 insertions, 8 deletions
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);
}