Modified: openoffice/branches/ooxml-osba/main/xmloff/source/text/txtfldi.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/ooxml-osba/main/xmloff/source/text/txtfldi.cxx?rev=1551920&r1=1551919&r2=1551920&view=diff
==============================================================================
--- openoffice/branches/ooxml-osba/main/xmloff/source/text/txtfldi.cxx 
(original)
+++ openoffice/branches/ooxml-osba/main/xmloff/source/text/txtfldi.cxx Wed Dec 
18 12:36:23 2013
@@ -3750,39 +3750,58 @@ void XMLAnnotationImportContext::EndElem
 
     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 start 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 annotation at the start 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
+            }
+            if ( xPrevField.is() )
+            {
+                // So we are ending a previous annotation,
+                // let's create a text range covering the start 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
+        {
+            if ( mxField.is() || CreateField( mxField, sServicePrefix + 
GetServiceName() ) )
+            {
+                // set field properties
+                PrepareField( mxField );
+
+                // attach field to document
+                Reference < XTextContent > xTextContent( mxField, UNO_QUERY );
+
+                // workaround for #80606#
+                try
                 {
                     GetImportHelper().InsertTextContent( xTextContent );
                 }
-            }
-            catch (lang::IllegalArgumentException)
-            {
-                // ignore
+                catch (lang::IllegalArgumentException)
+                {
+                    // ignore
+                }
             }
         }
     }
@@ -3791,42 +3810,8 @@ void XMLAnnotationImportContext::EndElem
 }
 
 void XMLAnnotationImportContext::PrepareField(
-    const Reference<XPropertySet> & xPropertySet)
+    const Reference<XPropertySet> & xPropertySet )
 {
-    if ( m_nToken == XML_TOK_TEXT_ANNOTATION_END
-         && aName.getLength() > 0 )
-    {
-        // 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())
-        {
-            uno::Reference<beans::XPropertySet> 
xCurrField(xFields->nextElement(), uno::UNO_QUERY);
-            OUString aFieldName;
-            xCurrField->getPropertyValue(sPropertyName) >>= aFieldName;
-            if ( aFieldName == aName )
-            {
-                xPrevField = xCurrField;
-                break;
-            }
-        }
-        if (xPrevField.is())
-        {
-            // 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;
-        }
-    }
-
     // import (possibly empty) author
     OUString sAuthor( aAuthorBuffer.makeStringAndClear() );
     xPropertySet->setPropertyValue(sPropertyAuthor, makeAny(sAuthor));

Modified: openoffice/branches/ooxml-osba/main/xmloff/source/text/txtparae.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/ooxml-osba/main/xmloff/source/text/txtparae.cxx?rev=1551920&r1=1551919&r2=1551920&view=diff
==============================================================================
--- openoffice/branches/ooxml-osba/main/xmloff/source/text/txtparae.cxx 
(original)
+++ openoffice/branches/ooxml-osba/main/xmloff/source/text/txtparae.cxx Wed Dec 
18 12:36:23 2013
@@ -110,7 +110,6 @@
 #include <basegfx/polygon/b2dpolypolygon.hxx>
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
 #include <basegfx/polygon/b2dpolygontools.hxx>
-#include <xmloff/odffields.hxx>
 
 using ::rtl::OUString;
 using ::rtl::OUStringBuffer;
@@ -2222,9 +2221,11 @@ void XMLTextParagraphExport::exportTextR
     sal_Bool bPrvChrIsSpc )
 {
     static OUString sMeta(RTL_CONSTASCII_USTRINGPARAM("InContentMetadata"));
+    static OUString sAnnotation(RTL_CONSTASCII_USTRINGPARAM("Annotation"));
+    static OUString 
sAnnotationEnd(RTL_CONSTASCII_USTRINGPARAM("AnnotationEnd"));
+
     sal_Bool bPrevCharIsSpace = bPrvChrIsSpc;
-    bool bAnnotationStarted = false;
-    
+
     while( rTextEnum->hasMoreElements() )
     {
         Reference<XPropertySet> xPropSet(rTextEnum->nextElement(), UNO_QUERY);
@@ -2242,15 +2243,23 @@ void XMLTextParagraphExport::exportTextR
             }
             else if( sType.equals(sTextField))
             {
-                if ( bAnnotationStarted )
-                {
-                    bAnnotationStarted = false;
-                }
-                else
+                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 ) )
             {
@@ -2303,52 +2312,29 @@ void XMLTextParagraphExport::exportTextR
             }
             else if (sType.equals(sTextFieldStart))
             {
-                Reference< ::com::sun::star::text::XFormField > 
xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
-                if ( xFormField.is()
-                     && xFormField->getFieldType().equalsAscii( 
ODF_COMMENTRANGE ) )
+                Reference<XNamed> 
xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
+                if (xBookmark.is())
                 {
-                    exportTextField( xTxtRange, bAutoStyles, bIsProgress );
-                    bPrevCharIsSpace = false;
-                    bAnnotationStarted = true;
+                    GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, 
xBookmark->getName());
                 }
-                else
-                {
-                    Reference<XNamed> 
xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
-                    if (xBookmark.is())
-                    {
-                        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, 
xBookmark->getName());
-                    }
 
-                    if (xFormField.is())
-                    {
-                        GetExport().AddAttribute(XML_NAMESPACE_FIELD, 
XML_TYPE, xFormField->getFieldType());
-                    }
+                Reference< ::com::sun::star::text::XFormField > 
xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
+                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())
-                    {
-                        FieldParamExporter(&GetExport(), 
xFormField->getParameters()).Export();
-                    }
-                    GetExport().EndElement(XML_NAMESPACE_FIELD, 
XML_FIELDMARK_START, sal_False);
+                GetExport().StartElement(XML_NAMESPACE_FIELD, 
XML_FIELDMARK_START, sal_False);
+                if (xFormField.is())
+                {
+                    FieldParamExporter(&GetExport(), 
xFormField->getParameters()).Export();
                 }
+                GetExport().EndElement(XML_NAMESPACE_FIELD, 
XML_FIELDMARK_START, sal_False);
             }
             else if (sType.equals(sTextFieldEnd))
             {
-                if (bAnnotationStarted)
-                {
-                    Reference<XNamed> 
xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
-                    const OUString& rName = xBookmark->getName();
-                    if ( rName.getLength() > 0 )
-                    {
-                        GetExport().AddAttribute(XML_NAMESPACE_OFFICE, 
XML_NAME, rName);
-                    }
-                    SvXMLElementExport aElem( GetExport(), !bAutoStyles, 
XML_NAMESPACE_OFFICE, XML_ANNOTATION_END, sal_False, sal_False );
-                }
-                else
-                {
-                    GetExport().StartElement(XML_NAMESPACE_FIELD, 
XML_FIELDMARK_END, sal_False);
-                    GetExport().EndElement(XML_NAMESPACE_FIELD, 
XML_FIELDMARK_END, sal_False);
-                }
+                GetExport().StartElement(XML_NAMESPACE_FIELD, 
XML_FIELDMARK_END, sal_False);
+                GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_END, 
sal_False);
             }
             else if (sType.equals(sTextFieldStartEnd))
             {


Reply via email to