diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-10-12 23:08:53 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-11-28 13:28:26 -0500 |
commit | 4f0516315c35882ef09fe3f44c3f2f5a7f12dc8d (patch) | |
tree | f9c5651ce57b68fd97079f2aff38fdc35c45497c /sc | |
parent | cc635c24f3f5ab761cd640bacc5ae12adc4d0846 (diff) |
Take care of the default element and attribute selection handlers.
Change-Id: I87aec99679f8beca2be82d6d7df275917ba66d62
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/orcusxml.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/tool/orcusxml.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/xmlsourcedlg.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/xmlsource/xmlsourcedlg.cxx | 73 |
4 files changed, 71 insertions, 7 deletions
diff --git a/sc/inc/orcusxml.hxx b/sc/inc/orcusxml.hxx index 4fa223e5b596..2c4b07b0a4cc 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 c5e0ac124b10..068fddfcb59c 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 c6a5008d1a62..c3953e4d2d78 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 561f98d8f410..e75f1f6e7278 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); |