diff options
-rw-r--r-- | sc/inc/orcusfilters.hxx | 4 | ||||
-rw-r--r-- | sc/inc/orcusxml.hxx | 22 | ||||
-rw-r--r-- | sc/source/core/tool/orcusxml.cxx | 8 | ||||
-rw-r--r-- | sc/source/filter/inc/orcusfiltersimpl.hxx | 3 | ||||
-rw-r--r-- | sc/source/filter/orcus/orcusfiltersimpl.cxx | 6 | ||||
-rw-r--r-- | sc/source/ui/inc/xmlsourcedlg.hxx | 5 | ||||
-rw-r--r-- | sc/source/ui/src/xmlsourcedlg.src | 3 | ||||
-rw-r--r-- | sc/source/ui/xmlsource/xmlsourcedlg.cxx | 129 |
8 files changed, 166 insertions, 14 deletions
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx index 019441cc954e..1b94f67bed40 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 a133b783daa7..2baac6959614 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 8d5d91b3f04c..fb74fec14301 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 956e94012b06..f2d270355293 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 0549156848b5..e7a2ef908226 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 058058a7da1e..e16b52a17a6f 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 99d6f5655c40..d90b4981eed5 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 2fd452de8d39..626058905b46 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: */ |