From 69156936693d4e580bd986fc6dbd0026f4f4c2d0 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 12 Jan 2021 17:10:49 +0100 Subject: sw edit win: fix read-only selections while handling ExtTextInput When typing into a protected section (or other read-only area), the code goes through SwEditWin::KeyInput(), which checks for HasReadonlySel(), and calls into sw::DocumentContentOperationsManager::InsertString() in the read-write case. When typing via ExtTextInput (e.g. Online), then SwEditWin::Command() called into sw::DocumentContentOperationsManager::InsertString() without such a check. The convention is to do a read-only check in the first Writer function called by vcl, so handle this in SwEditWin::Command(), to have exactly 1 read-only popup on typing a character. (cherry picked from commit 0c03a97fb8844ad0de1abea79b5265617a509460) Conflicts: sw/qa/extras/tiledrendering/tiledrendering.cxx Change-Id: I7d002e7d76bffeb6f16750de735c5bbf13a7bba9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109232 Tested-by: Jenkins CollaboraOffice Reviewed-by: Miklos Vajna --- sw/qa/extras/tiledrendering/tiledrendering.cxx | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'sw/qa') diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index ac481a9f7148..992972e9893a 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,7 @@ public: void testDropDownFormFieldButtonNoSelection(); void testDropDownFormFieldButtonNoItem(); void testTablePaintInvalidate(); + void testExtTextInputReadOnly(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -198,6 +200,7 @@ public: CPPUNIT_TEST(testDropDownFormFieldButtonNoSelection); CPPUNIT_TEST(testDropDownFormFieldButtonNoItem); CPPUNIT_TEST(testTablePaintInvalidate); + CPPUNIT_TEST(testExtTextInputReadOnly); CPPUNIT_TEST_SUITE_END(); private: @@ -2770,6 +2773,36 @@ void SwTiledRenderingTest::testTablePaintInvalidate() CPPUNIT_ASSERT_EQUAL(0, m_nInvalidations); } +void SwTiledRenderingTest::testExtTextInputReadOnly() +{ + // Create a document with a protected section + a normal paragraph after it. + SwXTextDocument* pXTextDocument = createDoc(); + uno::Reference xController( + pXTextDocument->getCurrentController(), uno::UNO_QUERY); + uno::Reference xCursor = xController->getViewCursor(); + uno::Reference xText = xCursor->getText(); + uno::Reference xSection( + pXTextDocument->createInstance("com.sun.star.text.TextSection"), uno::UNO_QUERY); + uno::Reference xSectionProps(xSection, uno::UNO_QUERY); + xSectionProps->setPropertyValue("IsProtected", uno::Any(true)); + xText->insertTextContent(xCursor, xSection, /*bAbsorb=*/true); + + // First paragraph is the protected section, is it empty? + VclPtr pEditWin = pXTextDocument->getDocWindow(); + CPPUNIT_ASSERT(pEditWin); + CPPUNIT_ASSERT(getParagraph(1)->getString().isEmpty()); + + // Try to type into the protected section, is it still empty? + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/true); + SfxLokHelper::postExtTextEventAsync(pEditWin, LOK_EXT_TEXTINPUT, "x"); + SfxLokHelper::postExtTextEventAsync(pEditWin, LOK_EXT_TEXTINPUT_END, "x"); + Scheduler::ProcessEventsToIdle(); + // Without the accompanying fix in place, this test would have failed, as it was possible to + // type into the protected section. + CPPUNIT_ASSERT(getParagraph(1)->getString().isEmpty()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3