[Libreoffice-commits] .: 60 commits - icon-themes/galaxy officecfg/registry sc/AllLangResTarget_sc.mk sc/inc sc/Library_scfilt.mk sc/Library_sc.mk sc/sdi sc/source sc/uiconfig svtools/inc svtools/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Nov 28 10:42:42 PST 2012
icon-themes/galaxy/sc/res/xml_attribute.png |binary
icon-themes/galaxy/sc/res/xml_element.png |binary
icon-themes/galaxy/sc/res/xml_element_repeat.png |binary
officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu | 5
sc/AllLangResTarget_sc.mk | 1
sc/Library_sc.mk | 2
sc/Library_scfilt.mk | 2
sc/inc/filter.hxx | 4
sc/inc/orcusfilters.hxx | 26
sc/inc/orcusxml.hxx | 83 +
sc/inc/sc.hrc | 2
sc/inc/scabstdlg.hxx | 1
sc/inc/sccommands.h | 1
sc/sdi/cellsh.sdi | 1
sc/sdi/scalc.sdi | 25
sc/source/core/tool/orcusxml.cxx | 32
sc/source/filter/inc/orcusfiltersimpl.hxx | 22
sc/source/filter/inc/orcusinterface.hxx | 63 +
sc/source/filter/orcus/interface.cxx | 121 +
sc/source/filter/orcus/orcusfiltersimpl.cxx | 140 --
sc/source/filter/orcus/xmlcontext.cxx | 274 ++++
sc/source/ui/app/scdll.cxx | 1
sc/source/ui/attrdlg/scdlgfact.cxx | 2
sc/source/ui/attrdlg/scdlgfact.hxx | 2
sc/source/ui/inc/cellsh.hxx | 1
sc/source/ui/inc/reffact.hxx | 1
sc/source/ui/inc/xmlsourcedlg.hrc | 30
sc/source/ui/inc/xmlsourcedlg.hxx | 114 +
sc/source/ui/src/xmlsourcedlg.src | 120 +
sc/source/ui/view/cellsh1.cxx | 18
sc/source/ui/view/cellsh2.cxx | 3
sc/source/ui/view/reffact.cxx | 4
sc/source/ui/view/tabvwsh.cxx | 1
sc/source/ui/view/tabvwshc.cxx | 7
sc/source/ui/xmlsource/xmlsourcedlg.cxx | 627 ++++++++++
sc/uiconfig/scalc/menubar/menubar.xml | 2
svtools/inc/svtools/treelistentry.hxx | 3
svtools/source/contnr/treelistentry.cxx | 10
38 files changed, 1623 insertions(+), 128 deletions(-)
New commits:
commit abfe16cec61eae33c64cb1901f0fc740b0466f60
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Nov 27 22:01:07 2012 -0500
Get it to build after the rebase.
Change-Id: I86bc4fb6aa4158f0efc3ab765841abcea9063693
diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
index c25ecb1..bdb99ca 100644
--- a/sc/Library_scfilt.mk
+++ b/sc/Library_scfilt.mk
@@ -222,7 +222,6 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\
sc/source/filter/oox/worksheetsettings \
sc/source/filter/orcus/orcusfiltersimpl \
sc/source/filter/orcus/interface \
- sc/source/filter/orcus/orcusxml \
sc/source/filter/orcus/xmlcontext \
))
diff --git a/sc/source/core/tool/orcusxml.cxx b/sc/source/core/tool/orcusxml.cxx
index b3cbd46..c4a7b77 100644
--- a/sc/source/core/tool/orcusxml.cxx
+++ b/sc/source/core/tool/orcusxml.cxx
@@ -10,6 +10,7 @@
#include "orcusxml.hxx"
#include "svtools/treelistbox.hxx"
+#include "svtools/treelistentry.hxx"
#include "rtl/strbuf.hxx"
ScOrcusXMLTreeParam::EntryData::EntryData(EntryType eType) :
diff --git a/sc/source/filter/orcus/xmlcontext.cxx b/sc/source/filter/orcus/xmlcontext.cxx
index c62d39b..337d107 100644
--- a/sc/source/filter/orcus/xmlcontext.cxx
+++ b/sc/source/filter/orcus/xmlcontext.cxx
@@ -13,6 +13,7 @@
#include "document.hxx"
#include "svtools/treelistbox.hxx"
+#include "svtools/treelistentry.hxx"
#define __ORCUS_STATIC_LIB
#include <orcus/spreadsheet/import_interface.hpp>
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 38a1d09..7a3afd4 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -20,6 +20,7 @@
#include "unotools/pathoptions.hxx"
#include "tools/urlobj.hxx"
#include "svtools/svlbitm.hxx"
+#include "svtools/treelistentry.hxx"
#include "sfx2/objsh.hxx"
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
diff --git a/svtools/inc/svtools/treelistentry.hxx b/svtools/inc/svtools/treelistentry.hxx
index ef33942..dfea265 100644
--- a/svtools/inc/svtools/treelistentry.hxx
+++ b/svtools/inc/svtools/treelistentry.hxx
@@ -72,6 +72,9 @@ public:
bool HasChildListPos() const;
sal_uLong GetChildListPos() const;
+ SvTreeListEntries& GetChildEntries();
+ const SvTreeListEntries& GetChildEntries() const;
+
void Clone(SvTreeListEntry* pSource);
size_t ItemCount() const;
diff --git a/svtools/source/contnr/treelistentry.cxx b/svtools/source/contnr/treelistentry.cxx
index 198c78e..5a97b09 100644
--- a/svtools/source/contnr/treelistentry.cxx
+++ b/svtools/source/contnr/treelistentry.cxx
@@ -97,6 +97,16 @@ sal_uLong SvTreeListEntry::GetChildListPos() const
return ( nListPos & 0x7fffffff );
}
+SvTreeListEntries& SvTreeListEntry::GetChildEntries()
+{
+ return maChildren;
+}
+
+const SvTreeListEntries& SvTreeListEntry::GetChildEntries() const
+{
+ return maChildren;
+}
+
void SvTreeListEntry::Clone(SvTreeListEntry* pSource)
{
nListPos &= 0x80000000;
commit f29c3435caf60b567bc67684b4633c57f6610fab
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Mon Nov 26 15:07:01 2012 -0500
Add preliminary icons for use in XML tree from Alexander Wilms.
Change-Id: I69ac622bd9ada7dccfbeda7a2a8c3cfd7717dace
diff --git a/icon-themes/galaxy/sc/res/xml_attribute.png b/icon-themes/galaxy/sc/res/xml_attribute.png
new file mode 100644
index 0000000..013bd4b
Binary files /dev/null and b/icon-themes/galaxy/sc/res/xml_attribute.png differ
diff --git a/icon-themes/galaxy/sc/res/xml_element.png b/icon-themes/galaxy/sc/res/xml_element.png
new file mode 100644
index 0000000..cda4265
Binary files /dev/null and b/icon-themes/galaxy/sc/res/xml_element.png differ
diff --git a/icon-themes/galaxy/sc/res/xml_element_repeat.png b/icon-themes/galaxy/sc/res/xml_element_repeat.png
new file mode 100644
index 0000000..fe90995
Binary files /dev/null and b/icon-themes/galaxy/sc/res/xml_element_repeat.png differ
diff --git a/sc/source/ui/src/xmlsourcedlg.src b/sc/source/ui/src/xmlsourcedlg.src
index d90b498..009fc96 100644
--- a/sc/source/ui/src/xmlsourcedlg.src
+++ b/sc/source/ui/src/xmlsourcedlg.src
@@ -82,19 +82,19 @@ ModelessDialog RID_SCDLG_XML_SOURCE
Image IMG_ELEMENT_DEFAULT
{
- ImageBitmap = Bitmap { File = "page.png" ; };
+ ImageBitmap = Bitmap { File = "xml_element.png" ; };
MaskColor = STD_MASKCOLOR ;
};
Image IMG_ELEMENT_REPEAT
{
- ImageBitmap = Bitmap { File = "pages.png" ; };
+ ImageBitmap = Bitmap { File = "xml_element_repeat.png" ; };
MaskColor = STD_MASKCOLOR ;
};
Image IMG_ELEMENT_ATTRIBUTE
{
- ImageBitmap = Bitmap { File = "time.png" ; };
+ ImageBitmap = Bitmap { File = "xml_attribute.png" ; };
MaskColor = STD_MASKCOLOR ;
};
commit 343538e2cca56393e6ee8ded07f1074c0b995c71
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Nov 21 21:19:58 2012 -0500
Use the method from orcus to get the short version of xml namespace name.
Change-Id: I5d64ae380982c09f53dacb1eac721430674e9a31
diff --git a/sc/inc/orcusxml.hxx b/sc/inc/orcusxml.hxx
index 87be8a2..36c41dd 100644
--- a/sc/inc/orcusxml.hxx
+++ b/sc/inc/orcusxml.hxx
@@ -76,8 +76,6 @@ struct ScOrcusImportXMLParam
std::vector<size_t> maNamespaces;
CellLinksType maCellLinks;
RangeLinksType maRangeLinks;
-
- SC_DLLPUBLIC static rtl::OString getShortNamespaceName(size_t nIndex);
};
#endif
diff --git a/sc/source/core/tool/orcusxml.cxx b/sc/source/core/tool/orcusxml.cxx
index cef0333..b3cbd46 100644
--- a/sc/source/core/tool/orcusxml.cxx
+++ b/sc/source/core/tool/orcusxml.cxx
@@ -28,12 +28,4 @@ const ScOrcusXMLTreeParam::EntryData* ScOrcusXMLTreeParam::getUserData(const SvT
ScOrcusImportXMLParam::CellLink::CellLink(const ScAddress& rPos, const OString& rPath) :
maPos(rPos), maPath(rPath) {}
-OString ScOrcusImportXMLParam::getShortNamespaceName(size_t nIndex)
-{
- OStringBuffer aBuf;
- aBuf.append("ns");
- aBuf.append(static_cast<sal_Int32>(nIndex));
- return aBuf.makeStringAndClear();
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/orcus/xmlcontext.cxx b/sc/source/filter/orcus/xmlcontext.cxx
index 3ad6951..c62d39b 100644
--- a/sc/source/filter/orcus/xmlcontext.cxx
+++ b/sc/source/filter/orcus/xmlcontext.cxx
@@ -21,6 +21,8 @@
#include <orcus/orcus_xml.hpp>
#include <orcus/global.hpp>
+#include <string>
+
namespace {
ScOrcusXMLTreeParam::EntryData& setUserDataToEntry(
@@ -43,17 +45,9 @@ OUString toString(const orcus::xml_structure_tree::entity_name& entity, const or
OUStringBuffer aBuf;
if (entity.ns)
{
- // Namespace exists. Namespaces are displayed as ns0, ns1, ns2, ....
- size_t index = walker.get_xmlns_index(entity.ns);
- if (index == orcus::xml_structure_tree::walker::index_not_found)
- // This namespace doesn't exist in this context. Something has gone wrong.
- aBuf.append("???");
- else
- {
- OString aName = ScOrcusImportXMLParam::getShortNamespaceName(index);
- aBuf.append(OUString(aName.getStr(), aName.getLength(), RTL_TEXTENCODING_UTF8));
- }
-
+ // Namespace exists. Use the short version of the xml namespace name for display.
+ std::string aShortName = walker.get_xmlns_short_name(entity.ns);
+ aBuf.appendAscii(aShortName.c_str());
aBuf.append(':');
}
aBuf.append(OUString(entity.name.get(), entity.name.size(), RTL_TEXTENCODING_UTF8));
@@ -212,8 +206,8 @@ public:
if (nsid == orcus::XMLNS_UNKNOWN_ID)
return;
- OString aAlias = ScOrcusImportXMLParam::getShortNamespaceName(index);
- mrFilter.set_namespace_alias(aAlias.getStr(), nsid);
+ std::string alias = mrNsRepo.get_short_name(index);
+ mrFilter.set_namespace_alias(alias.c_str(), nsid);
}
};
commit 9d6ed5dd8ba3824ba0f1a9d179cfd9b2f8ba75b3
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Nov 21 15:21:41 2012 -0500
Correctly handle xml namespaces when importing xml content.
But it's still not working. I need to dig some more.
Change-Id: I06d4d70e1a4234b031741a496f2651d016c35ecc
diff --git a/sc/inc/orcusxml.hxx b/sc/inc/orcusxml.hxx
index c3a981d..87be8a2 100644
--- a/sc/inc/orcusxml.hxx
+++ b/sc/inc/orcusxml.hxx
@@ -29,6 +29,7 @@ struct ScOrcusXMLTreeParam
/** Custom data stored with each tree item. */
struct EntryData
{
+ size_t mnNamespaceID; /// numerical ID for xml namespace
EntryType meType;
ScAddress maLinkedPos; /// linked cell position (invalid if unlinked)
bool mbRangeParent:1;
@@ -72,8 +73,11 @@ struct ScOrcusImportXMLParam
typedef std::vector<CellLink> CellLinksType;
typedef std::vector<RangeLink> RangeLinksType;
+ std::vector<size_t> maNamespaces;
CellLinksType maCellLinks;
RangeLinksType maRangeLinks;
+
+ SC_DLLPUBLIC static rtl::OString getShortNamespaceName(size_t nIndex);
};
#endif
diff --git a/sc/source/core/tool/orcusxml.cxx b/sc/source/core/tool/orcusxml.cxx
index 3f3c93c..cef0333 100644
--- a/sc/source/core/tool/orcusxml.cxx
+++ b/sc/source/core/tool/orcusxml.cxx
@@ -10,6 +10,7 @@
#include "orcusxml.hxx"
#include "svtools/treelistbox.hxx"
+#include "rtl/strbuf.hxx"
ScOrcusXMLTreeParam::EntryData::EntryData(EntryType eType) :
meType(eType), maLinkedPos(ScAddress::INITIALIZE_INVALID), mbRangeParent(false), mbLeafNode(true) {}
@@ -27,4 +28,12 @@ const ScOrcusXMLTreeParam::EntryData* ScOrcusXMLTreeParam::getUserData(const SvT
ScOrcusImportXMLParam::CellLink::CellLink(const ScAddress& rPos, const OString& rPath) :
maPos(rPos), maPath(rPath) {}
+OString ScOrcusImportXMLParam::getShortNamespaceName(size_t nIndex)
+{
+ OStringBuffer aBuf;
+ aBuf.append("ns");
+ aBuf.append(static_cast<sal_Int32>(nIndex));
+ return aBuf.makeStringAndClear();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/orcus/xmlcontext.cxx b/sc/source/filter/orcus/xmlcontext.cxx
index 86865cd..3ad6951 100644
--- a/sc/source/filter/orcus/xmlcontext.cxx
+++ b/sc/source/filter/orcus/xmlcontext.cxx
@@ -31,6 +31,13 @@ ScOrcusXMLTreeParam::EntryData& setUserDataToEntry(
return rStore.back();
}
+void setEntityNameToUserData(
+ ScOrcusXMLTreeParam::EntryData& rEntryData,
+ const orcus::xml_structure_tree::entity_name& entity, const orcus::xml_structure_tree::walker& walker)
+{
+ rEntryData.mnNamespaceID = walker.get_xmlns_index(entity.ns);
+}
+
OUString toString(const orcus::xml_structure_tree::entity_name& entity, const orcus::xml_structure_tree::walker& walker)
{
OUStringBuffer aBuf;
@@ -43,9 +50,10 @@ OUString toString(const orcus::xml_structure_tree::entity_name& entity, const or
aBuf.append("???");
else
{
- aBuf.append("ns");
- aBuf.append(static_cast<sal_Int32>(index));
+ OString aName = ScOrcusImportXMLParam::getShortNamespaceName(index);
+ aBuf.append(OUString(aName.getStr(), aName.getLength(), RTL_TEXTENCODING_UTF8));
}
+
aBuf.append(':');
}
aBuf.append(OUString(entity.name.get(), entity.name.size(), RTL_TEXTENCODING_UTF8));
@@ -66,6 +74,8 @@ void populateTree(
*pEntry, rParam.maUserDataStore,
bRepeat ? ScOrcusXMLTreeParam::ElementRepeat : ScOrcusXMLTreeParam::ElementDefault);
+ setEntityNameToUserData(rEntryData, rElemName, rWalker);
+
if (bRepeat)
{
// Recurring elements use different icon.
@@ -84,13 +94,16 @@ void populateTree(
orcus::xml_structure_tree::entity_names_type::const_iterator itEnd = aNames.end();
for (; it != itEnd; ++it)
{
- orcus::xml_structure_tree::entity_name aAttrName = *it;
- SvTreeListEntry* pAttr = rTreeCtrl.InsertEntry(toString(aAttrName, rWalker), pEntry);
+ const orcus::xml_structure_tree::entity_name& rAttrName = *it;
+ SvTreeListEntry* pAttr = rTreeCtrl.InsertEntry(toString(rAttrName, rWalker), pEntry);
if (!pAttr)
continue;
- setUserDataToEntry(*pAttr, rParam.maUserDataStore, ScOrcusXMLTreeParam::Attribute);
+ ScOrcusXMLTreeParam::EntryData& rAttrData =
+ setUserDataToEntry(*pAttr, rParam.maUserDataStore, ScOrcusXMLTreeParam::Attribute);
+ setEntityNameToUserData(rAttrData, rAttrName, rWalker);
+
rTreeCtrl.SetExpandedEntryBmp(pAttr, rParam.maImgAttribute);
rTreeCtrl.SetCollapsedEntryBmp(pAttr, rParam.maImgAttribute);
}
@@ -183,6 +196,30 @@ bool ScOrcusXMLContextImpl::loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXM
return true;
}
+namespace {
+
+class SetNamespaceAlias : std::unary_function<size_t, void>
+{
+ orcus::orcus_xml& mrFilter;
+ orcus::xmlns_repository& mrNsRepo;
+public:
+ SetNamespaceAlias(orcus::orcus_xml& filter, orcus::xmlns_repository& repo) :
+ mrFilter(filter), mrNsRepo(repo) {}
+
+ void operator() (size_t index)
+ {
+ orcus::xmlns_id_t nsid = mrNsRepo.get_identifier(index);
+ if (nsid == orcus::XMLNS_UNKNOWN_ID)
+ return;
+
+ OString aAlias = ScOrcusImportXMLParam::getShortNamespaceName(index);
+ mrFilter.set_namespace_alias(aAlias.getStr(), nsid);
+ }
+};
+
+
+}
+
bool ScOrcusXMLContextImpl::importXML(const ScOrcusImportXMLParam& rParam)
{
ScOrcusFactory aFactory(mrDoc);
@@ -192,8 +229,11 @@ bool ScOrcusXMLContextImpl::importXML(const ScOrcusImportXMLParam& rParam)
{
orcus::orcus_xml filter(maNsRepo, &aFactory, NULL);
- // Set cell links.
+ // Define all used namespaces.
+ std::for_each(rParam.maNamespaces.begin(), rParam.maNamespaces.end(), SetNamespaceAlias(filter, maNsRepo));
+
{
+ // Set cell links.
ScOrcusImportXMLParam::CellLinksType::const_iterator it = rParam.maCellLinks.begin();
ScOrcusImportXMLParam::CellLinksType::const_iterator itEnd = rParam.maCellLinks.end();
for (; it != itEnd; ++it)
@@ -208,8 +248,8 @@ bool ScOrcusXMLContextImpl::importXML(const ScOrcusImportXMLParam& rParam)
}
}
- // Set range links.
{
+ // Set range links.
ScOrcusImportXMLParam::RangeLinksType::const_iterator it = rParam.maRangeLinks.begin();
ScOrcusImportXMLParam::RangeLinksType::const_iterator itEnd = rParam.maRangeLinks.end();
for (; it != itEnd; ++it)
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 5019306..38a1d09 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -39,7 +39,8 @@ bool isAttribute(const SvTreeListEntry& rEntry)
return pUserData->meType == ScOrcusXMLTreeParam::Attribute;
}
-OUString getXPath(const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
+OUString getXPath(
+ const SvTreeListBox& rTree, const SvTreeListEntry& rEntry, std::vector<size_t>& rNamespaces)
{
OUStringBuffer aBuf;
for (const SvTreeListEntry* p = &rEntry; p; p = rTree.GetParent(p))
@@ -48,6 +49,11 @@ OUString getXPath(const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
if (!pItem)
continue;
+ // Collect used namespace.
+ const ScOrcusXMLTreeParam::EntryData* pData = ScOrcusXMLTreeParam::getUserData(*p);
+ if (pData)
+ rNamespaces.push_back(pData->mnNamespaceID);
+
const SvLBoxString* pStr = static_cast<const SvLBoxString*>(pItem);
aBuf.insert(0, pStr->GetText());
aBuf.insert(0, isAttribute(*p) ? '@' : '/');
@@ -428,7 +434,9 @@ namespace {
/**
* Pick only the leaf elements.
*/
-void getFieldLinks(ScOrcusImportXMLParam::RangeLink& rRangeLink, const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
+void getFieldLinks(
+ ScOrcusImportXMLParam::RangeLink& rRangeLink, std::vector<size_t>& rNamespaces,
+ const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
{
const SvTreeListEntries& rChildren = rEntry.GetChildEntries();
if (rChildren.empty())
@@ -439,7 +447,7 @@ void getFieldLinks(ScOrcusImportXMLParam::RangeLink& rRangeLink, const SvTreeLis
for (; it != itEnd; ++it)
{
const SvTreeListEntry& rChild = *it;
- OUString aPath = getXPath(rTree, rChild);
+ OUString aPath = getXPath(rTree, rChild, rNamespaces);
const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rChild);
if (pUserData && pUserData->mbLeafNode)
@@ -450,10 +458,17 @@ void getFieldLinks(ScOrcusImportXMLParam::RangeLink& rRangeLink, const SvTreeLis
}
// Walk recursively.
- getFieldLinks(rRangeLink, rTree, rChild);
+ getFieldLinks(rRangeLink, rNamespaces, rTree, rChild);
}
}
+void removeDuplicates(std::vector<size_t>& rArray)
+{
+ std::sort(rArray.begin(), rArray.end());
+ std::vector<size_t>::iterator it = std::unique(rArray.begin(), rArray.end());
+ rArray.erase(it, rArray.end());
+}
+
}
void ScXMLSourceDlg::OkPressed()
@@ -471,7 +486,7 @@ void ScXMLSourceDlg::OkPressed()
for (; it != itEnd; ++it)
{
const SvTreeListEntry& rEntry = **it;
- OUString aPath = getXPath(maLbTree, rEntry);
+ OUString aPath = getXPath(maLbTree, rEntry, aParam.maNamespaces);
const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rEntry);
aParam.maCellLinks.push_back(
@@ -493,14 +508,16 @@ void ScXMLSourceDlg::OkPressed()
aRangeLink.maPos = pUserData->maLinkedPos;
// Go through all its child elements.
- getFieldLinks(aRangeLink, maLbTree, rEntry);
+ getFieldLinks(aRangeLink, aParam.maNamespaces, maLbTree, rEntry);
aParam.maRangeLinks.push_back(aRangeLink);
}
}
- // Now do the import.
+ // Remove duplicate namespace IDs.
+ removeDuplicates(aParam.maNamespaces);
+ // Now do the import.
mpXMLContext->importXML(aParam);
// Don't forget to broadcast the change.
commit 3db55f9da3577653911c683091c72722288bc456
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Nov 21 12:01:51 2012 -0500
Display XML namespace IDs in the tree.
Change-Id: I7223b6ac750a5c96ce9638b490eeae109ed854ef
diff --git a/sc/source/filter/orcus/xmlcontext.cxx b/sc/source/filter/orcus/xmlcontext.cxx
index cc8eccd..86865cd 100644
--- a/sc/source/filter/orcus/xmlcontext.cxx
+++ b/sc/source/filter/orcus/xmlcontext.cxx
@@ -31,13 +31,33 @@ ScOrcusXMLTreeParam::EntryData& setUserDataToEntry(
return rStore.back();
}
+OUString toString(const orcus::xml_structure_tree::entity_name& entity, const orcus::xml_structure_tree::walker& walker)
+{
+ OUStringBuffer aBuf;
+ if (entity.ns)
+ {
+ // Namespace exists. Namespaces are displayed as ns0, ns1, ns2, ....
+ size_t index = walker.get_xmlns_index(entity.ns);
+ if (index == orcus::xml_structure_tree::walker::index_not_found)
+ // This namespace doesn't exist in this context. Something has gone wrong.
+ aBuf.append("???");
+ else
+ {
+ aBuf.append("ns");
+ aBuf.append(static_cast<sal_Int32>(index));
+ }
+ aBuf.append(':');
+ }
+ aBuf.append(OUString(entity.name.get(), entity.name.size(), RTL_TEXTENCODING_UTF8));
+ return aBuf.makeStringAndClear();
+}
+
void populateTree(
SvTreeListBox& rTreeCtrl, orcus::xml_structure_tree::walker& rWalker,
const orcus::xml_structure_tree::entity_name& rElemName, bool bRepeat,
SvTreeListEntry* pParent, ScOrcusXMLTreeParam& rParam)
{
- OUString aName(rElemName.name.get(), rElemName.name.size(), RTL_TEXTENCODING_UTF8);
- SvTreeListEntry* pEntry = rTreeCtrl.InsertEntry(aName, pParent);
+ SvTreeListEntry* pEntry = rTreeCtrl.InsertEntry(toString(rElemName, rWalker), pParent);
if (!pEntry)
// Can this ever happen!?
return;
@@ -65,8 +85,7 @@ void populateTree(
for (; it != itEnd; ++it)
{
orcus::xml_structure_tree::entity_name aAttrName = *it;
- SvTreeListEntry* pAttr = rTreeCtrl.InsertEntry(
- OUString(aAttrName.name.get(), aAttrName.name.size(), RTL_TEXTENCODING_UTF8), pEntry);
+ SvTreeListEntry* pAttr = rTreeCtrl.InsertEntry(toString(aAttrName, rWalker), pEntry);
if (!pAttr)
continue;
commit 5e4222bf11cbf8e7740c50bf1d206c2b1bc43b63
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Nov 21 10:58:24 2012 -0500
Adjusted for the orcus interface change on the master branch.
Change-Id: Ie99a1f90c55abf41f9f069fe26f19ed2f4370ae1
diff --git a/sc/source/filter/orcus/xmlcontext.cxx b/sc/source/filter/orcus/xmlcontext.cxx
index 9e0dbba..cc8eccd 100644
--- a/sc/source/filter/orcus/xmlcontext.cxx
+++ b/sc/source/filter/orcus/xmlcontext.cxx
@@ -171,7 +171,7 @@ bool ScOrcusXMLContextImpl::importXML(const ScOrcusImportXMLParam& rParam)
const char* path = aSysPath.getStr();
try
{
- orcus::orcus_xml filter(&aFactory, NULL);
+ orcus::orcus_xml filter(maNsRepo, &aFactory, NULL);
// Set cell links.
{
commit 814ae3e4dc75befa8540eb77a0a9a704ff8dd21f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Mon Nov 19 17:14:43 2012 -0500
Store the xml namespace repository with the context.
We need persistent xml namespaces between loading the structure and
importing the content.
Change-Id: I4b56a7e952ab89b93ea2590c8f0d6b5cb141f039
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx
index ee8d3f8..bcf8881 100644
--- a/sc/inc/orcusfilters.hxx
+++ b/sc/inc/orcusfilters.hxx
@@ -46,9 +46,9 @@ class ScOrcusXMLContext
public:
virtual ~ScOrcusXMLContext() {}
- virtual bool loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const = 0;
+ virtual bool loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) = 0;
- virtual bool importXML(const ScOrcusImportXMLParam& rParam) const = 0;
+ virtual bool importXML(const ScOrcusImportXMLParam& rParam) = 0;
};
#endif
diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx
index 0b6ffa6..673da91 100644
--- a/sc/source/filter/inc/orcusfiltersimpl.hxx
+++ b/sc/source/filter/inc/orcusfiltersimpl.hxx
@@ -12,6 +12,8 @@
#include "orcusfilters.hxx"
+#include <orcus/xml_namespace.hpp>
+
class ScOrcusFiltersImpl : public ScOrcusFilters
{
public:
@@ -26,13 +28,16 @@ class ScOrcusXMLContextImpl : public ScOrcusXMLContext
{
ScDocument& mrDoc;
rtl::OUString maPath;
+
+ orcus::xmlns_repository maNsRepo; /// XML namespace repository for this context.
+
public:
ScOrcusXMLContextImpl(ScDocument& rDoc, const rtl::OUString& rPath);
virtual ~ScOrcusXMLContextImpl();
- virtual bool loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const;
+ virtual bool loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam);
- virtual bool importXML(const ScOrcusImportXMLParam& rParam) const;
+ virtual bool importXML(const ScOrcusImportXMLParam& rParam);
};
#endif
diff --git a/sc/source/filter/orcus/xmlcontext.cxx b/sc/source/filter/orcus/xmlcontext.cxx
index d32a55c..9e0dbba 100644
--- a/sc/source/filter/orcus/xmlcontext.cxx
+++ b/sc/source/filter/orcus/xmlcontext.cxx
@@ -124,7 +124,7 @@ ScOrcusXMLContextImpl::ScOrcusXMLContextImpl(ScDocument& rDoc, const OUString& r
ScOrcusXMLContextImpl::~ScOrcusXMLContextImpl() {}
-bool ScOrcusXMLContextImpl::loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const
+bool ScOrcusXMLContextImpl::loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam)
{
rParam.maUserDataStore.clear();
@@ -138,8 +138,7 @@ bool ScOrcusXMLContextImpl::loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXM
if (aStrm.empty())
return false;
- orcus::xmlns_repository repo; // xml namespace repository.
- orcus::xmlns_context cxt = repo.create_context();
+ orcus::xmlns_context cxt = maNsRepo.create_context();
orcus::xml_structure_tree aXmlTree(cxt);
try
{
@@ -165,7 +164,7 @@ bool ScOrcusXMLContextImpl::loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXM
return true;
}
-bool ScOrcusXMLContextImpl::importXML(const ScOrcusImportXMLParam& rParam) const
+bool ScOrcusXMLContextImpl::importXML(const ScOrcusImportXMLParam& rParam)
{
ScOrcusFactory aFactory(mrDoc);
OString aSysPath = ScOrcusFiltersImpl::toSystemPath(maPath);
commit 7b3009bda41b58036c7a843611e6b46e5b3463d0
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Mon Nov 19 16:56:24 2012 -0500
Method description.
Change-Id: I754ef846c3bc2d032a818dce6c223da89b3f8ccd
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx
index dd9778d..ee8d3f8 100644
--- a/sc/inc/orcusfilters.hxx
+++ b/sc/inc/orcusfilters.hxx
@@ -29,6 +29,15 @@ public:
virtual bool importCSV(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
+ * for each XML file, and never to re-use the same context for multiple
+ * XML files.
+ *
+ * The caller is responsible for deleting the instance returned from this
+ * method when it's done.
+ */
virtual ScOrcusXMLContext* createXMLContext(ScDocument& rDoc, const rtl::OUString& rPath) const = 0;
};
commit 1157cbc99391c121bbe5e75291ce7a2cc75f5eba
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Mon Nov 19 16:45:55 2012 -0500
Separate the XML part of orcus filters into own class.
Along with other reorganization of the orcus interface code...
This XML context object will be used to store data specific to each
loaded XML file, such as XML stream, namespace repository and so on.
Change-Id: I21c43ab0026954c5d52f4985a169934f8fb9f704
diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
index 18e302a..c25ecb1 100644
--- a/sc/Library_scfilt.mk
+++ b/sc/Library_scfilt.mk
@@ -221,7 +221,9 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\
sc/source/filter/oox/worksheethelper \
sc/source/filter/oox/worksheetsettings \
sc/source/filter/orcus/orcusfiltersimpl \
+ sc/source/filter/orcus/interface \
sc/source/filter/orcus/orcusxml \
+ sc/source/filter/orcus/xmlcontext \
))
ifeq ($(SYSTEM_ZLIB),YES)
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx
index 1b94f67..dd9778d 100644
--- a/sc/inc/orcusfilters.hxx
+++ b/sc/inc/orcusfilters.hxx
@@ -17,6 +17,7 @@ class SvTreeListBox;
class Image;
struct ScOrcusXMLTreeParam;
struct ScOrcusImportXMLParam;
+class ScOrcusXMLContext;
/**
* Collection of orcus filter wrappers.
@@ -28,11 +29,17 @@ public:
virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const = 0;
- virtual bool loadXMLStructure(
- const rtl::OUString& rPath, SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const = 0;
+ virtual ScOrcusXMLContext* createXMLContext(ScDocument& rDoc, const rtl::OUString& rPath) const = 0;
+};
+
+class ScOrcusXMLContext
+{
+public:
+ virtual ~ScOrcusXMLContext() {}
+
+ virtual bool loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const = 0;
- virtual bool importXML(
- ScDocument& rDoc, const rtl::OUString& rPath, const ScOrcusImportXMLParam& rParam) const = 0;
+ virtual bool importXML(const ScOrcusImportXMLParam& rParam) const = 0;
};
#endif
diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx
index f2d2703..0b6ffa6 100644
--- a/sc/source/filter/inc/orcusfiltersimpl.hxx
+++ b/sc/source/filter/inc/orcusfiltersimpl.hxx
@@ -15,13 +15,24 @@
class ScOrcusFiltersImpl : public ScOrcusFilters
{
public:
+ static rtl::OString toSystemPath(const rtl::OUString& rPath);
+
virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const;
- virtual bool loadXMLStructure(
- const rtl::OUString& rPath, SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const;
+ virtual ScOrcusXMLContext* createXMLContext(ScDocument& rDoc, const rtl::OUString& rPath) const;
+};
+
+class ScOrcusXMLContextImpl : public ScOrcusXMLContext
+{
+ ScDocument& mrDoc;
+ rtl::OUString maPath;
+public:
+ ScOrcusXMLContextImpl(ScDocument& rDoc, const rtl::OUString& rPath);
+ virtual ~ScOrcusXMLContextImpl();
+
+ virtual bool loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const;
- virtual bool importXML(
- ScDocument& rDoc, const rtl::OUString& rPath, const ScOrcusImportXMLParam& rParam) const;
+ virtual bool importXML(const ScOrcusImportXMLParam& rParam) const;
};
#endif
diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx
new file mode 100644
index 0000000..e2c9c08
--- /dev/null
+++ b/sc/source/filter/inc/orcusinterface.hxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __SC_ORCUSINTERFACE_HXX__
+#define __SC_ORCUSINTERFACE_HXX__
+
+#include "address.hxx"
+
+#define __ORCUS_STATIC_LIB
+#include <orcus/spreadsheet/import_interface.hpp>
+
+#include <boost/ptr_container/ptr_vector.hpp>
+
+class ScDocument;
+class ScOrcusSheet;
+
+class ScOrcusFactory : public orcus::spreadsheet::iface::import_factory
+{
+ ScDocument& mrDoc;
+ boost::ptr_vector<ScOrcusSheet> maSheets;
+
+public:
+ ScOrcusFactory(ScDocument& rDoc);
+
+ virtual orcus::spreadsheet::iface::import_sheet* append_sheet(const char *sheet_name, size_t sheet_name_length);
+ virtual orcus::spreadsheet::iface::import_sheet* get_sheet(const char *sheet_name, size_t sheet_name_length);
+ virtual orcus::spreadsheet::iface::import_shared_strings* get_shared_strings();
+ virtual orcus::spreadsheet::iface::import_styles* get_styles();
+};
+
+class ScOrcusSheet : public orcus::spreadsheet::iface::import_sheet
+{
+ ScDocument& mrDoc;
+ SCTAB mnTab;
+public:
+ ScOrcusSheet(ScDocument& rDoc, SCTAB nTab);
+
+ // Orcus import interface
+ virtual void set_auto(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, const char* p, size_t n);
+ virtual void set_format(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, size_t xf_index);
+ virtual void set_formula(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, orcus::spreadsheet::formula_grammar_t grammar, const char* p, size_t n);
+ virtual void set_formula_result(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, const char* p, size_t n);
+ virtual void set_shared_formula(
+ orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, orcus::spreadsheet::formula_grammar_t grammar, size_t sindex,
+ const char* p_formula, size_t n_formula);
+ virtual void set_shared_formula(
+ orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, orcus::spreadsheet::formula_grammar_t grammar, size_t sindex,
+ const char* p_formula, size_t n_formula, const char* p_range, size_t n_range);
+ virtual void set_shared_formula(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, size_t sindex);
+ virtual void set_string(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, size_t sindex);
+ virtual void set_value(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, double value);
+
+ SCTAB getIndex() const { return mnTab; }
+};
+
+#endif
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx
new file mode 100644
index 0000000..d22c208
--- /dev/null
+++ b/sc/source/filter/orcus/interface.cxx
@@ -0,0 +1,121 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "orcusinterface.hxx"
+
+#include "document.hxx"
+
+using orcus::spreadsheet::row_t;
+using orcus::spreadsheet::col_t;
+using orcus::spreadsheet::formula_grammar_t;
+
+ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) : mrDoc(rDoc) {}
+
+orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::append_sheet(const char* sheet_name, size_t sheet_name_length)
+{
+ OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
+ if (!mrDoc.InsertTab(SC_TAB_APPEND, aTabName))
+ return NULL;
+
+ SCTAB nTab = mrDoc.GetTableCount() - 1;
+ maSheets.push_back(new ScOrcusSheet(mrDoc, nTab));
+ return &maSheets.back();
+}
+
+class FindSheetByIndex : std::unary_function<ScOrcusSheet, bool>
+{
+ SCTAB mnTab;
+public:
+ FindSheetByIndex(SCTAB nTab) : mnTab(nTab) {}
+ bool operator() (const ScOrcusSheet& rSheet) const
+ {
+ return rSheet.getIndex() == mnTab;
+ }
+};
+
+orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::get_sheet(const char* sheet_name, size_t sheet_name_length)
+{
+ OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
+ SCTAB nTab = -1;
+ if (!mrDoc.GetTable(aTabName, nTab))
+ // Sheet by that name not found.
+ return NULL;
+
+ // See if we already have an orcus sheet instance by that index.
+ boost::ptr_vector<ScOrcusSheet>::iterator it =
+ std::find_if(maSheets.begin(), maSheets.end(), FindSheetByIndex(nTab));
+
+ if (it != maSheets.end())
+ // We already have one. Return it.
+ return &(*it);
+
+ // Create a new orcus sheet instance for this.
+ maSheets.push_back(new ScOrcusSheet(mrDoc, nTab));
+ return &maSheets.back();
+}
+
+orcus::spreadsheet::iface::import_shared_strings* ScOrcusFactory::get_shared_strings()
+{
+ // We don't support it yet.
+ return NULL;
+}
+
+orcus::spreadsheet::iface::import_styles* ScOrcusFactory::get_styles()
+{
+ // We don't support it yet.
+ return NULL;
+}
+
+ScOrcusSheet::ScOrcusSheet(ScDocument& rDoc, SCTAB nTab) :
+ mrDoc(rDoc), mnTab(nTab) {}
+
+void ScOrcusSheet::set_auto(row_t row, col_t col, const char* p, size_t n)
+{
+ OUString aVal(p, n, RTL_TEXTENCODING_UTF8);
+ mrDoc.SetString(col, row, mnTab, aVal);
+}
+
+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*/)
+{
+}
+
+void ScOrcusSheet::set_formula_result(row_t /*row*/, col_t /*col*/, const char* /*p*/, size_t /*n*/)
+{
+}
+
+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*/)
+{
+}
+
+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*/)
+{
+}
+
+void ScOrcusSheet::set_shared_formula(row_t /*row*/, col_t /*col*/, size_t /*sindex*/)
+{
+}
+
+void ScOrcusSheet::set_string(row_t /*row*/, col_t /*col*/, size_t /*sindex*/)
+{
+}
+
+void ScOrcusSheet::set_value(row_t /*row*/, col_t /*col*/, double /*value*/)
+{
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 3fa23e1..0f1c329 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -8,187 +8,29 @@
*/
#include "orcusfiltersimpl.hxx"
+#include "orcusinterface.hxx"
#include "document.hxx"
-#include "orcusxml.hxx"
#include "tools/urlobj.hxx"
-#include "svtools/treelistbox.hxx"
#define __ORCUS_STATIC_LIB
#include <orcus/spreadsheet/import_interface.hpp>
#include <orcus/orcus_csv.hpp>
-#include <orcus/xml_structure_tree.hpp>
-#include <orcus/xml_namespace.hpp>
-#include <orcus/orcus_xml.hpp>
#include <orcus/global.hpp>
-#include <boost/ptr_container/ptr_vector.hpp>
-
-using orcus::spreadsheet::row_t;
-using orcus::spreadsheet::col_t;
-using orcus::spreadsheet::formula_grammar_t;
-
#ifdef WNT
#define SYSTEM_PATH INetURLObject::FSYS_DOS
#else
#define SYSTEM_PATH INetURLObject::FSYS_UNX
#endif
-namespace {
-
-OString toSystemPath(const OUString& rPath)
+OString ScOrcusFiltersImpl::toSystemPath(const OUString& rPath)
{
INetURLObject aURL(rPath);
return rtl::OUStringToOString(aURL.getFSysPath(SYSTEM_PATH), RTL_TEXTENCODING_UTF8);
}
-class ScOrcusSheet;
-
-class ScOrcusFactory : public orcus::spreadsheet::iface::import_factory
-{
- ScDocument& mrDoc;
- boost::ptr_vector<ScOrcusSheet> maSheets;
-
-public:
- ScOrcusFactory(ScDocument& rDoc);
-
- virtual orcus::spreadsheet::iface::import_sheet* append_sheet(const char *sheet_name, size_t sheet_name_length);
- virtual orcus::spreadsheet::iface::import_sheet* get_sheet(const char *sheet_name, size_t sheet_name_length);
- virtual orcus::spreadsheet::iface::import_shared_strings* get_shared_strings();
- virtual orcus::spreadsheet::iface::import_styles* get_styles();
-};
-
-class ScOrcusSheet : public orcus::spreadsheet::iface::import_sheet
-{
- ScDocument& mrDoc;
- SCTAB mnTab;
-public:
- ScOrcusSheet(ScDocument& rDoc, SCTAB nTab);
-
- // Orcus import interface
- virtual void set_auto(row_t row, col_t col, const char* p, size_t n);
- virtual void set_format(row_t row, col_t col, size_t xf_index);
- virtual void set_formula(row_t row, col_t col, formula_grammar_t grammar, const char* p, size_t n);
- virtual void set_formula_result(row_t row, col_t col, const char* p, size_t n);
- virtual void set_shared_formula(
- row_t row, col_t col, formula_grammar_t grammar, size_t sindex,
- const char* p_formula, size_t n_formula);
- virtual void 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);
- virtual void set_shared_formula(row_t row, col_t col, size_t sindex);
- virtual void set_string(row_t row, col_t col, size_t sindex);
- virtual void set_value(row_t row, col_t col, double value);
-
- SCTAB getIndex() const { return mnTab; }
-};
-
-ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) : mrDoc(rDoc) {}
-
-orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::append_sheet(const char* sheet_name, size_t sheet_name_length)
-{
- OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
- if (!mrDoc.InsertTab(SC_TAB_APPEND, aTabName))
- return NULL;
-
- SCTAB nTab = mrDoc.GetTableCount() - 1;
- maSheets.push_back(new ScOrcusSheet(mrDoc, nTab));
- return &maSheets.back();
-}
-
-class FindSheetByIndex : std::unary_function<ScOrcusSheet, bool>
-{
- SCTAB mnTab;
-public:
- FindSheetByIndex(SCTAB nTab) : mnTab(nTab) {}
- bool operator() (const ScOrcusSheet& rSheet) const
- {
- return rSheet.getIndex() == mnTab;
- }
-};
-
-orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::get_sheet(const char* sheet_name, size_t sheet_name_length)
-{
- OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
- SCTAB nTab = -1;
- if (!mrDoc.GetTable(aTabName, nTab))
- // Sheet by that name not found.
- return NULL;
-
- // See if we already have an orcus sheet instance by that index.
- boost::ptr_vector<ScOrcusSheet>::iterator it =
- std::find_if(maSheets.begin(), maSheets.end(), FindSheetByIndex(nTab));
-
- if (it != maSheets.end())
- // We already have one. Return it.
- return &(*it);
-
- // Create a new orcus sheet instance for this.
- maSheets.push_back(new ScOrcusSheet(mrDoc, nTab));
- return &maSheets.back();
-}
-
-orcus::spreadsheet::iface::import_shared_strings* ScOrcusFactory::get_shared_strings()
-{
- // We don't support it yet.
- return NULL;
-}
-
-orcus::spreadsheet::iface::import_styles* ScOrcusFactory::get_styles()
-{
- // We don't support it yet.
- return NULL;
-}
-
-ScOrcusSheet::ScOrcusSheet(ScDocument& rDoc, SCTAB nTab) :
- mrDoc(rDoc), mnTab(nTab) {}
-
-void ScOrcusSheet::set_auto(row_t row, col_t col, const char* p, size_t n)
-{
- OUString aVal(p, n, RTL_TEXTENCODING_UTF8);
- mrDoc.SetString(col, row, mnTab, aVal);
-}
-
-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*/)
-{
-}
-
-void ScOrcusSheet::set_formula_result(row_t /*row*/, col_t /*col*/, const char* /*p*/, size_t /*n*/)
-{
-}
-
-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*/)
-{
-}
-
-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*/)
-{
-}
-
-void ScOrcusSheet::set_shared_formula(row_t /*row*/, col_t /*col*/, size_t /*sindex*/)
-{
-}
-
-void ScOrcusSheet::set_string(row_t /*row*/, col_t /*col*/, size_t /*sindex*/)
-{
-}
-
-void ScOrcusSheet::set_value(row_t /*row*/, col_t /*col*/, double /*value*/)
-{
-}
-
-} // anonymous namespace
-
bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, const OUString& rPath) const
{
ScOrcusFactory aFactory(rDoc);
@@ -209,202 +51,9 @@ bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, const OUString& rPath) cons
return true;
}
-namespace {
-
-ScOrcusXMLTreeParam::EntryData& setUserDataToEntry(
- SvTreeListEntry& rEntry, ScOrcusXMLTreeParam::UserDataStoreType& rStore, ScOrcusXMLTreeParam::EntryType eType)
-{
- rStore.push_back(new ScOrcusXMLTreeParam::EntryData(eType));
- rEntry.SetUserData(&rStore.back());
- return rStore.back();
-}
-
-void populateTree(
- SvTreeListBox& rTreeCtrl, orcus::xml_structure_tree::walker& rWalker,
- const orcus::xml_structure_tree::entity_name& rElemName, bool bRepeat,
- SvTreeListEntry* pParent, ScOrcusXMLTreeParam& rParam)
-{
- OUString aName(rElemName.name.get(), rElemName.name.size(), RTL_TEXTENCODING_UTF8);
- SvTreeListEntry* pEntry = rTreeCtrl.InsertEntry(aName, pParent);
- if (!pEntry)
- // Can this ever happen!?
- return;
-
- ScOrcusXMLTreeParam::EntryData& rEntryData = setUserDataToEntry(
- *pEntry, rParam.maUserDataStore,
- bRepeat ? ScOrcusXMLTreeParam::ElementRepeat : ScOrcusXMLTreeParam::ElementDefault);
-
- if (bRepeat)
- {
- // Recurring elements use different icon.
- rTreeCtrl.SetExpandedEntryBmp(pEntry, rParam.maImgElementRepeat);
- rTreeCtrl.SetCollapsedEntryBmp(pEntry, rParam.maImgElementRepeat);
- }
-
- if (pParent)
- rTreeCtrl.Expand(pParent);
-
- orcus::xml_structure_tree::entity_names_type aNames;
-
- // Insert attributes.
- rWalker.get_attributes(aNames);
- orcus::xml_structure_tree::entity_names_type::const_iterator it = aNames.begin();
- orcus::xml_structure_tree::entity_names_type::const_iterator itEnd = aNames.end();
- for (; it != itEnd; ++it)
- {
- orcus::xml_structure_tree::entity_name aAttrName = *it;
- SvTreeListEntry* pAttr = rTreeCtrl.InsertEntry(
- OUString(aAttrName.name.get(), aAttrName.name.size(), RTL_TEXTENCODING_UTF8), pEntry);
-
- if (!pAttr)
- continue;
-
- setUserDataToEntry(*pAttr, rParam.maUserDataStore, ScOrcusXMLTreeParam::Attribute);
- rTreeCtrl.SetExpandedEntryBmp(pAttr, rParam.maImgAttribute);
- rTreeCtrl.SetCollapsedEntryBmp(pAttr, rParam.maImgAttribute);
- }
- rTreeCtrl.Expand(pEntry);
-
- rWalker.get_children(aNames);
-
- // Non-leaf if it has child elements, leaf otherwise.
- rEntryData.mbLeafNode = aNames.empty();
-
- // Insert child elements recursively.
- for (it = aNames.begin(), itEnd = aNames.end(); it != itEnd; ++it)
- {
- orcus::xml_structure_tree::element aElem = rWalker.descend(*it);
- populateTree(rTreeCtrl, rWalker, *it, aElem.repeat, pEntry, rParam);
- rWalker.ascend();
- }
-}
-
-class TreeUpdateSwitch
-{
- SvTreeListBox& mrTreeCtrl;
-public:
- TreeUpdateSwitch(SvTreeListBox& rTreeCtrl) : mrTreeCtrl(rTreeCtrl)
- {
- mrTreeCtrl.SetUpdateMode(false);
- }
-
- ~TreeUpdateSwitch()
- {
- mrTreeCtrl.SetUpdateMode(true);
- }
-};
-
-}
-
-bool ScOrcusFiltersImpl::loadXMLStructure(
- const rtl::OUString& rPath, SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const
-{
- rParam.maUserDataStore.clear();
-
- OString aSysPath = toSystemPath(rPath);
- const char* path = aSysPath.getStr();
-
- // TODO: Use our own stream loading call instead of one from orcus.
- std::string aStrm;
- orcus::load_file_content(path, aStrm);
-
- if (aStrm.empty())
- return false;
-
- orcus::xmlns_repository repo; // xml namespace repository.
- orcus::xmlns_context cxt = repo.create_context();
- orcus::xml_structure_tree aXmlTree(cxt);
- try
- {
- aXmlTree.parse(&aStrm[0], aStrm.size());
-
- TreeUpdateSwitch aSwitch(rTreeCtrl);
- rTreeCtrl.Clear();
- rTreeCtrl.SetDefaultCollapsedEntryBmp(rParam.maImgElementDefault);
- rTreeCtrl.SetDefaultExpandedEntryBmp(rParam.maImgElementDefault);
-
- orcus::xml_structure_tree::walker aWalker = aXmlTree.get_walker();
-
- // Root element.
- orcus::xml_structure_tree::element aElem = aWalker.root();
- populateTree(rTreeCtrl, aWalker, aElem.name, aElem.repeat, NULL, rParam);
- }
- catch (const std::exception&)
- {
- // Parsing of this XML file failed.
- return false;
- }
-
- return true;
-}
-
-namespace {
-
-class InsertFieldPath : std::unary_function<OString, void>
-{
- orcus::orcus_xml& mrFilter;
-public:
- InsertFieldPath(orcus::orcus_xml& rFilter) : mrFilter(rFilter) {}
- void operator() (const OString& rPath)
- {
- mrFilter.append_field_link(rPath.getStr());
- }
-};
-
-}
-
-bool ScOrcusFiltersImpl::importXML(
- ScDocument& rDoc, const rtl::OUString& rPath, const ScOrcusImportXMLParam& rParam) const
+ScOrcusXMLContext* ScOrcusFiltersImpl::createXMLContext(ScDocument& rDoc, const rtl::OUString& rPath) const
{
- ScOrcusFactory aFactory(rDoc);
- OString aSysPath = toSystemPath(rPath);
- const char* path = aSysPath.getStr();
- try
- {
- orcus::orcus_xml filter(&aFactory, NULL);
-
- // Set cell links.
- {
- ScOrcusImportXMLParam::CellLinksType::const_iterator it = rParam.maCellLinks.begin();
- ScOrcusImportXMLParam::CellLinksType::const_iterator itEnd = rParam.maCellLinks.end();
- for (; it != itEnd; ++it)
- {
- const ScOrcusImportXMLParam::CellLink& rLink = *it;
- OUString aTabName;
- rDoc.GetName(rLink.maPos.Tab(), aTabName);
- filter.set_cell_link(
- rLink.maPath.getStr(),
- rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr(),
- rLink.maPos.Row(), rLink.maPos.Col());
- }
- }
-
- // Set range links.
- {
- ScOrcusImportXMLParam::RangeLinksType::const_iterator it = rParam.maRangeLinks.begin();
- ScOrcusImportXMLParam::RangeLinksType::const_iterator itEnd = rParam.maRangeLinks.end();
- for (; it != itEnd; ++it)
- {
- const ScOrcusImportXMLParam::RangeLink& rLink = *it;
- OUString aTabName;
- rDoc.GetName(rLink.maPos.Tab(), aTabName);
- filter.start_range(
- rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr(),
- rLink.maPos.Row(), rLink.maPos.Col());
-
- std::for_each(rLink.maFieldPaths.begin(), rLink.maFieldPaths.end(), InsertFieldPath(filter));
-
- filter.commit_range();
- }
- }
-
- filter.read_file(path);
- }
- catch (const std::exception&)
- {
- return false;
- }
- return true;
+ return new ScOrcusXMLContextImpl(rDoc, rPath);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/orcus/xmlcontext.cxx b/sc/source/filter/orcus/xmlcontext.cxx
new file mode 100644
index 0000000..d32a55c
--- /dev/null
+++ b/sc/source/filter/orcus/xmlcontext.cxx
@@ -0,0 +1,221 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "orcusfiltersimpl.hxx"
+#include "orcusinterface.hxx"
+#include "orcusxml.hxx"
+#include "document.hxx"
+
+#include "svtools/treelistbox.hxx"
+
+#define __ORCUS_STATIC_LIB
+#include <orcus/spreadsheet/import_interface.hpp>
+#include <orcus/xml_structure_tree.hpp>
+#include <orcus/xml_namespace.hpp>
+#include <orcus/orcus_xml.hpp>
+#include <orcus/global.hpp>
+
+namespace {
+
+ScOrcusXMLTreeParam::EntryData& setUserDataToEntry(
+ SvTreeListEntry& rEntry, ScOrcusXMLTreeParam::UserDataStoreType& rStore, ScOrcusXMLTreeParam::EntryType eType)
+{
+ rStore.push_back(new ScOrcusXMLTreeParam::EntryData(eType));
+ rEntry.SetUserData(&rStore.back());
+ return rStore.back();
+}
+
+void populateTree(
+ SvTreeListBox& rTreeCtrl, orcus::xml_structure_tree::walker& rWalker,
+ const orcus::xml_structure_tree::entity_name& rElemName, bool bRepeat,
+ SvTreeListEntry* pParent, ScOrcusXMLTreeParam& rParam)
+{
+ OUString aName(rElemName.name.get(), rElemName.name.size(), RTL_TEXTENCODING_UTF8);
+ SvTreeListEntry* pEntry = rTreeCtrl.InsertEntry(aName, pParent);
+ if (!pEntry)
+ // Can this ever happen!?
+ return;
+
+ ScOrcusXMLTreeParam::EntryData& rEntryData = setUserDataToEntry(
+ *pEntry, rParam.maUserDataStore,
+ bRepeat ? ScOrcusXMLTreeParam::ElementRepeat : ScOrcusXMLTreeParam::ElementDefault);
+
+ if (bRepeat)
+ {
+ // Recurring elements use different icon.
+ rTreeCtrl.SetExpandedEntryBmp(pEntry, rParam.maImgElementRepeat);
+ rTreeCtrl.SetCollapsedEntryBmp(pEntry, rParam.maImgElementRepeat);
+ }
+
+ if (pParent)
+ rTreeCtrl.Expand(pParent);
+
+ orcus::xml_structure_tree::entity_names_type aNames;
+
+ // Insert attributes.
+ rWalker.get_attributes(aNames);
+ orcus::xml_structure_tree::entity_names_type::const_iterator it = aNames.begin();
+ orcus::xml_structure_tree::entity_names_type::const_iterator itEnd = aNames.end();
+ for (; it != itEnd; ++it)
+ {
+ orcus::xml_structure_tree::entity_name aAttrName = *it;
+ SvTreeListEntry* pAttr = rTreeCtrl.InsertEntry(
+ OUString(aAttrName.name.get(), aAttrName.name.size(), RTL_TEXTENCODING_UTF8), pEntry);
+
+ if (!pAttr)
+ continue;
+
+ setUserDataToEntry(*pAttr, rParam.maUserDataStore, ScOrcusXMLTreeParam::Attribute);
+ rTreeCtrl.SetExpandedEntryBmp(pAttr, rParam.maImgAttribute);
+ rTreeCtrl.SetCollapsedEntryBmp(pAttr, rParam.maImgAttribute);
+ }
+ rTreeCtrl.Expand(pEntry);
+
+ rWalker.get_children(aNames);
+
+ // Non-leaf if it has child elements, leaf otherwise.
+ rEntryData.mbLeafNode = aNames.empty();
+
+ // Insert child elements recursively.
+ for (it = aNames.begin(), itEnd = aNames.end(); it != itEnd; ++it)
+ {
+ orcus::xml_structure_tree::element aElem = rWalker.descend(*it);
+ populateTree(rTreeCtrl, rWalker, *it, aElem.repeat, pEntry, rParam);
+ rWalker.ascend();
+ }
+}
+
+class TreeUpdateSwitch
+{
+ SvTreeListBox& mrTreeCtrl;
+public:
+ TreeUpdateSwitch(SvTreeListBox& rTreeCtrl) : mrTreeCtrl(rTreeCtrl)
+ {
+ mrTreeCtrl.SetUpdateMode(false);
+ }
+
+ ~TreeUpdateSwitch()
+ {
+ mrTreeCtrl.SetUpdateMode(true);
+ }
+};
+
+class InsertFieldPath : std::unary_function<OString, void>
+{
+ orcus::orcus_xml& mrFilter;
+public:
+ InsertFieldPath(orcus::orcus_xml& rFilter) : mrFilter(rFilter) {}
+ void operator() (const OString& rPath)
+ {
+ mrFilter.append_field_link(rPath.getStr());
+ }
+};
+
+}
+
+ScOrcusXMLContextImpl::ScOrcusXMLContextImpl(ScDocument& rDoc, const OUString& rPath) :
+ ScOrcusXMLContext(), mrDoc(rDoc), maPath(rPath) {}
+
+ScOrcusXMLContextImpl::~ScOrcusXMLContextImpl() {}
+
+bool ScOrcusXMLContextImpl::loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const
+{
+ rParam.maUserDataStore.clear();
+
+ OString aSysPath = ScOrcusFiltersImpl::toSystemPath(maPath);
+ const char* path = aSysPath.getStr();
+
+ // TODO: Use our own stream loading call instead of one from orcus.
+ std::string aStrm;
+ orcus::load_file_content(path, aStrm);
+
+ if (aStrm.empty())
+ return false;
+
+ orcus::xmlns_repository repo; // xml namespace repository.
+ orcus::xmlns_context cxt = repo.create_context();
+ orcus::xml_structure_tree aXmlTree(cxt);
+ try
+ {
+ aXmlTree.parse(&aStrm[0], aStrm.size());
+
+ TreeUpdateSwitch aSwitch(rTreeCtrl);
+ rTreeCtrl.Clear();
+ rTreeCtrl.SetDefaultCollapsedEntryBmp(rParam.maImgElementDefault);
+ rTreeCtrl.SetDefaultExpandedEntryBmp(rParam.maImgElementDefault);
+
+ orcus::xml_structure_tree::walker aWalker = aXmlTree.get_walker();
+
+ // Root element.
+ orcus::xml_structure_tree::element aElem = aWalker.root();
+ populateTree(rTreeCtrl, aWalker, aElem.name, aElem.repeat, NULL, rParam);
+ }
+ catch (const std::exception&)
+ {
+ // Parsing of this XML file failed.
+ return false;
+ }
+
+ return true;
+}
+
+bool ScOrcusXMLContextImpl::importXML(const ScOrcusImportXMLParam& rParam) const
+{
+ ScOrcusFactory aFactory(mrDoc);
+ OString aSysPath = ScOrcusFiltersImpl::toSystemPath(maPath);
+ const char* path = aSysPath.getStr();
+ try
+ {
+ orcus::orcus_xml filter(&aFactory, NULL);
+
+ // Set cell links.
+ {
+ ScOrcusImportXMLParam::CellLinksType::const_iterator it = rParam.maCellLinks.begin();
+ ScOrcusImportXMLParam::CellLinksType::const_iterator itEnd = rParam.maCellLinks.end();
+ for (; it != itEnd; ++it)
+ {
+ const ScOrcusImportXMLParam::CellLink& rLink = *it;
+ OUString aTabName;
+ mrDoc.GetName(rLink.maPos.Tab(), aTabName);
+ filter.set_cell_link(
+ rLink.maPath.getStr(),
+ rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr(),
+ rLink.maPos.Row(), rLink.maPos.Col());
+ }
+ }
+
+ // Set range links.
+ {
+ ScOrcusImportXMLParam::RangeLinksType::const_iterator it = rParam.maRangeLinks.begin();
+ ScOrcusImportXMLParam::RangeLinksType::const_iterator itEnd = rParam.maRangeLinks.end();
+ for (; it != itEnd; ++it)
+ {
+ const ScOrcusImportXMLParam::RangeLink& rLink = *it;
+ OUString aTabName;
+ mrDoc.GetName(rLink.maPos.Tab(), aTabName);
+ filter.start_range(
+ rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr(),
+ rLink.maPos.Row(), rLink.maPos.Col());
+
+ std::for_each(rLink.maFieldPaths.begin(), rLink.maFieldPaths.end(), InsertFieldPath(filter));
+
+ filter.commit_range();
+ }
+ }
+
+ filter.read_file(path);
+ }
+ catch (const std::exception&)
+ {
+ return false;
+ }
+ return true;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/xmlsourcedlg.hxx b/sc/source/ui/inc/xmlsourcedlg.hxx
index e16b52a..1540b29 100644
--- a/sc/source/ui/inc/xmlsourcedlg.hxx
+++ b/sc/source/ui/inc/xmlsourcedlg.hxx
@@ -23,6 +23,7 @@
class ScDocument;
class ScRange;
+class ScOrcusXMLContext;
class ScXMLSourceTree : public SvTreeListBox
{
@@ -55,6 +56,8 @@ class ScXMLSourceDlg : public ScAnyRefDlg
std::set<const SvTreeListEntry*> maCellLinks;
std::set<const SvTreeListEntry*> maRangeLinks;
+ boost::scoped_ptr<ScOrcusXMLContext> mpXMLContext;
+
ScDocument* mpDoc;
formula::RefEdit* mpActiveEdit;
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index fa85970..5019306 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -208,7 +208,11 @@ void ScXMLSourceDlg::LoadSourceFileStructure(const OUString& rPath)
if (!pOrcus)
return;
- pOrcus->loadXMLStructure(rPath, maLbTree, maXMLParam);
+ mpXMLContext.reset(pOrcus->createXMLContext(*mpDoc, rPath));
+ if (!mpXMLContext)
+ return;
+
+ mpXMLContext->loadXMLStructure(maLbTree, maXMLParam);
}
void ScXMLSourceDlg::HandleGetFocus(Control* pCtrl)
@@ -454,6 +458,9 @@ void getFieldLinks(ScOrcusImportXMLParam::RangeLink& rRangeLink, const SvTreeLis
void ScXMLSourceDlg::OkPressed()
{
+ if (!mpXMLContext)
+ return;
+
// Begin import.
ScOrcusImportXMLParam aParam;
@@ -493,11 +500,8 @@ void ScXMLSourceDlg::OkPressed()
}
// Now do the import.
- ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
- if (!pOrcus)
- return;
- pOrcus->importXML(*mpDoc, maSrcPath, aParam);
+ mpXMLContext->importXML(aParam);
// Don't forget to broadcast the change.
SfxObjectShell* pShell = mpDoc->GetDocumentShell();
commit 83c2f4c830559ce3aa0b448a604c93882af4f231
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Mon Nov 19 15:47:10 2012 -0500
Get it to build after updating liborcus from latest master.
Change-Id: Ie9cace11bf869777ff0986d38e856e68ad8fdb57
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 2584770..3fa23e1 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -311,8 +311,9 @@ bool ScOrcusFiltersImpl::loadXMLStructure(
if (aStrm.empty())
return false;
- orcus::xmlns_repository aNsRepo; // xml namespace repository.
- orcus::xml_structure_tree aXmlTree(aNsRepo);
+ orcus::xmlns_repository repo; // xml namespace repository.
+ orcus::xmlns_context cxt = repo.create_context();
+ orcus::xml_structure_tree aXmlTree(cxt);
try
{
aXmlTree.parse(&aStrm[0], aStrm.size());
commit c85b1974be6f1bf96be1cc9a94c75dab99c1eb9e
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Thu Nov 15 19:28:23 2012 -0500
Now I can remove this ugly const_cast.
Change-Id: Ifc4d0028d334bd6fa9dfdea86543b5eaf25313e0
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 08cf7cc..fa85970 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -42,7 +42,7 @@ bool isAttribute(const SvTreeListEntry& rEntry)
OUString getXPath(const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
{
OUStringBuffer aBuf;
- for (SvTreeListEntry* p = const_cast<SvTreeListEntry*>(&rEntry); p; p = rTree.GetParent(p))
+ for (const SvTreeListEntry* p = &rEntry; p; p = rTree.GetParent(p))
{
const SvLBoxItem* pItem = p->GetFirstItem(SV_ITEM_ID_LBOXSTRING);
if (!pItem)
commit 40eb44c1cdce10bd4bdc7e1a8da08591a5178b75
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Nov 13 17:07:18 2012 -0500
Enable the 'Import' button only when linked data exists.
It makes no sense to allow import if there is no link specified.
Change-Id: I3ff4bfa7fd78c79a2c4ee74c7a1a34d2b7a2d1c4
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index dd1ab74..08cf7cc 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -104,8 +104,10 @@ ScXMLSourceDlg::ScXMLSourceDlg(
aLink = LINK(this, ScXMLSourceDlg, RefModifiedHdl);
maRefEdit.SetModifyHdl(aLink);
+ maBtnOk.Disable();
+
SetNonLinkable();
- maBtnSelectSource.GrabFocus();
+ maBtnSelectSource.GrabFocus(); // Initial focus is on the select source button.
}
ScXMLSourceDlg::~ScXMLSourceDlg()
@@ -559,6 +561,10 @@ void ScXMLSourceDlg::RefEditModified()
else
maCellLinks.erase(pEntry);
}
+
+ // Enable the import button only when at least one link exists.
+ bool bHasLink = !maCellLinks.empty() || !maRangeLinks.empty();
+ maBtnOk.Enable(bHasLink);
}
IMPL_LINK(ScXMLSourceDlg, GetFocusHdl, Control*, pCtrl)
commit 582931ec18c90ab4e60396256505d97578de6d84
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Nov 13 15:57:35 2012 -0500
Set initial focus to the 'Open XML source' button.
This helps with keyboard-only navigation in this dialog.
Change-Id: Ie3d580ba921c93ae256ad0a503615de7a037323a
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 68e819e..dd1ab74 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -105,6 +105,7 @@ ScXMLSourceDlg::ScXMLSourceDlg(
maRefEdit.SetModifyHdl(aLink);
SetNonLinkable();
+ maBtnSelectSource.GrabFocus();
}
ScXMLSourceDlg::~ScXMLSourceDlg()
commit fafbce473e135c9f3a266f3d04b2e214881c6f24
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Nov 13 15:54:52 2012 -0500
Just call it "XML Source" in the menu for now.
Change-Id: Ic802bd38e976df52ad5216820187ef1334eac5a6
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index 0d636ad..64ffb88 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -1206,7 +1206,7 @@
</node>
<node oor:name=".uno:ManageXMLSource" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
- <value xml:lang="en-US">Manage ~XML Source...</value>
+ <value xml:lang="en-US">~XML Source...</value>
</prop>
</node>
<node oor:name=".uno:DataSort" oor:op="replace">
commit 134c7e65df34b445ac6fa7b7ae63832396cc59ce
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Nov 13 15:36:14 2012 -0500
Setting a reference via ref picker should update the link ref data.
Change-Id: Ie1559e1ece8d57b09e68676f88991c67ff8db03e
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index f9c2c13..68e819e 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -127,6 +127,8 @@ void ScXMLSourceDlg::SetReference(const ScRange& rRange, ScDocument* pDoc)
OUString aStr;
rRange.aStart.Format(aStr, SCA_ABS_3D, pDoc, pDoc->GetAddressConvention());
mpActiveEdit->SetRefString(aStr);
+
+ RefEditModified();
}
void ScXMLSourceDlg::Deactivate()
commit 7a3bfca5862619260f8050e45085a7a74e1054ae
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Nov 13 15:15:53 2012 -0500
Broadcast and re-paint when the XML import is complete.
Change-Id: I8bf7a3331a24d39ce327264cd43ccb5910ce1251
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 5f3a6e1..f9c2c13 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -15,10 +15,12 @@
#include "orcusfilters.hxx"
#include "filter.hxx"
#include "reffact.hxx"
+#include "tabvwsh.hxx"
#include "unotools/pathoptions.hxx"
#include "tools/urlobj.hxx"
#include "svtools/svlbitm.hxx"
+#include "sfx2/objsh.hxx"
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
@@ -485,12 +487,22 @@ void ScXMLSourceDlg::OkPressed()
}
}
+ // Now do the import.
ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
if (!pOrcus)
return;
pOrcus->importXML(*mpDoc, maSrcPath, aParam);
+ // Don't forget to broadcast the change.
+ SfxObjectShell* pShell = mpDoc->GetDocumentShell();
+ pShell->Broadcast(SfxSimpleHint(FID_DATACHANGED));
+
+ // Repaint the grid to force repaint the cell values.
+ ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+ if (pViewShell)
+ pViewShell->PaintGrid();
+
Close();
}
commit 78ac5e853302566b191dd902ef75c1e16c48ccf1
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Nov 9 23:04:29 2012 -0500
Remove debug statements.
Change-Id: I3e3d4863bef27e91b95f9e6cbe5c2daa81ece0b2
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index ba3701a..2584770 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -113,11 +113,8 @@ orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::get_sheet(const char* s
OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
SCTAB nTab = -1;
if (!mrDoc.GetTable(aTabName, nTab))
- {
// Sheet by that name not found.
- fprintf(stdout, "ScOrcusFactory::get_sheet: no such sheet!!! (%s)\n", rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr());
return NULL;
- }
// See if we already have an orcus sheet instance by that index.
boost::ptr_vector<ScOrcusSheet>::iterator it =
@@ -349,7 +346,6 @@ public:
InsertFieldPath(orcus::orcus_xml& rFilter) : mrFilter(rFilter) {}
void operator() (const OString& rPath)
{
- fprintf(stdout, "InsertFieldPath::(): field path = '%s'\n", rPath.getStr());
mrFilter.append_field_link(rPath.getStr());
}
};
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 62d2f40..5f3a6e1 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -125,8 +125,6 @@ void ScXMLSourceDlg::SetReference(const ScRange& rRange, ScDocument* pDoc)
OUString aStr;
rRange.aStart.Format(aStr, SCA_ABS_3D, pDoc, pDoc->GetAddressConvention());
mpActiveEdit->SetRefString(aStr);
-
- fprintf(stdout, "ScXMLSourceDlg::SetReference: ref str = '%s'\n", rtl::OUStringToOString(aStr, RTL_TEXTENCODING_UTF8).getStr());
}
void ScXMLSourceDlg::Deactivate()
@@ -431,9 +429,8 @@ void getFieldLinks(ScOrcusImportXMLParam::RangeLink& rRangeLink, const SvTreeLis
{
const SvTreeListEntry& rChild = *it;
OUString aPath = getXPath(rTree, rChild);
-
const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rChild);
- fprintf(stdout, "getFieldLinks: path = '%s' leaf = %d\n", rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).getStr(), pUserData->mbLeafNode);
+
if (pUserData && pUserData->mbLeafNode)
{
if (!aPath.isEmpty())
@@ -510,8 +507,6 @@ void ScXMLSourceDlg::RefEditModified()
ScAddress aLinkedPos;
sal_uInt16 nRes = aLinkedPos.Parse(aRefStr, mpDoc, mpDoc->GetAddressConvention());
bool bValid = (nRes & SCA_VALID) == SCA_VALID;
- fprintf(stdout, "ScXMLSourceDlg::RefEditModified: ref str = '%s' valid = %d\n",
- rtl::OUStringToOString(aRefStr, RTL_TEXTENCODING_UTF8).getStr(), bValid);
// TODO: For some unknown reason, setting the ref invalid will hide the text altogether.
// Find out how to make this work.
commit f10c5f33c17093bac8dd09b1a3b6ea39bdb6020c
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Nov 9 22:10:54 2012 -0500
Register range links to orcus_xml too.
But range links fail to import. Looks like sheet names are corrupted.
I need to debug this...
Change-Id: If2aeb3b81db65749f05edfbdd2f3388be4f2539c
diff --git a/sc/inc/orcusxml.hxx b/sc/inc/orcusxml.hxx
index 1a0b192..c3a981d 100644
--- a/sc/inc/orcusxml.hxx
+++ b/sc/inc/orcusxml.hxx
@@ -31,7 +31,8 @@ struct ScOrcusXMLTreeParam
{
EntryType meType;
ScAddress maLinkedPos; /// linked cell position (invalid if unlinked)
- bool mbRangeParent;
+ bool mbRangeParent:1;
+ bool mbLeafNode:1; /// Leaf if it has no child elements. Child Attributes don't count.
SC_DLLPUBLIC EntryData(EntryType eType);
};
diff --git a/sc/source/core/tool/orcusxml.cxx b/sc/source/core/tool/orcusxml.cxx
index 5ad41de..3f3c93c 100644
--- a/sc/source/core/tool/orcusxml.cxx
+++ b/sc/source/core/tool/orcusxml.cxx
@@ -12,7 +12,7 @@
#include "svtools/treelistbox.hxx"
ScOrcusXMLTreeParam::EntryData::EntryData(EntryType eType) :
- meType(eType), maLinkedPos(ScAddress::INITIALIZE_INVALID), mbRangeParent(false) {}
+ meType(eType), maLinkedPos(ScAddress::INITIALIZE_INVALID), mbRangeParent(false), mbLeafNode(true) {}
ScOrcusXMLTreeParam::EntryData* ScOrcusXMLTreeParam::getUserData(SvTreeListEntry& rEntry)
{
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 2ced6b5..ba3701a 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -113,8 +113,11 @@ orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::get_sheet(const char* s
OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
SCTAB nTab = -1;
if (!mrDoc.GetTable(aTabName, nTab))
+ {
// Sheet by that name not found.
+ fprintf(stdout, "ScOrcusFactory::get_sheet: no such sheet!!! (%s)\n", rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr());
return NULL;
+ }
// See if we already have an orcus sheet instance by that index.
boost::ptr_vector<ScOrcusSheet>::iterator it =
@@ -211,11 +214,12 @@ bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, const OUString& rPath) cons
namespace {
-void setUserDataToEntry(
+ScOrcusXMLTreeParam::EntryData& setUserDataToEntry(
SvTreeListEntry& rEntry, ScOrcusXMLTreeParam::UserDataStoreType& rStore, ScOrcusXMLTreeParam::EntryType eType)
{
rStore.push_back(new ScOrcusXMLTreeParam::EntryData(eType));
rEntry.SetUserData(&rStore.back());
+ return rStore.back();
}
void populateTree(
@@ -229,7 +233,7 @@ void populateTree(
// Can this ever happen!?
return;
- setUserDataToEntry(
+ ScOrcusXMLTreeParam::EntryData& rEntryData = setUserDataToEntry(
*pEntry, rParam.maUserDataStore,
bRepeat ? ScOrcusXMLTreeParam::ElementRepeat : ScOrcusXMLTreeParam::ElementDefault);
@@ -266,6 +270,9 @@ void populateTree(
rWalker.get_children(aNames);
+ // Non-leaf if it has child elements, leaf otherwise.
+ rEntryData.mbLeafNode = aNames.empty();
+
// Insert child elements recursively.
for (it = aNames.begin(), itEnd = aNames.end(); it != itEnd; ++it)
{
@@ -333,6 +340,22 @@ bool ScOrcusFiltersImpl::loadXMLStructure(
return true;
}
+namespace {
+
+class InsertFieldPath : std::unary_function<OString, void>
+{
+ orcus::orcus_xml& mrFilter;
+public:
+ InsertFieldPath(orcus::orcus_xml& rFilter) : mrFilter(rFilter) {}
+ void operator() (const OString& rPath)
+ {
+ fprintf(stdout, "InsertFieldPath::(): field path = '%s'\n", rPath.getStr());
+ mrFilter.append_field_link(rPath.getStr());
+ }
+};
+
+}
+
bool ScOrcusFiltersImpl::importXML(
ScDocument& rDoc, const rtl::OUString& rPath, const ScOrcusImportXMLParam& rParam) const
{
@@ -344,18 +367,38 @@ bool ScOrcusFiltersImpl::importXML(
orcus::orcus_xml filter(&aFactory, NULL);
// Set cell links.
- ScOrcusImportXMLParam::CellLinksType::const_iterator it = rParam.maCellLinks.begin();
- ScOrcusImportXMLParam::CellLinksType::const_iterator itEnd = rParam.maCellLinks.end();
+ {
+ ScOrcusImportXMLParam::CellLinksType::const_iterator it = rParam.maCellLinks.begin();
+ ScOrcusImportXMLParam::CellLinksType::const_iterator itEnd = rParam.maCellLinks.end();
+ for (; it != itEnd; ++it)
+ {
+ const ScOrcusImportXMLParam::CellLink& rLink = *it;
+ OUString aTabName;
+ rDoc.GetName(rLink.maPos.Tab(), aTabName);
+ filter.set_cell_link(
+ rLink.maPath.getStr(),
+ rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr(),
+ rLink.maPos.Row(), rLink.maPos.Col());
+ }
+ }
- for (; it != itEnd; ++it)
+ // Set range links.
{
- const ScOrcusImportXMLParam::CellLink& rLink = *it;
- OUString aTabName;
- rDoc.GetName(rLink.maPos.Tab(), aTabName);
- filter.set_cell_link(
- rLink.maPath.getStr(),
- rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr(),
- rLink.maPos.Row(), rLink.maPos.Col());
+ ScOrcusImportXMLParam::RangeLinksType::const_iterator it = rParam.maRangeLinks.begin();
+ ScOrcusImportXMLParam::RangeLinksType::const_iterator itEnd = rParam.maRangeLinks.end();
+ for (; it != itEnd; ++it)
+ {
+ const ScOrcusImportXMLParam::RangeLink& rLink = *it;
+ OUString aTabName;
+ rDoc.GetName(rLink.maPos.Tab(), aTabName);
+ filter.start_range(
+ rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr(),
+ rLink.maPos.Row(), rLink.maPos.Col());
+
+ std::for_each(rLink.maFieldPaths.begin(), rLink.maFieldPaths.end(), InsertFieldPath(filter));
+
+ filter.commit_range();
+ }
}
filter.read_file(path);
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 7821b9b..62d2f40 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -414,26 +414,79 @@ bool ScXMLSourceDlg::IsChildrenDirty(SvTreeListEntry* pEntry) const
return false;
}
+namespace {
+
+/**
+ * Pick only the leaf elements.
+ */
+void getFieldLinks(ScOrcusImportXMLParam::RangeLink& rRangeLink, const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
+{
+ const SvTreeListEntries& rChildren = rEntry.GetChildEntries();
+ if (rChildren.empty())
+ // No more children. We're done.
+ return;
+
+ SvTreeListEntries::const_iterator it = rChildren.begin(), itEnd = rChildren.end();
+ for (; it != itEnd; ++it)
+ {
+ const SvTreeListEntry& rChild = *it;
+ OUString aPath = getXPath(rTree, rChild);
+
+ const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rChild);
+ fprintf(stdout, "getFieldLinks: path = '%s' leaf = %d\n", rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).getStr(), pUserData->mbLeafNode);
+ if (pUserData && pUserData->mbLeafNode)
+ {
+ if (!aPath.isEmpty())
+ // XPath should never be empty anyway, but it won't hurt to check...
+ rRangeLink.maFieldPaths.push_back(rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8));
+ }
+
+ // Walk recursively.
+ getFieldLinks(rRangeLink, rTree, rChild);
+ }
+}
+
+}
+
void ScXMLSourceDlg::OkPressed()
{
// Begin import.
ScOrcusImportXMLParam aParam;
- std::set<const SvTreeListEntry*>::const_iterator it = maCellLinks.begin(), itEnd = maCellLinks.end();
- for (; it != itEnd; ++it)
+ // Convert single cell links.
{
- const SvTreeListEntry& rEntry = **it;
- OUString aPath = getXPath(maLbTree, rEntry);
- const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rEntry);
- ScAddress aPos = pUserData->maLinkedPos;
-
- aParam.maCellLinks.push_back(
- ScOrcusImportXMLParam::CellLink(
- aPos, rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8)));
+ std::set<const SvTreeListEntry*>::const_iterator it = maCellLinks.begin(), itEnd = maCellLinks.end();
+ for (; it != itEnd; ++it)
+ {
+ const SvTreeListEntry& rEntry = **it;
+ OUString aPath = getXPath(maLbTree, rEntry);
+ const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rEntry);
+
+ aParam.maCellLinks.push_back(
+ ScOrcusImportXMLParam::CellLink(
+ pUserData->maLinkedPos, rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8)));
+ }
}
- // TODO: Process range links.
+ // Convert range links. For now, an element with range link takes all its
+ // child elements as its fields.
+ {
+ std::set<const SvTreeListEntry*>::const_iterator it = maRangeLinks.begin(), itEnd = maRangeLinks.end();
+ for (; it != itEnd; ++it)
+ {
+ const SvTreeListEntry& rEntry = **it;
+ const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rEntry);
+
+ ScOrcusImportXMLParam::RangeLink aRangeLink;
+ aRangeLink.maPos = pUserData->maLinkedPos;
+
+ // Go through all its child elements.
+ getFieldLinks(aRangeLink, maLbTree, rEntry);
+
+ aParam.maRangeLinks.push_back(aRangeLink);
+ }
+ }
ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
if (!pOrcus)
commit eb85e45358d641a9beb246a97c3144b3d4a591ee
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Nov 9 17:25:02 2012 -0500
Implement the required get_sheet() interface method.
Now we can import single-linked elements.
Change-Id: I0e2f2fd618bf6dadfcc18e8b96e235e3c08f443b
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 9b2244b..2ced6b5 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -66,6 +66,7 @@ class ScOrcusSheet : public orcus::spreadsheet::iface::import_sheet
public:
ScOrcusSheet(ScDocument& rDoc, SCTAB nTab);
+ // Orcus import interface
virtual void set_auto(row_t row, col_t col, const char* p, size_t n);
virtual void set_format(row_t row, col_t col, size_t xf_index);
virtual void set_formula(row_t row, col_t col, formula_grammar_t grammar, const char* p, size_t n);
@@ -79,6 +80,8 @@ public:
virtual void set_shared_formula(row_t row, col_t col, size_t sindex);
virtual void set_string(row_t row, col_t col, size_t sindex);
virtual void set_value(row_t row, col_t col, double value);
+
+ SCTAB getIndex() const { return mnTab; }
};
ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) : mrDoc(rDoc) {}
@@ -94,10 +97,36 @@ orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::append_sheet(const char
return &maSheets.back();
}
-orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::get_sheet(const char* /*sheet_name*/, size_t /*sheet_name_length*/)
+class FindSheetByIndex : std::unary_function<ScOrcusSheet, bool>
{
- // TODO: Implement this.
- return NULL;
+ SCTAB mnTab;
+public:
+ FindSheetByIndex(SCTAB nTab) : mnTab(nTab) {}
+ bool operator() (const ScOrcusSheet& rSheet) const
+ {
+ return rSheet.getIndex() == mnTab;
+ }
+};
+
+orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::get_sheet(const char* sheet_name, size_t sheet_name_length)
+{
+ OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
+ SCTAB nTab = -1;
+ if (!mrDoc.GetTable(aTabName, nTab))
+ // Sheet by that name not found.
+ return NULL;
+
+ // See if we already have an orcus sheet instance by that index.
+ boost::ptr_vector<ScOrcusSheet>::iterator it =
+ std::find_if(maSheets.begin(), maSheets.end(), FindSheetByIndex(nTab));
+
+ if (it != maSheets.end())
+ // We already have one. Return it.
+ return &(*it);
+
+ // Create a new orcus sheet instance for this.
+ maSheets.push_back(new ScOrcusSheet(mrDoc, nTab));
+ return &maSheets.back();
}
orcus::spreadsheet::iface::import_shared_strings* ScOrcusFactory::get_shared_strings()
commit 071928f290135dcc10d6de2365b32302c563e5f1
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Nov 9 17:05:49 2012 -0500
Set all single cell links to orcus_xml, and start reading the file.
Alas, data won't get imported because I haven't implemented get_sheet()
interface method.
Change-Id: Id53b2c68b2fdf4c03fa6d6de25dd7762a51bd610
diff --git a/sc/inc/orcusxml.hxx b/sc/inc/orcusxml.hxx
index 2baac69..1a0b192 100644
--- a/sc/inc/orcusxml.hxx
+++ b/sc/inc/orcusxml.hxx
@@ -57,19 +57,22 @@ struct ScOrcusImportXMLParam
struct CellLink
{
ScAddress maPos;
- rtl::OUString maPath;
+ rtl::OString maPath;
- CellLink(const ScAddress& rPos, const rtl::OUString& rPath);
+ CellLink(const ScAddress& rPos, const rtl::OString& rPath);
};
struct RangeLink
{
ScAddress maPos;
- std::vector<rtl::OUString> maFieldPaths;
+ std::vector<rtl::OString> maFieldPaths;
};
- std::vector<CellLink> maCellLinks;
- std::vector<RangeLink> maRangeLinks;
+ typedef std::vector<CellLink> CellLinksType;
+ typedef std::vector<RangeLink> RangeLinksType;
+
+ CellLinksType maCellLinks;
+ RangeLinksType maRangeLinks;
};
#endif
diff --git a/sc/source/core/tool/orcusxml.cxx b/sc/source/core/tool/orcusxml.cxx
index fb74fec..5ad41de 100644
--- a/sc/source/core/tool/orcusxml.cxx
+++ b/sc/source/core/tool/orcusxml.cxx
@@ -24,7 +24,7 @@ const ScOrcusXMLTreeParam::EntryData* ScOrcusXMLTreeParam::getUserData(const SvT
return static_cast<const ScOrcusXMLTreeParam::EntryData*>(rEntry.GetUserData());
}
-ScOrcusImportXMLParam::CellLink::CellLink(const ScAddress& rPos, const OUString& rPath) :
+ScOrcusImportXMLParam::CellLink::CellLink(const ScAddress& rPos, const OString& rPath) :
maPos(rPos), maPath(rPath) {}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index e7a2ef9..9b2244b 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -20,6 +20,7 @@
#include <orcus/orcus_csv.hpp>
#include <orcus/xml_structure_tree.hpp>
#include <orcus/xml_namespace.hpp>
+#include <orcus/orcus_xml.hpp>
#include <orcus/global.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
@@ -36,6 +37,12 @@ using orcus::spreadsheet::formula_grammar_t;
namespace {
+OString toSystemPath(const OUString& rPath)
+{
+ INetURLObject aURL(rPath);
+ return rtl::OUStringToOString(aURL.getFSysPath(SYSTEM_PATH), RTL_TEXTENCODING_UTF8);
+}
+
class ScOrcusSheet;
class ScOrcusFactory : public orcus::spreadsheet::iface::import_factory
@@ -156,8 +163,7 @@ void ScOrcusSheet::set_value(row_t /*row*/, col_t /*col*/, double /*value*/)
bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, const OUString& rPath) const
{
ScOrcusFactory aFactory(rDoc);
- INetURLObject aURL(rPath);
- OString aSysPath = rtl::OUStringToOString(aURL.getFSysPath(SYSTEM_PATH), RTL_TEXTENCODING_UTF8);
+ OString aSysPath = toSystemPath(rPath);
const char* path = aSysPath.getStr();
try
@@ -262,8 +268,7 @@ bool ScOrcusFiltersImpl::loadXMLStructure(
{
rParam.maUserDataStore.clear();
- INetURLObject aURL(rPath);
- OString aSysPath = rtl::OUStringToOString(aURL.getFSysPath(SYSTEM_PATH), RTL_TEXTENCODING_UTF8);
+ OString aSysPath = toSystemPath(rPath);
const char* path = aSysPath.getStr();
// TODO: Use our own stream loading call instead of one from orcus.
@@ -302,6 +307,34 @@ bool ScOrcusFiltersImpl::loadXMLStructure(
bool ScOrcusFiltersImpl::importXML(
ScDocument& rDoc, const rtl::OUString& rPath, const ScOrcusImportXMLParam& rParam) const
{
+ ScOrcusFactory aFactory(rDoc);
+ OString aSysPath = toSystemPath(rPath);
+ const char* path = aSysPath.getStr();
+ try
+ {
+ orcus::orcus_xml filter(&aFactory, NULL);
+
+ // Set cell links.
+ ScOrcusImportXMLParam::CellLinksType::const_iterator it = rParam.maCellLinks.begin();
+ ScOrcusImportXMLParam::CellLinksType::const_iterator itEnd = rParam.maCellLinks.end();
+
+ for (; it != itEnd; ++it)
+ {
+ const ScOrcusImportXMLParam::CellLink& rLink = *it;
+ OUString aTabName;
+ rDoc.GetName(rLink.maPos.Tab(), aTabName);
+ filter.set_cell_link(
+ rLink.maPath.getStr(),
+ rtl::OUStringToOString(aTabName, RTL_TEXTENCODING_UTF8).getStr(),
+ rLink.maPos.Row(), rLink.maPos.Col());
+ }
+
+ filter.read_file(path);
+ }
+ catch (const std::exception&)
+ {
+ return false;
+ }
return true;
}
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index c490d2e..7821b9b 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -428,10 +428,9 @@ void ScXMLSourceDlg::OkPressed()
const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rEntry);
ScAddress aPos = pUserData->maLinkedPos;
- fprintf(stdout, "ScXMLSourceDlg::OkPressed: linked to (col=%d,row=%d) path = '%s'\n",
- aPos.Col(), aPos.Row(), rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).getStr());
-
- aParam.maCellLinks.push_back(ScOrcusImportXMLParam::CellLink(aPos, aPath));
+ aParam.maCellLinks.push_back(
+ ScOrcusImportXMLParam::CellLink(
+ aPos, rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8)));
}
// TODO: Process range links.
commit 971f0e32f249fd3e7fbc805c7a9b44c88122fcd9
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Nov 9 16:46:22 2012 -0500
Not a good idea to close the dialog first then start the import.
Because that leads to a crash.
Change-Id: I7ca7d94e1164a44bbef9e9b41e3f8c5bcf113c22
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 6260589..c490d2e 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -436,13 +436,13 @@ void ScXMLSourceDlg::OkPressed()
// TODO: Process range links.
- Close();
-
ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
if (!pOrcus)
return;
pOrcus->importXML(*mpDoc, maSrcPath, aParam);
+
+ Close();
}
void ScXMLSourceDlg::CancelPressed()
commit 2ffceb198ef26579e2d3d6659384f76184ccc3e2
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Nov 9 15:21:36 2012 -0500
Press 'Import' in the dialog to start importing XML.
For now, the dialog only calls importXML() when the Import button
is pressed, and the importXML() function still does nothing.
Change-Id: I3427d343f88ba2a9b076ffc0ee4bcc44055d7717
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx
index 019441c..1b94f67 100644
--- a/sc/inc/orcusfilters.hxx
+++ b/sc/inc/orcusfilters.hxx
@@ -16,6 +16,7 @@ class ScDocument;
class SvTreeListBox;
class Image;
struct ScOrcusXMLTreeParam;
+struct ScOrcusImportXMLParam;
/**
* Collection of orcus filter wrappers.
@@ -29,6 +30,9 @@ public:
virtual bool loadXMLStructure(
const rtl::OUString& rPath, SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const = 0;
+
+ virtual bool importXML(
+ ScDocument& rDoc, const rtl::OUString& rPath, const ScOrcusImportXMLParam& rParam) const = 0;
};
#endif
diff --git a/sc/inc/orcusxml.hxx b/sc/inc/orcusxml.hxx
index a133b78..2baac69 100644
--- a/sc/inc/orcusxml.hxx
+++ b/sc/inc/orcusxml.hxx
@@ -14,6 +14,7 @@
#include "address.hxx"
#include "vcl/image.hxx"
+#include <vector>
#include <boost/ptr_container/ptr_vector.hpp>
class SvTreeListEntry;
@@ -48,6 +49,27 @@ struct ScOrcusXMLTreeParam
UserDataStoreType maUserDataStore;
static SC_DLLPUBLIC EntryData* getUserData(SvTreeListEntry& rEntry);
+ static SC_DLLPUBLIC const EntryData* getUserData(const SvTreeListEntry& rEntry);
+};
+
+struct ScOrcusImportXMLParam
+{
+ struct CellLink
+ {
+ ScAddress maPos;
+ rtl::OUString maPath;
+
+ CellLink(const ScAddress& rPos, const rtl::OUString& rPath);
+ };
+
+ struct RangeLink
+ {
+ ScAddress maPos;
+ std::vector<rtl::OUString> maFieldPaths;
+ };
+
+ std::vector<CellLink> maCellLinks;
+ std::vector<RangeLink> maRangeLinks;
};
#endif
diff --git a/sc/source/core/tool/orcusxml.cxx b/sc/source/core/tool/orcusxml.cxx
index 8d5d91b..fb74fec 100644
--- a/sc/source/core/tool/orcusxml.cxx
+++ b/sc/source/core/tool/orcusxml.cxx
@@ -19,4 +19,12 @@ ScOrcusXMLTreeParam::EntryData* ScOrcusXMLTreeParam::getUserData(SvTreeListEntry
return static_cast<ScOrcusXMLTreeParam::EntryData*>(rEntry.GetUserData());
}
+const ScOrcusXMLTreeParam::EntryData* ScOrcusXMLTreeParam::getUserData(const SvTreeListEntry& rEntry)
+{
+ return static_cast<const ScOrcusXMLTreeParam::EntryData*>(rEntry.GetUserData());
+}
+
+ScOrcusImportXMLParam::CellLink::CellLink(const ScAddress& rPos, const OUString& rPath) :
+ maPos(rPos), maPath(rPath) {}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx
index 956e940..f2d2703 100644
--- a/sc/source/filter/inc/orcusfiltersimpl.hxx
+++ b/sc/source/filter/inc/orcusfiltersimpl.hxx
@@ -19,6 +19,9 @@ public:
virtual bool loadXMLStructure(
const rtl::OUString& rPath, SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const;
+
+ virtual bool importXML(
+ ScDocument& rDoc, const rtl::OUString& rPath, const ScOrcusImportXMLParam& rParam) const;
};
#endif
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 0549156..e7a2ef9 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -299,4 +299,10 @@ bool ScOrcusFiltersImpl::loadXMLStructure(
return true;
}
+bool ScOrcusFiltersImpl::importXML(
+ ScDocument& rDoc, const rtl::OUString& rPath, const ScOrcusImportXMLParam& rParam) const
+{
+ return true;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/xmlsourcedlg.hxx b/sc/source/ui/inc/xmlsourcedlg.hxx
index 058058a..e16b52a 100644
--- a/sc/source/ui/inc/xmlsourcedlg.hxx
+++ b/sc/source/ui/inc/xmlsourcedlg.hxx
@@ -18,6 +18,7 @@
#include "anyrefdg.hxx"
#include "orcusxml.hxx"
+#include <set>
#include <boost/scoped_ptr.hpp>
class ScDocument;
@@ -51,6 +52,8 @@ class ScXMLSourceDlg : public ScAnyRefDlg
rtl::OUString maSrcPath;
ScOrcusXMLTreeParam maXMLParam;
+ std::set<const SvTreeListEntry*> maCellLinks;
+ std::set<const SvTreeListEntry*> maRangeLinks;
ScDocument* mpDoc;
@@ -94,11 +97,13 @@ private:
void OkPressed();
void CancelPressed();
+ void RefEditModified();
DECL_LINK(GetFocusHdl, Control*);
DECL_LINK(LoseFocusHdl, Control*);
DECL_LINK(BtnPressedHdl, Button*);
DECL_LINK(TreeItemSelectHdl, void*);
+ DECL_LINK(RefModifiedHdl, void*);
};
#endif
diff --git a/sc/source/ui/src/xmlsourcedlg.src b/sc/source/ui/src/xmlsourcedlg.src
index 99d6f56..d90b498 100644
--- a/sc/source/ui/src/xmlsourcedlg.src
+++ b/sc/source/ui/src/xmlsourcedlg.src
@@ -76,7 +76,7 @@ ModelessDialog RID_SCDLG_XML_SOURCE
{
Pos = MAP_APPFONT ( 216 , 66 ) ;
Size = MAP_APPFONT ( 13 , 15 ) ;
- TabStop = FALSE ;
+ TabStop = TRUE ;
QuickHelpText [ en-US ] = "Shrink" ;
};
@@ -106,6 +106,7 @@ ModelessDialog RID_SCDLG_XML_SOURCE
OKButton BTN_OK
{
+ Text [ en-US ] = "~Import" ;
Pos = MAP_APPFONT ( 139 , 181 ) ;
Size = MAP_APPFONT ( 50 , 14 ) ;
};
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 2fd452d..6260589 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -18,6 +18,7 @@
#include "unotools/pathoptions.hxx"
#include "tools/urlobj.hxx"
+#include "svtools/svlbitm.hxx"
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
@@ -25,6 +26,35 @@
using namespace com::sun::star;
+namespace {
+
+bool isAttribute(const SvTreeListEntry& rEntry)
+{
+ const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rEntry);
+ if (!pUserData)
+ return false;
+
+ return pUserData->meType == ScOrcusXMLTreeParam::Attribute;
+}
+
+OUString getXPath(const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
+{
+ OUStringBuffer aBuf;
+ for (SvTreeListEntry* p = const_cast<SvTreeListEntry*>(&rEntry); p; p = rTree.GetParent(p))
+ {
+ const SvLBoxItem* pItem = p->GetFirstItem(SV_ITEM_ID_LBOXSTRING);
+ if (!pItem)
+ continue;
+
+ const SvLBoxString* pStr = static_cast<const SvLBoxString*>(pItem);
+ aBuf.insert(0, pStr->GetText());
+ aBuf.insert(0, isAttribute(*p) ? '@' : '/');
+ }
+
+ return aBuf.makeStringAndClear();
+}
+
+}
ScXMLSourceTree::ScXMLSourceTree(Window* pParent, const ResId& rResId) :
SvTreeListBox(pParent, rResId) {}
@@ -69,6 +99,9 @@ ScXMLSourceDlg::ScXMLSourceDlg(
aLink = LINK(this, ScXMLSourceDlg, TreeItemSelectHdl);
maLbTree.SetSelectHdl(aLink);
+ aLink = LINK(this, ScXMLSourceDlg, RefModifiedHdl);
+ maRefEdit.SetModifyHdl(aLink);
+
SetNonLinkable();
}
@@ -93,17 +126,7 @@ void ScXMLSourceDlg::SetReference(const ScRange& rRange, ScDocument* pDoc)
rRange.aStart.Format(aStr, SCA_ABS_3D, pDoc, pDoc->GetAddressConvention());
mpActiveEdit->SetRefString(aStr);
- // Set this address to currently selected tree item.
- SvTreeListEntry* pEntry = maLbTree.GetCurEntry();
- if (!pEntry)
- return;
-
- ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pEntry);
- if (!pUserData)
- return;
-
- pUserData->maLinkedPos = rRange.aStart;
- pUserData->mbRangeParent = pUserData->meType == ScOrcusXMLTreeParam::ElementRepeat;
+ fprintf(stdout, "ScXMLSourceDlg::SetReference: ref str = '%s'\n", rtl::OUStringToOString(aStr, RTL_TEXTENCODING_UTF8).getStr());
}
void ScXMLSourceDlg::Deactivate()
@@ -312,7 +335,7 @@ void ScXMLSourceDlg::AttributeSelected(SvTreeListEntry& rEntry)
return;
}
- if (IsParentDirty(pParent))
+ if (IsParentDirty(&rEntry))
{
SetNonLinkable();
return;
@@ -393,8 +416,33 @@ bool ScXMLSourceDlg::IsChildrenDirty(SvTreeListEntry* pEntry) const
void ScXMLSourceDlg::OkPressed()
{
- // Store the xml link data to document.
+ // Begin import.
+
+ ScOrcusImportXMLParam aParam;
+
+ std::set<const SvTreeListEntry*>::const_iterator it = maCellLinks.begin(), itEnd = maCellLinks.end();
+ for (; it != itEnd; ++it)
+ {
+ const SvTreeListEntry& rEntry = **it;
+ OUString aPath = getXPath(maLbTree, rEntry);
+ const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rEntry);
+ ScAddress aPos = pUserData->maLinkedPos;
+
+ fprintf(stdout, "ScXMLSourceDlg::OkPressed: linked to (col=%d,row=%d) path = '%s'\n",
+ aPos.Col(), aPos.Row(), rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).getStr());
+
+ aParam.maCellLinks.push_back(ScOrcusImportXMLParam::CellLink(aPos, aPath));
+ }
+
+ // TODO: Process range links.
+
Close();
+
+ ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
+ if (!pOrcus)
+ return;
+
+ pOrcus->importXML(*mpDoc, maSrcPath, aParam);
}
void ScXMLSourceDlg::CancelPressed()
@@ -402,6 +450,55 @@ void ScXMLSourceDlg::CancelPressed()
Close();
}
+void ScXMLSourceDlg::RefEditModified()
+{
+ OUString aRefStr = maRefEdit.GetText();
+
+ // Check if the address is valid.
+ ScAddress aLinkedPos;
+ sal_uInt16 nRes = aLinkedPos.Parse(aRefStr, mpDoc, mpDoc->GetAddressConvention());
+ bool bValid = (nRes & SCA_VALID) == SCA_VALID;
+ fprintf(stdout, "ScXMLSourceDlg::RefEditModified: ref str = '%s' valid = %d\n",
+ rtl::OUStringToOString(aRefStr, RTL_TEXTENCODING_UTF8).getStr(), bValid);
+
+ // TODO: For some unknown reason, setting the ref invalid will hide the text altogether.
+ // Find out how to make this work.
+// maRefEdit.SetRefValid(bValid);
+
+ if (!bValid)
+ aLinkedPos.SetInvalid();
+
+ // Set this address to currently selected tree item.
+ SvTreeListEntry* pEntry = maLbTree.GetCurEntry();
+ if (!pEntry)
+ // This should never happen.
+ return;
+
+ ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pEntry);
+ if (!pUserData)
+ // This should never happen either.
+ return;
+
+ bool bRepeatElem = pUserData->meType == ScOrcusXMLTreeParam::ElementRepeat;
+ pUserData->maLinkedPos = aLinkedPos;
+ pUserData->mbRangeParent = aLinkedPos.IsValid() && bRepeatElem;
+
+ if (bRepeatElem)
+ {
+ if (bValid)
+ maRangeLinks.insert(pEntry);
+ else
+ maRangeLinks.erase(pEntry);
+ }
+ else
+ {
+ if (bValid)
+ maCellLinks.insert(pEntry);
+ else
+ maCellLinks.erase(pEntry);
+ }
+}
+
IMPL_LINK(ScXMLSourceDlg, GetFocusHdl, Control*, pCtrl)
{
HandleGetFocus(pCtrl);
@@ -431,4 +528,10 @@ IMPL_LINK_NOARG(ScXMLSourceDlg, TreeItemSelectHdl)
return 0;
}
+IMPL_LINK_NOARG(ScXMLSourceDlg, RefModifiedHdl)
+{
+ RefEditModified();
+ return 0;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 450bca12a14b090feb8e288da0ea2c5e2555b9ce
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Nov 7 22:27:35 2012 -0500
Handler methods for OK and Cancel.
Change-Id: I8637543dc10ade3e75205031581eeaadd1b7ca4d
diff --git a/sc/source/ui/inc/xmlsourcedlg.hxx b/sc/source/ui/inc/xmlsourcedlg.hxx
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list