diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-11-29 23:40:48 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-11-29 23:42:21 -0500 |
commit | 949a4e15de7560f72481f2ff90f9f3b3571a8e90 (patch) | |
tree | 535386cbba7a540b871c8958d537f2e791fc59c8 | |
parent | dabd8121433bf7c363ba9cb99357e5b84e69db91 (diff) |
Selecting a child entry of a recurring element should select all sub-tree.
And use the parent element entry to set the mapped cell position.
Change-Id: I1def045000e707903dcc91ab46da3c66195506da
-rw-r--r-- | sc/source/ui/inc/xmlsourcedlg.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/xmlsource/xmlsourcedlg.cxx | 68 |
2 files changed, 57 insertions, 13 deletions
diff --git a/sc/source/ui/inc/xmlsourcedlg.hxx b/sc/source/ui/inc/xmlsourcedlg.hxx index 1914df1c00e7..95f379e3c9ba 100644 --- a/sc/source/ui/inc/xmlsourcedlg.hxx +++ b/sc/source/ui/inc/xmlsourcedlg.hxx @@ -57,7 +57,7 @@ class ScXMLSourceDlg : public ScAnyRefDlg std::set<const SvTreeListEntry*> maCellLinks; std::set<const SvTreeListEntry*> maRangeLinks; std::vector<SvTreeListEntry*> maHighlightedEntries; - + SvTreeListEntry* mpCurRefEntry; boost::scoped_ptr<ScOrcusXMLContext> mpXMLContext; ScDocument* mpDoc; diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx index 3a153108abe6..c60cc1d65a47 100644 --- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx +++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx @@ -83,6 +83,7 @@ ScXMLSourceDlg::ScXMLSourceDlg( maBtnOk(this, ScResId(BTN_OK)), maBtnCancel(this, ScResId(BTN_CANCEL)), maImgFileOpen(ScResId(IMG_FILE_OPEN)), + mpCurRefEntry(NULL), mpDoc(pDoc), mpActiveEdit(&maRefEdit), mbDlgLostFocus(false) @@ -256,6 +257,37 @@ public: } }; +/** + * When the current entry is a direct or indirect child of a mappable + * repeat element entry, that entry becomes the reference entry. + * Otherwise the reference entry equals the current entry. A reference + * entry is the entry that stores mapped cell position. + */ +SvTreeListEntry* getReferenceEntry(SvTreeListBox& rTree, SvTreeListEntry* pCurEntry) +{ + SvTreeListEntry* pParent = rTree.GetParent(pCurEntry); + SvTreeListEntry* pRefEntry = NULL; + while (pParent) + { + ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pParent); + OSL_ASSERT(pUserData); + if (pUserData->meType == ScOrcusXMLTreeParam::ElementRepeat) + { + // This is a repeat element. + if (pRefEntry) + { + // Second repeat element encountered. Not good. + return pCurEntry; + } + + pRefEntry = pParent; + } + pParent = rTree.GetParent(pParent); + } + + return pRefEntry ? pRefEntry : pCurEntry; +} + } void ScXMLSourceDlg::TreeItemSelected() @@ -271,7 +303,20 @@ void ScXMLSourceDlg::TreeItemSelected() maHighlightedEntries.clear(); } - ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pEntry); + mpCurRefEntry = getReferenceEntry(maLbTree, pEntry); + if (mpCurRefEntry != pEntry) + { + // Highlight the reference entry if it differs from the current entry. + SvViewDataEntry* pView = maLbTree.GetViewDataEntry(mpCurRefEntry); + if (pView) + { + pView->SetHighlighted(true); + maLbTree.PaintEntry(mpCurRefEntry); + maHighlightedEntries.push_back(mpCurRefEntry); + } + } + + ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*mpCurRefEntry); OSL_ASSERT(pUserData); const ScAddress& rPos = pUserData->maLinkedPos; @@ -287,13 +332,13 @@ void ScXMLSourceDlg::TreeItemSelected() switch (pUserData->meType) { case ScOrcusXMLTreeParam::Attribute: - AttributeSelected(*pEntry); + AttributeSelected(*mpCurRefEntry); break; case ScOrcusXMLTreeParam::ElementDefault: - DefaultElementSelected(*pEntry); + DefaultElementSelected(*mpCurRefEntry); break; case ScOrcusXMLTreeParam::ElementRepeat: - RepeatElementSelected(*pEntry); + RepeatElementSelected(*mpCurRefEntry); break; default: ; @@ -599,13 +644,12 @@ void ScXMLSourceDlg::RefEditModified() if (!bValid) aLinkedPos.SetInvalid(); - // Set this address to currently selected tree item. - SvTreeListEntry* pEntry = maLbTree.GetCurEntry(); - if (!pEntry) + // Set this address to the current reference entry. + if (!mpCurRefEntry) // This should never happen. return; - ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*pEntry); + ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(*mpCurRefEntry); if (!pUserData) // This should never happen either. return; @@ -617,16 +661,16 @@ void ScXMLSourceDlg::RefEditModified() if (bRepeatElem) { if (bValid) - maRangeLinks.insert(pEntry); + maRangeLinks.insert(mpCurRefEntry); else - maRangeLinks.erase(pEntry); + maRangeLinks.erase(mpCurRefEntry); } else { if (bValid) - maCellLinks.insert(pEntry); + maCellLinks.insert(mpCurRefEntry); else - maCellLinks.erase(pEntry); + maCellLinks.erase(mpCurRefEntry); } // Enable the import button only when at least one link exists. |