Insert matrix formula vis ScDocumentImport, and more formula imorts.

Now SetGroupFormulaCell() is no longer used.

Change-Id: I10a387da04724794974eaf491a8efa4cda09d82a
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 3ee53d6..0a03ad9 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -284,7 +284,6 @@ public:
     */
    ScFormulaCell* SetFormulaCell( SCROW nRow, ScFormulaCell* pCell );
    ScFormulaCell* SetFormulaCell( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, ScFormulaCell* pCell );
    bool SetGroupFormulaCell( SCROW nRow, ScFormulaCell* pCell );

    svl::SharedString GetSharedString( SCROW nRow ) const;

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index fb3a175..6929e9b4 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -825,16 +825,6 @@ public:
     */
    SC_DLLPUBLIC ScFormulaCell* SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell );

    /**
     * Set formula cell, and transfer its ownership to the document.  Unlike
     * SetFormulaCell(), this call will <i>not</i> attempt to group the passed
     * formula cell with the adjacent cells or cell groups.
     *
     * @return true if the cell is inserted, false otherwise. The caller
     *         should delete the cell instance if the method returns false.
     */
    SC_DLLPUBLIC bool SetGroupFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell );

    SC_DLLPUBLIC void InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
                                        SCCOL nCol2, SCROW nRow2,
                                        const ScMarkData& rMark,
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 126b0ae..8eb75be 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -339,7 +339,6 @@ public:
     *         is deleted automatically on failure to insert.
     */
    ScFormulaCell* SetFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell );
    bool SetGroupFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell );

    svl::SharedString GetSharedString( SCCOL nCol, SCROW nRow ) const;

diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 991039c..ece9035 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1769,21 +1769,6 @@ ScFormulaCell* ScColumn::SetFormulaCell( sc::ColumnBlockPosition& rBlockPos, SCR
    return pCell;
}

bool ScColumn::SetGroupFormulaCell( SCROW nRow, ScFormulaCell* pCell )
{
    sc::CellStoreType::iterator it = GetPositionToInsert(nRow);
    sal_uInt32 nCellFormat = GetNumberFormat(nRow);
    if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
        pCell->SetNeedNumberFormat(true);
    it = maCells.set(it, nRow, pCell);
    maCellTextAttrs.set(nRow, sc::CellTextAttr());

    CellStorageModified();

    ActivateNewFormulaCell(it, nRow, *pCell, false);
    return true;
}

svl::SharedString ScColumn::GetSharedString( SCROW nRow ) const
{
    sc::CellStoreType::const_position_type aPos = maCells.position(nRow);
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 930c8d10..1e0bb87 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -1093,14 +1093,6 @@ ScFormulaCell* ScDocument::SetFormulaCell( const ScAddress& rPos, ScFormulaCell*
    return maTabs[rPos.Tab()]->SetFormulaCell(rPos.Col(), rPos.Row(), pCell);
}

bool ScDocument::SetGroupFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell )
{
    if (!TableExists(rPos.Tab()))
        return false;

    return maTabs[rPos.Tab()]->SetGroupFormulaCell(rPos.Col(), rPos.Row(), pCell);
}

void ScDocument::SetConsolidateDlgData( const ScConsolidateParam* pData )
{
    delete pConsolidateDlgData;
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 5295af6..c94d66a 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1383,14 +1383,6 @@ ScFormulaCell* ScTable::SetFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* p
    return aCol[nCol].SetFormulaCell(nRow, pCell);
}

bool ScTable::SetGroupFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell )
{
    if (!ValidColRow(nCol, nRow))
        return false;

    return aCol[nCol].SetGroupFormulaCell(nRow, pCell);
}

svl::SharedString ScTable::GetSharedString( SCCOL nCol, SCROW nRow ) const
{
    if (!ValidColRow(nCol, nRow))
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index a4e3b7b..ade158f 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -16,6 +16,7 @@
#include <com/sun/star/table/XCell2.hpp>
#include "formulacell.hxx"
#include "document.hxx"
#include "documentimport.hxx"
#include "convuno.hxx"

#include "rangelst.hxx"
@@ -92,9 +93,7 @@ void FormulaBuffer::applyCellFormula( ScDocument& rDoc, const ApiTokenSequence& 
    ScUnoConversion::FillScAddress( aCellPos, rAddress );
    ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, rTokens );
    ScFormulaCell* pNewCell = new ScFormulaCell( &rDoc, aCellPos, &aTokenArray );
    pNewCell->StartListeningTo( &rDoc );
    rDoc.EnsureTable(aCellPos.Tab());
    rDoc.SetGroupFormulaCell(aCellPos, pNewCell);
    getDocImport().setFormulaCell(aCellPos, pNewCell);
}

void FormulaBuffer::applyCellFormulas( const std::vector< TokenAddressItem >& rVector )
@@ -140,7 +139,7 @@ void FormulaBuffer::applySharedFormulas( sal_Int32 nTab )
    const std::vector<SharedFormulaEntry>& rSharedFormulas = itShared->second;
    const std::vector<SharedFormulaDesc>& rCells = itCells->second;

    ScDocument& rDoc = getScDocument();
    ScDocumentImport& rDoc = getDocImport();

    sc::SharedFormulaGroups aGroups;
    {
@@ -154,7 +153,7 @@ void FormulaBuffer::applySharedFormulas( sal_Int32 nTab )

            ScAddress aPos;
            ScUnoConversion::FillScAddress(aPos, rAddr);
            ScCompiler aComp(&rDoc, aPos);
            ScCompiler aComp(&rDoc.getDoc(), aPos);
            aComp.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
            ScTokenArray* pArray = aComp.CompileString(rTokenStr);
            if (pArray)
@@ -174,17 +173,8 @@ void FormulaBuffer::applySharedFormulas( sal_Int32 nTab )

            ScAddress aPos;
            ScUnoConversion::FillScAddress(aPos, rAddr);
            ScFormulaCell* pCell = new ScFormulaCell(&rDoc, aPos, pArray);
            bool bInserted = rDoc.SetGroupFormulaCell(aPos, pCell);
            if (!bInserted)
            {
                // Insertion failed.
                delete pCell;
                continue;
            }

            pCell->StartListeningTo(&rDoc);

            ScFormulaCell* pCell = new ScFormulaCell(&rDoc.getDoc(), aPos, pArray);
            rDoc.setFormulaCell(aPos, pCell);
            if (it->maCellValue.isEmpty())
            {
                // No cached cell value. Mark it for re-calculation.
@@ -210,7 +200,7 @@ void FormulaBuffer::applySharedFormulas( sal_Int32 nTab )

void FormulaBuffer::applyArrayFormulas( const std::vector< TokenRangeAddressItem >& rVector )
{
    ScDocument& rDoc = getScDocument();
    ScDocumentImport& rDocImport = getDocImport();
    std::vector<TokenRangeAddressItem>::const_iterator it = rVector.begin(), itEnd = rVector.end();
    for (; it != itEnd; ++it)
    {
@@ -219,21 +209,11 @@ void FormulaBuffer::applyArrayFormulas( const std::vector< TokenRangeAddressItem
        ScRange aRange;
        ScUnoConversion::FillScRange(aRange, it->maCellRangeAddress);

        ScCompiler aComp(&rDoc, aPos);
        ScCompiler aComp(&rDocImport.getDoc(), aPos);
        aComp.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
        ScTokenArray* pArray = aComp.CompileString(it->maTokenAndAddress.maTokenStr);
        if (pArray)
        {
            ScMarkData aMark;
            aMark.SelectOneTable(aPos.Tab());
            rDoc.InsertMatrixFormula(
                aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(),
                aMark, it->maTokenAndAddress.maTokenStr, pArray, formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);

            ScFormulaCell* pFC = rDoc.GetFormulaCell(aPos);
            if (pFC)
                pFC->StartListeningTo(&rDoc);
        }
            rDocImport.setMatrixCells(aRange, *pArray, formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
    }
}

diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index fe02efa..fb5eadd 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -1578,12 +1578,12 @@ void WorksheetHelper::putRichString( const CellAddress& rAddress, const RichStri

void WorksheetHelper::putFormulaTokens( const CellAddress& rAddress, const ApiTokenSequence& rTokens )
{
    ScDocument& rDoc = getScDocument();
    ScDocumentImport& rDoc = getDocImport();
    ScTokenArray aTokenArray;
    ScAddress aCellPos;
    ScUnoConversion::FillScAddress( aCellPos, rAddress );
    ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, rTokens );
    getDocImport().setFormulaCell(aCellPos, aTokenArray);
    ScTokenConversion::ConvertToTokenArray(rDoc.getDoc(), aTokenArray, rTokens);
    rDoc.setFormulaCell(aCellPos, aTokenArray);
}

void WorksheetHelper::initializeWorksheetImport()