Kaydet (Commit) 7140da91 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

tdf#124118 Qt5 post non-code keys via ExtTextInput

Originally I tried to implement the gtk3 way by shoving all key
input in some way through the QInputMethod. But that turned out
to be impossible, because all the nice input event filtering is
privately hidden in the platform abstraction. And it took me
much longer to realize that gtk3 is doing this.

Still the delivered code point in the KeyEvent is correct, so
this simply uses ExtTextInput events for non-code key events,
if LO has enabled input method support for a frame.

Change-Id: Ia9bb6baf013cf790deecb9675f8309e32294e982
Reviewed-on: https://gerrit.libreoffice.org/73322
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst ffed2de3
......@@ -48,6 +48,7 @@ class Qt5Widget : public QWidget
bool handleKeyEvent(QKeyEvent*, bool);
void handleMouseButtonEvent(QMouseEvent*, bool);
void commitText(const QString& aText) const;
virtual bool event(QEvent*) override;
......
......@@ -394,13 +394,35 @@ static sal_uInt16 GetKeyCode(int keyval, Qt::KeyboardModifiers modifiers)
return nCode;
}
void Qt5Widget::commitText(const QString& aText) const
{
SalExtTextInputEvent aInputEvent;
aInputEvent.mpTextAttr = nullptr;
aInputEvent.mnCursorFlags = 0;
aInputEvent.maText = toOUString(aText);
aInputEvent.mnCursorPos = aInputEvent.maText.getLength();
SolarMutexGuard aGuard;
vcl::DeletionListener aDel(&m_rFrame);
m_rFrame.CallCallback(SalEvent::ExtTextInput, &aInputEvent);
if (!aDel.isDeleted())
m_rFrame.CallCallback(SalEvent::EndExtTextInput, nullptr);
}
bool Qt5Widget::handleKeyEvent(QKeyEvent* pEvent, bool bDown)
{
SalKeyEvent aEvent;
sal_uInt16 nCode = GetKeyCode(pEvent->key(), pEvent->modifiers());
if (bDown && nCode == 0 && !pEvent->text().isEmpty()
&& testAttribute(Qt::WA_InputMethodEnabled))
{
commitText(pEvent->text());
return true;
}
SalKeyEvent aEvent;
aEvent.mnCharCode = (pEvent->text().isEmpty() ? 0 : pEvent->text().at(0).unicode());
aEvent.mnRepeat = 0;
aEvent.mnCode = GetKeyCode(pEvent->key(), pEvent->modifiers());
aEvent.mnCode = nCode;
aEvent.mnCode |= GetKeyModCode(pEvent->modifiers());
QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle);
......@@ -483,24 +505,13 @@ static ExtTextInputAttr lcl_MapUndrelineStyle(QTextCharFormat::UnderlineStyle us
void Qt5Widget::inputMethodEvent(QInputMethodEvent* pEvent)
{
SolarMutexGuard aGuard;
SalExtTextInputEvent aInputEvent;
aInputEvent.mpTextAttr = nullptr;
aInputEvent.mnCursorFlags = 0;
vcl::DeletionListener aDel(&m_rFrame);
if (!pEvent->commitString().isEmpty())
{
aInputEvent.maText = toOUString(pEvent->commitString());
aInputEvent.mnCursorPos = aInputEvent.maText.getLength();
if (!aDel.isDeleted())
m_rFrame.CallCallback(SalEvent::ExtTextInput, &aInputEvent);
if (!aDel.isDeleted())
m_rFrame.CallCallback(SalEvent::EndExtTextInput, nullptr);
}
commitText(pEvent->commitString());
else
{
SalExtTextInputEvent aInputEvent;
aInputEvent.mpTextAttr = nullptr;
aInputEvent.mnCursorFlags = 0;
aInputEvent.maText = toOUString(pEvent->preeditString());
aInputEvent.mnCursorPos = 0;
......@@ -549,8 +560,9 @@ void Qt5Widget::inputMethodEvent(QInputMethodEvent* pEvent)
const bool bIsEmpty = aInputEvent.maText.isEmpty();
if (m_bNonEmptyIMPreeditSeen || !bIsEmpty)
{
if (!aDel.isDeleted())
m_rFrame.CallCallback(SalEvent::ExtTextInput, &aInputEvent);
SolarMutexGuard aGuard;
vcl::DeletionListener aDel(&m_rFrame);
m_rFrame.CallCallback(SalEvent::ExtTextInput, &aInputEvent);
if (!aDel.isDeleted() && bIsEmpty)
m_rFrame.CallCallback(SalEvent::EndExtTextInput, nullptr);
m_bNonEmptyIMPreeditSeen = !bIsEmpty;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment