Kaydet (Commit) 512ccd16 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Make the same change to the orcus interface & remove unused methods.

Change-Id: I1263026133b694e531c0a99b16d622e1ae12db48
üst 0eabc71b
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "scdllapi.h" #include "scdllapi.h"
#include "types.hxx" #include "types.hxx"
#include "calcmacros.hxx" #include "calcmacros.hxx"
#include "address.hxx"
#include "global.hxx"
#include <formula/tokenarray.hxx> #include <formula/tokenarray.hxx>
namespace sc { namespace sc {
......
...@@ -11,50 +11,17 @@ ...@@ -11,50 +11,17 @@
namespace sc { namespace sc {
SharedFormulaGroups::Key::Key(size_t nId, SCCOL nCol) : mnId(nId), mnCol(nCol) {}
bool SharedFormulaGroups::Key::operator== ( const Key& rOther ) const
{
return mnId == rOther.mnId && mnCol == rOther.mnCol;
}
bool SharedFormulaGroups::Key::operator!= ( const Key& rOther ) const
{
return !operator==(rOther);
}
size_t SharedFormulaGroups::KeyHash::operator ()( const Key& rKey ) const
{
double nVal = rKey.mnId;
nVal *= 256.0;
nVal += rKey.mnCol;
return static_cast<size_t>(nVal);
}
void SharedFormulaGroups::set( size_t nSharedId, ScTokenArray* pArray ) void SharedFormulaGroups::set( size_t nSharedId, ScTokenArray* pArray )
{ {
maStore.insert(nSharedId, pArray); maStore.insert(nSharedId, pArray);
} }
void SharedFormulaGroups::set( size_t nSharedId, SCCOL nCol, const ScFormulaCellGroupRef& xGroup )
{
Key aKey(nSharedId, nCol);
maColStore.insert(ColStoreType::value_type(aKey, xGroup));
}
const ScTokenArray* SharedFormulaGroups::get( size_t nSharedId ) const const ScTokenArray* SharedFormulaGroups::get( size_t nSharedId ) const
{ {
StoreType::const_iterator it = maStore.find(nSharedId); StoreType::const_iterator it = maStore.find(nSharedId);
return it == maStore.end() ? NULL : it->second; return it == maStore.end() ? NULL : it->second;
} }
ScFormulaCellGroupRef SharedFormulaGroups::get( size_t nSharedId, SCCOL nCol ) const
{
Key aKey(nSharedId, nCol);
ColStoreType::const_iterator it = maColStore.find(aKey);
return it == maColStore.end() ? ScFormulaCellGroupRef() : it->second;
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -10,43 +10,20 @@ ...@@ -10,43 +10,20 @@
#ifndef SC_FILTER_SHAREDFORMULAGROUPS_HXX #ifndef SC_FILTER_SHAREDFORMULAGROUPS_HXX
#define SC_FILTER_SHAREDFORMULAGROUPS_HXX #define SC_FILTER_SHAREDFORMULAGROUPS_HXX
#include "address.hxx"
#include "formulacell.hxx"
#include "tokenarray.hxx" #include "tokenarray.hxx"
#include <boost/ptr_container/ptr_map.hpp> #include <boost/ptr_container/ptr_map.hpp>
#include <boost/unordered_map.hpp>
namespace sc { namespace sc {
class SharedFormulaGroups class SharedFormulaGroups
{ {
struct Key
{
size_t mnId;
SCCOL mnCol;
Key(size_t nId, SCCOL nCol);
bool operator== ( const Key& rOther ) const;
bool operator!= ( const Key& rOther ) const;
};
struct KeyHash
{
size_t operator() ( const Key& rKey ) const;
};
typedef boost::ptr_map<size_t, ScTokenArray> StoreType; typedef boost::ptr_map<size_t, ScTokenArray> StoreType;
typedef boost::unordered_map<Key, ScFormulaCellGroupRef, KeyHash> ColStoreType;
ColStoreType maColStore;
StoreType maStore; StoreType maStore;
public: public:
void set( size_t nSharedId, ScTokenArray* pArray ); void set( size_t nSharedId, ScTokenArray* pArray );
void set( size_t nSharedId, SCCOL nCol, const ScFormulaCellGroupRef& xGroup );
const ScTokenArray* get( size_t nSharedId ) const; const ScTokenArray* get( size_t nSharedId ) const;
ScFormulaCellGroupRef get( size_t nSharedId, SCCOL nCol ) const;
}; };
} }
......
...@@ -340,29 +340,13 @@ void ScOrcusSheet::set_formula_result(os::row_t row, os::col_t col, const char* ...@@ -340,29 +340,13 @@ void ScOrcusSheet::set_formula_result(os::row_t row, os::col_t col, const char*
pCell->SetHybridString(aResult); pCell->SetHybridString(aResult);
} }
void ScOrcusSheet::set_shared_formula(
os::row_t /*row*/, os::col_t /*col*/, os::formula_grammar_t /*grammar*/, size_t /*sindex*/,
const char* /*p_formula*/, size_t /*n_formula*/)
{
// TODO: We need to revise this interface in orcus.
}
void ScOrcusSheet::set_shared_formula( void ScOrcusSheet::set_shared_formula(
os::row_t row, os::col_t col, os::formula_grammar_t grammar, size_t sindex, os::row_t row, os::col_t col, os::formula_grammar_t grammar, size_t sindex,
const char* p_formula, size_t n_formula, const char* p_range, size_t n_range) const char* p_formula, size_t n_formula)
{ {
ScAddress aPos(col, row, mnTab); ScAddress aPos(col, row, mnTab);
OUString aFormula(p_formula, n_formula, RTL_TEXTENCODING_UTF8); OUString aFormula(p_formula, n_formula, RTL_TEXTENCODING_UTF8);
OUString aRangeStr(p_range, n_range, RTL_TEXTENCODING_UTF8);
formula::FormulaGrammar::Grammar eGram = getCalcGrammarFromOrcus(grammar); formula::FormulaGrammar::Grammar eGram = getCalcGrammarFromOrcus(grammar);
formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::extractRefConvention(eGram);
// Convert the shared formula range.
ScRange aRange;
sal_uInt16 nRes = aRange.Parse(aRangeStr, &mrDoc.getDoc(), eConv);
if (!(nRes & SCA_VALID))
// Conversion failed.
return;
// Compile the formula expression into tokens. // Compile the formula expression into tokens.
ScCompiler aComp(&mrDoc.getDoc(), aPos); ScCompiler aComp(&mrDoc.getDoc(), aPos);
...@@ -372,24 +356,9 @@ void ScOrcusSheet::set_shared_formula( ...@@ -372,24 +356,9 @@ void ScOrcusSheet::set_shared_formula(
// Tokenization failed. // Tokenization failed.
return; return;
for (sal_Int32 nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); ++nCol) maFormulaGroups.set(sindex, pArray);
{
// Create one group per column, since Calc doesn't support shared
// formulas across multiple columns.
ScFormulaCellGroupRef xNewGroup(new ScFormulaCellGroup);
xNewGroup->mnStart = aRange.aStart.Row();
xNewGroup->mnLength = 1;
xNewGroup->setCode(*pArray);
maFormulaGroups.set(sindex, nCol, xNewGroup);
}
ScFormulaCellGroupRef xGroup = maFormulaGroups.get(sindex, aPos.Col());
if (!xGroup)
return;
// Generate code for the top cell only. ScFormulaCell* pCell = new ScFormulaCell(&mrDoc.getDoc(), aPos, pArray);
xGroup->compileCode(mrDoc.getDoc(), aPos, formula::FormulaGrammar::GRAM_DEFAULT);
ScFormulaCell* pCell = new ScFormulaCell(&mrDoc.getDoc(), aPos, xGroup);
mrDoc.setFormulaCell(aPos, pCell); mrDoc.setFormulaCell(aPos, pCell);
cellInserted(); cellInserted();
...@@ -398,16 +367,22 @@ void ScOrcusSheet::set_shared_formula( ...@@ -398,16 +367,22 @@ void ScOrcusSheet::set_shared_formula(
pCell->StartListeningTo(&mrDoc.getDoc()); pCell->StartListeningTo(&mrDoc.getDoc());
} }
void ScOrcusSheet::set_shared_formula(
os::row_t row, os::col_t col, os::formula_grammar_t grammar, size_t sindex,
const char* p_formula, size_t n_formula, const char* /*p_range*/, size_t /*n_range*/)
{
set_shared_formula(row, col, grammar, sindex, p_formula, n_formula);
}
void ScOrcusSheet::set_shared_formula(os::row_t row, os::col_t col, size_t sindex) void ScOrcusSheet::set_shared_formula(os::row_t row, os::col_t col, size_t sindex)
{ {
ScAddress aPos(col, row, mnTab); ScAddress aPos(col, row, mnTab);
ScFormulaCellGroupRef xGroup = maFormulaGroups.get(sindex, aPos.Col()); const ScTokenArray* pArray = maFormulaGroups.get(sindex);
if (!xGroup) if (!pArray)
return; return;
xGroup->mnLength = aPos.Row() - xGroup->mnStart + 1; ScFormulaCell* pCell = new ScFormulaCell(&mrDoc.getDoc(), aPos, pArray);
ScFormulaCell* pCell = new ScFormulaCell(&mrDoc.getDoc(), aPos, xGroup);
mrDoc.setFormulaCell(aPos, pCell); mrDoc.setFormulaCell(aPos, pCell);
cellInserted(); cellInserted();
......
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