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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Oct 12 14:20:46 PDT 2012


 sc/Library_scfilt.mk                        |    1 
 sc/inc/orcusfilters.hxx                     |    4 +-
 sc/inc/orcusxml.hxx                         |   47 +++++++++++++++++++++++++
 sc/source/filter/inc/orcusfiltersimpl.hxx   |    3 -
 sc/source/filter/orcus/orcusfiltersimpl.cxx |   51 ++++++++++++++++++++--------
 sc/source/filter/orcus/orcusxml.cxx         |   15 ++++++++
 sc/source/ui/inc/xmlsourcedlg.hxx           |    6 +--
 sc/source/ui/xmlsource/xmlsourcedlg.cxx     |   10 ++---
 8 files changed, 112 insertions(+), 25 deletions(-)

New commits:
commit b259bba4637795c52b3d4b3a0201236567057bcc
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Oct 12 17:20:52 2012 -0400

    Set user data to each tree entry.
    
    Change-Id: I708bbbae7696a66f7acae8a8d01c98a3c81d32e8

diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
index 7a5256e..8809028 100644
--- a/sc/Library_scfilt.mk
+++ b/sc/Library_scfilt.mk
@@ -219,6 +219,7 @@ $(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/orcusxml \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx
index 506e822..019441c 100644
--- a/sc/inc/orcusfilters.hxx
+++ b/sc/inc/orcusfilters.hxx
@@ -28,7 +28,7 @@ public:
     virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const = 0;
 
     virtual bool loadXMLStructure(
-       SvTreeListBox& rTreeCtrl, const rtl::OUString& rPath, ScOrcusXMLTreeParam& rParam) const = 0;
+       const rtl::OUString& rPath, SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const = 0;
 };
 
 #endif
diff --git a/sc/inc/orcusxml.hxx b/sc/inc/orcusxml.hxx
index dfb2867..cdc4679 100644
--- a/sc/inc/orcusxml.hxx
+++ b/sc/inc/orcusxml.hxx
@@ -25,6 +25,8 @@ struct ScOrcusXMLTreeParam
     struct TreeEntryUserData
     {
         EntryType meType;
+
+        TreeEntryUserData(EntryType eType);
     };
 
     typedef boost::ptr_vector<TreeEntryUserData> UserDataStoreType;
diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx
index 29562c2..956e940 100644
--- a/sc/source/filter/inc/orcusfiltersimpl.hxx
+++ b/sc/source/filter/inc/orcusfiltersimpl.hxx
@@ -18,7 +18,7 @@ public:
     virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const;
 
     virtual bool loadXMLStructure(
-        SvTreeListBox& rTreeCtrl, const rtl::OUString& rPath, ScOrcusXMLTreeParam& rParam) const;
+        const rtl::OUString& rPath, SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const;
 };
 
 #endif
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 3e9bca0..c5b8711 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -176,6 +176,13 @@ bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, const OUString& rPath) cons
 
 namespace {
 
+void setUserDataToEntry(
+    SvLBoxEntry& rEntry, ScOrcusXMLTreeParam::UserDataStoreType& rStore, ScOrcusXMLTreeParam::EntryType eType)
+{
+    rStore.push_back(new ScOrcusXMLTreeParam::TreeEntryUserData(eType));
+    rEntry.SetUserData(&rStore.back());
+}
+
 void populateTree(
    SvTreeListBox& rTreeCtrl, orcus::xml_structure_tree::walker& rWalker,
    const orcus::xml_structure_tree::entity_name& rElemName, bool bRepeat,
@@ -183,8 +190,17 @@ void populateTree(
 {
     OUString aName(rElemName.name.get(), rElemName.name.size(), RTL_TEXTENCODING_UTF8);
     SvLBoxEntry* pEntry = rTreeCtrl.InsertEntry(aName, pParent);
+    if (!pEntry)
+        // Can this ever happen!?
+        return;
+
+    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);
     }
@@ -194,13 +210,20 @@ void populateTree(
 
     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;
-        SvLBoxEntry* pAttr = rTreeCtrl.InsertEntry(OUString(aAttrName.name.get(), aAttrName.name.size(), RTL_TEXTENCODING_UTF8), pEntry);
+        SvLBoxEntry* 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);
     }
@@ -208,6 +231,7 @@ void populateTree(
 
     rWalker.get_children(aNames);
 
+    // Insert child elements recursively.
     for (it = aNames.begin(), itEnd = aNames.end(); it != itEnd; ++it)
     {
         orcus::xml_structure_tree::element aElem = rWalker.descend(*it);
@@ -234,8 +258,10 @@ public:
 }
 
 bool ScOrcusFiltersImpl::loadXMLStructure(
-   SvTreeListBox& rTreeCtrl, const rtl::OUString& rPath, ScOrcusXMLTreeParam& rParam) const
+   const rtl::OUString& rPath, SvTreeListBox& rTreeCtrl, ScOrcusXMLTreeParam& rParam) const
 {
+    rParam.maUserDataStore.clear();
+
     INetURLObject aURL(rPath);
     OString aSysPath = rtl::OUStringToOString(aURL.getFSysPath(SYSTEM_PATH), RTL_TEXTENCODING_UTF8);
     const char* path = aSysPath.getStr();
diff --git a/sc/source/filter/orcus/orcusxml.cxx b/sc/source/filter/orcus/orcusxml.cxx
new file mode 100644
index 0000000..68746be
--- /dev/null
+++ b/sc/source/filter/orcus/orcusxml.cxx
@@ -0,0 +1,15 @@
+/* -*- 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 "orcusxml.hxx"
+
+ScOrcusXMLTreeParam::TreeEntryUserData::TreeEntryUserData(EntryType eType) :
+    meType(eType) {}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 6c3369a..1b9f213 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -165,7 +165,7 @@ void ScXMLSourceDlg::LoadSourceFileStructure(const OUString& rPath)
     if (!pOrcus)
         return;
 
-    pOrcus->loadXMLStructure(maLbTree, rPath, maXMLParam);
+    pOrcus->loadXMLStructure(rPath, maLbTree, maXMLParam);
 }
 
 void ScXMLSourceDlg::HandleGetFocus(Control* pCtrl)
commit 4e736ba81d1a32a39eec7b78f6f8db9fbc8c7a30
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Oct 12 16:35:27 2012 -0400

    Use param structure to consolidate parameters for loadXMLStructure() call.
    
    Change-Id: I3e5895cd6b2bae4fd18aa13ebf88321f32a95f8d

diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx
index 7db7034..506e822 100644
--- a/sc/inc/orcusfilters.hxx
+++ b/sc/inc/orcusfilters.hxx
@@ -15,6 +15,7 @@
 class ScDocument;
 class SvTreeListBox;
 class Image;
+struct ScOrcusXMLTreeParam;
 
 /**
  * Collection of orcus filter wrappers.
@@ -27,8 +28,7 @@ public:
     virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const = 0;
 
     virtual bool loadXMLStructure(
-       SvTreeListBox& rTreeCtrl, const rtl::OUString& rPath,
-       const Image& rImgDefaultElem, const Image& rImgRepeatElem, const Image& rImgElemAttr) const = 0;
+       SvTreeListBox& rTreeCtrl, const rtl::OUString& rPath, ScOrcusXMLTreeParam& rParam) const = 0;
 };
 
 #endif
diff --git a/sc/inc/orcusxml.hxx b/sc/inc/orcusxml.hxx
new file mode 100644
index 0000000..dfb2867
--- /dev/null
+++ b/sc/inc/orcusxml.hxx
@@ -0,0 +1,45 @@
+/* -*- 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_ORCUSXML_HXX__
+#define __SC_ORCUSXML_HXX__
+
+#include "vcl/image.hxx"
+
+#include <boost/ptr_container/ptr_vector.hpp>
+
+/**
+ * Parameter used during call to ScOrcusFilters::loadXMLStructure().
+ */
+struct ScOrcusXMLTreeParam
+{
+    enum EntryType { ElementDefault, ElementRepeat, Attribute };
+
+    /** Custom data stored with each tree item. */
+    struct TreeEntryUserData
+    {
+        EntryType meType;
+    };
+
+    typedef boost::ptr_vector<TreeEntryUserData> UserDataStoreType;
+
+    Image maImgElementDefault;
+    Image maImgElementRepeat;
+    Image maImgAttribute;
+
+    /**
+     * Store all custom data instances since the tree control doesn't manage
+     * the life cycle of user datas.
+     */
+    UserDataStoreType maUserDataStore;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx
index 2f42d0b..29562c2 100644
--- a/sc/source/filter/inc/orcusfiltersimpl.hxx
+++ b/sc/source/filter/inc/orcusfiltersimpl.hxx
@@ -18,8 +18,7 @@ public:
     virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const;
 
     virtual bool loadXMLStructure(
-       SvTreeListBox& rTreeCtrl, const rtl::OUString& rPath,
-       const Image& rImgDefaultElem, const Image& rImgRepeatElem, const Image& rImgElemAttr) const;
+        SvTreeListBox& rTreeCtrl, const rtl::OUString& rPath, ScOrcusXMLTreeParam& rParam) const;
 };
 
 #endif
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 8d8705c..3e9bca0 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -10,6 +10,7 @@
 #include "orcusfiltersimpl.hxx"
 
 #include "document.hxx"
+#include "orcusxml.hxx"
 
 #include "tools/urlobj.hxx"
 #include "svtools/treelistbox.hxx"
@@ -178,15 +179,14 @@ namespace {
 void populateTree(
    SvTreeListBox& rTreeCtrl, orcus::xml_structure_tree::walker& rWalker,
    const orcus::xml_structure_tree::entity_name& rElemName, bool bRepeat,
-   const Image& rImgRepeatElem, const Image& rImgElemAttr,
-   SvLBoxEntry* pParent)
+   SvLBoxEntry* pParent, ScOrcusXMLTreeParam& rParam)
 {
     OUString aName(rElemName.name.get(), rElemName.name.size(), RTL_TEXTENCODING_UTF8);
     SvLBoxEntry* pEntry = rTreeCtrl.InsertEntry(aName, pParent);
     if (bRepeat)
     {
-        rTreeCtrl.SetExpandedEntryBmp(pEntry, rImgRepeatElem);
-        rTreeCtrl.SetCollapsedEntryBmp(pEntry, rImgRepeatElem);
+        rTreeCtrl.SetExpandedEntryBmp(pEntry, rParam.maImgElementRepeat);
+        rTreeCtrl.SetCollapsedEntryBmp(pEntry, rParam.maImgElementRepeat);
     }
 
     if (pParent)
@@ -201,8 +201,8 @@ void populateTree(
     {
         orcus::xml_structure_tree::entity_name aAttrName = *it;
         SvLBoxEntry* pAttr = rTreeCtrl.InsertEntry(OUString(aAttrName.name.get(), aAttrName.name.size(), RTL_TEXTENCODING_UTF8), pEntry);
-        rTreeCtrl.SetExpandedEntryBmp(pAttr, rImgElemAttr);
-        rTreeCtrl.SetCollapsedEntryBmp(pAttr, rImgElemAttr);
+        rTreeCtrl.SetExpandedEntryBmp(pAttr, rParam.maImgAttribute);
+        rTreeCtrl.SetCollapsedEntryBmp(pAttr, rParam.maImgAttribute);
     }
     rTreeCtrl.Expand(pEntry);
 
@@ -211,7 +211,7 @@ void populateTree(
     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, rImgRepeatElem, rImgElemAttr, pEntry);
+        populateTree(rTreeCtrl, rWalker, *it, aElem.repeat, pEntry, rParam);
         rWalker.ascend();
     }
 }
@@ -234,8 +234,7 @@ public:
 }
 
 bool ScOrcusFiltersImpl::loadXMLStructure(
-   SvTreeListBox& rTreeCtrl, const rtl::OUString& rPath,
-   const Image& rImgDefaultElem, const Image& rImgRepeatElem, const Image& rImgElemAttr) const
+   SvTreeListBox& rTreeCtrl, const rtl::OUString& rPath, ScOrcusXMLTreeParam& rParam) const
 {
     INetURLObject aURL(rPath);
     OString aSysPath = rtl::OUStringToOString(aURL.getFSysPath(SYSTEM_PATH), RTL_TEXTENCODING_UTF8);
@@ -256,14 +255,14 @@ bool ScOrcusFiltersImpl::loadXMLStructure(
 
         TreeUpdateSwitch aSwitch(rTreeCtrl);
         rTreeCtrl.Clear();
-        rTreeCtrl.SetDefaultCollapsedEntryBmp(rImgDefaultElem);
-        rTreeCtrl.SetDefaultExpandedEntryBmp(rImgDefaultElem);
+        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, rImgRepeatElem, rImgElemAttr, NULL);
+        populateTree(rTreeCtrl, aWalker, aElem.name, aElem.repeat, NULL, rParam);
     }
     catch (const std::exception&)
     {
diff --git a/sc/source/ui/inc/xmlsourcedlg.hxx b/sc/source/ui/inc/xmlsourcedlg.hxx
index 28e39c3..75d698f 100644
--- a/sc/source/ui/inc/xmlsourcedlg.hxx
+++ b/sc/source/ui/inc/xmlsourcedlg.hxx
@@ -16,6 +16,7 @@
 
 #include "expftext.hxx"
 #include "anyrefdg.hxx"
+#include "orcusxml.hxx"
 
 #include <boost/scoped_ptr.hpp>
 
@@ -45,15 +46,14 @@ class ScXMLSourceDlg : public ScAnyRefDlg
     CancelButton maBtnCancel;
 
     Image maImgFileOpen;
-    Image maImgElemDefault;
-    Image maImgElemRepeat;
-    Image maImgElemAttribute;
 
     rtl::OUString maStrCellLink;
     rtl::OUString maStrRangeLink;
 
     rtl::OUString maSrcPath;
 
+    ScOrcusXMLTreeParam maXMLParam;
+
     ScDocument* mpDoc;
 
     formula::RefEdit* mpActiveEdit;
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 5f244f2..6c3369a 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -42,15 +42,16 @@ ScXMLSourceDlg::ScXMLSourceDlg(
     maLbTree(this, ScResId(LB_SOURCE_TREE)),
     maBtnCancel(this, ScResId(BTN_CANCEL)),
     maImgFileOpen(ScResId(IMG_FILE_OPEN)),
-    maImgElemDefault(ScResId(IMG_ELEMENT_DEFAULT)),
-    maImgElemRepeat(ScResId(IMG_ELEMENT_REPEAT)),
-    maImgElemAttribute(ScResId(IMG_ELEMENT_ATTRIBUTE)),
     maStrCellLink(ScResId(STR_CELL_LINK).toString()),
     maStrRangeLink(ScResId(STR_RANGE_LINK).toString()),
     mpDoc(pDoc),
     mpActiveEdit(&maEdit),
     mbDlgLostFocus(false)
 {
+    maXMLParam.maImgElementDefault = Image(ScResId(IMG_ELEMENT_DEFAULT));
+    maXMLParam.maImgElementRepeat = Image(ScResId(IMG_ELEMENT_REPEAT));
+    maXMLParam.maImgAttribute = Image(ScResId(IMG_ELEMENT_ATTRIBUTE));
+
     maBtnSelectSource.SetModeImage(maImgFileOpen);
     FreeResource();
 
@@ -164,8 +165,7 @@ void ScXMLSourceDlg::LoadSourceFileStructure(const OUString& rPath)
     if (!pOrcus)
         return;
 
-    pOrcus->loadXMLStructure(
-        maLbTree, rPath, maImgElemDefault, maImgElemRepeat, maImgElemAttribute);
+    pOrcus->loadXMLStructure(maLbTree, rPath, maXMLParam);
 }
 
 void ScXMLSourceDlg::HandleGetFocus(Control* pCtrl)


More information about the Libreoffice-commits mailing list