diff options
Diffstat (limited to 'xmloff/source/text')
-rw-r--r-- | xmloff/source/text/txtfldi.cxx | 110 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 49 |
2 files changed, 67 insertions, 92 deletions
diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index 0369b42ac67e..b555e722fb5c 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -3704,84 +3704,68 @@ void XMLAnnotationImportContext::EndElement() if ( bValid ) { - if ( mxField.is() || CreateField( mxField, sServicePrefix + GetServiceName() ) ) + if ( m_nToken == XML_TOK_TEXT_ANNOTATION_END ) { - // set field properties - PrepareField( mxField ); - - // attach field to document - Reference < XTextContent > xTextContent( mxField, UNO_QUERY ); - - // workaround for #80606# - try + // Search for a previous annotation with the same name. + uno::Reference< text::XTextContent > xPrevField; { - if (m_nToken == XML_TOK_TEXT_ANNOTATION_END && m_xStart.is()) + Reference<XTextFieldsSupplier> xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + while (xFields->hasMoreElements()) { - // So we are ending a previous annotation, let's create a - // text range covering the old and the current position. - uno::Reference<text::XText> xText = GetImportHelper().GetText(); - uno::Reference<text::XTextCursor> xCursor = xText->createTextCursorByRange(m_xStart->getAnchor()); - xCursor->gotoRange(GetImportHelper().GetCursorAsRange(), true); - uno::Reference<text::XTextRange> xTextRange(xCursor, uno::UNO_QUERY); - xText->insertTextContent(xTextRange, xTextContent, !xCursor->isCollapsed()); - - // Now we can delete the old annotation with the incorrect position. - uno::Reference<lang::XComponent>(m_xStart, uno::UNO_QUERY)->dispose(); + uno::Reference<beans::XPropertySet> xCurrField(xFields->nextElement(), uno::UNO_QUERY); + OUString aFieldName; + xCurrField->getPropertyValue(sPropertyName) >>= aFieldName; + if ( aFieldName == aName ) + { + xPrevField.set( xCurrField, uno::UNO_QUERY ); + break; + } } - else - GetImportHelper().InsertTextContent( xTextContent ); } - catch (const lang::IllegalArgumentException&) + if ( xPrevField.is() ) { - // ignore + // So we are ending a previous annotation, + // let's create a text range covering the old and the current position. + uno::Reference<text::XText> xText = GetImportHelper().GetText(); + uno::Reference<text::XTextCursor> xCursor = + xText->createTextCursorByRange(xPrevField->getAnchor()); + xCursor->gotoRange(GetImportHelper().GetCursorAsRange(), true); + uno::Reference<text::XTextRange> xTextRange(xCursor, uno::UNO_QUERY); + + xText->insertTextContent(xTextRange, xPrevField, !xCursor->isCollapsed()); } } - } - else - GetImportHelper().InsertString(GetContent()); -} - -void XMLAnnotationImportContext::PrepareField( - const Reference<XPropertySet> & xPropertySet) -{ - if (m_nToken == XML_TOK_TEXT_ANNOTATION_END && !aName.isEmpty()) - { - // Search for a previous annotation with the same name. - Reference<XTextFieldsSupplier> xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY); - uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); - uno::Reference<beans::XPropertySet> xPrevField; - while (xFields->hasMoreElements()) + else { - uno::Reference<beans::XPropertySet> xCurrField(xFields->nextElement(), uno::UNO_QUERY); - uno::Reference<beans::XPropertySetInfo> xPropsInfo(xCurrField->getPropertySetInfo()); + if ( mxField.is() || CreateField( mxField, sServicePrefix + GetServiceName() ) ) + { + // set field properties + PrepareField( mxField ); - if (!xPropsInfo->hasPropertyByName(sPropertyName)) - continue; + // attach field to document + Reference < XTextContent > xTextContent( mxField, UNO_QUERY ); - OUString aFieldName; - xCurrField->getPropertyValue(sPropertyName) >>= aFieldName; - if (aFieldName == aName) - { - xPrevField = xCurrField; - break; + // workaround for #80606# + try + { + GetImportHelper().InsertTextContent( xTextContent ); + } + catch (lang::IllegalArgumentException) + { + // ignore + } } } - if (xPrevField.is()) - { - // Found? Then copy over the properties. - xPropertySet->setPropertyValue(sPropertyAuthor, xPrevField->getPropertyValue(sPropertyAuthor)); - xPropertySet->setPropertyValue(sPropertyInitials, xPrevField->getPropertyValue(sPropertyInitials)); - xPropertySet->setPropertyValue(sPropertyDate, xPrevField->getPropertyValue(sPropertyDate)); - xPropertySet->setPropertyValue(sPropertyName, xPrevField->getPropertyValue(sPropertyName)); - xPropertySet->setPropertyValue(sPropertyContent, xPrevField->getPropertyValue(sPropertyContent)); - - // And save a reference to it, so we can delete it later. - m_xStart.set(xPrevField, uno::UNO_QUERY); - return; - } } + else + GetImportHelper().InsertString(GetContent()); +} +void XMLAnnotationImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet ) +{ // import (possibly empty) author OUString sAuthor( aAuthorBuffer.makeStringAndClear() ); xPropertySet->setPropertyValue(sPropertyAuthor, makeAny(sAuthor)); diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 8835667d46ee..0dcdefce34bd 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -2180,6 +2180,9 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( { static const OUString sMeta("InContentMetadata"); static const OUString sFieldMarkName("__FieldMark_"); + static OUString sAnnotation("Annotation"); + static OUString sAnnotationEnd("AnnotationEnd"); + bool bPrevCharIsSpace = bPrvChrIsSpc; /* This is used for exporting to strict OpenDocument 1.2, in which case traditional @@ -2204,21 +2207,23 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( } else if( sType.equals(sTextField)) { - Reference< ::com::sun::star::text::XFormField > xFormField; - try - { - xFormField.set(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); - } - catch( const uno::Exception& ) - { - SAL_WARN("xmloff", "unexpected bookmark exception"); - } - - if (!xFormField.is() || xFormField->getFieldType() != ODF_COMMENTRANGE) + exportTextField( xTxtRange, bAutoStyles, bIsProgress ); + bPrevCharIsSpace = false; + } + else if ( sType.equals( sAnnotation ) ) + { + exportTextField( xTxtRange, bAutoStyles, bIsProgress ); + bPrevCharIsSpace = false; + } + else if ( sType.equals( sAnnotationEnd ) ) + { + Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); + const OUString& rName = xBookmark->getName(); + if ( rName.getLength() > 0 ) { - exportTextField( xTxtRange, bAutoStyles, bIsProgress ); - bPrevCharIsSpace = false; + GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME, rName); } + SvXMLElementExport aElem( GetExport(), !bAutoStyles, XML_NAMESPACE_OFFICE, XML_ANNOTATION_END, sal_False, sal_False ); } else if( sType.equals( sFrame ) ) { @@ -2279,11 +2284,6 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( else if (sType.equals(sTextFieldStart)) { Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); - if (xFormField.is() && xFormField->getFieldType() == ODF_COMMENTRANGE) - { - exportTextField( xTxtRange, bAutoStyles, bIsProgress ); - continue; - } /* As of now, textmarks are a proposed extension to the OpenDocument standard. */ if ( GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012 ) @@ -2293,10 +2293,12 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( { GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName()); } + if (xFormField.is()) { GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType()); } + GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False); if (xFormField.is()) { @@ -2346,17 +2348,6 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( else if (sType.equals(sTextFieldEnd)) { Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); - if (xFormField.is() && xFormField->getFieldType() == ODF_COMMENTRANGE) - { - Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); - const OUString& rName = xBookmark->getName(); - if (!rName.isEmpty()) - GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME, rName); - SvXMLElementExport aElem( GetExport(), !bAutoStyles, - XML_NAMESPACE_OFFICE, XML_ANNOTATION_END, - sal_False, sal_False ); - continue; - } if ( GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012 ) { |