[Libreoffice-commits] .: 2 commits - framework/source sc/inc sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Dec 3 23:29:19 PST 2012
framework/source/loadenv/loadenv.cxx | 24 ++
sc/inc/orcusfilters.hxx | 2
sc/source/filter/inc/orcusfiltersimpl.hxx | 1
sc/source/filter/inc/orcusinterface.hxx | 67 +++++++
sc/source/filter/orcus/interface.cxx | 242 ++++++++++++++++++++++++++--
sc/source/filter/orcus/orcusfiltersimpl.cxx | 21 ++
sc/source/ui/docshell/docsh.cxx | 2
7 files changed, 346 insertions(+), 13 deletions(-)
New commits:
commit 9c2dfa9b41f82cfa763c500d34fe2a32a075f566
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Tue Dec 4 07:50:20 2012 +0100
activate basic gnumeric support in experimental mode
Please note that this is nothing mroe than a technical demo showing the
great opportunities provided by orcus.
It only imports some basic objects for now but provides the basis for
the future calc filter framework.
Change-Id: I6c6fb8d07e33482b2efdcbbe9a0f43224c5aa5a1
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
index c676fe4..78bc67c 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -32,6 +32,9 @@
#include <services.h>
#include <comphelper/interaction.hxx>
#include <framework/interaction.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/configuration.hxx>
+#include "officecfg/Office/Common.hxx"
#include <com/sun/star/task/ErrorCodeRequest.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>
@@ -703,15 +706,22 @@ LoadEnv::EContentType LoadEnv::classifyContent(const ::rtl::OUString&
namespace {
-#if 1
+#if 0
+// TODO: We will reinstate this function later, so don't remove this!
bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>&, OUString&, OUString&)
{
return false;
}
#else
-// TODO: We will reinstate this function later, so don't remove this!
bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>& rDescriptor, OUString& rType, OUString& rFilter)
{
+ // depending on the experimental mode
+ uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
+ if (!xContext.is() || !officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
+ {
+ return false;
+ }
+
OUString aURL;
sal_Int32 nSize = rDescriptor.getLength();
for (sal_Int32 i = 0; i < nSize; ++i)
@@ -727,13 +737,21 @@ bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>& rDescrip
if (aURL.isEmpty() || aURL.copy(0,8).equalsIgnoreAsciiCase("private:"))
return false;
- if (aURL.endsWith(".csv"))
+ if(aURL.endsWith(".gnumeric"))
+ {
+ rType = "generic_Text";
+ rFilter = "orcus-gnumeric";
+ return true;
+ }
+#if 0
+ else if (aURL.endsWith(".csv"))
{
// Use .csv as the first test file type.
rType = "generic_Text";
rFilter = "orcus-test-filter";
return true;
}
+#endif
return false;
}
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx
index bcf8881..9f3ca13 100644
--- a/sc/inc/orcusfilters.hxx
+++ b/sc/inc/orcusfilters.hxx
@@ -29,6 +29,8 @@ public:
virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const = 0;
+ virtual bool importGnumeric(ScDocument& rDoc, const rtl::OUString& rPath) const = 0;
+
/**
* Create a context for XML file. The context object stores session
* information for each unique XML file. You must create a new context
diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx
index 2238b70..a97a50c 100644
--- a/sc/source/filter/inc/orcusfiltersimpl.hxx
+++ b/sc/source/filter/inc/orcusfiltersimpl.hxx
@@ -21,6 +21,7 @@ public:
static rtl::OString toSystemPath(const rtl::OUString& rPath);
virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const;
+ virtual bool importGnumeric(ScDocument& rDoc, const rtl::OUString& rPath) const;
virtual ScOrcusXMLContext* createXMLContext(ScDocument& rDoc, const rtl::OUString& rPath) const;
};
diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx
index d800474..2f8380c 100644
--- a/sc/source/filter/inc/orcusinterface.hxx
+++ b/sc/source/filter/inc/orcusinterface.hxx
@@ -17,6 +17,8 @@
#include <boost/ptr_container/ptr_vector.hpp>
+#include <map>
+
class ScDocument;
class ScOrcusSheet;
class ScRangeData;
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 4e6c98b..ed33cc1 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -16,6 +16,7 @@
#include <orcus/spreadsheet/import_interface.hpp>
#include <orcus/orcus_csv.hpp>
+#include <orcus/orcus_gnumeric.hpp>
#include <orcus/global.hpp>
#ifdef WNT
@@ -50,6 +51,26 @@ bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, const OUString& rPath) cons
return true;
}
+bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, const OUString& rPath) const
+{
+ ScOrcusFactory aFactory(rDoc);
+ OString aSysPath = toSystemPath(rPath);
+ const char* path = aSysPath.getStr();
+
+ try
+ {
+ orcus::orcus_gnumeric filter(&aFactory);
+ filter.read_file(path);
+ }
+ catch (const std::exception& e)
+ {
+ SAL_WARN("sc", "Unable to load gnumeric file! " << e.what());
+ return false;
+ }
+
+ return true;
+}
+
ScOrcusXMLContext* ScOrcusFiltersImpl::createXMLContext(ScDocument& rDoc, const rtl::OUString& rPath) const
{
return new ScOrcusXMLContextImpl(rDoc, rPath);
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 2fe4cad..52355d6 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1426,7 +1426,7 @@ bool ScDocShell::LoadExternal(SfxMedium& rMed, const OUString& rProvider)
if (!pOrcus)
return false;
- if (!pOrcus->importCSV(aDocument, rMed.GetName()))
+ if (!pOrcus->importGnumeric(aDocument, rMed.GetName()))
return false;
FinishedLoading(SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES);
commit cb9cc446b39cafea018d2492fb4842a94aed7b77
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Tue Dec 4 06:48:59 2012 +0100
shared formula import for orcus
Change-Id: I97970c19d69263c34ed0cdb0ed789086608d4bf1
diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx
index 6bf3311..d800474 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 2e99eaa..b21e7e5 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: */
More information about the Libreoffice-commits
mailing list