diff options
author | Oliver-Rainer Wittmann <orw@apache.org> | 2013-12-19 18:50:58 +0000 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-01-08 15:58:35 +0100 |
commit | 0761f81643a6890457e9ef7d913ab5c88c2593a4 (patch) | |
tree | 91bf122795dfac3f9263942ab3c5dee2b4ecea26 /xmloff | |
parent | df002e39f7518036ae1c1d2afec7a525ef902327 (diff) |
123792: complete annotations on text ranges feature
- rely annotations on text ranges on new annotation marks
- support arbitrary text ranges for annotations
- fix undo/redo regarding annotations an text ranges
- support annotations on overlapping text ranges
- fix *.docx import for annotations on overlapping text ranges
- fix ODF import of annotations on text ranges
cherry-picked from branch ooxml-osba
(cherry picked from commit ebd2922ebd3cf2d3899fb80780d38f367197aadf)
Conflicts:
sw/Library_sw.mk
sw/inc/IDocumentMarkAccess.hxx
sw/inc/SidebarWin.hxx
sw/inc/doc.hxx
sw/inc/docufld.hxx
sw/inc/hintids.hxx
sw/inc/ndhints.hxx
sw/inc/txatbase.hxx
sw/inc/unobookmark.hxx
sw/inc/unofield.hxx
sw/inc/unoport.hxx
sw/source/core/access/accpara.cxx
sw/source/core/bastyp/init.cxx
sw/source/core/crsr/bookmrk.cxx
sw/source/core/crsr/findtxt.cxx
sw/source/core/doc/dbgoutsw.cxx
sw/source/core/doc/docbm.cxx
sw/source/core/doc/doccorr.cxx
sw/source/core/doc/docdde.cxx
sw/source/core/doc/docedt.cxx
sw/source/core/doc/docfld.cxx
sw/source/core/doc/doclay.cxx
sw/source/core/doc/tblrwcl.cxx
sw/source/core/docnode/ndcopy.cxx
sw/source/core/docnode/nodes.cxx
sw/source/core/docnode/section.cxx
sw/source/core/edit/edfld.cxx
sw/source/core/fields/docufld.cxx
sw/source/core/fields/postithelper.cxx
sw/source/core/fields/reffld.cxx
sw/source/core/inc/MarkManager.hxx
sw/source/core/inc/crossrefbookmark.hxx
sw/source/core/text/inftxt.cxx
sw/source/core/text/itratr.cxx
sw/source/core/text/txtfrm.cxx
sw/source/core/txtnode/atrfld.cxx
sw/source/core/txtnode/ndtxt.cxx
sw/source/core/txtnode/thints.cxx
sw/source/core/undo/undel.cxx
sw/source/core/undo/undobj.cxx
sw/source/core/unocore/unofield.cxx
sw/source/core/unocore/unoport.cxx
sw/source/core/unocore/unoportenum.cxx
sw/source/filter/html/htmlatr.cxx
sw/source/filter/html/htmlgrin.cxx
sw/source/filter/html/wrthtml.cxx
sw/source/filter/writer/writer.cxx
sw/source/filter/ww1/fltshell.cxx
sw/source/filter/ww8/wrtw8nds.cxx
sw/source/filter/ww8/ww8par.cxx
sw/source/ui/dialog/uiregionsw.cxx
sw/source/ui/dochdl/swdtflvr.cxx
sw/source/ui/docvw/PostItMgr.cxx
sw/source/ui/docvw/SidebarWin.cxx
sw/source/ui/fldui/fldmgr.cxx
sw/source/ui/fldui/fldref.cxx
sw/source/ui/inc/fldmgr.hxx
sw/source/ui/inc/wrtsh.hxx
sw/source/ui/shells/textfld.cxx
sw/source/ui/uiview/view2.cxx
sw/source/ui/utlui/navipi.cxx
sw/source/ui/wrtsh/wrtsh2.cxx
writerfilter/source/dmapper/DomainMapper_Impl.cxx
writerfilter/source/dmapper/DomainMapper_Impl.hxx
writerfilter/source/dmapper/PropertyMap.cxx
xmloff/inc/txtfldi.hxx
xmloff/source/text/txtfldi.cxx
xmloff/source/text/txtparae.cxx
Change-Id: Ie4cc467dbb837054c73742262ee20f35c151ff3f
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/inc/txtfldi.hxx | 6 | ||||
-rw-r--r-- | xmloff/source/text/txtfldi.cxx | 110 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 49 |
3 files changed, 69 insertions, 96 deletions
diff --git a/xmloff/inc/txtfldi.hxx b/xmloff/inc/txtfldi.hxx index 4c60f1100a18..1ee1680966a1 100644 --- a/xmloff/inc/txtfldi.hxx +++ b/xmloff/inc/txtfldi.hxx @@ -1219,8 +1219,7 @@ class XMLAnnotationImportContext : public XMLTextFieldImportContext com::sun::star::uno::Reference < com::sun::star::beans::XPropertySet > mxField; com::sun::star::uno::Reference < com::sun::star::text::XTextCursor > mxCursor; com::sun::star::uno::Reference < com::sun::star::text::XTextCursor > mxOldCursor; - /// If this is an annotation end, then position of the start. - com::sun::star::uno::Reference < com::sun::star::text::XTextContent > m_xStart; + sal_uInt16 m_nToken; public: @@ -1239,8 +1238,7 @@ protected: /// set properties virtual void PrepareField( - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertySet> & xPropertySet); + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xPropertySet); virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, 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 ) { |