diff --git a/sw/qa/extras/unowriter/data/section-table.fodt b/sw/qa/extras/unowriter/data/section-table.fodt new file mode 100644 index 000000000000..4f46ac086c91 --- /dev/null +++ b/sw/qa/extras/unowriter/data/section-table.fodt @@ -0,0 +1,162 @@ + + + GCC2024-11-25T12:23:18.3609789502024-11-25T12:24:38.999591414GCCPT1M22S1LibreOfficeDev/25.2.0.0.alpha0$Linux_X86_64 LibreOffice_project/10f916791e49306b51a6a299739b130fc2129de1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Table in section + + + + + + + + + + + + + + + + Outside section + + + \ No newline at end of file diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index 75f034a73773..51bd211a0a87 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -562,6 +562,37 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testSectionAnchorCopyTable) xCursor->getString()); } +CPPUNIT_TEST_FIXTURE(SwUnoWriter, testSectionAnchorProperties) +{ + createSwDoc("section-table.fodt"); + + uno::Reference const xTextSectionsSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference const xSections( + xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + + uno::Reference const xSection(xSections->getByIndex(0), uno::UNO_QUERY); + uno::Reference const xAnchor(xSection->getAnchor()); + uno::Reference const xAnchorProp(xAnchor, uno::UNO_QUERY); + + // the problem was that the property set didn't work + auto xSecFromProp = getProperty>(xAnchorProp, "TextSection"); + CPPUNIT_ASSERT_EQUAL(xSection, xSecFromProp); + + xAnchorProp->setPropertyValue("CharHeight", uno::Any(float(64))); + CPPUNIT_ASSERT_EQUAL(float(64), getProperty(xAnchorProp, "CharHeight")); + uno::Reference const xAnchorState(xAnchor, uno::UNO_QUERY); + // TODO: why does this return DEFAULT_VALUE instead of DIRECT_VALUE? + CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DEFAULT_VALUE, + xAnchorState->getPropertyState("CharHeight")); + CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DEFAULT_VALUE, + xAnchorState->getPropertyStates({ "CharHeight" })[0]); + CPPUNIT_ASSERT_EQUAL(float(12), xAnchorState->getPropertyDefault("CharHeight").get()); + xAnchorState->setPropertyToDefault("CharHeight"); + CPPUNIT_ASSERT_EQUAL(float(12), getProperty(xAnchorProp, "CharHeight")); +} + CPPUNIT_TEST_FIXTURE(SwUnoWriter, testTextRangeInTable) { createSwDoc("bookmarkintable.fodt"); diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 1e10a532c2a9..6b755eafc1af 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -364,7 +364,8 @@ void SwDoc::ResetAttrs( const SwPaM &rRg, ++aTmpStt; } - if( pEnd->GetContentIndex() == pEnd->GetNode().GetContentNode()->Len() ) + if (!pEnd->GetNode().IsContentNode() + || pEnd->GetContentIndex() == pEnd->GetNode().GetContentNode()->Len()) { // set up a later, and all CharFormatAttr -> TextFormatAttr ++aTmpEnd; diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index 4a3cd81c3c7f..d2910db91710 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -1470,12 +1470,12 @@ SwXTextRange::setPropertyValue( { SolarMutexGuard aGuard; - if (!m_pMark) + if (!m_pMark && (m_eRangePosition != RANGE_IS_SECTION || !m_pTableOrSectionFormat)) { throw uno::RuntimeException(u"range has no mark (table?)"_ustr); } SwPaM aPaM(GetDoc().GetNodes()); - GetPositions(aPaM); + GetPositions(aPaM, ::sw::TextRangeMode::AllowNonTextNode); SwUnoCursorHelper::SetPropertyValue(aPaM, m_rPropSet, rPropertyName, rValue); } @@ -1485,12 +1485,12 @@ SwXTextRange::getPropertyValue(const OUString& rPropertyName) { SolarMutexGuard aGuard; - if (!m_pMark) + if (!m_pMark && (m_eRangePosition != RANGE_IS_SECTION || !m_pTableOrSectionFormat)) { throw uno::RuntimeException(u"range has no mark (table?)"_ustr); } SwPaM aPaM(GetDoc().GetNodes()); - GetPositions(aPaM); + GetPositions(aPaM, ::sw::TextRangeMode::AllowNonTextNode); return SwUnoCursorHelper::GetPropertyValue(aPaM, m_rPropSet, rPropertyName); } @@ -1532,12 +1532,12 @@ SwXTextRange::getPropertyState(const OUString& rPropertyName) { SolarMutexGuard aGuard; - if (!m_pMark) + if (!m_pMark && (m_eRangePosition != RANGE_IS_SECTION || !m_pTableOrSectionFormat)) { throw uno::RuntimeException(u"range has no mark (table?)"_ustr); } SwPaM aPaM(GetDoc().GetNodes()); - GetPositions(aPaM); + GetPositions(aPaM, ::sw::TextRangeMode::AllowNonTextNode); return SwUnoCursorHelper::GetPropertyState(aPaM, m_rPropSet, rPropertyName); } @@ -1547,12 +1547,12 @@ SwXTextRange::getPropertyStates(const uno::Sequence< OUString >& rPropertyName) { SolarMutexGuard g; - if (!m_pMark) + if (!m_pMark && (m_eRangePosition != RANGE_IS_SECTION || !m_pTableOrSectionFormat)) { throw uno::RuntimeException(u"range has no mark (table?)"_ustr); } SwPaM aPaM(GetDoc().GetNodes()); - GetPositions(aPaM); + GetPositions(aPaM, ::sw::TextRangeMode::AllowNonTextNode); return SwUnoCursorHelper::GetPropertyStates(aPaM, m_rPropSet, rPropertyName); } @@ -1561,12 +1561,12 @@ void SAL_CALL SwXTextRange::setPropertyToDefault(const OUString& rPropertyName) { SolarMutexGuard aGuard; - if (!m_pMark) + if (!m_pMark && (m_eRangePosition != RANGE_IS_SECTION || !m_pTableOrSectionFormat)) { throw uno::RuntimeException(u"range has no mark (table?)"_ustr); } SwPaM aPaM(GetDoc().GetNodes()); - GetPositions(aPaM); + GetPositions(aPaM, ::sw::TextRangeMode::AllowNonTextNode); SwUnoCursorHelper::SetPropertyToDefault(aPaM, m_rPropSet, rPropertyName); } @@ -1576,12 +1576,12 @@ SwXTextRange::getPropertyDefault(const OUString& rPropertyName) { SolarMutexGuard aGuard; - if (!m_pMark) + if (!m_pMark && (m_eRangePosition != RANGE_IS_SECTION || !m_pTableOrSectionFormat)) { throw uno::RuntimeException(u"range has no mark (table?)"_ustr); } SwPaM aPaM(GetDoc().GetNodes()); - GetPositions(aPaM); + GetPositions(aPaM, ::sw::TextRangeMode::AllowNonTextNode); return SwUnoCursorHelper::GetPropertyDefault(aPaM, m_rPropSet, rPropertyName); }