[Libreoffice-commits] .: Branch 'feature/calc-xml-source' - 4 commits - sc/inc sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Nov 9 14:27:49 PST 2012


 sc/inc/orcusfilters.hxx                     |    4 
 sc/inc/orcusxml.hxx                         |   25 +++++
 sc/source/core/tool/orcusxml.cxx            |    8 +
 sc/source/filter/inc/orcusfiltersimpl.hxx   |    3 
 sc/source/filter/orcus/orcusfiltersimpl.cxx |   82 ++++++++++++++++-
 sc/source/ui/inc/xmlsourcedlg.hxx           |    5 +
 sc/source/ui/src/xmlsourcedlg.src           |    3 
 sc/source/ui/xmlsource/xmlsourcedlg.cxx     |  128 +++++++++++++++++++++++++---
 8 files changed, 237 insertions(+), 21 deletions(-)

New commits:
commit fce1dd3c1707fe722c5a82db864c967c9390cea2
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 fa25861e163fed7b64b93691ce103067912d3c01
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 f53535d9d45da4caa3cd2f37f2d3b2ce7aea3a5a
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 54170a0d7bf42d87980b18f9b6e5479126b21a28
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: */


More information about the Libreoffice-commits mailing list