[Libreoffice-commits] core.git: desktop/qa desktop/source include/LibreOfficeKit include/vcl sw/inc sw/qa sw/source vcl/source
Pranav Kant
pranavk at collabora.co.uk
Thu Feb 8 07:40:47 UTC 2018
desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 +-
desktop/source/lib/init.cxx | 19 ++++++++++++++
include/LibreOfficeKit/LibreOfficeKit.h | 5 +++
include/LibreOfficeKit/LibreOfficeKit.hxx | 11 ++++++++
include/LibreOfficeKit/LibreOfficeKitEnums.h | 11 ++++++++
include/vcl/ITiledRenderable.hxx | 7 +++++
include/vcl/vclevent.hxx | 2 +
include/vcl/window.hxx | 1
sw/inc/unotxdoc.hxx | 2 +
sw/qa/extras/tiledrendering/tiledrendering.cxx | 33 +++++++++++++++++++++++++
sw/source/uibase/uno/unotxdoc.cxx | 22 ++++++++++++++++
vcl/source/window/window.cxx | 20 ++++++++++++++-
12 files changed, 134 insertions(+), 2 deletions(-)
New commits:
commit 7f9f58f3a304733f7089719a5a65eef8c68c2b8d
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Wed Feb 7 17:19:58 2018 +0530
sw lok: IME support + unit test
Change-Id: I557493db23dfa3529606050c86161628dbd722e7
Reviewed-on: https://gerrit.libreoffice.org/49354
Reviewed-by: pranavk <pranavk at collabora.co.uk>
Tested-by: pranavk <pranavk at collabora.co.uk>
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 4488aa8c155c..4d2d50644b16 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2291,10 +2291,11 @@ void DesktopLOKTest::testABI()
CPPUNIT_ASSERT_EQUAL(documentClassOffset(37), offsetof(struct _LibreOfficeKitDocumentClass, postWindowKeyEvent));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(38), offsetof(struct _LibreOfficeKitDocumentClass, postWindowMouseEvent));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(39), offsetof(struct _LibreOfficeKitDocumentClass, setViewLanguage));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(40), offsetof(struct _LibreOfficeKitDocumentClass, postExtTextInputEvent));
// Extending is fine, update this, and add new assert for the offsetof the
// new method
- CPPUNIT_ASSERT_EQUAL(documentClassOffset(40), sizeof(struct _LibreOfficeKitDocumentClass));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(41), sizeof(struct _LibreOfficeKitDocumentClass));
}
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index ab7b72d526dc..2165a781725a 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -540,6 +540,9 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis,
int nType,
int nCharCode,
int nKeyCode);
+static void doc_postExtTextInputEvent(LibreOfficeKitDocument* pThis,
+ int nType,
+ const char* pText);
static void doc_postWindowKeyEvent(LibreOfficeKitDocument* pThis,
unsigned nLOKWindowId,
int nType,
@@ -633,6 +636,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->initializeForRendering = doc_initializeForRendering;
m_pDocumentClass->registerCallback = doc_registerCallback;
m_pDocumentClass->postKeyEvent = doc_postKeyEvent;
+ m_pDocumentClass->postExtTextInputEvent = doc_postExtTextInputEvent;
m_pDocumentClass->postWindowKeyEvent = doc_postWindowKeyEvent;
m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
m_pDocumentClass->postWindowMouseEvent = doc_postWindowMouseEvent;
@@ -2288,9 +2292,24 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
return;
}
+
pDoc->postKeyEvent(nType, nCharCode, nKeyCode);
}
+static void doc_postExtTextInputEvent(LibreOfficeKitDocument* pThis, int nType, const char* pText)
+{
+ SolarMutexGuard aGuard;
+
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+ return;
+ }
+
+ pDoc->postExtTextInputEvent(nType, OUString::fromUtf8(OString(pText, strlen(pText))));
+}
+
static void doc_postWindowKeyEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId, int nType, int nCharCode, int nKeyCode)
{
SolarMutexGuard aGuard;
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index d42bd3434689..ebc112fb7bd5 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -300,6 +300,11 @@ struct _LibreOfficeKitDocumentClass
/// @see lok::Document::setViewLanguage().
void (*setViewLanguage) (LibreOfficeKitDocument* pThis, int nId, const char* language);
+ /// @see lok::Document::postExtTextInputEvent
+ void (*postExtTextInputEvent) (LibreOfficeKitDocument* pThis,
+ int nType,
+ const char* pText);
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 310b9cfcee88..0983560898a4 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -537,6 +537,17 @@ public:
mpDoc->pClass->setViewLanguage(mpDoc, nId, language);
}
+ /**
+ * Post the text input from external input window, like IME
+ *
+ * @param nType see LibreOfficeKitExtTextInputType
+ * @param pText Text for LOK_EXT_TEXTINPUT
+ */
+ void postExtTextInputEvent(int nType, const char* pText)
+ {
+ mpDoc->pClass->postExtTextInputEvent(mpDoc, nType, pText);
+ }
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index b1349b45a1c1..b90aa6279c41 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -582,6 +582,17 @@ LibreOfficeKitKeyEventType;
typedef enum
{
+ /// cf. SalEvent::ExtTextInput
+ LOK_EXT_TEXTINPUT,
+ /// cf. SalEvent::ExtTextInputPos
+ LOK_EXT_TEXTINPUT_POS,
+ /// cf. SalEvent::EndExtTextInput
+ LOK_EXT_TEXTINPUT_END
+}
+LibreOfficeKitExtTextInputType;
+
+typedef enum
+{
/// A pressed gesture has started.
LOK_MOUSEEVENT_MOUSEBUTTONDOWN,
/// A pressed gesture has finished.
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 4a89a4cb394b..135f74064afa 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -103,6 +103,13 @@ public:
virtual void postKeyEvent(int nType, int nCharCode, int nKeyCode) = 0;
/**
+ * Posts an external text input event
+ *
+ * @see lok::Document::postExtTextInputEvent().
+ */
+ virtual void postExtTextInputEvent(int /*nType*/, const OUString& /*rText*/) {}
+
+ /**
* Posts a mouse event on the document.
*
* @see lok::Document::postMouseEvent().
diff --git a/include/vcl/vclevent.hxx b/include/vcl/vclevent.hxx
index e56ed670cc1e..8f15df2228c4 100644
--- a/include/vcl/vclevent.hxx
+++ b/include/vcl/vclevent.hxx
@@ -59,6 +59,8 @@ enum class VclEventId
EditCaretChanged,
EditModify,
EditSelectionChanged,
+ ExtTextInput,
+ EndExtTextInput,
ItemCollapsed,
ItemExpanded,
ListboxDoubleClick,
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 7028255f5999..2cd63578b0f1 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -892,6 +892,7 @@ public:
void SetInputContext( const InputContext& rInputContext );
const InputContext& GetInputContext() const;
+ void PostExtTextInputEvent(VclEventId nType, const OUString& rText);
void EndExtTextInput();
void SetCursorRect( const tools::Rectangle* pRect = nullptr, long nExtTextInputWidth = 0 );
const tools::Rectangle* GetCursorRect() const;
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 770cf0c1d1d0..fe01d4722b6c 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -403,6 +403,8 @@ public:
virtual void initializeForTiledRendering(const css::uno::Sequence<css::beans::PropertyValue>& rArguments) override;
/// @see vcl::ITiledRenderable::postKeyEvent().
virtual void postKeyEvent(int nType, int nCharCode, int nKeyCode) override;
+ /// @see vcl::ITiledRenderable::postExtTextInputEvent().
+ virtual void postExtTextInputEvent(int nType, const OUString& rText) override;
/// @see vcl::ITiledRenderable::postMouseEvent().
virtual void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier) override;
/// @see vcl::ITiledRenderable::setTextSelection().
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index ab470e7436e9..cfd5fab7dc2f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -102,6 +102,7 @@ public:
void testPageFooter();
void testTdf115088();
void testRedlineField();
+ void testIMESupport();
CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
CPPUNIT_TEST(testRegisterCallback);
@@ -153,6 +154,7 @@ public:
CPPUNIT_TEST(testPageFooter);
CPPUNIT_TEST(testTdf115088);
CPPUNIT_TEST(testRedlineField);
+ CPPUNIT_TEST(testIMESupport);
CPPUNIT_TEST_SUITE_END();
private:
@@ -2088,6 +2090,37 @@ void SwTiledRenderingTest::testRedlineField()
comphelper::LibreOfficeKit::setActive(false);
}
+void SwTiledRenderingTest::testIMESupport()
+{
+ comphelper::LibreOfficeKit::setActive();
+ SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
+
+ SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
+ SwWrtShell* pWrtShell = pView->GetWrtShellPtr();
+
+ // sequence of chineese IME compositions when 'nihao' is typed in an IME
+ const std::vector<OString> aUtf8Inputs{ "年", "你", "你好", "你哈", "你好", "你好" };
+ std::vector<OUString> aInputs;
+ std::transform(aUtf8Inputs.begin(), aUtf8Inputs.end(),
+ std::back_inserter(aInputs), [](OString aInput) {
+ return OUString::fromUtf8(aInput);
+ });
+ for (const auto& aInput: aInputs)
+ {
+ pXTextDocument->postExtTextInputEvent(LOK_EXT_TEXTINPUT, aInput);
+ }
+ pXTextDocument->postExtTextInputEvent(LOK_EXT_TEXTINPUT_END, "");
+
+ // the cursor should be at position 2nd
+ SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), pShellCursor->GetPoint()->nContent.GetIndex());
+
+ // content contains only the last IME composition, not all
+ CPPUNIT_ASSERT_EQUAL(aInputs[aInputs.size() - 1].concat("Aaa bbb."), pShellCursor->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
+
+ comphelper::LibreOfficeKit::setActive(false);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index aa6e3395270b..19f7c24b2a37 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -25,7 +25,9 @@
#include <AnnotationWin.hxx>
#include <o3tl/any.hxx>
#include <osl/mutex.hxx>
+#include <vcl/commandevent.hxx>
#include <vcl/image.hxx>
+#include <vcl/vclevent.hxx>
#include <vcl/virdev.hxx>
#include <vcl/sysdata.hxx>
#include <vcl/svapp.hxx>
@@ -3493,6 +3495,26 @@ void SwXTextDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
}
}
+void SwXTextDocument::postExtTextInputEvent(int nType, const OUString& rText)
+{
+ SolarMutexGuard aGuard;
+
+ vcl::Window* pWindow = &(pDocShell->GetView()->GetEditWin());
+
+ CommandExtTextInputData aTextInputData(rText, nullptr, 0, 0, false);
+ switch (nType)
+ {
+ case LOK_EXT_TEXTINPUT:
+ pWindow->PostExtTextInputEvent(VclEventId::ExtTextInput, rText);
+ break;
+ case LOK_EXT_TEXTINPUT_END:
+ pWindow->PostExtTextInputEvent(VclEventId::EndExtTextInput, "");
+ break;
+ default:
+ assert(false && "Unhandled External Text input event!");
+ }
+}
+
void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
{
SolarMutexGuard aGuard;
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 22471ada2ff8..a9431e72ac49 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -26,6 +26,7 @@
#include <vcl/help.hxx>
#include <vcl/cursor.hxx>
#include <vcl/svapp.hxx>
+#include <vcl/vclevent.hxx>
#include <vcl/window.hxx>
#include <vcl/syswin.hxx>
#include <vcl/syschild.hxx>
@@ -2069,9 +2070,26 @@ void Window::SetInputContext( const InputContext& rInputContext )
ImplNewInputContext();
}
-void Window::EndExtTextInput()
+void Window::PostExtTextInputEvent(VclEventId nType, const OUString& rText)
{
+ switch (nType)
+ {
+ case VclEventId::ExtTextInput:
+ {
+ SalExtTextInputEvent aEvent { rText, nullptr, rText.getLength(), 0 };
+ ImplWindowFrameProc(this, SalEvent::ExtTextInput, &aEvent);
+ }
+ break;
+ case VclEventId::EndExtTextInput:
+ ImplWindowFrameProc(this, SalEvent::EndExtTextInput, nullptr);
+ break;
+ default:
+ assert(false);
+ }
+}
+void Window::EndExtTextInput()
+{
if ( mpWindowImpl->mbExtTextInput )
ImplGetFrame()->EndExtTextInput( EndExtTextInputFlags::Complete );
}
More information about the Libreoffice-commits
mailing list