diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-12-04 06:48:59 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-12-04 08:24:17 +0100 |
commit | cb9cc446b39cafea018d2492fb4842a94aed7b77 (patch) | |
tree | 9b4c8bd802695c1ebe395cf5953b9720f7cd008c /sc | |
parent | 16155fdc39c004dc924a3b6919eb7c86da23c119 (diff) |
shared formula import for orcus
Change-Id: I97970c19d69263c34ed0cdb0ed789086608d4bf1
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/inc/orcusinterface.hxx | 65 | ||||
-rw-r--r-- | sc/source/filter/orcus/interface.cxx | 242 |
2 files changed, 298 insertions, 9 deletions
diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx index 6bf3311c61e5..d800474d560a 100644 --- a/sc/source/filter/inc/orcusinterface.hxx +++ b/sc/source/filter/inc/orcusinterface.hxx @@ -19,6 +19,7 @@ class ScDocument; class ScOrcusSheet; +class ScRangeData; class ScOrcusSharedStrings : public orcus::spreadsheet::iface::import_shared_strings { @@ -59,6 +60,9 @@ class ScOrcusSheet : public orcus::spreadsheet::iface::import_sheet ScDocument& mrDoc; SCTAB mnTab; ScOrcusSharedStrings& mrSharedStrings; + + typedef std::map<size_t, ScRangeData*> SharedFormulaContainer; + SharedFormulaContainer maSharedFormulas; public: ScOrcusSheet(ScDocument& rDoc, SCTAB nTab, ScOrcusSharedStrings& rSharedStrings); @@ -80,5 +84,66 @@ public: SCTAB getIndex() const { return mnTab; } }; +class ScOrcusStyles : public orcus::spreadsheet::iface::import_styles +{ + +public: + // font + + virtual void set_font_count(size_t n); + virtual void set_font_bold(bool b); + virtual void set_font_italic(bool b); + virtual void set_font_name(const char* s, size_t n); + virtual void set_font_size(double point); + virtual void set_font_underline(orcus::spreadsheet::underline_t e); + virtual size_t commit_font(); + + // fill + + virtual void set_fill_count(size_t n); + virtual void set_fill_pattern_type(const char* s, size_t n); + virtual void set_fill_fg_color(orcus::spreadsheet::color_elem_t alpha, orcus::spreadsheet::color_elem_t red, orcus::spreadsheet::color_elem_t green, orcus::spreadsheet::color_elem_t blue); + virtual void set_fill_bg_color(orcus::spreadsheet::color_elem_t alpha, orcus::spreadsheet::color_elem_t red, orcus::spreadsheet::color_elem_t green, orcus::spreadsheet::color_elem_t blue); + virtual size_t commit_fill(); + + // border + + virtual void set_border_count(size_t n); + virtual void set_border_style(orcus::spreadsheet::border_direction_t dir, const char* s, size_t n); + virtual size_t commit_border(); + + // cell protection + virtual void set_cell_hidden(bool b); + virtual void set_cell_locked(bool b); + virtual size_t commit_cell_protection(); + + // cell style xf + + virtual void set_cell_style_xf_count(size_t n); + virtual size_t commit_cell_style_xf(); + + // cell xf + + virtual void set_cell_xf_count(size_t n); + virtual size_t commit_cell_xf(); + + // xf (cell format) - used both by cell xf and cell style xf. + + virtual void set_xf_number_format(size_t index); + virtual void set_xf_font(size_t index); + virtual void set_xf_fill(size_t index); + virtual void set_xf_border(size_t index); + virtual void set_xf_protection(size_t index); + virtual void set_xf_style_xf(size_t index); + + // cell style entry + + virtual void set_cell_style_count(size_t n); + virtual void set_cell_style_name(const char* s, size_t n); + virtual void set_cell_style_xf(size_t index); + virtual void set_cell_style_builtin(size_t index); + virtual size_t commit_cell_style(); +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx index 2e99eaae7f3e..b21e7e56e6c3 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -11,6 +11,10 @@ #include "document.hxx" #include "cell.hxx" +#include "rangenam.hxx" +#include "tokenarray.hxx" +#include <formula/token.hxx> + using orcus::spreadsheet::row_t; using orcus::spreadsheet::col_t; @@ -69,7 +73,7 @@ orcus::spreadsheet::iface::import_shared_strings* ScOrcusFactory::get_shared_str orcus::spreadsheet::iface::import_styles* ScOrcusFactory::get_styles() { // We don't support it yet. - return NULL; + return new ScOrcusStyles; } ScOrcusSheet::ScOrcusSheet(ScDocument& rDoc, SCTAB nTab, ScOrcusSharedStrings& rSharedStrings) : @@ -85,10 +89,10 @@ void ScOrcusSheet::set_format(row_t /*row*/, col_t /*col*/, size_t /*xf_index*/) { } -void ScOrcusSheet::set_formula( - row_t row, col_t col, formula_grammar_t grammar, const char* p, size_t n) +namespace { + +formula::FormulaGrammar::Grammar getCalcGrammarFromOrcus( formula_grammar_t grammar ) { - OUString aFormula(p, n, RTL_TEXTENCODING_UTF8); formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_ODFF; switch(grammar) { @@ -104,6 +108,17 @@ void ScOrcusSheet::set_formula( break; } + return eGrammar; +} + +} + +void ScOrcusSheet::set_formula( + row_t row, col_t col, formula_grammar_t grammar, const char* p, size_t n) +{ + OUString aFormula(p, n, RTL_TEXTENCODING_UTF8); + formula::FormulaGrammar::Grammar eGrammar = getCalcGrammarFromOrcus( grammar ); + ScFormulaCell* pCell = new ScFormulaCell(&mrDoc, ScAddress(col, row, mnTab), aFormula, eGrammar); mrDoc.PutCell(col, row, mnTab, pCell); } @@ -123,19 +138,57 @@ void ScOrcusSheet::set_formula_result(row_t row, col_t col, const char* p, size_ } void ScOrcusSheet::set_shared_formula( - row_t /*row*/, col_t /*col*/, formula_grammar_t /*grammar*/, size_t /*sindex*/, - const char* /*p_formula*/, size_t /*n_formula*/) + row_t row, col_t col, formula_grammar_t grammar, size_t sindex, + const char* p_formula, size_t n_formula) { + OUString aFormula( p_formula, n_formula, RTL_TEXTENCODING_UTF8 ); + formula::FormulaGrammar::Grammar eGrammar = getCalcGrammarFromOrcus( grammar ); + ScRangeName* pRangeName = mrDoc.GetRangeName(); + + OUString aName("shared_"); + aName += OUString::valueOf(sal_Int32(pRangeName->size())); + ScRangeData* pSharedFormula = new ScRangeData( &mrDoc, aName, aFormula, ScAddress(col, row, mnTab), RT_SHARED, eGrammar); + if(pRangeName->insert(pSharedFormula)) + { + maSharedFormulas.insert( std::pair<size_t, ScRangeData*>(sindex, pSharedFormula) ); + ScTokenArray aArr; + aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) ); + ScFormulaCell* pCell = new ScFormulaCell( &mrDoc, ScAddress( row, col, mnTab ), &aArr ); + mrDoc.PutCell( col, row, mnTab, pCell ); + } } void ScOrcusSheet::set_shared_formula( - row_t /*row*/, col_t /*col*/, formula_grammar_t /*grammar*/, size_t /*sindex*/, - const char* /*p_formula*/, size_t /*n_formula*/, const char* /*p_range*/, size_t /*n_range*/) + row_t row, col_t col, formula_grammar_t grammar, size_t sindex, + const char* p_formula, size_t n_formula, const char* /*p_range*/, size_t /*n_range*/) { + OUString aFormula( p_formula, n_formula, RTL_TEXTENCODING_UTF8 ); + formula::FormulaGrammar::Grammar eGrammar = getCalcGrammarFromOrcus( grammar ); + ScRangeName* pRangeName = mrDoc.GetRangeName(); + + OUString aName("shared_"); + aName += OUString::valueOf(sal_Int32(pRangeName->size())); + ScRangeData* pSharedFormula = new ScRangeData( &mrDoc, aName, aFormula, ScAddress(col, row, mnTab), RT_SHARED, eGrammar); + if(pRangeName->insert(pSharedFormula)) + { + maSharedFormulas.insert( std::pair<size_t, ScRangeData*>(sindex, pSharedFormula) ); + ScTokenArray aArr; + aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) ); + ScFormulaCell* pCell = new ScFormulaCell( &mrDoc, ScAddress( row, col, mnTab ), &aArr ); + mrDoc.PutCell( col, row, mnTab, pCell ); + } } -void ScOrcusSheet::set_shared_formula(row_t /*row*/, col_t /*col*/, size_t /*sindex*/) +void ScOrcusSheet::set_shared_formula(row_t row, col_t col, size_t sindex) { + if(maSharedFormulas.find(sindex) == maSharedFormulas.end()) + return; + + ScRangeData* pSharedFormula = maSharedFormulas.find(sindex)->second; + ScTokenArray aArr; + aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) ); + ScFormulaCell* pCell = new ScFormulaCell( &mrDoc, ScAddress( row, col, mnTab ), &aArr ); + mrDoc.PutCell( col, row, mnTab, pCell ); } void ScOrcusSheet::set_string(row_t row, col_t col, size_t sindex) @@ -199,4 +252,175 @@ size_t ScOrcusSharedStrings::commit_segments() { return 0; } + +void ScOrcusStyles::set_font_count(size_t /*n*/) +{ + // needed at all? +} + +void ScOrcusStyles::set_font_bold(bool /*b*/) +{ +} + +void ScOrcusStyles::set_font_italic(bool /*b*/) +{ +} + +void ScOrcusStyles::set_font_name(const char* /*s*/, size_t /*n*/) +{ +} + +void ScOrcusStyles::set_font_size(double /*point*/) +{ +} + +void ScOrcusStyles::set_font_underline(orcus::spreadsheet::underline_t /*e*/) +{ +} + +size_t ScOrcusStyles::commit_font() +{ + return 0; +} + + +// fill + +void ScOrcusStyles::set_fill_count(size_t /*n*/) +{ + // needed at all? +} + +void ScOrcusStyles::set_fill_pattern_type(const char* /*s*/, size_t /*n*/) +{ +} + +void ScOrcusStyles::set_fill_fg_color(orcus::spreadsheet::color_elem_t /*alpha*/, orcus::spreadsheet::color_elem_t /*red*/, orcus::spreadsheet::color_elem_t /*green*/, orcus::spreadsheet::color_elem_t /*blue*/) +{ +} + +void ScOrcusStyles::set_fill_bg_color(orcus::spreadsheet::color_elem_t /*alpha*/, orcus::spreadsheet::color_elem_t /*red*/, orcus::spreadsheet::color_elem_t /*green*/, orcus::spreadsheet::color_elem_t /*blue*/) +{ +} + +size_t ScOrcusStyles::commit_fill() +{ + return 0; +} + + +// border + +void ScOrcusStyles::set_border_count(size_t /*n*/) +{ + // needed at all? +} + +void ScOrcusStyles::set_border_style(orcus::spreadsheet::border_direction_t /*dir*/, const char* /*s*/, size_t /*n*/) +{ + // implement later +} + +size_t ScOrcusStyles::commit_border() +{ + return 0; +} + + +// cell protection +void ScOrcusStyles::set_cell_hidden(bool /*b*/) +{ +} + +void ScOrcusStyles::set_cell_locked(bool /*b*/) +{ +} + +size_t ScOrcusStyles::commit_cell_protection() +{ + return 0; +} + + +// cell style xf + +void ScOrcusStyles::set_cell_style_xf_count(size_t /*n*/) +{ + // needed at all? +} + +size_t ScOrcusStyles::commit_cell_style_xf() +{ + return 0; +} + + +// cell xf + +void ScOrcusStyles::set_cell_xf_count(size_t /*n*/) +{ + // needed at all? +} + +size_t ScOrcusStyles::commit_cell_xf() +{ + return 0; +} + + +// xf (cell format) - used both by cell xf and cell style xf. + +void ScOrcusStyles::set_xf_number_format(size_t /*index*/) +{ + // no number format interfaces implemented yet +} + +void ScOrcusStyles::set_xf_font(size_t /*index*/) +{ +} + +void ScOrcusStyles::set_xf_fill(size_t /*index*/) +{ +} + +void ScOrcusStyles::set_xf_border(size_t /*index*/) +{ +} + +void ScOrcusStyles::set_xf_protection(size_t /*index*/) +{ +} + +void ScOrcusStyles::set_xf_style_xf(size_t /*index*/) +{ +} + + +// cell style entry +// not needed for now for gnumeric + +void ScOrcusStyles::set_cell_style_count(size_t /*n*/) +{ + // needed at all? +} + +void ScOrcusStyles::set_cell_style_name(const char* /*s*/, size_t /*n*/) +{ +} + +void ScOrcusStyles::set_cell_style_xf(size_t /*index*/) +{ +} + +void ScOrcusStyles::set_cell_style_builtin(size_t /*index*/) +{ + // not needed for gnumeric +} + +size_t ScOrcusStyles::commit_cell_style() +{ + return 0; +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |