From f72b866c9cf4f07fce6744fbf482c4c6488106e2 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Tue, 31 Jan 2017 00:32:48 +0300 Subject: tdf#105625: allow editing around field marks This commit fixes commit aa799f64723933bbb46544f835a970cfcbb90384, and partially reverts commits bd505fdb9f669f365ff39b0ef46f0742c638e333 and 9104d5e8905c2ec2b576b5ca452d3e23d5555e49 that seem unnecessary now. Unit test included, the existing unit tests of partially reverted commits are kept. Change-Id: I2a02cda546f5d484553c3b9467993fca36dae140 Reviewed-on: https://gerrit.libreoffice.org/33722 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- sw/qa/extras/uiwriter/data/tdf105625.fodt | 8 +++++ sw/qa/extras/uiwriter/data/tdf90362.fodt | 6 ++-- sw/qa/extras/uiwriter/uiwriter.cxx | 26 ++++++++++++++-- sw/source/core/crsr/pam.cxx | 52 +++++++++++-------------------- 4 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 sw/qa/extras/uiwriter/data/tdf105625.fodt (limited to 'sw') diff --git a/sw/qa/extras/uiwriter/data/tdf105625.fodt b/sw/qa/extras/uiwriter/data/tdf105625.fodt new file mode 100644 index 000000000000..44c0577d301b --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf105625.fodt @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/sw/qa/extras/uiwriter/data/tdf90362.fodt b/sw/qa/extras/uiwriter/data/tdf90362.fodt index bf74255aee7f..97db3d59a71a 100644 --- a/sw/qa/extras/uiwriter/data/tdf90362.fodt +++ b/sw/qa/extras/uiwriter/data/tdf90362.fodt @@ -3,8 +3,10 @@ Before - + + Inside + After - + \ No newline at end of file diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 0ddc4397b8a7..da819d402a23 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -226,6 +226,7 @@ public: void testTdf35021_tabOverMarginDemo(); void testTdf104492(); void testTdf105417(); + void testTdf105625(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -346,6 +347,7 @@ public: CPPUNIT_TEST(testTdf35021_tabOverMarginDemo); CPPUNIT_TEST(testTdf104492); CPPUNIT_TEST(testTdf105417); + CPPUNIT_TEST(testTdf105625); CPPUNIT_TEST_SUITE_END(); private: @@ -3030,17 +3032,21 @@ void SwUiWriterTest::testTdf88899() void SwUiWriterTest::testTdf90362() { - // First check if the end of the second paragraph is indeed protected. SwDoc* pDoc = createDoc("tdf90362.fodt"); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + uno::Reference xComponentContext(comphelper::getProcessComponentContext()); + // Ensure correct initial setting + comphelper::ConfigurationHelper::writeDirectKey(xComponentContext, "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea", css::uno::Any(false), comphelper::EConfigurationModes::Standard); + // First check if the end of the second paragraph is indeed protected. pWrtShell->EndPara(); pWrtShell->Down(/*bSelect=*/false); CPPUNIT_ASSERT_EQUAL(true, pWrtShell->HasReadonlySel()); // Then enable ignoring of protected areas and make sure that this time the cursor is read-write. - uno::Reference xComponentContext(comphelper::getProcessComponentContext()); comphelper::ConfigurationHelper::writeDirectKey(xComponentContext, "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea", css::uno::Any(true), comphelper::EConfigurationModes::Standard); CPPUNIT_ASSERT_EQUAL(false, pWrtShell->HasReadonlySel()); + // Clean up, otherwise following tests will have that option set + comphelper::ConfigurationHelper::writeDirectKey(xComponentContext, "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea", css::uno::Any(false), comphelper::EConfigurationModes::Standard); } void SwUiWriterTest::testUndoCharAttribute() @@ -4265,6 +4271,22 @@ void SwUiWriterTest::testTdf105417() aWrap.SpellDocument(); } +void SwUiWriterTest::testTdf105625() +{ + // We should be able to edit at positions adjacent to fields. + // Check if the start and the end of the only paragraph are not protected + // (they are adjacent to FORMCHECKBOX) + SwDoc* pDoc = createDoc("tdf105625.fodt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + uno::Reference xComponentContext(comphelper::getProcessComponentContext()); + // Ensure correct initial setting + comphelper::ConfigurationHelper::writeDirectKey(xComponentContext, "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea", css::uno::Any(false), comphelper::EConfigurationModes::Standard); + pWrtShell->SttPara(); + CPPUNIT_ASSERT_EQUAL(false, pWrtShell->HasReadonlySel()); + pWrtShell->EndPara(); + CPPUNIT_ASSERT_EQUAL(false, pWrtShell->HasReadonlySel()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index d5cf3da666e4..ee5ad68010ed 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -564,7 +564,7 @@ static const SwFrame* lcl_FindEditInReadonlyFrame( const SwFrame& rFrame ) } /// is in protected section or selection surrounds something protected -bool SwPaM::HasReadonlySel( bool bFormView, bool bAnnotationMode ) const +bool SwPaM::HasReadonlySel( bool bFormView, bool /*bAnnotationMode*/ ) const { bool bRet = false; @@ -675,32 +675,33 @@ bool SwPaM::HasReadonlySel( bool bFormView, bool bAnnotationMode ) const } } - //FIXME FieldBk - // TODO: Form Protection when Enhanced Fields are enabled const SwDoc *pDoc = GetDoc(); const IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess(); - sw::mark::IMark* pA = GetPoint() ? pMarksAccess->getFieldmarkFor( *GetPoint( ) ) : nullptr; - sw::mark::IMark* pB = GetMark( ) ? pMarksAccess->getFieldmarkFor( *GetMark( ) ) : pA; - - bool bUnhandledMark = false; - sw::mark::IFieldmark* pFieldmark = pMarksAccess->getFieldmarkFor( *GetPoint() ); - if ( pFieldmark ) - bUnhandledMark = pFieldmark->GetFieldname( ) == ODF_UNHANDLED; + sw::mark::IFieldmark* pA = GetPoint() ? pMarksAccess->getFieldmarkFor( *GetPoint( ) ) : nullptr; + sw::mark::IFieldmark* pB = GetMark() ? pMarksAccess->getFieldmarkFor( *GetMark( ) ) : pA; if (!bRet) { + bool bUnhandledMark = pA && pA->GetFieldname( ) == ODF_UNHANDLED; // Unhandled fieldmarks case shouldn't be edited manually to avoid breaking anything if ( ( pA == pB ) && bUnhandledMark ) bRet = true; else { - // Form protection case - bool bAtStartA = pA != nullptr && pA->GetMarkStart() == *GetPoint(); - bool bAtStartB = pB != nullptr && pB->GetMarkStart() == *GetMark(); - bRet = ( pA != pB ) || bAtStartA || bAtStartB; - bool bProtectForm = pDoc->GetDocumentSettingManager().get( DocumentSettingId::PROTECT_FORM ); - if ( bProtectForm ) - bRet |= ( pA == nullptr || pB == nullptr ); + bool bAtStartA = (pA != nullptr) && (pA->GetMarkStart() == *GetPoint()); + bool bAtStartB = (pB != nullptr) && (pB->GetMarkStart() == *GetMark()); + + if (pA != pB) + { + // If both points are either outside or at marks edges (i.e. selection either + // touches fields, or fully encloses it), then don't disable editing + bRet = !( ( !pA || bAtStartA ) && ( !pB || bAtStartB ) ); + } + if( !bRet && pDoc->GetDocumentSettingManager().get( DocumentSettingId::PROTECT_FORM ) ) + { + // Form protection case + bRet = ( pA == nullptr ) || ( pB == nullptr ) || ( bAtStartA ) || ( bAtStartB ); + } } } else @@ -708,23 +709,6 @@ bool SwPaM::HasReadonlySel( bool bFormView, bool bAnnotationMode ) const bRet = !( pA == pB && pA != nullptr ); } - // Don't allow inserting characters between the 'field mark end' and - // the 'comment anchor', unless the cursor is inside the annotation. - if (!bRet && !bAnnotationMode) - { - if (!pA && GetPoint() && GetPoint()->nNode.GetNode().IsTextNode() && GetPoint()->nContent.GetIndex() > 0) - { - // getFieldmarkFor() searches for >= start and < end, so check for - // the previous character, to also get the fieldmark, if we're - // exactly at the end. - SwPosition aPrevChar(*GetPoint()); - --aPrevChar.nContent; - pFieldmark = pMarksAccess->getFieldmarkFor(aPrevChar); - if (pFieldmark && pFieldmark->GetMarkEnd() == *GetPoint()) - bRet = true; - } - } - return bRet; } -- cgit