[Libreoffice-commits] core.git: Branch 'feature/ods-edit-cell-import' - 2 commits - sc/Library_sc.mk sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Thu Feb 7 19:26:19 PST 2013


 sc/Library_sc.mk                             |    3 
 sc/source/filter/xml/XMLTextPContext.cxx     |  209 ---------------------------
 sc/source/filter/xml/XMLTextPContext.hxx     |   65 --------
 sc/source/filter/xml/celltextparacontext.cxx |   98 ++++++++++++
 sc/source/filter/xml/celltextparacontext.hxx |   56 +++++++
 sc/source/filter/xml/importcontext.cxx       |   28 +++
 sc/source/filter/xml/importcontext.hxx       |   29 +++
 sc/source/filter/xml/xmlcelli.cxx            |  126 +++++-----------
 sc/source/filter/xml/xmlcelli.hxx            |   15 +
 sc/source/filter/xml/xmlimprt.cxx            |   16 ++
 sc/source/filter/xml/xmlimprt.hxx            |    6 
 11 files changed, 288 insertions(+), 363 deletions(-)

New commits:
commit 5eb8eb2312b191fabb0da0426ab7baa6e540e85e
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Feb 7 22:27:14 2013 -0500

    First cut on the re-work. Lots of things are still broken.
    
    Change-Id: Iec54d5f04cef1e17375d7414a71bec64431905d5

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 865f5f0..a0d4bf8 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -266,9 +266,10 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
 	sc/source/filter/xml/XMLTableShapeResizer \
 	sc/source/filter/xml/XMLTableShapesContext \
 	sc/source/filter/xml/XMLTableSourceContext \
-	sc/source/filter/xml/XMLTextPContext \
 	sc/source/filter/xml/XMLTrackedChangesContext \
 	sc/source/filter/xml/cachedattraccess \
+	sc/source/filter/xml/celltextparacontext \
+	sc/source/filter/xml/importcontext \
 	sc/source/filter/xml/sheetdata \
 	sc/source/filter/xml/xmlannoi \
 	sc/source/filter/xml/xmlbodyi \
diff --git a/sc/source/filter/xml/XMLTextPContext.cxx b/sc/source/filter/xml/XMLTextPContext.cxx
deleted file mode 100644
index 6e850f2..0000000
--- a/sc/source/filter/xml/XMLTextPContext.cxx
+++ /dev/null
@@ -1,209 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include "XMLTextPContext.hxx"
-#include "xmlimprt.hxx"
-#include "xmlcelli.hxx"
-#include <xmloff/xmlnmspe.hxx>
-#include <xmloff/xmltoken.hxx>
-#include <xmloff/nmspmap.hxx>
-#include <com/sun/star/text/XTextCursor.hpp>
-
-using namespace com::sun::star;
-using namespace xmloff::token;
-
-class ScXMLTextTContext : public SvXMLImportContext
-{
-    const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
-    ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
-public:
-    ScXMLTextTContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
-                        const ::rtl::OUString& rLName,
-                        const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
-                        ScXMLTextPContext* pTextPContext);
-
-    virtual ~ScXMLTextTContext();
-};
-
-
-ScXMLTextTContext::ScXMLTextTContext( ScXMLImport& rImport,
-                                      sal_uInt16 nPrfx,
-                                      const ::rtl::OUString& rLName,
-                                      const ::com::sun::star::uno::Reference<
-                                      ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
-                                      ScXMLTextPContext* pTextPContext) :
-    SvXMLImportContext( rImport, nPrfx, rLName )
-{
-    if (pTextPContext)
-    {
-        sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
-        rtl::OUString aLocalName;
-        sal_Int32 nCount(1);
-        for( sal_Int16 i=0; i < nAttrCount; ++i )
-        {
-            sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
-                                                xAttrList->getNameByIndex( i ), &aLocalName ));
-            const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
-
-            if ((nPrefix == XML_NAMESPACE_TEXT) && IsXMLToken(aLocalName, XML_C))
-                nCount = sValue.toInt32();
-        }
-        pTextPContext->AddSpaces(nCount);
-    }
-}
-
-ScXMLTextTContext::~ScXMLTextTContext()
-{
-}
-
-//------------------------------------------------------------------
-
-ScXMLTextPContext::ScXMLTextPContext( ScXMLImport& rImport,
-                                      sal_uInt16 nPrfx,
-                                      const ::rtl::OUString& rLName,
-                                      const ::com::sun::star::uno::Reference<
-                                      ::com::sun::star::xml::sax::XAttributeList>& xTempAttrList,
-                                      ScXMLTableRowCellContext* pTempCellContext) :
-    SvXMLImportContext( rImport, nPrfx, rLName ),
-    xAttrList(xTempAttrList),
-    pTextPContext(NULL),
-    pCellContext(pTempCellContext),
-    sLName(rLName),
-    sSimpleContent(),
-    pContentBuffer(NULL),
-    nPrefix(nPrfx)
-{
-    // here are no attributes
-}
-
-ScXMLTextPContext::~ScXMLTextPContext()
-{
-    if (pTextPContext)
-        delete pTextPContext;
-    if (pContentBuffer)
-        delete pContentBuffer;
-}
-
-void ScXMLTextPContext::AddSpaces(sal_Int32 nSpaceCount)
-{
-    // use pContentBuffer
-    if ( !pContentBuffer )
-        pContentBuffer = new rtl::OUStringBuffer( sSimpleContent );
-
-    sal_Char* pChars = new sal_Char[nSpaceCount];
-    memset(pChars, ' ', nSpaceCount);
-    pContentBuffer->appendAscii(pChars, nSpaceCount);
-}
-
-SvXMLImportContext *ScXMLTextPContext::CreateChildContext( sal_uInt16 nTempPrefix,
-                                            const ::rtl::OUString& rLName,
-                                            const ::com::sun::star::uno::Reference<
-                                          ::com::sun::star::xml::sax::XAttributeList>& xTempAttrList )
-{
-    SvXMLImportContext *pContext(NULL);
-    if (!pTextPContext &&
-        (nTempPrefix == XML_NAMESPACE_TEXT) &&
-        IsXMLToken(rLName, XML_S))
-        pContext = new ScXMLTextTContext( GetScImport(), nTempPrefix, rLName, xTempAttrList, this);
-    else
-    {
-        if (!pTextPContext)
-        {
-            rtl::OUString sSetString;
-            if ( pContentBuffer )
-                sSetString = pContentBuffer->makeStringAndClear();
-            else
-                sSetString = sSimpleContent;
-
-            sal_Unicode cNonSpace(0);
-
-            sal_Int32 nLength = sSetString.getLength();
-            if ( nLength > 0 )
-            {
-                sal_Unicode cLast = sSetString.getStr()[ nLength - 1 ];
-                if ( cLast != (sal_Unicode)' ' )
-                {
-                    // #i53253# To keep XMLParaContext's whitespace handling in sync,
-                    // if there's a non-space character at the end of the existing string,
-                    // it has to be processed by XMLParaContext.
-
-                    cNonSpace = cLast;
-                    sSetString = sSetString.copy( 0, nLength - 1 );  // remove from the string for SetCursorOnTextImport
-                }
-            }
-
-            pCellContext->SetCursorOnTextImport( sSetString );
-
-            pTextPContext = GetScImport().GetTextImport()->CreateTextChildContext(
-                                    GetScImport(), nPrefix, sLName, xAttrList);
-
-            if ( cNonSpace != 0 )
-            {
-                // pass non-space character through XMLParaContext, so a following space isn't ignored
-                pTextPContext->Characters( rtl::OUString( cNonSpace ) );
-            }
-        }
-        if (pTextPContext)
-            pContext = pTextPContext->CreateChildContext(nTempPrefix, rLName, xTempAttrList);
-    }
-
-    if( !pContext )
-        pContext = new SvXMLImportContext( GetScImport(), nTempPrefix, rLName );
-
-    return pContext;
-}
-
-void ScXMLTextPContext::Characters( const ::rtl::OUString& rChars )
-{
-    if (!pTextPContext)
-    {
-        // For the first call to an empty context, copy (ref-counted) the OUString.
-        // The OUStringBuffer is used only if there is more complex content.
-
-        if ( !pContentBuffer && sSimpleContent.isEmpty() )
-            sSimpleContent = rChars;
-        else
-        {
-            if ( !pContentBuffer )
-                pContentBuffer = new rtl::OUStringBuffer( sSimpleContent );
-            pContentBuffer->append(rChars);
-        }
-    }
-    else
-        pTextPContext->Characters(rChars);
-}
-
-void ScXMLTextPContext::EndElement()
-{
-    if (!pTextPContext)
-    {
-        if ( pContentBuffer )
-            pCellContext->SetString(pContentBuffer->makeStringAndClear());
-        else
-            pCellContext->SetString(sSimpleContent);
-    }
-    else
-    {
-        pTextPContext->EndElement();
-        GetScImport().SetRemoveLastChar(sal_True);
-    }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/XMLTextPContext.hxx b/sc/source/filter/xml/XMLTextPContext.hxx
deleted file mode 100644
index 23b4caa..0000000
--- a/sc/source/filter/xml/XMLTextPContext.hxx
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef SC_XMLTEXTPCONTEXT_HXX
-#define SC_XMLTEXTPCONTEXT_HXX
-
-#include <xmloff/xmlictxt.hxx>
-#include <rtl/ustrbuf.hxx>
-
-class ScXMLImport;
-class ScXMLTableRowCellContext;
-
-class ScXMLTextPContext : public SvXMLImportContext
-{
-    ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList> xAttrList;
-    SvXMLImportContext*         pTextPContext;
-    ScXMLTableRowCellContext*   pCellContext;
-    rtl::OUString               sLName;
-    rtl::OUString               sSimpleContent;     // copy of the first Character call's argument
-    rtl::OUStringBuffer*        pContentBuffer;     // used if there's more than one string
-    sal_uInt16                      nPrefix;
-
-    const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
-    ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
-
-public:
-    ScXMLTextPContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
-                        const ::rtl::OUString& rLName,
-                        const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
-                        ScXMLTableRowCellContext* pCellContext);
-
-    virtual ~ScXMLTextPContext();
-
-    virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
-                                     const ::rtl::OUString& rLocalName,
-                                     const ::com::sun::star::uno::Reference<
-                                          ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
-
-    virtual void Characters( const ::rtl::OUString& rChars );
-
-    virtual void EndElement();
-
-    void AddSpaces(sal_Int32 nSpaceCount);
-};
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/celltextparacontext.cxx b/sc/source/filter/xml/celltextparacontext.cxx
new file mode 100644
index 0000000..a70143e
--- /dev/null
+++ b/sc/source/filter/xml/celltextparacontext.cxx
@@ -0,0 +1,98 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "celltextparacontext.hxx"
+#include "xmlimprt.hxx"
+#include "xmlcelli.hxx"
+
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+
+using namespace com::sun::star;
+
+ScXMLCellTextParaContext::ScXMLCellTextParaContext(
+    ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLTableRowCellContext& rParent) :
+    ScXMLImportContext(rImport, nPrefix, rLName),
+    mrParentCxt(rParent)
+{
+}
+
+void ScXMLCellTextParaContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
+{
+}
+
+void ScXMLCellTextParaContext::EndElement()
+{
+    OUString aPara = maContent.makeStringAndClear();
+    if (aPara.isEmpty())
+        return;
+
+    mrParentCxt.PushParagraph(aPara);
+}
+
+void ScXMLCellTextParaContext::Characters(const OUString& rChars)
+{
+    if (rChars.isEmpty())
+        return;
+
+    maContent.append(rChars);
+}
+
+SvXMLImportContext* ScXMLCellTextParaContext::CreateChildContext(
+    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& xAttrList)
+{
+    const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextParaElemTokenMap();
+    switch (rTokenMap.Get(nPrefix, rLocalName))
+    {
+        case XML_TOK_CELL_TEXT_SPAN:
+            return new ScXMLCellTextSpanContext(GetScImport(), nPrefix, rLocalName, *this);
+        break;
+        default:
+            ;
+    }
+
+    return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
+}
+
+void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan)
+{
+    if (rSpan.isEmpty())
+        return;
+
+    maContent.append(rSpan);
+}
+
+ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
+    ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
+    ScXMLImportContext(rImport, nPrefix, rLName),
+    mrParentCxt(rParent)
+{
+}
+
+void ScXMLCellTextSpanContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
+{
+}
+
+void ScXMLCellTextSpanContext::EndElement()
+{
+    if (!maContent.isEmpty())
+        mrParentCxt.PushSpan(maContent);
+}
+
+void ScXMLCellTextSpanContext::Characters(const OUString& rChars)
+{
+    maContent = rChars;
+}
+
+SvXMLImportContext* ScXMLCellTextSpanContext::CreateChildContext(
+    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& xAttrList)
+{
+    return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/celltextparacontext.hxx b/sc/source/filter/xml/celltextparacontext.hxx
new file mode 100644
index 0000000..ecc6880
--- /dev/null
+++ b/sc/source/filter/xml/celltextparacontext.hxx
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __SC_XML_CELLTEXTPARACONTEXT_HXX__
+#define __SC_XML_CELLTEXTPARACONTEXT_HXX__
+
+#include "importcontext.hxx"
+
+class ScXMLImport;
+class ScXMLTableRowCellContext;
+
+/**
+ * This context handles <text:p> element inside <table:table-cell>.
+ */
+class ScXMLCellTextParaContext : public ScXMLImportContext
+{
+    ScXMLTableRowCellContext& mrParentCxt;
+    OUStringBuffer maContent;
+public:
+    ScXMLCellTextParaContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLTableRowCellContext& rParent);
+
+    virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+    virtual void EndElement();
+    virtual void Characters(const OUString& rChars);
+    virtual SvXMLImportContext* CreateChildContext(
+        sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+
+    void PushSpan(const OUString& rSpan);
+};
+
+/**
+ * This context handles <text:span> element inside <text:p>.
+ */
+class ScXMLCellTextSpanContext : public ScXMLImportContext
+{
+    ScXMLCellTextParaContext& mrParentCxt;
+    OUString maContent;
+public:
+    ScXMLCellTextSpanContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
+
+    virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+    virtual void EndElement();
+    virtual void Characters(const OUString& rChars);
+    virtual SvXMLImportContext* CreateChildContext(
+        sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/sc/source/filter/xml/importcontext.cxx b/sc/source/filter/xml/importcontext.cxx
new file mode 100644
index 0000000..b4e1207
--- /dev/null
+++ b/sc/source/filter/xml/importcontext.cxx
@@ -0,0 +1,28 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "importcontext.hxx"
+#include "xmlimprt.hxx"
+
+ScXMLImportContext::ScXMLImportContext(SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName) :
+    SvXMLImportContext(rImport, nPrefix, rLocalName)
+{
+}
+
+ScXMLImport& ScXMLImportContext::GetScImport()
+{
+    return static_cast<ScXMLImport&>(GetImport());
+}
+
+const ScXMLImport& ScXMLImportContext::GetScImport() const
+{
+    return static_cast<const ScXMLImport&>(GetImport());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/importcontext.hxx b/sc/source/filter/xml/importcontext.hxx
new file mode 100644
index 0000000..d2db48a
--- /dev/null
+++ b/sc/source/filter/xml/importcontext.hxx
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "xmloff/xmlictxt.hxx"
+#include "xmloff/xmlimp.hxx"
+
+class ScXMLImport;
+
+/**
+ * This class exists only to provide GetScImport() to its derived classes.
+ */
+class ScXMLImportContext : public SvXMLImportContext
+{
+public:
+    ScXMLImportContext(
+        SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName);
+
+protected:
+    ScXMLImport& GetScImport();
+    const ScXMLImport& GetScImport() const;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index cf787e9..4659c2a 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -37,8 +37,8 @@
 #include "docpool.hxx"
 
 #include "XMLTableShapeImportHelper.hxx"
-#include "XMLTextPContext.hxx"
 #include "XMLStylesImportHelper.hxx"
+#include "celltextparacontext.hxx"
 
 #include "arealink.hxx"
 #include <sfx2/linkmgr.hxx>
@@ -301,6 +301,11 @@ bool cellExists( const ScAddress& rCellPos )
 
 }
 
+void ScXMLTableRowCellContext::PushParagraph(const OUString& rPara)
+{
+    maParagraphs.push_back(rPara);
+}
+
 void ScXMLTableRowCellContext::SetCursorOnTextImport(const rtl::OUString& rOUTempText)
 {
     ScAddress aCellPos = rXMLImport.GetTables().GetCurrentCellPos();
@@ -353,49 +358,7 @@ SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPr
             bIsEmpty = false;
             bTextP = true;
 
-            ScAddress aCellPos = rXMLImport.GetTables().GetCurrentCellPos();
-
-            if (((nCellType == util::NumberFormat::TEXT) || maFormula || bFormulaTextResult))
-            {
-                if (maFormula)
-                {
-                    pContext = new ScXMLTextPContext(rXMLImport, nPrefix, rLName, xAttrList, this);
-                }
-                else if (!bHasTextImport)
-                {
-                    bIsFirstTextImport = true;
-                    bHasTextImport = true;
-                    pContext = new ScXMLTextPContext(rXMLImport, nPrefix, rLName, xAttrList, this);
-                }
-                else
-                {
-                    if (cellExists(aCellPos))
-                    {
-                        if (bIsFirstTextImport && !rXMLImport.GetRemoveLastChar())
-                        {
-                            if (pOUTextContent)
-                            {
-                                SetCursorOnTextImport(*pOUTextContent);
-                                pOUTextContent.reset();
-                            }
-                            else
-                                SetCursorOnTextImport(rtl::OUString());
-                            rXMLImport.SetRemoveLastChar(true);
-                            uno::Reference < text::XTextCursor > xTextCursor(rXMLImport.GetTextImport()->GetCursor());
-                            if (xTextCursor.is())
-                            {
-                                uno::Reference < text::XText > xText (xTextCursor->getText());
-                                uno::Reference < text::XTextRange > xTextRange (xTextCursor, uno::UNO_QUERY);
-                                if (xText.is() && xTextRange.is())
-                                    xText->insertControlCharacter(xTextRange, text::ControlCharacter::PARAGRAPH_BREAK, false);
-                            }
-                        }
-                        pContext = rXMLImport.GetTextImport()->CreateTextChildContext(
-                            rXMLImport, nPrefix, rLName, xAttrList);
-                        bIsFirstTextImport = false;
-                    }
-                }
-            }
+            pContext = new ScXMLCellTextParaContext(rXMLImport, nPrefix, rLName, *this);
         }
         break;
         case XML_TOK_TABLE_ROW_CELL_TABLE:
@@ -740,8 +703,8 @@ void ScXMLTableRowCellContext::SetFormulaCell(ScFormulaCell* pFCell) const
         }
         else if (!rtl::math::isNan(fValue))
         {
-            if( pOUTextContent )
-                pFCell->SetHybridValueString( fValue, *pOUTextContent );
+            if (!maParagraphs.empty())
+                pFCell->SetHybridValueString(fValue, maParagraphs.back());
             else
                 pFCell->SetHybridDouble(fValue);
             pFCell->ResetDirty();
@@ -766,8 +729,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
             OUString aCellString;
             if (maStringValue && !maStringValue->isEmpty())
                 aCellString = *maStringValue;
-            else if (pOUTextContent && !pOUTextContent->isEmpty())
-                aCellString = *pOUTextContent;
+            else if (!maParagraphs.empty())
+                aCellString = maParagraphs.back();
             else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
                 aCellString = *pOUText;
             else
@@ -801,8 +764,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
         ScDocument* pDoc = rXMLImport.GetDocument();
         if (maStringValue && !maStringValue->isEmpty())
             pNewCell = ScBaseCell::CreateTextCell( *maStringValue, pDoc );
-        else if (pOUTextContent && !pOUTextContent->isEmpty())
-            pNewCell = ScBaseCell::CreateTextCell( *pOUTextContent, pDoc );
+        else if (!maParagraphs.empty())
+            pNewCell = ScBaseCell::CreateTextCell(maParagraphs.back(), pDoc);
         else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
             pNewCell = ScBaseCell::CreateTextCell( *pOUText, pDoc );
 
@@ -1013,7 +976,7 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rCellPos )
         if( cellExists(rCellPos) && CellsAreRepeated() )
             pOUText.reset( getOutputString(rXMLImport.GetDocument(), rCellPos) );
 
-        if( !pOUTextContent && !pOUText && !maStringValue )
+        if (maParagraphs.empty() && !pOUText && !maStringValue)
                 bIsEmpty = true;
     }
 
@@ -1163,11 +1126,12 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
 // - has an "Err:[###]" (where "[###]" is an error number)
 void ScXMLTableRowCellContext::HasSpecialCaseFormulaText()
 {
-    if(  pOUTextContent )
+    if (!maParagraphs.empty())
     {
-        if ( pOUTextContent->isEmpty() || pOUTextContent->startsWith("Err:") )
+        const OUString& rStr = maParagraphs.back();
+        if (rStr.isEmpty() || rStr.startsWith("Err:"))
             mbPossibleErrorCell = true;
-        else if (pOUTextContent->startsWith("#"))
+        else if (rStr.startsWith("#"))
             mbCheckWithCompilerForError = true;
     }
 }
@@ -1196,7 +1160,7 @@ void ScXMLTableRowCellContext::EndElement()
     HasSpecialCaseFormulaText();
     if( bFormulaTextResult && (mbPossibleErrorCell || mbCheckWithCompilerForError) )
     {
-        maStringValue.reset(*pOUTextContent);
+        maStringValue.reset(maParagraphs.back());
         nCellType = util::NumberFormat::TEXT;
     }
 
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 2f7b3e6..cd0ce08 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -40,7 +40,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
     boost::optional<OUString> maStringValue;         /// office:string-value attribute
     boost::optional<OUString> maContentValidationName;
 
-    ::boost::optional< rtl::OUString > pOUTextContent;
+    std::vector<OUString> maParagraphs;
+
     boost::scoped_ptr< ScXMLAnnotationData > mxAnnotationData;
     ScMyImpDetectiveObjVec* pDetectiveObjVec;
     ScMyImpCellRangeSource* pCellRangeSource;
@@ -106,7 +107,7 @@ public:
                                      const ::com::sun::star::uno::Reference<
                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
 
-    inline void SetString(const rtl::OUString& rOUTempText) { pOUTextContent.reset(rOUTempText); }
+    void PushParagraph(const OUString& rPara);
     void SetCursorOnTextImport(const rtl::OUString& rOUTempText);
 
     void SetAnnotation( const ScAddress& rPosition );
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 492662d..a35b934 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -1839,6 +1839,20 @@ const SvXMLTokenMap& ScXMLImport::GetConsolidationAttrTokenMap()
     return *pConsolidationAttrTokenMap;
 }
 
+const SvXMLTokenMap& ScXMLImport::GetCellTextParaElemTokenMap()
+{
+    if (!pCellTextParaElemTokemMap)
+    {
+        static SvXMLTokenMapEntry aMap[] =
+        {
+            { XML_NAMESPACE_TEXT, XML_SPAN, XML_TOK_CELL_TEXT_SPAN },
+            XML_TOKEN_MAP_END
+        };
+
+        pCellTextParaElemTokemMap = new SvXMLTokenMap(aMap);
+    }
+    return *pCellTextParaElemTokemMap;
+}
 
 SvXMLImportContext *ScXMLImport::CreateContext( sal_uInt16 nPrefix,
                                                const OUString& rLocalName,
@@ -1962,6 +1976,7 @@ ScXMLImport::ScXMLImport(
     pDataPilotMembersElemTokenMap( 0 ),
     pDataPilotMemberAttrTokenMap( 0 ),
     pConsolidationAttrTokenMap( 0 ),
+    pCellTextParaElemTokemMap(NULL),
     aTables(*this),
     pMyNamedExpressions(NULL),
     pMyLabelRanges(NULL),
@@ -2099,6 +2114,7 @@ ScXMLImport::~ScXMLImport() throw()
     delete pDataPilotMembersElemTokenMap;
     delete pDataPilotMemberAttrTokenMap;
     delete pConsolidationAttrTokenMap;
+    delete pCellTextParaElemTokemMap;
 
     delete pChangeTrackingImportHelper;
     delete pNumberFormatAttributesExportHelper;
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index 532d83a..09970ad 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -681,6 +681,10 @@ enum ScXMLConsolidationAttrTokens
     XML_TOK_CONSOLIDATION_ATTR_LINK_TO_SOURCE
 };
 
+enum ScXMLCellTextParaElemTokens
+{
+    XML_TOK_CELL_TEXT_SPAN
+};
 
 class SvXMLTokenMap;
 class XMLShapeImportHelper;
@@ -847,6 +851,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
     SvXMLTokenMap           *pDataPilotMembersElemTokenMap;
     SvXMLTokenMap           *pDataPilotMemberAttrTokenMap;
     SvXMLTokenMap           *pConsolidationAttrTokenMap;
+    SvXMLTokenMap           *pCellTextParaElemTokemMap;
 
     ScMyTables              aTables;
 
@@ -1012,6 +1017,7 @@ public:
     const SvXMLTokenMap& GetDataPilotMembersElemTokenMap();
     const SvXMLTokenMap& GetDataPilotMemberAttrTokenMap();
     const SvXMLTokenMap& GetConsolidationAttrTokenMap();
+    const SvXMLTokenMap& GetCellTextParaElemTokenMap();
 
     void AddNamedExpression(ScMyNamedExpression* pMyNamedExpression)
     {
commit f92e6214e64ef04907e44d1ae7db505ac3e9e957
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Feb 7 14:51:45 2013 -0500

    Bit of re-organization...
    
    Change-Id: I843d798007eaeb7175991210bd4f0d42078836d9

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index b0cd059..cf787e9 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -106,7 +106,6 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
                                       const bool bTempIsCovered,
                                       const sal_Int32 nTempRepeatedRows ) :
     SvXMLImportContext( rImport, nPrfx, rLName ),
-    pContentValidationName(NULL),
     pDetectiveObjVec(NULL),
     pCellRangeSource(NULL),
     fValue(0.0),
@@ -150,8 +149,9 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
                 pStyleName = new rtl::OUString(sValue);
             break;
             case XML_TOK_TABLE_ROW_CELL_ATTR_CONTENT_VALIDATION_NAME:
-                OSL_ENSURE(!pContentValidationName, "here should be only one Validation Name");
-                pContentValidationName = new rtl::OUString(sValue);
+                OSL_ENSURE(!maContentValidationName, "here should be only one Validation Name");
+                if (!sValue.isEmpty())
+                    maContentValidationName.reset(sValue);
             break;
             case XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_ROWS:
                 bIsMerged = true;
@@ -214,8 +214,8 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
             {
                 if (!sValue.isEmpty())
                 {
-                    OSL_ENSURE(!pOUTextValue, "here should be only one string value");
-                    pOUTextValue.reset(sValue);
+                    OSL_ENSURE(!maStringValue, "here should be only one string value");
+                    maStringValue.reset(sValue);
                     bIsEmpty = false;
                 }
             }
@@ -238,10 +238,10 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
             {
                 if (!sValue.isEmpty())
                 {
-                    OSL_ENSURE(!pOUFormula, "here should be only one formula");
+                    OSL_ENSURE(!maFormula, "here should be only one formula");
                     rtl::OUString aFormula, aFormulaNmsp;
                     rXMLImport.ExtractFormulaNamespaceGrammar( aFormula, aFormulaNmsp, eGrammar, sValue );
-                    pOUFormula.reset( FormulaWithNamespace( aFormula, aFormulaNmsp ) );
+                    maFormula.reset( FormulaWithNamespace(aFormula, aFormulaNmsp) );
                 }
             }
             break;
@@ -252,7 +252,7 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
                 ;
         }
     }
-    if (pOUFormula)
+    if (maFormula)
     {
         if (nCellType == util::NumberFormat::TEXT)
             bFormulaTextResult = true;
@@ -269,7 +269,6 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
 
 ScXMLTableRowCellContext::~ScXMLTableRowCellContext()
 {
-    delete pContentValidationName;
     delete pDetectiveObjVec;
     delete pCellRangeSource;
 }
@@ -356,9 +355,9 @@ SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPr
 
             ScAddress aCellPos = rXMLImport.GetTables().GetCurrentCellPos();
 
-            if( ((nCellType == util::NumberFormat::TEXT) || pOUFormula || bFormulaTextResult) )
+            if (((nCellType == util::NumberFormat::TEXT) || maFormula || bFormulaTextResult))
             {
-                if ( pOUFormula )
+                if (maFormula)
                 {
                     pContext = new ScXMLTextPContext(rXMLImport, nPrefix, rLName, xAttrList, this);
                 }
@@ -515,12 +514,12 @@ ScValidErrorStyle validAlertToValidError( const sheet::ValidationAlertStyle eVAl
 
 void ScXMLTableRowCellContext::SetContentValidation( const ScRange& rScRange )
 {
-    if( pContentValidationName && !pContentValidationName->isEmpty() )
+    if (maContentValidationName)
     {
         ScDocument* pDoc = rXMLImport.GetDocument();
         ScMyImportValidation aValidation;
         aValidation.eGrammar1 = aValidation.eGrammar2 = pDoc->GetStorageGrammar();
-        if( rXMLImport.GetValidation(*pContentValidationName, aValidation) )
+        if( rXMLImport.GetValidation(*maContentValidationName, aValidation) )
         {
             ScValidationData aScValidationData(
                 validationTypeToMode(aValidation.aValidationType),
@@ -731,11 +730,11 @@ void ScXMLTableRowCellContext::SetFormulaCell(ScFormulaCell* pFCell) const
 {
     if(pFCell)
     {
-        if( bFormulaTextResult && pOUTextValue )
+        if( bFormulaTextResult && maStringValue )
         {
             if( !IsPossibleErrorString() )
             {
-                pFCell->SetHybridString( *pOUTextValue );
+                pFCell->SetHybridString( *maStringValue );
                 pFCell->ResetDirty();
             }
         }
@@ -765,8 +764,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
         {
             ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
             OUString aCellString;
-            if (pOUTextValue && !pOUTextValue->isEmpty())
-                aCellString = *pOUTextValue;
+            if (maStringValue && !maStringValue->isEmpty())
+                aCellString = *maStringValue;
             else if (pOUTextContent && !pOUTextContent->isEmpty())
                 aCellString = *pOUTextContent;
             else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
@@ -800,8 +799,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
     {
         ScBaseCell* pNewCell = NULL;
         ScDocument* pDoc = rXMLImport.GetDocument();
-        if (pOUTextValue && !pOUTextValue->isEmpty())
-            pNewCell = ScBaseCell::CreateTextCell( *pOUTextValue, pDoc );
+        if (maStringValue && !maStringValue->isEmpty())
+            pNewCell = ScBaseCell::CreateTextCell( *maStringValue, pDoc );
         else if (pOUTextContent && !pOUTextContent->isEmpty())
             pNewCell = ScBaseCell::CreateTextCell( *pOUTextContent, pDoc );
         else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
@@ -958,8 +957,7 @@ void ScXMLTableRowCellContext::AddTextAndValueCells( const ScAddress& rCellPos,
 
 bool ScXMLTableRowCellContext::HasSpecialContent() const
 {
-    return ( (pContentValidationName && !pContentValidationName->isEmpty()) ||
-              mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource );
+    return (maContentValidationName || mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource);
 }
 
 bool ScXMLTableRowCellContext::CellsAreRepeated() const
@@ -1015,7 +1013,7 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rCellPos )
         if( cellExists(rCellPos) && CellsAreRepeated() )
             pOUText.reset( getOutputString(rXMLImport.GetDocument(), rCellPos) );
 
-        if( !pOUTextContent && !pOUText && !pOUTextValue )
+        if( !pOUTextContent && !pOUText && !maStringValue )
                 bIsEmpty = true;
     }
 
@@ -1046,8 +1044,8 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
 {
     ScDocument* pDoc = rXMLImport.GetDocument();
 
-    rtl::OUString aText = pOUFormula->first;
-    rtl::OUString aFormulaNmsp = pOUFormula->second;
+    OUString aText = maFormula->first;
+    OUString aFormulaNmsp = maFormula->second;
 
     ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard (
             new ScExternalRefManager::ApiGuard(pDoc));
@@ -1111,7 +1109,7 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
                         rCellPos.Col(), rCellPos.Row(),
                         std::min<SCCOL>(rCellPos.Col() + nMatrixCols - 1, MAXCOL),
                         std::min<SCROW>(rCellPos.Row() + nMatrixRows - 1, MAXROW),
-                        pOUFormula->first, pOUFormula->second, eGrammar);
+                        maFormula->first, maFormula->second, eGrammar);
 
                 // Set the value/text of the top-left matrix position in its
                 // cached result.  For import, we only need to set the correct
@@ -1121,12 +1119,12 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
                     static_cast<ScFormulaCell*>( rXMLImport.GetDocument()->GetCell(rCellPos) );
 
                 ScMatrixRef pMat(new ScMatrix(nMatrixCols, nMatrixRows));
-                if (bFormulaTextResult && pOUTextValue)
+                if (bFormulaTextResult && maStringValue)
                 {
                     if (!IsPossibleErrorString())
                     {
                         pFCell->SetResultMatrix(
-                            nMatrixCols, nMatrixRows, pMat, new formula::FormulaStringToken(*pOUTextValue));
+                            nMatrixCols, nMatrixRows, pMat, new formula::FormulaStringToken(*maStringValue));
                         pFCell->ResetDirty();
                     }
                 }
@@ -1176,7 +1174,7 @@ void ScXMLTableRowCellContext::HasSpecialCaseFormulaText()
 
 bool ScXMLTableRowCellContext::IsPossibleErrorString() const
 {
-     return mbPossibleErrorCell || ( mbCheckWithCompilerForError && GetScImport().IsFormulaErrorConstant(*pOUTextValue) );
+     return mbPossibleErrorCell || ( mbCheckWithCompilerForError && GetScImport().IsFormulaErrorConstant(*maStringValue) );
 }
 
 
@@ -1198,7 +1196,7 @@ void ScXMLTableRowCellContext::EndElement()
     HasSpecialCaseFormulaText();
     if( bFormulaTextResult && (mbPossibleErrorCell || mbCheckWithCompilerForError) )
     {
-        pOUTextValue.reset(*pOUTextContent);
+        maStringValue.reset(*pOUTextContent);
         nCellType = util::NumberFormat::TEXT;
     }
 
@@ -1207,9 +1205,9 @@ void ScXMLTableRowCellContext::EndElement()
         aCellPos.SetRow( aCellPos.Row() - (nRepeatedRows - 1) );
     if( bIsMerged )
         DoMerge( aCellPos, nMergedCols - 1, nMergedRows - 1 );
-    if( !pOUFormula )
+    if (!maFormula)
         AddNonFormulaCells( aCellPos );
-    else // if ( pOUFormula )
+    else
         AddFormulaCell( aCellPos );
 
     UnlockSolarMutex(); //if LockSolarMutex got used, we presumably need to ensure an UnlockSolarMutex
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 9584d8e..2f7b3e6 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -34,11 +34,13 @@ struct ScXMLAnnotationData;
 
 class ScXMLTableRowCellContext : public SvXMLImportContext
 {
-    typedef ::std::pair< ::rtl::OUString, ::rtl::OUString > FormulaWithNamespace;
-    ::boost::optional< rtl::OUString > pOUTextValue;
+    typedef std::pair<OUString, OUString> FormulaWithNamespace;
+
+    boost::optional<FormulaWithNamespace> maFormula; /// table:formula attribute
+    boost::optional<OUString> maStringValue;         /// office:string-value attribute
+    boost::optional<OUString> maContentValidationName;
+
     ::boost::optional< rtl::OUString > pOUTextContent;
-    ::boost::optional< FormulaWithNamespace > pOUFormula;
-    rtl::OUString* pContentValidationName;
     boost::scoped_ptr< ScXMLAnnotationData > mxAnnotationData;
     ScMyImpDetectiveObjVec* pDetectiveObjVec;
     ScMyImpCellRangeSource* pCellRangeSource;


More information about the Libreoffice-commits mailing list