[Libreoffice-commits] core.git: 3 commits - sc/inc sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Mon Dec 18 18:10:01 UTC 2017


 sc/inc/table.hxx                        |    2 
 sc/source/core/data/documen3.cxx        |   14 +--
 sc/source/core/data/documentimport.cxx  |   12 --
 sc/source/core/data/table2.cxx          |   15 +++
 sc/source/filter/inc/orcusinterface.hxx |   21 ++++-
 sc/source/filter/orcus/interface.cxx    |  130 +++++++++++++++++++++++---------
 6 files changed, 140 insertions(+), 54 deletions(-)

New commits:
commit ecfb22783f2462ba264e8793e3798c676dc9b727
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Sat Dec 9 14:32:30 2017 -0500

    Handle per-cell settings of cell formats.
    
    Change-Id: I500d01921d436643499a24d375d40a607d8fd576
    Reviewed-on: https://gerrit.libreoffice.org/46663
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>

diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx
index d85308732fea..e8c216308941 100644
--- a/sc/source/filter/orcus/interface.cxx
+++ b/sc/source/filter/orcus/interface.cxx
@@ -644,9 +644,13 @@ void ScOrcusSheet::set_date_time(
     cellInserted();
 }
 
-void ScOrcusSheet::set_format(os::row_t /*row*/, os::col_t /*col*/, size_t xf_index)
+void ScOrcusSheet::set_format(os::row_t row, os::col_t col, size_t xf_index)
 {
     SAL_INFO("sc.orcus.style", "set format: " << xf_index);
+
+    ScPatternAttr aPattern(mrDoc.getDoc().GetPool());
+    mrStyles.applyXfToItemSet(aPattern.GetItemSet(), xf_index);
+    mrDoc.getDoc().ApplyPattern(col, row, mnTab, aPattern);
 }
 
 void ScOrcusSheet::set_format(os::row_t row_start, os::col_t col_start,
commit c7529c1ecab2d22ed10e83627884da6b08f84e6d
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Sat Dec 9 13:38:27 2017 -0500

    Implement a reference resolver for orcus.
    
    Orcus uses this to resolve cell addresses for some ops.
    
    Change-Id: I6ee9667ad994fb830e545ba3368004866a048c25
    Reviewed-on: https://gerrit.libreoffice.org/46662
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>

diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx
index af5020c8ace4..e502d49296b1 100644
--- a/sc/source/filter/inc/orcusinterface.hxx
+++ b/sc/source/filter/inc/orcusinterface.hxx
@@ -47,6 +47,8 @@ class XStatusIndicator;
 class ScOrcusGlobalSettings : public orcus::spreadsheet::iface::import_global_settings
 {
     ScDocumentImport& mrDoc;
+    formula::FormulaGrammar::Grammar meCalcGrammar;
+    orcus::spreadsheet::formula_grammar_t meOrcusGrammar;
 
 public:
     ScOrcusGlobalSettings(ScDocumentImport& rDoc);
@@ -55,6 +57,22 @@ public:
 
     virtual void set_default_formula_grammar(orcus::spreadsheet::formula_grammar_t grammar) override;
     virtual orcus::spreadsheet::formula_grammar_t get_default_formula_grammar() const override;
+
+    formula::FormulaGrammar::Grammar getCalcGrammar() const
+    {
+        return meCalcGrammar;
+    }
+};
+
+class ScOrcusRefResolver : public orcus::spreadsheet::iface::import_reference_resolver
+{
+    const ScOrcusGlobalSettings& mrGlobalSettings;
+
+public:
+    ScOrcusRefResolver( const ScOrcusGlobalSettings& rGS );
+
+    orcus::spreadsheet::address_t resolve_address(const char* p, size_t n) override;
+    orcus::spreadsheet::range_t resolve_range(const char* p, size_t n) override;
 };
 
 class ScOrcusSharedStrings : public orcus::spreadsheet::iface::import_shared_strings
@@ -202,7 +220,7 @@ class ScOrcusSheet : public orcus::spreadsheet::iface::import_sheet
 public:
     ScOrcusSheet(ScDocumentImport& rDoc, SCTAB nTab, ScOrcusFactory& rFactory);
 
-    virtual orcus::spreadsheet::iface::import_auto_filter* get_auto_filter() override { return &maAutoFilter; }
+    virtual orcus::spreadsheet::iface::import_auto_filter* get_auto_filter() override;
     virtual orcus::spreadsheet::iface::import_table* get_table() override;
     virtual orcus::spreadsheet::iface::import_sheet_properties* get_sheet_properties() override;
     virtual orcus::spreadsheet::iface::import_conditional_format* get_conditional_format() override;
@@ -497,6 +515,7 @@ class ScOrcusFactory : public orcus::spreadsheet::iface::import_factory
 
     StringCellCaches maStringCells;
     ScOrcusGlobalSettings maGlobalSettings;
+    ScOrcusRefResolver maRefResolver;
     ScOrcusSharedStrings maSharedStrings;
     std::vector< std::unique_ptr<ScOrcusSheet> > maSheets;
     ScOrcusStyles maStyles;
diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx
index ec93824093a2..d85308732fea 100644
--- a/sc/source/filter/orcus/interface.cxx
+++ b/sc/source/filter/orcus/interface.cxx
@@ -58,20 +58,103 @@ using namespace com::sun::star;
 
 namespace os = orcus::spreadsheet;
 
-ScOrcusGlobalSettings::ScOrcusGlobalSettings(ScDocumentImport& rDoc) : mrDoc(rDoc) {}
+namespace {
+
+formula::FormulaGrammar::Grammar getCalcGrammarFromOrcus( os::formula_grammar_t grammar )
+{
+    formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_ODFF;
+    switch(grammar)
+    {
+        case orcus::spreadsheet::formula_grammar_t::ods:
+            eGrammar = formula::FormulaGrammar::GRAM_ODFF;
+            break;
+        case orcus::spreadsheet::formula_grammar_t::xlsx_2007:
+        case orcus::spreadsheet::formula_grammar_t::xlsx_2010:
+            eGrammar = formula::FormulaGrammar::GRAM_OOXML;
+            break;
+        case orcus::spreadsheet::formula_grammar_t::gnumeric:
+            eGrammar = formula::FormulaGrammar::GRAM_ENGLISH_XL_A1;
+            break;
+        case orcus::spreadsheet::formula_grammar_t::xls_xml:
+            eGrammar = formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1;
+            break;
+        case orcus::spreadsheet::formula_grammar_t::unknown:
+            break;
+    }
+
+    return eGrammar;
+}
+
+}
+
+ScOrcusGlobalSettings::ScOrcusGlobalSettings(ScDocumentImport& rDoc) :
+    mrDoc(rDoc), meOrcusGrammar(os::formula_grammar_t::unknown) {}
 
 void ScOrcusGlobalSettings::set_origin_date(int year, int month, int day)
 {
     mrDoc.setOriginDate(year, month, day);
 }
 
-void ScOrcusGlobalSettings::set_default_formula_grammar(orcus::spreadsheet::formula_grammar_t /*grammar*/)
+void ScOrcusGlobalSettings::set_default_formula_grammar(os::formula_grammar_t grammar)
 {
+    meCalcGrammar = getCalcGrammarFromOrcus(grammar);
+    meOrcusGrammar = grammar;
 }
 
 orcus::spreadsheet::formula_grammar_t ScOrcusGlobalSettings::get_default_formula_grammar() const
 {
-    return orcus::spreadsheet::formula_grammar_t::unknown;
+    return meOrcusGrammar;
+}
+
+ScOrcusRefResolver::ScOrcusRefResolver( const ScOrcusGlobalSettings& rGS ) :
+    mrGlobalSettings(rGS) {}
+
+os::address_t ScOrcusRefResolver::resolve_address(const char* p, size_t n)
+{
+    OUString aStr(p, n, RTL_TEXTENCODING_UTF8);
+
+    ScAddress aAddr;
+    aAddr.Parse(aStr, nullptr,
+        formula::FormulaGrammar::extractRefConvention(
+            mrGlobalSettings.getCalcGrammar()));
+
+    os::address_t ret;
+    ret.column = 0;
+    ret.row = 0;
+
+    if (aAddr.IsValid())
+    {
+        ret.column = aAddr.Col();
+        ret.row = aAddr.Row();
+    }
+
+    return ret;
+}
+
+os::range_t ScOrcusRefResolver::resolve_range(const char* p, size_t n)
+{
+    OUString aStr(p, n, RTL_TEXTENCODING_UTF8);
+
+    ScRange aRange;
+    aRange.Parse(aStr, nullptr,
+        formula::FormulaGrammar::extractRefConvention(
+            mrGlobalSettings.getCalcGrammar()));
+
+    os::range_t ret;
+    ret.first.column = 0;
+    ret.first.row = 0;
+    ret.last.column = 0;
+    ret.last.row = 0;
+
+    if (aRange.IsValid())
+    {
+        ret.first.column = aRange.aStart.Col();
+        ret.first.row    = aRange.aStart.Row();
+        ret.last.column  = aRange.aEnd.Col();
+        ret.last.row     = aRange.aEnd.Row();
+    }
+
+    return ret;
 }
 
 ScOrcusFactory::StringCellCache::StringCellCache(const ScAddress& rPos, size_t nIndex) :
@@ -80,6 +163,7 @@ ScOrcusFactory::StringCellCache::StringCellCache(const ScAddress& rPos, size_t n
 ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) :
     maDoc(rDoc),
     maGlobalSettings(maDoc),
+    maRefResolver(maGlobalSettings),
     maSharedStrings(*this),
     maStyles(rDoc),
     mnProgress(0) {}
@@ -487,6 +571,11 @@ void ScOrcusSheet::cellInserted()
     }
 }
 
+os::iface::import_auto_filter* ScOrcusSheet::get_auto_filter()
+{
+    return &maAutoFilter;
+}
+
 os::iface::import_table* ScOrcusSheet::get_table()
 {
     return nullptr;
@@ -569,35 +658,6 @@ void ScOrcusSheet::set_format(os::row_t row_start, os::col_t col_start,
     mrDoc.getDoc().ApplyPatternAreaTab(col_start, row_start, col_end, row_end, mnTab, aPattern);
 }
 
-namespace {
-
-formula::FormulaGrammar::Grammar getCalcGrammarFromOrcus( os::formula_grammar_t grammar )
-{
-    formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_ODFF;
-    switch(grammar)
-    {
-        case orcus::spreadsheet::formula_grammar_t::ods:
-            eGrammar = formula::FormulaGrammar::GRAM_ODFF;
-            break;
-        case orcus::spreadsheet::formula_grammar_t::xlsx_2007:
-        case orcus::spreadsheet::formula_grammar_t::xlsx_2010:
-            eGrammar = formula::FormulaGrammar::GRAM_OOXML;
-            break;
-        case orcus::spreadsheet::formula_grammar_t::gnumeric:
-            eGrammar = formula::FormulaGrammar::GRAM_ENGLISH_XL_A1;
-            break;
-        case orcus::spreadsheet::formula_grammar_t::xls_xml:
-            eGrammar = formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1;
-            break;
-        case orcus::spreadsheet::formula_grammar_t::unknown:
-            break;
-    }
-
-    return eGrammar;
-}
-
-}
-
 void ScOrcusSheet::set_formula(
     os::row_t row, os::col_t col, os::formula_grammar_t grammar, const char* p, size_t n)
 {
commit f06be8e23f4aabba9386ac7f93133bf418cb36d6
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Sat Dec 9 09:47:10 2017 -0500

    Remove almost duplicate code blocks.
    
    Change-Id: Ib75d0caa41876908091bed374d3afd802928acf7
    Reviewed-on: https://gerrit.libreoffice.org/46661
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>
    Tested-by: Kohei Yoshida <libreoffice at kohei.us>

diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index e9f47167dab0..0f6c10621b9b 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -669,6 +669,8 @@ public:
     bool        ExtendMerge( SCCOL nStartCol, SCROW nStartRow,
                                 SCCOL& rEndCol, SCROW& rEndRow,
                                 bool bRefresh );
+    void SetMergedCells( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
+
     const SfxPoolItem*      GetAttr( SCCOL nCol, SCROW nRow, sal_uInt16 nWhich ) const;
     const ScPatternAttr*    GetPattern( SCCOL nCol, SCROW nRow ) const;
     const ScPatternAttr*    GetMostUsedPattern( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const;
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 62c98d964c37..092044704c21 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -2020,15 +2020,11 @@ void ScDocument::DoEmptyBlock( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
 void ScDocument::DoMerge( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
                                     SCCOL nEndCol, SCROW nEndRow, bool bDeleteCaptions )
 {
-    ScMergeAttr aAttr( nEndCol-nStartCol+1, nEndRow-nStartRow+1 );
-    ApplyAttr( nStartCol, nStartRow, nTab, aAttr );
-
-    if ( nEndCol > nStartCol )
-        ApplyFlagsTab( nStartCol+1, nStartRow, nEndCol, nStartRow, nTab, ScMF::Hor );
-    if ( nEndRow > nStartRow )
-        ApplyFlagsTab( nStartCol, nStartRow+1, nStartCol, nEndRow, nTab, ScMF::Ver );
-    if ( nEndCol > nStartCol && nEndRow > nStartRow )
-        ApplyFlagsTab( nStartCol+1, nStartRow+1, nEndCol, nEndRow, nTab, ScMF::Hor | ScMF::Ver );
+    ScTable* pTab = FetchTable(nTab);
+    if (!pTab)
+        return;
+
+    pTab->SetMergedCells(nStartCol, nStartRow, nEndCol, nEndRow);
 
     // Remove all covered notes (removed captions are collected by drawing undo if active)
     InsertDeleteFlags nDelFlag = InsertDeleteFlags::NOTE | (bDeleteCaptions ? InsertDeleteFlags::NONE : InsertDeleteFlags::NOCAPTIONS);
diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index ddfcf8b10a94..183f3e1650af 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -518,17 +518,7 @@ void ScDocumentImport::setMergedCells(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCO
     if (!pTab)
         return;
 
-    ScMergeAttr aAttr(nCol2-nCol1+1, nRow2-nRow1+1);
-    pTab->ApplyAttr(nCol1, nRow1, aAttr);
-
-    if (nCol1 < nCol2)
-        pTab->ApplyFlags(nCol1+1, nRow1, nCol2, nRow2, ScMF::Hor);
-
-    if (nRow1 < nRow2)
-        pTab->ApplyFlags(nCol1, nRow1+1, nCol1, nRow2, ScMF::Ver);
-
-    if (nCol1 < nCol2 && nRow1 < nRow2)
-        pTab->ApplyFlags(nCol1+1, nRow1+1, nCol2, nRow2, ScMF::Hor | ScMF::Ver);
+    pTab->SetMergedCells(nCol1, nRow1, nCol2, nRow2);
 }
 
 namespace {
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 751b7f0d5f4f..184f57e719d6 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2023,6 +2023,21 @@ bool ScTable::ExtendMerge( SCCOL nStartCol, SCROW nStartRow,
     return bFound;
 }
 
+void ScTable::SetMergedCells( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
+{
+    ScMergeAttr aAttr(nCol2-nCol1+1, nRow2-nRow1+1);
+    ApplyAttr(nCol1, nRow1, aAttr);
+
+    if (nCol1 < nCol2)
+        ApplyFlags(nCol1+1, nRow1, nCol2, nRow2, ScMF::Hor);
+
+    if (nRow1 < nRow2)
+        ApplyFlags(nCol1, nRow1+1, nCol1, nRow2, ScMF::Ver);
+
+    if (nCol1 < nCol2 && nRow1 < nRow2)
+        ApplyFlags(nCol1+1, nRow1+1, nCol2, nRow2, ScMF::Hor | ScMF::Ver);
+}
+
 bool ScTable::IsBlockEmpty( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bIgnoreNotes ) const
 {
     if (!(ValidCol(nCol1) && ValidCol(nCol2)))


More information about the Libreoffice-commits mailing list