Kaydet (Commit) 96d89d9c authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Use EditEngine to create ScEditCell directly.

Change-Id: I51a37482e793f620cf0dffcf392ce69822652cef
üst 9f023774
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#ifndef __IMPORTCONTEXT_HXX__
#define __IMPORTCONTEXT_HXX__
#include "xmloff/xmlictxt.hxx" #include "xmloff/xmlictxt.hxx"
#include "xmloff/xmlimp.hxx" #include "xmloff/xmlimp.hxx"
...@@ -27,3 +30,5 @@ protected: ...@@ -27,3 +30,5 @@ protected:
}; };
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#endif
...@@ -105,7 +105,8 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport, ...@@ -105,7 +105,8 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
::com::sun::star::xml::sax::XAttributeList>& xAttrList, ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
const bool bTempIsCovered, const bool bTempIsCovered,
const sal_Int32 nTempRepeatedRows ) : const sal_Int32 nTempRepeatedRows ) :
SvXMLImportContext( rImport, nPrfx, rLName ), ScXMLImportContext(rImport, nPrfx, rLName),
mpEditEngine(GetScImport().GetEditEngine()),
pDetectiveObjVec(NULL), pDetectiveObjVec(NULL),
pCellRangeSource(NULL), pCellRangeSource(NULL),
fValue(0.0), fValue(0.0),
...@@ -127,6 +128,7 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport, ...@@ -127,6 +128,7 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
mbCheckWithCompilerForError(false) mbCheckWithCompilerForError(false)
{ {
rtl::math::setNan(&fValue); // NaN by default rtl::math::setNan(&fValue); // NaN by default
mpEditEngine->Clear();
rXMLImport.SetRemoveLastChar(false); rXMLImport.SetRemoveLastChar(false);
rXMLImport.GetTables().AddColumn(bTempIsCovered); rXMLImport.GetTables().AddColumn(bTempIsCovered);
...@@ -307,7 +309,8 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan) ...@@ -307,7 +309,8 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan)
void ScXMLTableRowCellContext::PushParagraphEnd() void ScXMLTableRowCellContext::PushParagraphEnd()
{ {
maParagraphs.push_back(maParagraph.makeStringAndClear()); mpEditEngine->InsertParagraph(
mpEditEngine->GetParagraphCount(), maParagraph.makeStringAndClear());
} }
SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPrefix, SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPrefix,
...@@ -671,8 +674,8 @@ void ScXMLTableRowCellContext::SetFormulaCell(ScFormulaCell* pFCell) const ...@@ -671,8 +674,8 @@ void ScXMLTableRowCellContext::SetFormulaCell(ScFormulaCell* pFCell) const
} }
else if (!rtl::math::isNan(fValue)) else if (!rtl::math::isNan(fValue))
{ {
if (!maParagraphs.empty()) if (mpEditEngine->GetParagraphCount())
pFCell->SetHybridValueString(fValue, maParagraphs.back()); pFCell->SetHybridValueString(fValue, mpEditEngine->GetText(0));
else else
pFCell->SetHybridDouble(fValue); pFCell->SetHybridDouble(fValue);
pFCell->ResetDirty(); pFCell->ResetDirty();
...@@ -681,27 +684,6 @@ void ScXMLTableRowCellContext::SetFormulaCell(ScFormulaCell* pFCell) const ...@@ -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, void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText ) const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText )
{ {
...@@ -718,8 +700,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos, ...@@ -718,8 +700,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
OUString aCellString; OUString aCellString;
if (maStringValue) if (maStringValue)
aCellString = *maStringValue; aCellString = *maStringValue;
else if (!maParagraphs.empty()) else if (mpEditEngine->GetParagraphCount())
aCellString = maParagraphs.back(); aCellString = mpEditEngine->GetText(0);
else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() ) else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
aCellString = *pOUText; aCellString = *pOUText;
else else
...@@ -753,8 +735,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos, ...@@ -753,8 +735,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
ScDocument* pDoc = rXMLImport.GetDocument(); ScDocument* pDoc = rXMLImport.GetDocument();
if (maStringValue) if (maStringValue)
pNewCell = ScBaseCell::CreateTextCell( *maStringValue, pDoc ); pNewCell = ScBaseCell::CreateTextCell( *maStringValue, pDoc );
else if (!maParagraphs.empty()) else if (mpEditEngine->GetParagraphCount())
pNewCell = createEditCell(pDoc, maParagraphs); pNewCell = new ScEditCell(mpEditEngine->CreateTextObject(), pDoc, pDoc->GetEditPool());
else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() ) else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
pNewCell = ScBaseCell::CreateTextCell( *pOUText, pDoc ); pNewCell = ScBaseCell::CreateTextCell( *pOUText, pDoc );
...@@ -960,7 +942,7 @@ void ScXMLTableRowCellContext::AddNonFormulaCell( const ScAddress& rCellPos ) ...@@ -960,7 +942,7 @@ void ScXMLTableRowCellContext::AddNonFormulaCell( const ScAddress& rCellPos )
if( cellExists(rCellPos) && CellsAreRepeated() ) if( cellExists(rCellPos) && CellsAreRepeated() )
pOUText.reset( getOutputString(rXMLImport.GetDocument(), rCellPos) ); pOUText.reset( getOutputString(rXMLImport.GetDocument(), rCellPos) );
if (maParagraphs.empty() && !pOUText && !maStringValue) if (!mpEditEngine->GetParagraphCount() && !pOUText && !maStringValue)
bIsEmpty = true; bIsEmpty = true;
} }
...@@ -1110,14 +1092,14 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos ) ...@@ -1110,14 +1092,14 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
// - has an "Err:[###]" (where "[###]" is an error number) // - has an "Err:[###]" (where "[###]" is an error number)
void ScXMLTableRowCellContext::HasSpecialCaseFormulaText() void ScXMLTableRowCellContext::HasSpecialCaseFormulaText()
{ {
if (!maParagraphs.empty()) if (!mpEditEngine->GetParagraphCount())
{ return;
const OUString& rStr = maParagraphs.back();
if (rStr.isEmpty() || rStr.startsWith("Err:")) OUString aStr = mpEditEngine->GetText(0);
mbPossibleErrorCell = true; if (aStr.isEmpty() || aStr.startsWith("Err:"))
else if (rStr.startsWith("#")) mbPossibleErrorCell = true;
mbCheckWithCompilerForError = true; else if (aStr.startsWith("#"))
} mbCheckWithCompilerForError = true;
} }
bool ScXMLTableRowCellContext::IsPossibleErrorString() const bool ScXMLTableRowCellContext::IsPossibleErrorString() const
...@@ -1131,7 +1113,7 @@ void ScXMLTableRowCellContext::EndElement() ...@@ -1131,7 +1113,7 @@ void ScXMLTableRowCellContext::EndElement()
HasSpecialCaseFormulaText(); HasSpecialCaseFormulaText();
if( bFormulaTextResult && (mbPossibleErrorCell || mbCheckWithCompilerForError) ) if( bFormulaTextResult && (mbPossibleErrorCell || mbCheckWithCompilerForError) )
{ {
maStringValue.reset(maParagraphs.back()); maStringValue.reset(mpEditEngine->GetText(0));
nCellType = util::NumberFormat::TEXT; nCellType = util::NumberFormat::TEXT;
} }
......
...@@ -21,18 +21,17 @@ ...@@ -21,18 +21,17 @@
#include "XMLDetectiveContext.hxx" #include "XMLDetectiveContext.hxx"
#include "XMLCellRangeSourceContext.hxx" #include "XMLCellRangeSourceContext.hxx"
#include <xmloff/xmlictxt.hxx> #include "importcontext.hxx"
#include <xmloff/xmlimp.hxx>
#include "formula/grammar.hxx" #include "formula/grammar.hxx"
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
class ScXMLImport; class ScXMLImport;
class ScFormulaCell; class ScFormulaCell;
class ScEditEngineDefaulter;
struct ScXMLAnnotationData; struct ScXMLAnnotationData;
class ScXMLTableRowCellContext : public SvXMLImportContext class ScXMLTableRowCellContext : public ScXMLImportContext
{ {
typedef std::pair<OUString, OUString> FormulaWithNamespace; typedef std::pair<OUString, OUString> FormulaWithNamespace;
...@@ -40,7 +39,7 @@ class ScXMLTableRowCellContext : public SvXMLImportContext ...@@ -40,7 +39,7 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
boost::optional<OUString> maStringValue; /// office:string-value attribute boost::optional<OUString> maStringValue; /// office:string-value attribute
boost::optional<OUString> maContentValidationName; boost::optional<OUString> maContentValidationName;
std::vector<OUString> maParagraphs; ScEditEngineDefaulter* mpEditEngine;
OUStringBuffer maParagraph; OUStringBuffer maParagraph;
boost::scoped_ptr< ScXMLAnnotationData > mxAnnotationData; boost::scoped_ptr< ScXMLAnnotationData > mxAnnotationData;
...@@ -62,9 +61,6 @@ class ScXMLTableRowCellContext : public SvXMLImportContext ...@@ -62,9 +61,6 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
bool mbPossibleErrorCell; bool mbPossibleErrorCell;
bool mbCheckWithCompilerForError; bool mbCheckWithCompilerForError;
const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
sal_Int16 GetCellType(const rtl::OUString& sOUValue) const; sal_Int16 GetCellType(const rtl::OUString& sOUValue) const;
void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows); void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows);
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <svl/zformat.hxx> #include <svl/zformat.hxx>
#include <svl/languageoptions.hxx> #include <svl/languageoptions.hxx>
#include "editeng/editstat.hxx"
#include "xmlimprt.hxx" #include "xmlimprt.hxx"
#include "document.hxx" #include "document.hxx"
...@@ -63,6 +64,8 @@ ...@@ -63,6 +64,8 @@
#include "postit.hxx" #include "postit.hxx"
#include "formulaparserpool.hxx" #include "formulaparserpool.hxx"
#include "externalrefmgr.hxx" #include "externalrefmgr.hxx"
#include "editutil.hxx"
#include <comphelper/extract.hxx> #include <comphelper/extract.hxx>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
...@@ -3341,4 +3344,18 @@ bool ScXMLImport::IsFormulaErrorConstant( const OUString& rStr ) const ...@@ -3341,4 +3344,18 @@ bool ScXMLImport::IsFormulaErrorConstant( const OUString& rStr ) const
return mpComp->GetErrorConstant(rStr) > 0; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
class ScMyStyleNumberFormats; class ScMyStyleNumberFormats;
class XMLNumberFormatAttributesExportHelper; class XMLNumberFormatAttributesExportHelper;
class ScEditEngineDefaulter;
enum ScXMLDocTokens enum ScXMLDocTokens
{ {
...@@ -756,6 +757,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable ...@@ -756,6 +757,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
ScDocument* pDoc; ScDocument* pDoc;
boost::scoped_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values. boost::scoped_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values.
boost::scoped_ptr<ScEditEngineDefaulter> mpEditEngine;
ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper; ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
ScMyViewContextList aViewContextList; ScMyViewContextList aViewContextList;
ScMyStylesImportHelper* pStylesImportHelper; ScMyStylesImportHelper* pStylesImportHelper;
...@@ -1163,6 +1165,8 @@ public: ...@@ -1163,6 +1165,8 @@ public:
bool bRestrictToExternalNmsp = false ) const; bool bRestrictToExternalNmsp = false ) const;
bool IsFormulaErrorConstant( const OUString& rStr ) const; bool IsFormulaErrorConstant( const OUString& rStr ) const;
ScEditEngineDefaulter* GetEditEngine();
}; };
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment