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

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


 sc/inc/orcusxml.hxx                     |    1 
 sc/source/core/tool/orcusxml.cxx        |    2 
 sc/source/ui/inc/xmlsourcedlg.hxx       |    9 ++
 sc/source/ui/xmlsource/xmlsourcedlg.cxx |  128 +++++++++++++++++++++++++++++---
 4 files changed, 128 insertions(+), 12 deletions(-)

New commits:
commit ada462b976afcf8427b2fc546e67c89c389a6b84
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Oct 12 23:42:27 2012 -0400

    Handle selection of repeat element.
    
    Change-Id: I73eb83fbbd6deb39ba3e736410b8d5b50f3dffaa

diff --git a/sc/source/ui/inc/xmlsourcedlg.hxx b/sc/source/ui/inc/xmlsourcedlg.hxx
index 6f20942..0f8f0cb 100644
--- a/sc/source/ui/inc/xmlsourcedlg.hxx
+++ b/sc/source/ui/inc/xmlsourcedlg.hxx
@@ -83,10 +83,14 @@ private:
     void SetRangeLinkable();
 
     /**
-     * Check if any of its parents is linked or repeated.
+     * Check if any of its parents is linked or repeated.  The passed entry is
+     * not checked; its parent is the first one to be checked, then all its
+     * parents get checked all the way to the root.
      */
     bool IsParentDirty(SvLBoxEntry* pEntry) const;
 
+    bool IsChildrenDirty(SvLBoxEntry* pEntry) const;
+
     DECL_LINK(GetFocusHdl, Control*);
     DECL_LINK(LoseFocusHdl, Control*);
     DECL_LINK(BtnPressedHdl, Button*);
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 75cba63..e6f39e3 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -267,12 +267,26 @@ void ScXMLSourceDlg::DefaultElementSelected(SvLBoxEntry& rEntry)
 
 void ScXMLSourceDlg::RepeatElementSelected(SvLBoxEntry& rEntry)
 {
-    // TODO: Check all its child elements / attributes and make sure non of
-    // them are linked or repeat elements.  In the future we will support
-    // range linking of repeat element who has another repeat elements. But
-    // first I need to support that in orcus.
+    // Check all its parents first.
 
-    SetNonLinkable();
+    if (IsParentDirty(&rEntry))
+    {
+        SetNonLinkable();
+        return;
+    }
+
+    // Check all its child elements / attributes and make sure non of them are
+    // linked or repeat elements.  In the future we will support range linking
+    // of repeat element who has another repeat elements. But first I need to
+    // support that scenario in orcus.
+
+    if (IsChildrenDirty(&rEntry))
+    {
+        SetNonLinkable();
+        return;
+    }
+
+    SetRangeLinkable();
 }
 
 void ScXMLSourceDlg::AttributeSelected(SvLBoxEntry& rEntry)
@@ -346,6 +360,32 @@ bool ScXMLSourceDlg::IsParentDirty(SvLBoxEntry* pEntry) const
     return false;
 }
 
+bool ScXMLSourceDlg::IsChildrenDirty(SvLBoxEntry* pEntry) const
+{
+    ScOrcusXMLTreeParam::EntryData* pUserData = NULL;
+    for (SvLBoxEntry* pChild = maLbTree.FirstChild(pEntry); pChild; pChild = maLbTree.NextSibling(pChild))
+    {
+        pUserData = ScOrcusXMLTreeParam::getUserData(*pChild);
+        OSL_ASSERT(pUserData);
+        if (pUserData->maLinkedPos.IsValid())
+            // Already linked.
+            return true;
+
+        if (pUserData->meType == ScOrcusXMLTreeParam::ElementRepeat)
+            // We don't support linking of nested repeat elements (yet).
+            return true;
+
+        if (pUserData->meType == ScOrcusXMLTreeParam::ElementDefault)
+        {
+            // Check recursively.
+            if (IsChildrenDirty(pChild))
+                return true;
+        }
+    }
+
+    return false;
+}
+
 IMPL_LINK(ScXMLSourceDlg, GetFocusHdl, Control*, pCtrl)
 {
     HandleGetFocus(pCtrl);
commit 259a08ae77b24c8805ff023813f2f36394baee12
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Oct 12 23:12:52 2012 -0400

    I need to check for repeating parent elements too.
    
    Change-Id: I52e87c93e6f3d0108cf517c33f605490dd9a1fc4

diff --git a/sc/source/ui/inc/xmlsourcedlg.hxx b/sc/source/ui/inc/xmlsourcedlg.hxx
index c3953e4..6f20942 100644
--- a/sc/source/ui/inc/xmlsourcedlg.hxx
+++ b/sc/source/ui/inc/xmlsourcedlg.hxx
@@ -82,6 +82,9 @@ private:
     void SetSingleLinkable();
     void SetRangeLinkable();
 
+    /**
+     * Check if any of its parents is linked or repeated.
+     */
     bool IsParentDirty(SvLBoxEntry* pEntry) const;
 
     DECL_LINK(GetFocusHdl, Control*);
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index e75f1f6..75cba63 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -336,6 +336,11 @@ bool ScXMLSourceDlg::IsParentDirty(SvLBoxEntry* pEntry) const
             // This parent is already linked.
             return true;
         }
+        if (pUserData->meType == ScOrcusXMLTreeParam::ElementRepeat)
+        {
+            // This is a repeat element.
+            return true;
+        }
         pParent = maLbTree.GetParent(pParent);
     }
     return false;
commit 19821e5fd3276efba310ea772629fc5c13abe733
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Oct 12 23:08:53 2012 -0400

    Take care of the default element and attribute selection handlers.
    
    Change-Id: I87aec99679f8beca2be82d6d7df275917ba66d62

diff --git a/sc/inc/orcusxml.hxx b/sc/inc/orcusxml.hxx
index 4fa223e..2c4b07b 100644
--- a/sc/inc/orcusxml.hxx
+++ b/sc/inc/orcusxml.hxx
@@ -30,6 +30,7 @@ struct ScOrcusXMLTreeParam
     {
         EntryType meType;
         ScAddress maLinkedPos; /// linked cell position (invalid if unlinked)
+        bool mbRangeParent;
 
         SC_DLLPUBLIC EntryData(EntryType eType);
     };
diff --git a/sc/source/core/tool/orcusxml.cxx b/sc/source/core/tool/orcusxml.cxx
index c5e0ac1..068fddf 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) {}
+    meType(eType), maLinkedPos(ScAddress::INITIALIZE_INVALID), mbRangeParent(false) {}
 
 ScOrcusXMLTreeParam::EntryData* ScOrcusXMLTreeParam::getUserData(SvLBoxEntry& rEntry)
 {
diff --git a/sc/source/ui/inc/xmlsourcedlg.hxx b/sc/source/ui/inc/xmlsourcedlg.hxx
index c6a5008..c3953e4 100644
--- a/sc/source/ui/inc/xmlsourcedlg.hxx
+++ b/sc/source/ui/inc/xmlsourcedlg.hxx
@@ -82,6 +82,8 @@ private:
     void SetSingleLinkable();
     void SetRangeLinkable();
 
+    bool IsParentDirty(SvLBoxEntry* pEntry) const;
+
     DECL_LINK(GetFocusHdl, Control*);
     DECL_LINK(LoseFocusHdl, Control*);
     DECL_LINK(BtnPressedHdl, Button*);
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 561f98d..e75f1f6 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -199,8 +199,7 @@ void ScXMLSourceDlg::TreeItemSelected()
         return;
 
     ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pEntry);
-    if (!pUserData)
-        return;
+    OSL_ASSERT(pUserData);
 
     const ScAddress& rPos = pUserData->maLinkedPos;
     if (rPos.IsValid())
@@ -230,15 +229,39 @@ void ScXMLSourceDlg::TreeItemSelected()
 
 void ScXMLSourceDlg::DefaultElementSelected(SvLBoxEntry& rEntry)
 {
+    ScOrcusXMLTreeParam::EntryData* pUserData = NULL;
+
     if (maLbTree.GetChildCount(&rEntry) > 0)
     {
         // Only an element with no child elements (leaf element) can be linked.
+        bool bHasChild = false;
+        for (SvLBoxEntry* pChild = maLbTree.FirstChild(&rEntry); pChild; pChild = maLbTree.NextSibling(pChild))
+        {
+            pUserData = ScOrcusXMLTreeParam::getUserData(*pChild);
+            OSL_ASSERT(pUserData);
+            if (pUserData->meType != ScOrcusXMLTreeParam::Attribute)
+            {
+                // This child is not an attribute. Bail out.
+                bHasChild = true;
+                break;
+            }
+        }
+
+        if (bHasChild)
+        {
+            SetNonLinkable();
+            return;
+        }
+    }
+
+    // Check all its parents and make sure non of them are range-linked nor
+    // repeat elements.
+    if (IsParentDirty(&rEntry))
+    {
         SetNonLinkable();
         return;
     }
 
-    // TODO: Check all its parents and make sure non of them are range-linked
-    // nor repeat elements.
     SetSingleLinkable();
 }
 
@@ -254,8 +277,28 @@ void ScXMLSourceDlg::RepeatElementSelected(SvLBoxEntry& rEntry)
 
 void ScXMLSourceDlg::AttributeSelected(SvLBoxEntry& rEntry)
 {
-    // TODO: Check all its parent elements and make sure non of them are
-    // range-linked nor repeat elements.
+    // Check all its parent elements and make sure non of them are linked nor
+    // repeat elements.  In attribute's case, it's okay to have the immediate
+    // parent element linked (but not range-linked).
+
+    SvLBoxEntry* pParent = maLbTree.GetParent(&rEntry);
+    OSL_ASSERT(pParent); // attribute should have a parent element.
+
+    ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pParent);
+    OSL_ASSERT(pUserData);
+    if (pUserData->maLinkedPos.IsValid() && pUserData->mbRangeParent)
+    {
+        // Parent element is range-linked.  Bail out.
+        SetNonLinkable();
+        return;
+    }
+
+    if (IsParentDirty(pParent))
+    {
+        SetNonLinkable();
+        return;
+    }
+
     SetSingleLinkable();
 }
 
@@ -280,6 +323,24 @@ void ScXMLSourceDlg::SetRangeLinkable()
     maRefBtn.Enable();
 }
 
+bool ScXMLSourceDlg::IsParentDirty(SvLBoxEntry* pEntry) const
+{
+    ScOrcusXMLTreeParam::EntryData* pUserData = NULL;
+    SvLBoxEntry* pParent = maLbTree.GetParent(pEntry);
+    while (pParent)
+    {
+        pUserData = ScOrcusXMLTreeParam::getUserData(*pParent);
+        OSL_ASSERT(pUserData);
+        if (pUserData->maLinkedPos.IsValid())
+        {
+            // This parent is already linked.
+            return true;
+        }
+        pParent = maLbTree.GetParent(pParent);
+    }
+    return false;
+}
+
 IMPL_LINK(ScXMLSourceDlg, GetFocusHdl, Control*, pCtrl)
 {
     HandleGetFocus(pCtrl);


More information about the Libreoffice-commits mailing list