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

Kohei Yoshida kohei.yoshida at gmail.com
Thu Feb 7 22:09:35 PST 2013


 sc/source/filter/xml/importcontext.hxx |    5 ++
 sc/source/filter/xml/xmlcelli.cxx      |   60 +++++++++++----------------------
 sc/source/filter/xml/xmlcelli.hxx      |   12 ++----
 sc/source/filter/xml/xmlimprt.cxx      |   17 +++++++++
 sc/source/filter/xml/xmlimprt.hxx      |    4 ++
 5 files changed, 51 insertions(+), 47 deletions(-)

New commits:
commit 28a8b806b2048cdbc79162f1c6bd1cf11ac2fc09
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Feb 8 01:10:37 2013 -0500

    Use EditEngine to create ScEditCell directly.
    
    Change-Id: I51a37482e793f620cf0dffcf392ce69822652cef

diff --git a/sc/source/filter/xml/importcontext.hxx b/sc/source/filter/xml/importcontext.hxx
index d2db48a..146e7e8 100644
--- a/sc/source/filter/xml/importcontext.hxx
+++ b/sc/source/filter/xml/importcontext.hxx
@@ -7,6 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#ifndef __IMPORTCONTEXT_HXX__
+#define __IMPORTCONTEXT_HXX__
+
 #include "xmloff/xmlictxt.hxx"
 #include "xmloff/xmlimp.hxx"
 
@@ -27,3 +30,5 @@ protected:
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+
+#endif
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index e13cb82..4e13655 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -105,7 +105,8 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
                                       const bool bTempIsCovered,
                                       const sal_Int32 nTempRepeatedRows ) :
-    SvXMLImportContext( rImport, nPrfx, rLName ),
+    ScXMLImportContext(rImport, nPrfx, rLName),
+    mpEditEngine(GetScImport().GetEditEngine()),
     pDetectiveObjVec(NULL),
     pCellRangeSource(NULL),
     fValue(0.0),
@@ -127,6 +128,7 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
     mbCheckWithCompilerForError(false)
 {
     rtl::math::setNan(&fValue); // NaN by default
+    mpEditEngine->Clear();
 
     rXMLImport.SetRemoveLastChar(false);
     rXMLImport.GetTables().AddColumn(bTempIsCovered);
@@ -307,7 +309,8 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan)
 
 void ScXMLTableRowCellContext::PushParagraphEnd()
 {
-    maParagraphs.push_back(maParagraph.makeStringAndClear());
+    mpEditEngine->InsertParagraph(
+        mpEditEngine->GetParagraphCount(), maParagraph.makeStringAndClear());
 }
 
 SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPrefix,
@@ -671,8 +674,8 @@ void ScXMLTableRowCellContext::SetFormulaCell(ScFormulaCell* pFCell) const
         }
         else if (!rtl::math::isNan(fValue))
         {
-            if (!maParagraphs.empty())
-                pFCell->SetHybridValueString(fValue, maParagraphs.back());
+            if (mpEditEngine->GetParagraphCount())
+                pFCell->SetHybridValueString(fValue, mpEditEngine->GetText(0));
             else
                 pFCell->SetHybridDouble(fValue);
             pFCell->ResetDirty();
@@ -681,27 +684,6 @@ void ScXMLTableRowCellContext::SetFormulaCell(ScFormulaCell* pFCell) const
     }
 }
 
-namespace {
-
-ScBaseCell* createEditCell(ScDocument* pDoc, const std::vector<OUString>& rParagraphs)
-{
-    // Create edit cell.
-    OUStringBuffer aBuf;
-    std::vector<OUString>::const_iterator it = rParagraphs.begin(), itEnd = rParagraphs.end();
-    bool bFirst = true;
-    for (; it != itEnd; ++it)
-    {
-        if (bFirst)
-            bFirst = false;
-        else
-            aBuf.append('\n');
-        aBuf.append(*it);
-    }
-    return ScBaseCell::CreateTextCell(aBuf.makeStringAndClear(), pDoc);
-}
-
-}
-
 void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
         const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText )
 {
@@ -718,8 +700,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
             OUString aCellString;
             if (maStringValue)
                 aCellString = *maStringValue;
-            else if (!maParagraphs.empty())
-                aCellString = maParagraphs.back();
+            else if (mpEditEngine->GetParagraphCount())
+                aCellString = mpEditEngine->GetText(0);
             else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
                 aCellString = *pOUText;
             else
@@ -753,8 +735,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
         ScDocument* pDoc = rXMLImport.GetDocument();
         if (maStringValue)
             pNewCell = ScBaseCell::CreateTextCell( *maStringValue, pDoc );
-        else if (!maParagraphs.empty())
-            pNewCell = createEditCell(pDoc, maParagraphs);
+        else if (mpEditEngine->GetParagraphCount())
+            pNewCell = new ScEditCell(mpEditEngine->CreateTextObject(), pDoc, pDoc->GetEditPool());
         else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
             pNewCell = ScBaseCell::CreateTextCell( *pOUText, pDoc );
 
@@ -960,7 +942,7 @@ void ScXMLTableRowCellContext::AddNonFormulaCell( const ScAddress& rCellPos )
         if( cellExists(rCellPos) && CellsAreRepeated() )
             pOUText.reset( getOutputString(rXMLImport.GetDocument(), rCellPos) );
 
-        if (maParagraphs.empty() && !pOUText && !maStringValue)
+        if (!mpEditEngine->GetParagraphCount() && !pOUText && !maStringValue)
             bIsEmpty = true;
     }
 
@@ -1110,14 +1092,14 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
 // - has an "Err:[###]" (where "[###]" is an error number)
 void ScXMLTableRowCellContext::HasSpecialCaseFormulaText()
 {
-    if (!maParagraphs.empty())
-    {
-        const OUString& rStr = maParagraphs.back();
-        if (rStr.isEmpty() || rStr.startsWith("Err:"))
-            mbPossibleErrorCell = true;
-        else if (rStr.startsWith("#"))
-            mbCheckWithCompilerForError = true;
-    }
+    if (!mpEditEngine->GetParagraphCount())
+        return;
+
+    OUString aStr = mpEditEngine->GetText(0);
+    if (aStr.isEmpty() || aStr.startsWith("Err:"))
+        mbPossibleErrorCell = true;
+    else if (aStr.startsWith("#"))
+        mbCheckWithCompilerForError = true;
 }
 
 bool ScXMLTableRowCellContext::IsPossibleErrorString() const
@@ -1131,7 +1113,7 @@ void ScXMLTableRowCellContext::EndElement()
     HasSpecialCaseFormulaText();
     if( bFormulaTextResult && (mbPossibleErrorCell || mbCheckWithCompilerForError) )
     {
-        maStringValue.reset(maParagraphs.back());
+        maStringValue.reset(mpEditEngine->GetText(0));
         nCellType = util::NumberFormat::TEXT;
     }
 
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index cb61ce4..cbd622f 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -21,18 +21,17 @@
 
 #include "XMLDetectiveContext.hxx"
 #include "XMLCellRangeSourceContext.hxx"
-#include <xmloff/xmlictxt.hxx>
-#include <xmloff/xmlimp.hxx>
-
+#include "importcontext.hxx"
 #include "formula/grammar.hxx"
 #include <boost/optional.hpp>
 #include <boost/scoped_ptr.hpp>
 
 class ScXMLImport;
 class ScFormulaCell;
+class ScEditEngineDefaulter;
 struct ScXMLAnnotationData;
 
-class ScXMLTableRowCellContext : public SvXMLImportContext
+class ScXMLTableRowCellContext : public ScXMLImportContext
 {
     typedef std::pair<OUString, OUString> FormulaWithNamespace;
 
@@ -40,7 +39,7 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
     boost::optional<OUString> maStringValue;         /// office:string-value attribute
     boost::optional<OUString> maContentValidationName;
 
-    std::vector<OUString> maParagraphs;
+    ScEditEngineDefaulter* mpEditEngine;
     OUStringBuffer maParagraph;
 
     boost::scoped_ptr< ScXMLAnnotationData > mxAnnotationData;
@@ -62,9 +61,6 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
     bool        mbPossibleErrorCell;
     bool        mbCheckWithCompilerForError;
 
-    const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
-    ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
-
     sal_Int16 GetCellType(const rtl::OUString& sOUValue) const;
 
     void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows);
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index a35b934..e62ec9b 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -40,6 +40,7 @@
 
 #include <svl/zformat.hxx>
 #include <svl/languageoptions.hxx>
+#include "editeng/editstat.hxx"
 
 #include "xmlimprt.hxx"
 #include "document.hxx"
@@ -63,6 +64,8 @@
 #include "postit.hxx"
 #include "formulaparserpool.hxx"
 #include "externalrefmgr.hxx"
+#include "editutil.hxx"
+
 #include <comphelper/extract.hxx>
 
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
@@ -3341,4 +3344,18 @@ bool ScXMLImport::IsFormulaErrorConstant( const OUString& rStr ) const
     return mpComp->GetErrorConstant(rStr) > 0;
 }
 
+ScEditEngineDefaulter* ScXMLImport::GetEditEngine()
+{
+    if (!mpEditEngine)
+    {
+        mpEditEngine.reset(new ScEditEngineDefaulter(pDoc->GetEnginePool()));
+        mpEditEngine->SetRefMapMode(MAP_100TH_MM);
+        mpEditEngine->SetEditTextObjectPool(pDoc->GetEditPool());
+        mpEditEngine->SetUpdateMode(false);
+        mpEditEngine->EnableUndo(false);
+        mpEditEngine->SetControlWord(mpEditEngine->GetControlWord() & ~EE_CNTRL_ALLOWBIGOBJS);
+    }
+    return mpEditEngine.get();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index 09970ad..3ae05c0 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -52,6 +52,7 @@
 
 class ScMyStyleNumberFormats;
 class XMLNumberFormatAttributesExportHelper;
+class ScEditEngineDefaulter;
 
 enum ScXMLDocTokens
 {
@@ -756,6 +757,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
 
     ScDocument*             pDoc;
     boost::scoped_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values.
+    boost::scoped_ptr<ScEditEngineDefaulter> mpEditEngine;
     ScXMLChangeTrackingImportHelper*    pChangeTrackingImportHelper;
     ScMyViewContextList                 aViewContextList;
     ScMyStylesImportHelper*             pStylesImportHelper;
@@ -1163,6 +1165,8 @@ public:
             bool bRestrictToExternalNmsp = false ) const;
 
     bool IsFormulaErrorConstant( const OUString& rStr ) const;
+
+    ScEditEngineDefaulter* GetEditEngine();
 };
 
 #endif


More information about the Libreoffice-commits mailing list